From 4e3949d809acecc63fe62e772218dbe3ab761e4b Mon Sep 17 00:00:00 2001 From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de> Date: Fri, 4 Oct 2013 01:53:32 +0000 Subject: [PATCH] snc: removed global variable for symbol table in the code generator Since we now resolve built-in functions as well as constants during analysis, we no longer need to access the symbol table in the code generator. This means we can get rid of an ugly hack. The gen_ss_init procedure is also no longer needed and has been removed. --- src/snc/gen_code.c | 6 +----- src/snc/gen_ss_code.c | 23 +++++++++-------------- src/snc/gen_ss_code.h | 3 +-- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/snc/gen_code.c b/src/snc/gen_code.c index 305bce78..843f2a10 100644 --- a/src/snc/gen_code.c +++ b/src/snc/gen_code.c @@ -49,10 +49,6 @@ void generate_code(Program *p, const char *header_name) report("-------------------- Code Generation --------------------\n"); #endif - /* Initialize tables in gen_ss_code module */ - /* TODO: find a better way to do this */ - init_gen_ss_code(p); - set_gen_h(); /* Initial comments */ @@ -105,7 +101,7 @@ void generate_code(Program *p, const char *header_name) } /* Generate code for each state set */ - gen_ss_code(p); + gen_ss_code(p->prog, p->options); /* Generate tables */ gen_tables(p); diff --git a/src/snc/gen_ss_code.c b/src/snc/gen_ss_code.c index 3c773735..c30db382 100644 --- a/src/snc/gen_ss_code.c +++ b/src/snc/gen_ss_code.c @@ -78,26 +78,21 @@ enum expr_context }; /* - * HACK: use global variables to make program options and - * symbol table available to subroutines + * HACK: use global variable to make reentrant option available + * to gen_var_access below. Otherwise we'd have to pass it through + * almost every subroutine in this module. */ -static int global_opt_reent; -static SymTable global_sym_table; - -void init_gen_ss_code(Program *program) -{ - /* HACK: intialise globals */ - global_opt_reent = program->options.reent; - global_sym_table = program->sym_table; -} +static Options global_options; /* Generate state set C code from analysed syntax tree */ -void gen_ss_code(Program *program) +void gen_ss_code(Expr *prog, Options options) { - Expr *prog = program->prog; Expr *sp, *ssp; uint ss_num = 0; + /* HACK: intialise global variable as implicit parameter */ + global_options = options; + /* Generate program init func */ gen_prog_func(prog, "init", NM_INIT, gen_prog_init_body); @@ -298,7 +293,7 @@ static void gen_event_body(Expr *xp, int context) static void gen_var_access(Var *vp) { - const char *pre = global_opt_reent ? NM_VARS_ARG "->" : ""; + const char *pre = global_options.reent ? NM_VARS_ARG "->" : ""; assert(vp); assert(vp->scope); diff --git a/src/snc/gen_ss_code.h b/src/snc/gen_ss_code.h index 13964ca1..05f9b08e 100644 --- a/src/snc/gen_ss_code.h +++ b/src/snc/gen_ss_code.h @@ -15,7 +15,6 @@ in the file LICENSE that is included with this distribution. #include "types.h" -void init_gen_ss_code(Program *program); -void gen_ss_code(Program *program); +void gen_ss_code(Expr *prog, Options options); #endif /*INCLgensscodeh*/ -- GitLab