From 3004a96a9bba4bf645bc072ef564f4debb509057 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Wed, 9 Oct 2019 09:34:50 -0400 Subject: Add SUB (NEG) to gen_load --- gen_code.c | 15 +++++---------- 1 file 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"); } -- cgit v1.1