Don't relax function calls

This commit is contained in:
Eugen Wissner 2024-04-12 00:07:46 +02:00
parent 159a3a4f38
commit 9c7614dd25
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
10 changed files with 55 additions and 16 deletions

8
TODO
View File

@ -2,6 +2,7 @@
- Catch exceptions thrown by the argument parser and print them normally.
- Structs or records.
- Unions.
- While loop.
- Type checking.
- Calculate additional stack space needed for subexpressions in the allocator
@ -9,8 +10,9 @@
- Support immediates greater than 12 bits.
- It seems instructions are correctly encoded only if the compiler is running
on a little endian architecture.
- Pointer.
- Assignment to a pointer.
- Static array.
- Syscalls.
# Shell
- Persist the history.
@ -24,7 +26,3 @@
- Send the word under the cursor to fzf as initial input.
- Home directory expansion.
- Show files in the PATH if starting at the beginning of the prompt
## Appearance
- Add a bar with additional information under the prompt (edit_bar), like the hostname.

View File

@ -280,7 +280,7 @@ namespace elna::riscv
instructions.push_back(instruction(base_opcode::branch));
statement->body().accept(this);
instructions[before_branch]
.b((instructions.size() - before_branch) * 4 - 4, funct3_t::beq, x_register::zero, free_register);
.b((instructions.size() - before_branch) * 4, funct3_t::beq, x_register::zero, free_register);
}
void visitor::visit(source::while_statement *statement)
@ -400,6 +400,15 @@ namespace elna::riscv
void visitor::visit(source::unary_expression *expression)
{
switch (expression->operation())
{
case source::unary_operator::dereference:
expression->operand().accept(this);
this->instructions.push_back(instruction(base_opcode::load)
.i(x_register::a0, funct3_t::lw, x_register::a0, 0));
break;
case source::unary_operator::reference:
const auto free_register = this->register_in_use ? x_register::a0 : x_register::t0;
auto operand_identifier = dynamic_cast<source::variable_expression&>(expression->operand()).name();
auto variable_symbol =
@ -407,6 +416,8 @@ namespace elna::riscv
this->instructions.push_back(instruction(base_opcode::opImm)
.i(free_register, funct3_t::addi, x_register::s0, variable_symbol->offset));
break;
}
}
void visitor::visit(source::integer_literal *number)

View File

@ -211,15 +211,15 @@ namespace elna::riscv
{
case address_t::high20:
rela.add_entry(reference.offset, relocated_symbol, 26 /* ELFIO::R_RISCV_HI20 */);
rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
// rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
break;
case address_t::lower12i:
rela.add_entry(reference.offset, relocated_symbol, 27 /* ELFIO::R_RISCV_LO12_I */);
rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
// rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
break;
case address_t::text:
rela.add_entry(reference.offset, relocated_symbol, 18 /* ELFIO::R_RISCV_CALL */);
rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
// rela.add_entry(reference.offset, relocated_symbol, 51 /* ELFIO::R_RISCV_RELAX */);
break;
}
}

View File

@ -375,6 +375,11 @@ namespace elna::source
return *m_operand;
}
unary_operator unary_expression::operation() const noexcept
{
return this->m_operator;
}
call_statement::call_statement(const struct position position, const std::string& name)
: statement(position), m_name(name)
{

View File

@ -1 +1,2 @@
8
9

View File

@ -0,0 +1 @@
5

View File

@ -0,0 +1,5 @@
1
2
3
4
5

View File

@ -5,5 +5,7 @@ begin
writei(5);
writei(5);
writei(5)
end
end;
if 1 < 2 then writei(9);
if 1 > 2 then writei(10)
end.

View File

@ -0,0 +1,6 @@
var a: Int, b: ^Int;
begin
a := 5;
b := @a;
writei(b^)
end.

10
tests/print_in_loop.eln Normal file
View File

@ -0,0 +1,10 @@
var i: Int;
begin
i := 1;
while i <= 6 do
begin
writei(i);
i := i + 1
end;
end.