EXECUTION!!!!!!!!!!!!!!!!!!!
This commit is contained in:
@ -7,6 +7,10 @@ int generate(){
|
||||
offset = 0;
|
||||
currentsp = 0;
|
||||
Instruction *i = begin;
|
||||
|
||||
// temporary
|
||||
fprintf(cg_flag, ".globl entry\n");
|
||||
|
||||
while (i != NULL) {
|
||||
switch(getOp(i)) {
|
||||
case E_LABEL:
|
||||
@ -170,9 +174,8 @@ int generateAdd(Instruction *inst) {
|
||||
printdebug("generateAdd failed, %s is not initialized/in CG", getName(getTN(op2)));
|
||||
return -1;
|
||||
}
|
||||
fprintf(cg_flag, "\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%%edx, %%eax\n");
|
||||
fprintf(cg_flag, "\n\tmovl\t%d(%%rbp), %%eax\t#addition start\n", getAddress(op1CG));
|
||||
fprintf(cg_flag, "\taddl\t%d(%%rbp), %%eax\n", getAddress(op2CG));
|
||||
fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\t#addition end\n", getAddress(cg));
|
||||
return 0;
|
||||
}
|
||||
@ -629,7 +632,6 @@ int generateCall(Instruction *inst){
|
||||
|
||||
|
||||
fprintf(cg_flag, "\tcall %s\n", getName(getTN(op1)));
|
||||
fprintf(cg_flag, "\taddq\t$%d, %%rsp\n", 8 + getConst(op1));
|
||||
|
||||
//now for the return
|
||||
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, "\tpopq\t%%rbp\n");
|
||||
fprintf(cg_flag, "\tleave\n");
|
||||
fprintf(cg_flag, "\tret\n");
|
||||
return 0;
|
||||
}
|
||||
@ -688,8 +690,7 @@ int generateParam(Instruction *inst){
|
||||
return -1;
|
||||
}
|
||||
|
||||
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", getPrimSize(getTypeEntry(getTN(op1))));
|
||||
fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%edi\t#adding param start\n", getAddress(op1CG));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -706,6 +707,7 @@ int generateFunctionStart(Instruction *inst) {
|
||||
fprintf(cg_flag, "%s:\n", getName(funDecTN));
|
||||
fprintf(cg_flag, "\tpushq\t%%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
|
||||
// have function declararation node
|
||||
|
Reference in New Issue
Block a user