aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-10-09 09:34:50 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-10-09 09:34:50 -0400
commit3004a96a9bba4bf645bc072ef564f4debb509057 (patch)
tree6478f95d66860bda00f78339d45c8e5e6dae2287
parentdd7ae3ded95d2a2d110507ad32c17c771422c360 (diff)
Add SUB (NEG) to gen_load
-rw-r--r--gen_code.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/gen_code.c b/gen_code.c
index 686e61c..3f72446 100644
--- a/gen_code.c
+++ b/gen_code.c
@@ -191,18 +191,9 @@ ptree *t;
gen_arguments(t->l);
}
-
-/*Based on Dragon Book gen_code()*/
-void gen_expr(t)
+void gen_load(t)
ptree *t;
{
- if (!t) {
- fprintf(stderr, "GEN_EXPR: NOT T\n");
- return;
- }
-
-
- if (t->label == 0){
switch (t->type) {
case ID:
fprintf(stdout, "movq\t%d(%%rbp), %s\n",
@@ -227,6 +218,10 @@ ptree *t;
- t->l->attr.nval->offset * OFFSET_SIZE,
*reg_ptr);
break;
+ case SUB:
+ gen_load(t->l);
+ fprintf(stdout, "negq\t%s\n", *reg_ptr);
+ break;
default:
fprintf(stdout, "movq OTHER");
}