diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-08 22:25:04 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-08 22:34:00 -0400 |
commit | 3aedb2dba1343172ebca96ffd181c96cdaddd698 (patch) | |
tree | 96941f15bb2ddbbce4dc6fd5aed6a63c6512a3d2 | |
parent | 57bc5ca2c7044658f446036cc5b75bf50de5bd24 (diff) |
Fix gen_label/gen_expr for right leafs
-rw-r--r-- | gen_code.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -24,8 +24,10 @@ ptree *t; { int tmp; - if (!(t->l && t->r)) + if (!(t->l && t->r)) { + t->label = 0; return 0; + } if (t->l) { tmp = gen_label(t->l); @@ -56,9 +58,23 @@ ptree *t; return; } + if ((!t->r) && (!t->l) && t->label == 0){ + switch (t->type) { + case ID: + fprintf(stdout, "mov\t%d(%%rbp), %s\n", + - t->attr.nval->offset * OFFSET_SIZE, *reg_ptr); + break; + case INUM: + fprintf(stdout, "mov\t$%d, %s\n",t->attr.ival, *reg_ptr); + break; + default: + fprintf(stdout, "mov OTHER"); + } + } /*case 0 * t is a left leaf*/ - if ((!t->r) && (!t->l) && t->label != 0) { + else if ((!t->r) && (!t->l) && t->label != 0) { + /*TODO check if correct*/ switch (t->type) { case ID: fprintf(stdout, "mov\t%s, %s\n",t->attr.nval->name, *reg_ptr); |