EXECUTION!!!!!!!!!!!!!!!!!!!
This commit is contained in:
@ -7,6 +7,10 @@ int generate(){
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
currentsp = 0;
|
currentsp = 0;
|
||||||
Instruction *i = begin;
|
Instruction *i = begin;
|
||||||
|
|
||||||
|
// temporary
|
||||||
|
fprintf(cg_flag, ".globl entry\n");
|
||||||
|
|
||||||
while (i != NULL) {
|
while (i != NULL) {
|
||||||
switch(getOp(i)) {
|
switch(getOp(i)) {
|
||||||
case E_LABEL:
|
case E_LABEL:
|
||||||
@ -170,9 +174,8 @@ int generateAdd(Instruction *inst) {
|
|||||||
printdebug("generateAdd failed, %s is not initialized/in CG", getName(getTN(op2)));
|
printdebug("generateAdd failed, %s is not initialized/in CG", getName(getTN(op2)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#addition start\n", getAddress(op1CG));
|
fprintf(cg_flag, "\n\tmovl\t%d(%%rbp), %%eax\t#addition start\n", getAddress(op1CG));
|
||||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op2CG));
|
fprintf(cg_flag, "\taddl\t%d(%%rbp), %%eax\n", getAddress(op2CG));
|
||||||
fprintf(cg_flag, "\taddl\t%%edx, %%eax\n");
|
|
||||||
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#addition end\n", getAddress(cg));
|
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#addition end\n", getAddress(cg));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -629,7 +632,6 @@ int generateCall(Instruction *inst){
|
|||||||
|
|
||||||
|
|
||||||
fprintf(cg_flag, "\tcall %s\n", getName(getTN(op1)));
|
fprintf(cg_flag, "\tcall %s\n", getName(getTN(op1)));
|
||||||
fprintf(cg_flag, "\taddq\t$%d, %%rsp\n", 8 + getConst(op1));
|
|
||||||
|
|
||||||
//now for the return
|
//now for the return
|
||||||
CGNode *cg = findCG(getResult(inst));
|
CGNode *cg = findCG(getResult(inst));
|
||||||
@ -660,7 +662,7 @@ int generateReturn(Instruction *inst){
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)));
|
||||||
fprintf(cg_flag, "\tpopq\t%%rbp\n");
|
fprintf(cg_flag, "\tleave\n");
|
||||||
fprintf(cg_flag, "\tret\n");
|
fprintf(cg_flag, "\tret\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -688,8 +690,7 @@ int generateParam(Instruction *inst){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\t#adding param start\n", getAddress(op1CG));
|
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%edi\t#adding param start\n", getAddress(op1CG));
|
||||||
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#adding param end\n", getPrimSize(getTypeEntry(getTN(op1))));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,6 +707,7 @@ int generateFunctionStart(Instruction *inst) {
|
|||||||
fprintf(cg_flag, "%s:\n", getName(funDecTN));
|
fprintf(cg_flag, "%s:\n", getName(funDecTN));
|
||||||
fprintf(cg_flag, "\tpushq\t%%rbp\n");
|
fprintf(cg_flag, "\tpushq\t%%rbp\n");
|
||||||
fprintf(cg_flag, "\tmovq\t%%rsp, %%rbp\n");
|
fprintf(cg_flag, "\tmovq\t%%rsp, %%rbp\n");
|
||||||
|
fprintf(cg_flag, "\tsubq\t$%d, %%rsp\n", 128); // [CHANGE ME] 128 is a placeholder for the stack size
|
||||||
|
|
||||||
//now we need to add the CGs of nodes to the CG list by doing assign from the
|
//now we need to add the CGs of nodes to the CG list by doing assign from the
|
||||||
// have function declararation node
|
// have function declararation node
|
||||||
|
@ -1,12 +1,35 @@
|
|||||||
(* TEST: [-asc -tc -cg -ir] *)
|
(* TEST: [-asc -tc -cg -ir] *)
|
||||||
|
|
||||||
type main: string -> integer
|
type string: 1 -> character
|
||||||
function entry: main
|
type BooleanXBoolean: [Boolean: x; Boolean: y]
|
||||||
|
type characterXcharacter: [character: x; character: y]
|
||||||
|
type integerXinteger: [integer: x; integer: y]
|
||||||
|
|
||||||
|
type Boolean2Boolean: Boolean -> Boolean
|
||||||
|
type integer2integer: integer -> integer
|
||||||
|
type character2integer: character -> integer
|
||||||
|
type Boolean2integer0: Boolean -> integer
|
||||||
|
type string2integer: string -> integer
|
||||||
|
type integerXinteger2integer: integerXinteger -> integer
|
||||||
|
type integerXinteger2Boolean: integerXinteger -> Boolean
|
||||||
|
type characterXcharacter2Boolean: characterXcharacter -> Boolean
|
||||||
|
type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean
|
||||||
|
type integer2address: integer -> address
|
||||||
|
type address2integer: address -> integer
|
||||||
|
|
||||||
|
external function printInteger: integer2integer
|
||||||
|
external function printCharacter: character2integer
|
||||||
|
external function printBoolean: Boolean2integer
|
||||||
|
|
||||||
|
function entry: string2integer
|
||||||
|
|
||||||
entry (arg) := {
|
entry (arg) := {
|
||||||
[integer:x; integer:y]
|
[integer:x; integer:y; integer: result]
|
||||||
y := 1;
|
y := 1;
|
||||||
x := 3;
|
x := 3;
|
||||||
y := x + y;
|
y := x + y;
|
||||||
|
|
||||||
|
result := printInteger(y);
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
Reference in New Issue
Block a user