Aarch64 jit compiler wip: suppport floating-point arguments
This commit is contained in:
parent
428283dbf8
commit
c9f4a9c19d
3 changed files with 26 additions and 13 deletions
|
|
@ -172,8 +172,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 = (float(*)())(module.code.memory.data.get() + offset);
|
auto fptr = (float(*)(float))(module.code.memory.data.get() + offset);
|
||||||
auto x = fptr();
|
auto x = fptr(6.f);
|
||||||
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
std::cout << "Result: " << std::boolalpha << x << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,2 @@
|
||||||
func test() -> f32:
|
func test(x : f32) -> f32:
|
||||||
if 0.0 >= 1.0:
|
return x * 1.5
|
||||||
return 3.1415
|
|
||||||
return 2.71828
|
|
||||||
|
|
|
||||||
|
|
@ -634,18 +634,33 @@ namespace pslang::jit::aarch64
|
||||||
{
|
{
|
||||||
// TODO: floating-point / struct arguments
|
// TODO: floating-point / struct arguments
|
||||||
scopes.emplace_back();
|
scopes.emplace_back();
|
||||||
for (std::size_t i = 0; i < node.arguments.size(); ++i)
|
|
||||||
|
std::uint8_t reg = 0;
|
||||||
|
std::uint8_t fp_reg = 0;
|
||||||
|
|
||||||
|
for (auto const & argument : node.arguments)
|
||||||
{
|
{
|
||||||
auto type = ast::get_type(*node.arguments[i].type);
|
auto type = ast::get_type(*argument.type);
|
||||||
if (types::is_bool_type(*type))
|
if (types::is_bool_type(*type))
|
||||||
{
|
{
|
||||||
builder.tst(i, i);
|
builder.tst(reg, reg);
|
||||||
builder.csetm(i, 0b0001);
|
builder.csetm(reg, 0b0001);
|
||||||
|
push(reg);
|
||||||
|
++reg;
|
||||||
}
|
}
|
||||||
else if (types::is_integer_type(*type))
|
else if (types::is_integer_type(*type))
|
||||||
extend(i, type);
|
{
|
||||||
push(i);
|
extend(reg, type);
|
||||||
scopes.back().variables[node.arguments[i].name] = {.frame_offset = stack_offset};
|
push(reg);
|
||||||
|
++reg;
|
||||||
|
}
|
||||||
|
else if (types::is_floating_point_type(*type))
|
||||||
|
{
|
||||||
|
auto mode = fp_mode_for(*type);
|
||||||
|
push_fp(fp_reg, mode);
|
||||||
|
++fp_reg;
|
||||||
|
}
|
||||||
|
scopes.back().variables[argument.name] = {.frame_offset = stack_offset};
|
||||||
}
|
}
|
||||||
apply(*node.statements);
|
apply(*node.statements);
|
||||||
scopes.pop_back();
|
scopes.pop_back();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue