1
1
mirror of https://github.com/anoma/juvix.git synced 2024-09-19 04:27:20 +03:00
juvix/tests/Reg/positive/test010.jvr
Łukasz Czajka cb808c1696
Transform JuvixReg into SSA form (#2646)
* Closes #2560 
* Adds a transformation of JuvixReg into SSA form.
* Adds an "output variable" field to branching instructions (`Case`,
`Branch`) which indicates the output variable to which the result is
assigned in both branches. The output variable corresponds to top of
stack in JuvixAsm after executing the branches. In the SSA
transformation, differently renamed output variables are unified by
inserting assignment instructions at the end of branches.
* Adds tests for the SSA transformation.
* Depends on #2641.
2024-02-20 11:45:14 +01:00

29 lines
503 B
Plaintext

function sum(integer) : integer;
function main() : *;
function sum(integer) : integer {
tmp[0] = arg[0];
tmp[1] = 0;
tmp[0] = eq tmp[1] tmp[0];
br tmp[0], out: tmp[0] {
true: {
tmp[0] = 0;
};
false: {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = sub tmp[1] tmp[0];
tmp[0] = call sum (tmp[0]), live: (arg[0]);
tmp[1] = arg[0];
tmp[0] = add tmp[1] tmp[0];
};
};
ret tmp[0];
}
function main() : * {
tmp[0] = 1000;
tcall sum (tmp[0]);
}