aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen_code.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/gen_code.c b/gen_code.c
index c6e23eb..02c75aa 100644
--- a/gen_code.c
+++ b/gen_code.c
@@ -117,7 +117,8 @@ ptree *t;
return;
}
- if ((!t->r) && (!t->l) && t->label == 0){
+
+ if (t->label == 0){
switch (t->type) {
case ID:
fprintf(stdout, "movq\t%d(%%rbp), %s\n",
@@ -126,6 +127,22 @@ ptree *t;
case INUM:
fprintf(stdout, "movq\t$%d, %s\n",t->attr.ival, *reg_ptr);
break;
+ case FCALL:
+ STACK_SAVE
+ fprintf(stdout, "subq $%d, %%rsp\n",
+ t->l->attr.nval->func_info->argc
+ * OFFSET_SIZE);
+ gen_arguments(t->r);
+
+ fprintf(stdout, "call\t%s\n", t->l->attr.nval->name);
+ fprintf(stdout, "movq\t%s,%d(%%rbp)\n",
+ *reg_ptr,
+ - t->l->attr.nval->offset * OFFSET_SIZE);
+ STACK_LOAD
+ fprintf(stdout, "movq\t%d(%%rbp),%s\n",
+ - t->l->attr.nval->offset * OFFSET_SIZE,
+ *reg_ptr);
+ break;
default:
fprintf(stdout, "movq OTHER");
}
@@ -235,7 +252,7 @@ ptree *t;
}
STACK_SAVE
- fprintf(stdout, "subq $%d, %%rsp\n",
+ fprintf(stdout, "subq $%d, %%rsp\n",
t->l->attr.nval->func_info->argc * OFFSET_SIZE);
gen_arguments(t->r);
@@ -244,14 +261,6 @@ ptree *t;
break;
- case FCALL:
- if (t->l->ret_type == INT) {
- fprintf(stderr, "FCALL (INT) %s\n", t->l->attr.nval->name);
- } else {
- fprintf(stderr, "FCALL (REAL) %s\n", t->l->attr.nval->name);
- yyerror(FLOAT_ERROR);
- }
- break;
case LIST:
yyerror("Issue with statement code generation\n");
break;
@@ -305,8 +314,8 @@ char *name;
assert(reg_stack);
reg_stack[0] = "%rax"; reg_stack[1] = "%rcx";
reg_stack[2] = "%rdx"; reg_stack[3] = "%rsi";
- reg_stack[4] = "%rdi"; reg_stack[5] = "r8";
- reg_stack[6] = "r9"; reg_stack[7] = "%r10";
+ reg_stack[4] = "%rdi"; reg_stack[5] = "%r8";
+ reg_stack[6] = "%r9"; reg_stack[7] = "%r10";
reg_stack[8] = "%r11"; reg_stack[9] = "%r12";
reg_stack[10] = "%r13"; reg_stack[11] = "%r14";
reg_stack[12] = "%r15";