From ff6e1b4d6cb4504626ac346a2d6c6c7a647d4930 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 19 Jan 2011 08:38:09 +0900 Subject: [PATCH] Get functions attempting to generate code. However, the statements are only printed as expressions. --- tools/qfcc/include/function.h | 3 ++- tools/qfcc/source/function.c | 17 ++++++++--------- tools/qfcc/source/qp-parse.y | 21 +++++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tools/qfcc/include/function.h b/tools/qfcc/include/function.h index faaba2493..e1d74178a 100644 --- a/tools/qfcc/include/function.h +++ b/tools/qfcc/include/function.h @@ -97,7 +97,8 @@ function_t *new_function (const char *name, const char *nice_name); void add_function (function_t *f); function_t *begin_function (struct symbol_s *sym, const char *nicename, struct symtab_s *parent); -function_t *build_code_function (function_t *f, struct expr_s *state_expr, +function_t *build_code_function (struct symbol_s *fsym, + struct expr_s *state_expr, struct expr_s *statements); function_t *build_builtin_function (struct symbol_s *sym, struct expr_s *bi_val); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index ae99cd6b6..06a7f9bfd 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -518,17 +518,16 @@ begin_function (symbol_t *sym, const char *nicename, symtab_t *parent) } function_t * -build_code_function (function_t *f, expr_t *state_expr, expr_t *statements) +build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements) { - build_function (f); + build_function (fsym->s.func); if (state_expr) { state_expr->next = statements; - emit_function (f, state_expr); - } else { - emit_function (f, statements); + statements = state_expr; } - finish_function (f); - return f; + emit_function (fsym->s.func, statements); + finish_function (fsym->s.func); + return fsym->s.func; } function_t * @@ -602,9 +601,9 @@ emit_function (function_t *f, expr_t *e) { int last_is_label = 0; dstatement_t *s; -//#define DUMP_EXPR +#define DUMP_EXPR #ifdef DUMP_EXPR - printf (" %s =\n", f->def->name); + printf (" %s =\n", f->sym->name); #endif if (f->aux) diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y index 669db5132..6cd154963 100644 --- a/tools/qfcc/source/qp-parse.y +++ b/tools/qfcc/source/qp-parse.y @@ -154,9 +154,18 @@ program symtab_removesymbol (current_symtab, $1); symtab_addsymbol (current_symtab, $1); - $$ = current_symtab; current_func = begin_function ($1, 0, current_symtab); current_symtab = current_func->symtab; + build_code_function ($1, 0, $4); + + $4 = function_expr (new_symbol_expr ($1), 0); + $1 = new_symbol (".main"); + $1->params = 0; + $1->type = parse_params (&type_void, 0); + $1 = function_symbol ($1, 0, 1); + current_func = begin_function ($1, 0, current_symtab); + current_symtab = current_func->symtab; + build_code_function ($1, 0, $4); } ; @@ -234,16 +243,8 @@ subprogram_declaration } declarations compound_statement ';' { - dstring_t *str = dstring_newstr (); - symbol_t *s; - - for (s = current_symtab->symbols; s; s = s->next) { - dstring_clearstr (str); - print_type_str (str, s->type); - printf (" %s %s\n", s->name, str->str); - } + build_code_function ($1, 0, $5); current_symtab = $3; - dstring_delete (str); } | subprogram_head ASSIGNOP '#' CONST ';' {