Aarch64 compiler wip: support function arguments (integers only)
This commit is contained in:
parent
43f2d4531a
commit
7ed008543c
3 changed files with 13 additions and 10 deletions
|
|
@ -170,8 +170,8 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
// TODO: remove, testing-only code; should execute entry point instead
|
// TODO: remove, testing-only code; should execute entry point instead
|
||||||
auto offset = module.code.symbol_table.at("test");
|
auto offset = module.code.symbol_table.at("test");
|
||||||
auto fptr = (int(*)())(module.code.memory.data.get() + offset);
|
auto fptr = (int(*)(int))(module.code.memory.data.get() + offset);
|
||||||
auto x = fptr();
|
auto x = fptr(42);
|
||||||
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,2 @@
|
||||||
func test() -> i32:
|
func test(x : i32) -> i32:
|
||||||
let x = 42 + 69
|
return x * x
|
||||||
mut y = (x * 2) / 3
|
|
||||||
y = y + 13
|
|
||||||
return x - y
|
|
||||||
|
|
|
||||||
|
|
@ -345,17 +345,23 @@ namespace pslang::jit::aarch64
|
||||||
|
|
||||||
void apply(ast::statement_list const & node)
|
void apply(ast::statement_list const & node)
|
||||||
{
|
{
|
||||||
scopes.emplace_back();
|
|
||||||
for (auto const & statement : node.statements)
|
for (auto const & statement : node.statements)
|
||||||
apply(*statement);
|
apply(*statement);
|
||||||
builder.add_imm(31, 31, scopes.back().stack_offset);
|
builder.add_imm(31, 31, scopes.back().stack_offset);
|
||||||
scopes.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_apply(ast::function_definition const & node)
|
void do_apply(ast::function_definition const & node)
|
||||||
{
|
{
|
||||||
// TODO: arguments
|
// TODO: floating-point / struct arguments
|
||||||
|
scopes.emplace_back();
|
||||||
|
for (std::size_t i = 0; i < node.arguments.size(); ++i)
|
||||||
|
{
|
||||||
|
extend(i, ast::get_type(*node.arguments[i].type));
|
||||||
|
push(i);
|
||||||
|
scopes.back().variables[node.arguments[i].name] = {.frame_offset = stack_offset};
|
||||||
|
}
|
||||||
apply(*node.statements);
|
apply(*node.statements);
|
||||||
|
scopes.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue