Skip to content

Instantly share code, notes, and snippets.

@halfdan
Created December 23, 2011 17:21
Show Gist options
  • Save halfdan/1514831 to your computer and use it in GitHub Desktop.
Save halfdan/1514831 to your computer and use it in GitHub Desktop.
Ninja Compiler - translation into tree language
// Programm
void f(boolean b) {
local integer a1;
local integer a2;
if (b) {
a1 = 2;
a2 = 22;
} else {
a1 = 3;
a2 = 33;
}
}
// Tree
// Angenommen a1 offset -4, a2 offset -8
T_Seq(
T_CJump(T_eq, "b", true,
// true case
T_Seq(
T_Move(T_Mem(FP-4), T_Const(2)),
T_Move(T_Mem(FP-8), T_Const(22))
),
// false case
T_Seq(
T_Move(T_Mem(FP-4), T_Const(3)),
T_Move(T_Mem(FP-8), T_Const(33))
)
),
NULL
)
// Absyn
DecList(
FuncDec(
f,
Ty(void),
DecList(
ParDec(
b,
Ty(boolean))),
DecList(
VarDec(
a1,
Ty(int)),
VarDec(
a2,
Ty(int))),
StmList(
IfStm2(
VarExp(b),
CompStm(
StmList(
AssignStm(
a1,
IntExp(2)),
AssignStm(
a2,
IntExp(22)))),
CompStm(
StmList(
AssignStm(
a1,
IntExp(3)),
AssignStm(
a2,
IntExp(33))))))),
FuncDec(
main,
Ty(void),
DecList(),
DecList(),
StmList()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment