final submission

This commit is contained in:
Meyer Simon
2025-05-06 23:49:01 -04:00
parent a95930c0e5
commit cfb3d9d08e
2 changed files with 35 additions and 13 deletions

View File

@@ -618,7 +618,7 @@ int generateIfFalse(Instruction *inst) {
return -1; return -1;
} }
fprintf(cg_flag, "\tcmpl\t$0, %d(%%rbp)\t#if false start\n", getAddress(cg)); fprintf(cg_flag, "\tcmpb\t$0, %d(%%rbp)\t#if false start\n", getAddress(cg));
fprintf(cg_flag, "\tje\t.L%d\t\t#if false end\n", getLabel(inst)); fprintf(cg_flag, "\tje\t.L%d\t\t#if false end\n", getLabel(inst));
} }
@@ -690,9 +690,31 @@ int generateEqualTo(Instruction *inst) {
printdebug("generateLessThan failed, %s is not initialized/in CG", getName(getTN(op2))); printdebug("generateLessThan failed, %s is not initialized/in CG", getName(getTN(op2)));
return -1; return -1;
} }
char *movtype;
char *reg;
char *cmptype;
TableNode *typetn = getTypeEntry(getTN(op1));
if (typetn == integ) {
movtype = "movl";
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#equal to start\n", getAddress(op1CG)); cmptype = "cmpl";
fprintf(cg_flag, "\tcmpl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); reg = "%eax";
} else if (typetn == boo) {
cmptype = "cmpb";
movtype = "movb";
reg = "%al";
} else if (typetn == chara) {
cmptype = "cmpb";
movtype = "movb";
reg = "%al";
} else {
cmptype = "cmpq";
movtype = "movq";
reg = "%rax";
}
fprintf(cg_flag, "\t%s\t%d(%%rbp), %s\t#equal to start\n", movtype, getAddress(op1CG), reg);
fprintf(cg_flag, "\t%s\t%d(%%rbp), %s\n", cmptype, getAddress(op2CG), reg);
fprintf(cg_flag, "\tsete\t%%al\n"); fprintf(cg_flag, "\tsete\t%%al\n");
fprintf(cg_flag, "\tmovb\t$0, %d(%%rbp)\n", getAddress(cg)); 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)); fprintf(cg_flag, "\tmovb\t%%al, %d(%%rbp)\t#equal to end\n", getAddress(cg));

View File

@@ -15,9 +15,9 @@ bar (r,s) := {
*) *)
entry (arg) := { entry (arg) := {
[ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t; integer: c] [ Boolean:x ; Boolean:y ; Boolean:z ; Boolean:t; integer: c]
x := true; x := false;
y := true; y := false;
if ( x | y ) then { if ( (x | y) | !( y = x ) ) then {
(* (*
if ( x<y & !(x=y) ) then { if ( x<y & !(x=y) ) then {
@@ -27,10 +27,10 @@ entry (arg) := {
*) *)
z := 1 < 2; z := 1 < 2;
c := printBoolean(true); c := printBoolean(z);
} else { } else {
y := false; (* bar('c', 7); *) y := false; (* bar('c', 7); *)
c := printBoolean(false); c := printBoolean(y);
} }
return 0; return 0;
} }