From 63f1baa5f4583fb1d919a01b7e658c0e305ac96c Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 6 Oct 2019 21:34:28 -0400 Subject: Fix gen code gets name of function being created for labeling --- gen_code.c | 6 +++++- gen_code.h | 2 +- main.c | 2 +- pc.y | 21 ++++++++++++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gen_code.c b/gen_code.c index 7471e8f..22d1e76 100644 --- a/gen_code.c +++ b/gen_code.c @@ -32,8 +32,12 @@ ptree *t; } +void gen_expr(t) +ptree *t; +{ +} -void gen_code(t) +void gen_code(t, name) ptree *t; { /*Test gen_label*/ diff --git a/gen_code.h b/gen_code.h index 8c9ad00..3d44755 100644 --- a/gen_code.h +++ b/gen_code.h @@ -2,7 +2,7 @@ #define GEN_CODEH #include "tree.h" -void gen_code(ptree*); +void gen_code(ptree*, char*); void gen_expr(ptree*); void gen_statement(ptree*); diff --git a/main.c b/main.c index c1de792..1657259 100644 --- a/main.c +++ b/main.c @@ -203,7 +203,7 @@ int size, *nxt; int main() { #ifdef DEBUG_TYPES - printf( + fprintf(stderr, "\nPROG\t\t%d\n" "VAR\t\t%d\n" "PROC\t\t%d\n" diff --git a/pc.y b/pc.y index 616b37d..98c0bdc 100644 --- a/pc.y +++ b/pc.y @@ -93,7 +93,7 @@ extern scope *cur_scope; %type TD -%type sub_prog_head +%type sub_prog_head %% @@ -108,7 +108,7 @@ program #ifdef DEBUG print_tree($9); #endif - gen_code($9); + gen_code($9, $2); free_tree($9); #ifdef DEBUG @@ -187,14 +187,20 @@ sub_prog_declaration sub_prog_declarations compound_statement { - if ($1) - check_func_return($4, $1); + char *name = $1->l->attr.nval->name; + $1->l->attr.nval = NULL; + + if ($1->type == FCALL) + check_func_return($4, name); + + free_tree($1); + set_ret_type($4); #ifdef DEBUG print_tree($4); #endif - gen_code($4); + gen_code($4, name); free_tree($4); #ifdef DEBUG @@ -240,7 +246,8 @@ sub_prog_head cur_scope->ret_var = mknode($2); cur_scope->ret_var->var_type = $5; - $$ = $2; + $$ = mktree(FCALL, mkid(tmp), NULL); + } |PROC ID arguments ';' { @@ -262,7 +269,7 @@ sub_prog_head assert(!set_func_types($3, tmp->func_info->argv, i)); free_tree($3); - $$ = NULL; + $$ = mktree(PCALL, mkid(tmp), NULL); } ; -- cgit v1.1