ifs work
This commit is contained in:
@ -548,7 +548,7 @@ int generateIfTrue(Instruction *inst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\t#if true start\n", getAddress(cg));
|
||||
fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\t#if true start\n", getAddress(cg));
|
||||
fprintf(cg_flag, "\tjne\t.L%d\t\t#if true end\n", getLabel(inst));
|
||||
}
|
||||
|
||||
@ -642,6 +642,7 @@ int generateEqualTo(Instruction *inst) {
|
||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#equal to start\n", getAddress(op1CG));
|
||||
fprintf(cg_flag, "\tcmpl\t%d(%%rbp), %%eax\n", getAddress(op2CG));
|
||||
fprintf(cg_flag, "\tsete\t%%al\n");
|
||||
fprintf(cg_flag, "\tmovb\t$0, %d(%%rbp)\n", getAddress(cg));
|
||||
fprintf(cg_flag, "\tmovb\t%%al, %d(%%rbp)\t#equal to end\n", getAddress(cg));
|
||||
return 0;
|
||||
}
|
||||
|
@ -627,6 +627,8 @@ int getConst(TNodeOrConst *tnc) {
|
||||
return tnc->tnc_union->character;
|
||||
} else if (tnc->d == BOOLEAN) {
|
||||
return tnc->tnc_union->Boolean;
|
||||
} else if (tnc->d == ADDRESS) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -6,26 +6,34 @@ function entry : string2integer
|
||||
function Fib : integer2integer
|
||||
|
||||
Fib(i) := {
|
||||
[ Boolean: a ; Boolean: b ; Boolean: c]
|
||||
if( i = 0 ) then {
|
||||
[integer: a; integer: b ; Boolean: d ; integer: c]
|
||||
(*if( i = 0 ) then {
|
||||
return 7;
|
||||
} else {
|
||||
i := i;
|
||||
}
|
||||
}*)
|
||||
(*b := b | (a & c);
|
||||
b := 2 < 3;*)
|
||||
if(i = 1) then {
|
||||
i := printCharacter('a');
|
||||
return 1;
|
||||
} else {
|
||||
return i + Fib(i - 1);
|
||||
|
||||
(* `if(i = 1) then { return 1; } else {
|
||||
return Fib(i - 1) + Fib(i - 2);
|
||||
}
|
||||
*)
|
||||
|
||||
a := 0;
|
||||
b := 1;
|
||||
while(0 < i) {
|
||||
c := a + b;
|
||||
a := b;
|
||||
b := c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
entry (arg) := {
|
||||
[ integer: x; integer: y ]
|
||||
x := 2;
|
||||
x := Fib(2);
|
||||
y := printInteger(Fib(2));
|
||||
(* x := Fib(2);*)
|
||||
y := printInteger(Fib(3));
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user