final submission
This commit is contained in:
@ -588,7 +588,7 @@ int generateCondGoto(Instruction *inst) {
|
|||||||
|
|
||||||
int generateIfTrue(Instruction *inst) {
|
int generateIfTrue(Instruction *inst) {
|
||||||
TNodeOrConst *op1 = getOperand1(inst);
|
TNodeOrConst *op1 = getOperand1(inst);
|
||||||
|
|
||||||
if (op1 == NULL) {
|
if (op1 == NULL) {
|
||||||
printdebug("%sgenerateIfTrue failed, NULL operand", COLOR_RED);
|
printdebug("%sgenerateIfTrue failed, NULL operand", COLOR_RED);
|
||||||
return -1;
|
return -1;
|
||||||
@ -606,7 +606,7 @@ int generateIfTrue(Instruction *inst) {
|
|||||||
|
|
||||||
int generateIfFalse(Instruction *inst) {
|
int generateIfFalse(Instruction *inst) {
|
||||||
TNodeOrConst *op1 = getOperand1(inst);
|
TNodeOrConst *op1 = getOperand1(inst);
|
||||||
|
|
||||||
if (op1 == NULL) {
|
if (op1 == NULL) {
|
||||||
printdebug("%sgenerateIfFalse failed, NULL operand", COLOR_RED);
|
printdebug("%sgenerateIfFalse failed, NULL operand", COLOR_RED);
|
||||||
return -1;
|
return -1;
|
||||||
@ -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));
|
||||||
@ -734,7 +756,7 @@ int generateCall(Instruction *inst) {
|
|||||||
// }
|
// }
|
||||||
//now for the return
|
//now for the return
|
||||||
CGNode *cg = findCG(getResult(inst));
|
CGNode *cg = findCG(getResult(inst));
|
||||||
|
|
||||||
if (cg == NULL) {
|
if (cg == NULL) {
|
||||||
cg = addCG(getResult(inst), offset);
|
cg = addCG(getResult(inst), offset);
|
||||||
}
|
}
|
||||||
@ -757,7 +779,7 @@ int generateReturn(Instruction *inst) {
|
|||||||
printdebug("generateReturn failed, trying to return %s not in CGList", getName(getTN(op1)));
|
printdebug("generateReturn failed, trying to return %s not in CGList", getName(getTN(op1)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (table_lookup(getAncestor(cur), getName(getTN(op1))) != undefined) {
|
if (table_lookup(getAncestor(cur), getName(getTN(op1))) != undefined) {
|
||||||
fprintf(cg_flag, "\tmovl\t$%s,%%eax\t#return a function\n", getName(getTN(op1)));
|
fprintf(cg_flag, "\tmovl\t$%s,%%eax\t#return a function\n", getName(getTN(op1)));
|
||||||
} else {
|
} else {
|
||||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#return %s\n", getAddress(cg), getName(getTN(op1)));
|
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#return %s\n", getAddress(cg), getName(getTN(op1)));
|
||||||
@ -812,7 +834,7 @@ int generateParam(Instruction *inst) {
|
|||||||
default:
|
default:
|
||||||
align(getTN(op1));
|
align(getTN(op1));
|
||||||
offset += getPrimSize(getTypeEntry(getTN(op1)));
|
offset += getPrimSize(getTypeEntry(getTN(op1)));
|
||||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#adding param start\n", getAddress(op1CG));
|
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#adding param start\n", getAddress(op1CG));
|
||||||
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#adding param end\n", offset - getPrimSize(getTypeEntry(getTN(op1))));
|
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#adding param end\n", offset - getPrimSize(getTypeEntry(getTN(op1))));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user