From 1999230265bac512c9aa8d190af15d77f5e57e8d Mon Sep 17 00:00:00 2001 From: Partho Date: Fri, 25 Apr 2025 16:55:27 -0400 Subject: [PATCH] got compilation to work --- cg.s | 44 +++++++ src/runner.c | 12 +- src/runner.h | 1 + src/symbol_table.c | 289 +++++++++++++++++++++++++++++---------------- 4 files changed, 241 insertions(+), 105 deletions(-) create mode 100644 cg.s diff --git a/cg.s b/cg.s new file mode 100644 index 0000000..47bbe30 --- /dev/null +++ b/cg.s @@ -0,0 +1,44 @@ + movl $3, 0(%rbp) + movl $2, 1(%rbp) + movl $8, 2(%rbp) + movl 1(%rbp), %eax + subl 2(%rbp), %eax + movl %eax, 3(%rbp) + movl 0(%rbp), %eax + addl 0(%rbp), %eax + movl %eax, 4(%rbp) + movl $3, 5(%rbp) + movl $2, 6(%rbp) + movl $8, 7(%rbp) + movl 6(%rbp), %eax + cltd + idivl 7(%rbp) + movl %eax, 8(%rbp) + movl 5(%rbp), %eax + subl 8(%rbp), %eax + movl %eax, 9(%rbp) + movl $2, 10(%rbp) + movl $8, 11(%rbp) + movl $3, 12(%rbp) + movl $2, 13(%rbp) + movl 12(%rbp), %eax + subl 13(%rbp), %eax + movl %eax, 14(%rbp) + movl $8, 15(%rbp) + movl 14(%rbp), %eax + cltd + idivl 15(%rbp) + movl %edx, 16(%rbp) + movl $3, 17(%rbp) + movl $2, 18(%rbp) + movl 17(%rbp), %eax + cltd + idivl 18(%rbp) + movl %edx, 19(%rbp) + movl $8, 20(%rbp) + movl 19(%rbp), %eax + subl 20(%rbp), %eax + movl %eax, 21(%rbp) + movl $3, 22(%rbp) + movl $8, 23(%rbp) + movl $0, 24(%rbp) diff --git a/src/runner.c b/src/runner.c index 736be1c..2253b73 100644 --- a/src/runner.c +++ b/src/runner.c @@ -3,7 +3,6 @@ #include "runner.h" FILE *ir_flag = NULL; -FILE *cg_flag = NULL; //Constant_Stack *head = NULL; int main(int argc, char *argv[]) { if (argc == 1) { @@ -38,6 +37,7 @@ int main(int argc, char *argv[]) { alpha_file = fopen(argv[argc - 1], "r"); } } + cg_flag = fopen("cg.s", "w"); return run(alpha_file); } @@ -125,6 +125,8 @@ int run(FILE *alpha) { print_symbol_table(top, st_flag); emit_as_file(stdout, begin); fclose(st_flag); + generate(); + fclose(cg_flag); } if (asc_flag != NULL) { @@ -141,10 +143,10 @@ int run(FILE *alpha) { fclose(ir_flag); } - if (cg_flag != NULL) { - printf("Flag -cg is not implemented yet\n"); - fclose(cg_flag); - } + //if (cg_flag != NULL) { + // printf("Flag -cg is not implemented yet\n"); + //fclose(cg_flag); + //} if (yyin != NULL) { fclose(yyin); diff --git a/src/runner.h b/src/runner.h index 7e134f2..503b319 100644 --- a/src/runner.h +++ b/src/runner.h @@ -48,6 +48,7 @@ FILE *alpha_file; FILE *tok_flag = NULL; FILE *st_flag = NULL; FILE *asc_flag = NULL; +FILE *cg_flag = NULL; bool tc_flag = false; bool DEBUG = false; int no_flag = 0; diff --git a/src/symbol_table.c b/src/symbol_table.c index 4ec3e70..441eb5c 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -1948,10 +1948,24 @@ char * label_gen(){ label_count++; return ret; } + +TableNode* getTN(TNodeOrConst * tnc){ + if(tnc->d == NODE){ + return tnc->tnc_union->node; + } + return NULL; +} +//we must fix this +int getConst(TNodeOrConst * tnc){ + if(tnc->d == INTEGER){ + return tnc->tnc_union->integer; + } + return -1; +} //------------------------------------------------------------------------------------- int generate(){ offset = 0; - Instruction* i = begin; + Instruction *i = begin; while (i != NULL) { switch(getOp(i)) { case E_LABEL: @@ -2023,6 +2037,7 @@ int generate(){ default: ; } + i = i->next; } return -1; } @@ -2038,6 +2053,7 @@ int getAddress(CGNode *cg) { if (cg == NULL) { return -1; } + return currentsp - cg->address; } @@ -2047,10 +2063,7 @@ TableNode *getTNofCG(CGNode *cg) { } return cg->tn; } -/* -movl $1, -4(%rbp) -add -4(%rbp), $2 -*/ + CGNode *findCG(TableNode *tn) { CGNode *cg = cgList; while (cg != NULL) { @@ -2085,20 +2098,20 @@ int generateAdd(Instruction *inst) { */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateAdd failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op1)); if (op1CG == NULL) { printdebug("generateAdd failed, %s is not initialized/in CG", getName(getTN(op1))); return -1; @@ -2109,9 +2122,9 @@ int generateAdd(Instruction *inst) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\taddl\t%d(\%rbp), \%eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\taddl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } @@ -2121,21 +2134,21 @@ int generateSub(Instruction *instruction) { One immediate: Neither immediate: */ - TNodeOrConst *op1 = getOperand1(inst); - TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + TNodeOrConst *op1 = getOperand1(instruction); + TNodeOrConst *op2 = getOperand2(instruction); + CGNode *cg = findCG(getResult(instruction)); if (op1 == NULL || op2 == NULL) { printdebug("generateSub failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(instruction), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateSub failed, op1 is not constant but not in CGlist"); return -1; @@ -2146,13 +2159,13 @@ int generateSub(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tsubl\t%d(\%rbp), \%eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tsubl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } -int generateMult(Instruction *instruction){ +int generateMult(Instruction *inst){ /* Both immediate: One immediate: @@ -2160,18 +2173,18 @@ int generateMult(Instruction *instruction){ */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateMult failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateMult failed, op1 is not constant but not in CGlist"); return -1; @@ -2182,13 +2195,13 @@ int generateMult(Instruction *instruction){ return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tsubl\t%d(\%rbp), \%eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tsubl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } -int generateDiv(Instruction *instruction) { +int generateDiv(Instruction *inst) { /* Both immediate: One immediate: @@ -2196,19 +2209,19 @@ int generateDiv(Instruction *instruction) { */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateDiv failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateDiv failed, op1 is not constant but not in CGlist"); return -1; @@ -2219,14 +2232,14 @@ int generateDiv(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); //moves dividend into eax + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); //moves dividend into eax fprintf(cg_flag, "\tcltd\n"); //sign extends the dividend in eax - fprintf(cg_flag, "\tidivl\t%d(\%rbp)\n", getAddress(op2CG));//divides edx by value accessed from stack - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); //stores result + fprintf(cg_flag, "\tidivl\t%d(%%rbp)\n", getAddress(op2CG));//divides edx by value accessed from stack + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); //stores result return 0; } -int generateMod(Instruction *instruction) { +int generateMod(Instruction *inst) { /* Both immediate: One immediate: @@ -2234,18 +2247,18 @@ int generateMod(Instruction *instruction) { */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateMod failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateMod failed, op1 is not constant but not in CGlist"); return -1; @@ -2256,14 +2269,14 @@ int generateMod(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); //moves dividend into eax + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); //moves dividend into eax fprintf(cg_flag, "\tcltd\n"); //sign extends the dividend in eax - fprintf(cg_flag, "\tidivl\t%d(\%rbp)\n", getAddress(op2CG));//divides edx by value accessed from stack - fprintf(cg_flag, "\tmovl\t\%edx, %d(\%rbp)\n", getAddress(cg)); //stores result from edx (remainder) + fprintf(cg_flag, "\tidivl\t%d(%%rbp)\n", getAddress(op2CG));//divides edx by value accessed from stack + fprintf(cg_flag, "\tmovl\t%%edx, %d(%%rbp)\n", getAddress(cg)); //stores result from edx (remainder) return 0; } -int generateOr(Instruction *instruction) { +int generateOr(Instruction *inst) { /* Both immediate: One immediate: @@ -2271,19 +2284,19 @@ int generateOr(Instruction *instruction) { */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateOr failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateOr failed, op1 is not constant but not in CGlist"); return -1; @@ -2294,13 +2307,13 @@ int generateOr(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\torll\t%d(\%rbp), %eax\n", getAddress(op2CG));//divides edx by value accessed from stack - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); //stores result + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\torll\t%d(%%rbp), %%eax\n", getAddress(op2CG));//divides edx by value accessed from stack + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); //stores result return 0; } -int generateAnd(Instruction *instruction) { +int generateAnd(Instruction *inst) { /* Both immediate: One immediate: @@ -2308,50 +2321,50 @@ int generateAnd(Instruction *instruction) { */ TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("%sgenerateAnd failed, NULL operand", COLOR_RED); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { - printdebug("generateNeg failed, op1 is not constant but not in CGlist"); + printdebug("generateAnd failed, op1 is not constant but not in CGlist"); return -1; } if (op2CG == NULL) { - printdebug("generateNeg failed, %s is not initialized/in CG", getName(getTN(op2))); + printdebug("generateAnd failed, %s is not initialized/in CG", getName(getTN(op2))); return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tandl\t%d(\%rbp), %eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tandl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } -int generateNeg(Instruction *instruction) { +int generateNeg(Instruction *inst) { TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateNeg failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateNeg failed, op1 is not constant but not in CGlist"); return -1; @@ -2362,27 +2375,27 @@ int generateNeg(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tnegl\t%d %eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tnegl\t%d %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } -int generateNot(Instruction *instruction) { +int generateNot(Instruction *inst) { TNodeOrConst *op1 = getOperand1(inst); TNodeOrConst *op2 = getOperand2(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL || op2 == NULL) { printdebug("generateNot failed, NULL operand"); return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } - CGNode *op1CG = findCG(op1); - CGNode *op2CG = findCG(op2); + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); if (op1CG == NULL) { printdebug("generateNot failed, op1 is not constant but not in CGlist"); return -1; @@ -2393,15 +2406,15 @@ int generateNot(Instruction *instruction) { return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tnotl\t\%eax\n", getAddress(op2CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tnotl\t%%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } -int generateAssign(Instruction *instruction) { +int generateAssign(Instruction *inst) { TNodeOrConst *op1 = getOperand1(inst); - CGNode *result = findCG(getResult(inst)); + CGNode *cg = findCG(getResult(inst)); if (op1 == NULL) { @@ -2409,22 +2422,25 @@ int generateAssign(Instruction *instruction) { return -1; } - if (result == NULL) { - result = addCG(getResult(inst), offset); + if (cg == NULL) { + cg = addCG(getResult(inst), offset); } //add option for constant assignment (should be easy) + if (isConst(op1) == true) { + fprintf(cg_flag, "\tmovl\t$%d, %d(%%rbp)\n", getConst(op1), getAddress(cg)); + } - CGNode *op1CG = findCG(op1); + CGNode *op1CG = findCG(getTN(op1)); if (op1CG == NULL) { printdebug("generateAssign failed, op1 is not constant but not in CGlist"); return -1; } - fprintf(cg_flag, "\tmovl\t%d(\%rbp), \%eax\n", getAddress(op1CG)); - fprintf(cg_flag, "\tmovl\t\%eax, %d(\%rbp)\n", getAddress(cg)); + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tmovl\t%%eax, %d(%%rbp)\n", getAddress(cg)); return 0; } @@ -2432,29 +2448,101 @@ int generateGoto(Instruction *instruction){ return -1; } -int generateCondGoto(Instruciton *instruction) { +int generateCondGoto(Instruction *instruction) { return -1; } int generateIfTrue(Instruction *instruction){ return -1; + // might just be a goto for where to go if something is true, or returning if something is true, or checking if true and writing goto if thats the case } int generateIfFalse(Instruction *instruction){ return -1; } -int generateLessThan(Instruction *instruction){ - return -1; +int generateLessThan(Instruction *inst){ + /* + Both immediate: + One immediate: + Neither immediate: + */ + TNodeOrConst *op1 = getOperand1(inst); + TNodeOrConst *op2 = getOperand2(inst); + CGNode *cg = findCG(getResult(inst)); + + if (op1 == NULL || op2 == NULL) { + printdebug("%sgenerateLessThan failed, NULL operand", COLOR_RED); + return -1; + } + + if (cg == NULL) { + cg = addCG(getResult(inst), offset); + } + + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); + if (op1CG == NULL) { + printdebug("generateLessThan failed, op1 is not constant but not in CGlist"); + return -1; + } + + if (op2CG == NULL) { + printdebug("generateLessThan failed, %s is not initialized/in CG", getName(getTN(op2))); + return -1; + } + + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\n", getAddress(op1CG)); + fprintf(cg_flag, "\tcmpl\t%d(%%rbp), %%eax\n", getAddress(op2CG)); + fprintf(cg_flag, "\tsetl\t%%al\n"); + fprintf(cg_flag, "\tmovb\t%%al, %d(%%rbp)\n", getAddress(cg)); + return 0; } -int generateEqualTo(Instruction *instruction){ - return -1; + +int generateEqualTo(Instruction *inst){ + /* + Both immediate: + One immediate: + Neither immediate: + */ + TNodeOrConst *op1 = getOperand1(inst); + TNodeOrConst *op2 = getOperand2(inst); + CGNode *cg = findCG(getResult(inst)); + + if (op1 == NULL || op2 == NULL) { + printdebug("%sgenerateLessThan failed, NULL operand", COLOR_RED); + return -1; + } + + if (cg == NULL) { + cg = addCG(getResult(inst), offset); + } + + CGNode *op1CG = findCG(getTN(op1)); + CGNode *op2CG = findCG(getTN(op2)); + if (op1CG == NULL) { + printdebug("generateLessThan failed, op1 is not constant but not in CGlist"); + return -1; + } + + if (op2CG == NULL) { + printdebug("generateLessThan failed, %s is not initialized/in CG", getName(getTN(op2))); + return -1; + } + + fprintf(cg_flag, "\tmovl\t%d(%%rbp), %%eax\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%%al, %d(%%rbp)\n", getAddress(cg)); + return 0; } int generateCall(Instruction *instruction){ return -1; + //will want to store parameters and then update the offset by adding 8? for stack pointer stuff, can then print call subroutine name, followed by movl of the result into the result's cg } int generateReturn(Instruction *instruction){ return -1; + //will movl the result into the appropriate register and move the stack pointer/offset stuff back to correct value } int generateCopyRight(Instruction *instruction){ return -1; @@ -2466,5 +2554,6 @@ int generateAddressOf(Instruction *instruction){ return -1; } int generateParam(Instruction *instruction){ + //need to check if op1 is null, then add it to the appropriate register/cg node. need a way to keep track of this, maybe just have global count of params generated return -1; } \ No newline at end of file