Don't relax function calls
This commit is contained in:
parent
159a3a4f38
commit
9c7614dd25
8
TODO
8
TODO
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- Catch exceptions thrown by the argument parser and print them normally.
|
- Catch exceptions thrown by the argument parser and print them normally.
|
||||||
- Structs or records.
|
- Structs or records.
|
||||||
|
- Unions.
|
||||||
- While loop.
|
- While loop.
|
||||||
- Type checking.
|
- Type checking.
|
||||||
- Calculate additional stack space needed for subexpressions in the allocator
|
- Calculate additional stack space needed for subexpressions in the allocator
|
||||||
@ -9,8 +10,9 @@
|
|||||||
- Support immediates greater than 12 bits.
|
- Support immediates greater than 12 bits.
|
||||||
- It seems instructions are correctly encoded only if the compiler is running
|
- It seems instructions are correctly encoded only if the compiler is running
|
||||||
on a little endian architecture.
|
on a little endian architecture.
|
||||||
- Pointer.
|
- Assignment to a pointer.
|
||||||
- Static array.
|
- Static array.
|
||||||
|
- Syscalls.
|
||||||
|
|
||||||
# Shell
|
# Shell
|
||||||
- Persist the history.
|
- Persist the history.
|
||||||
@ -24,7 +26,3 @@
|
|||||||
- Send the word under the cursor to fzf as initial input.
|
- Send the word under the cursor to fzf as initial input.
|
||||||
- Home directory expansion.
|
- Home directory expansion.
|
||||||
- Show files in the PATH if starting at the beginning of the prompt
|
- 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.
|
|
||||||
|
@ -280,7 +280,7 @@ namespace elna::riscv
|
|||||||
instructions.push_back(instruction(base_opcode::branch));
|
instructions.push_back(instruction(base_opcode::branch));
|
||||||
statement->body().accept(this);
|
statement->body().accept(this);
|
||||||
instructions[before_branch]
|
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)
|
void visitor::visit(source::while_statement *statement)
|
||||||
@ -400,13 +400,24 @@ namespace elna::riscv
|
|||||||
|
|
||||||
void visitor::visit(source::unary_expression *expression)
|
void visitor::visit(source::unary_expression *expression)
|
||||||
{
|
{
|
||||||
const auto free_register = this->register_in_use ? x_register::a0 : x_register::t0;
|
switch (expression->operation())
|
||||||
auto operand_identifier = dynamic_cast<source::variable_expression&>(expression->operand()).name();
|
{
|
||||||
auto variable_symbol =
|
case source::unary_operator::dereference:
|
||||||
std::dynamic_pointer_cast<source::variable_info>(this->table->lookup(operand_identifier));
|
expression->operand().accept(this);
|
||||||
|
|
||||||
this->instructions.push_back(instruction(base_opcode::opImm)
|
this->instructions.push_back(instruction(base_opcode::load)
|
||||||
.i(free_register, funct3_t::addi, x_register::s0, variable_symbol->offset));
|
.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 =
|
||||||
|
std::dynamic_pointer_cast<source::variable_info>(this->table->lookup(operand_identifier));
|
||||||
|
|
||||||
|
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)
|
void visitor::visit(source::integer_literal *number)
|
||||||
|
@ -211,15 +211,15 @@ namespace elna::riscv
|
|||||||
{
|
{
|
||||||
case address_t::high20:
|
case address_t::high20:
|
||||||
rela.add_entry(reference.offset, relocated_symbol, 26 /* ELFIO::R_RISCV_HI20 */);
|
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;
|
break;
|
||||||
case address_t::lower12i:
|
case address_t::lower12i:
|
||||||
rela.add_entry(reference.offset, relocated_symbol, 27 /* ELFIO::R_RISCV_LO12_I */);
|
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;
|
break;
|
||||||
case address_t::text:
|
case address_t::text:
|
||||||
rela.add_entry(reference.offset, relocated_symbol, 18 /* ELFIO::R_RISCV_CALL */);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,6 +375,11 @@ namespace elna::source
|
|||||||
return *m_operand;
|
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)
|
call_statement::call_statement(const struct position position, const std::string& name)
|
||||||
: statement(position), m_name(name)
|
: statement(position), m_name(name)
|
||||||
{
|
{
|
||||||
|
@ -1 +1,2 @@
|
|||||||
8
|
8
|
||||||
|
9
|
||||||
|
1
tests/expectations/pointer_in_expression.txt
Normal file
1
tests/expectations/pointer_in_expression.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
5
|
5
tests/expectations/print_in_loop.txt
Normal file
5
tests/expectations/print_in_loop.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
@ -5,5 +5,7 @@ begin
|
|||||||
writei(5);
|
writei(5);
|
||||||
writei(5);
|
writei(5);
|
||||||
writei(5)
|
writei(5)
|
||||||
end
|
end;
|
||||||
|
if 1 < 2 then writei(9);
|
||||||
|
if 1 > 2 then writei(10)
|
||||||
end.
|
end.
|
||||||
|
6
tests/pointer_in_expression.eln
Normal file
6
tests/pointer_in_expression.eln
Normal 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
10
tests/print_in_loop.eln
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
var i: Int;
|
||||||
|
begin
|
||||||
|
i := 1;
|
||||||
|
|
||||||
|
while i <= 6 do
|
||||||
|
begin
|
||||||
|
writei(i);
|
||||||
|
i := i + 1
|
||||||
|
end;
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user