aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-10-07 19:25:33 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-10-07 22:50:25 -0400
commit23a872f315ae56e8e6126363003a0de3e56bc78a (patch)
tree6c1d14a083b5e1b3dfc611b13cc9130f5a00a3e7
parentf64eced412b2d779af7785b0409ca10889741118 (diff)
Add debug prints for all gen_statements
To check order of statements generated
-rw-r--r--gen_code.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/gen_code.c b/gen_code.c
index 0faa068..d7b2524 100644
--- a/gen_code.c
+++ b/gen_code.c
@@ -15,7 +15,6 @@ ptree *t;
t->l->label = (!tmp ? 1 : tmp);
} else
yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n");
-
if (t->r)
t->r->label = gen_label(t->r);
@@ -23,8 +22,6 @@ ptree *t;
t->r->label = 0;
-
-
if (t->r->label == t->l->label) {
return 1 + t->l->label;
} else {
@@ -48,22 +45,44 @@ ptree *t;
switch (t->type){
case ASSIGNOP:
-
+ if (t->l->ret_type == INT) {
+ fprintf(stderr, "ASSIGN (INT) %s\n", t->l->attr.nval->name);
+ } else {
+ fprintf(stderr, "ASSIGN (REAL) %s\n", t->l->attr.nval->name);
+ }
break;
case PCALL:
-
+ fprintf(stderr, "PCALL\n");
+ 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);
+ }
break;
case LIST:
-
+ yyerror("Issue with statement code generation\n");
break;
case IF:
+ if (t->l->l->ret_type == INT) {
+ fprintf(stderr, "IF (INT)\n");
+ } else {
+ fprintf(stderr, "IF (REAL)\n");
+ }
break;
case WHILE:
+ if (t->l->l->ret_type == INT) {
+ fprintf(stderr, "WHILE (INT)\n");
+ } else {
+ fprintf(stderr, "WHILE (REAL)\n");
+ }
break;
case FOR:
+ fprintf(stderr, "FOR\n");
break;
default:
snprintf(buf, 100, "Unknown statement type: %d\n", t->type);
@@ -71,7 +90,7 @@ ptree *t;
}
}
-gen_statement_order(t)
+void gen_statement_order(t)
ptree *t;
{
if (t->type != LIST){
@@ -88,7 +107,8 @@ void gen_code(t, name)
ptree *t;
char *name;
{
- printf("\n.globl %s\n.type %s, @function\n%s:\n", name, name, name);
+ fprintf(stdout, "\n.globl %s\n", name);
+ fprintf(stdout, ".type %s, @function\n%s:\n", name, name);
gen_statement_order(t);
}