From 0de23c97e1aee2fb7896c03b34bc36e9fc1ffa51 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Tue, 8 Oct 2019 23:36:48 -0400 Subject: Add error message for reals code generation --- gen_code.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gen_code.c b/gen_code.c index 67cacdd..43e85a8 100644 --- a/gen_code.c +++ b/gen_code.c @@ -6,6 +6,8 @@ #include "pc.h" #include "scope.h" +#define FLOAT_ERROR "Cannot produce code with reals\n" + scope *cur_scope; #define REG_SWAP {\ @@ -96,6 +98,8 @@ ptree *t; if (t->r && t->r->type == INT) { fprintf(stdout, "op\t$%d,\n", t->r->attr.ival); fprintf(stdout, "op\t$%d,%s\n", t->r->attr.ival, *reg_ptr); + } else { + yyerror(FLOAT_ERROR); } } /*case 2 @@ -148,10 +152,14 @@ ptree *t; fprintf(stdout, "mov %s, %d(%%rbp)\n", *reg_ptr, - t->l->attr.nval->offset * OFFSET_SIZE); } else { + yyerror(FLOAT_ERROR); fprintf(stderr, "ASSIGN (REAL) %s\n", t->l->attr.nval->name); } break; case PCALL: + if (t->r->ret_type == REAL) + yyerror(FLOAT_ERROR); + if (!strcmp(t->l->attr.nval->name, "write")) { GEN_EXPR(t->r); fprintf(stdout, "mov %s, %%rsi\n", *reg_ptr); @@ -168,6 +176,7 @@ ptree *t; 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: @@ -178,6 +187,7 @@ ptree *t; fprintf(stderr, "IF (INT)\n"); } else { fprintf(stderr, "IF (REAL)\n"); + yyerror(FLOAT_ERROR); } break; @@ -186,6 +196,7 @@ ptree *t; fprintf(stderr, "WHILE (INT)\n"); } else { fprintf(stderr, "WHILE (REAL)\n"); + yyerror(FLOAT_ERROR); } break; -- cgit v1.1