Get functions attempting to generate code.

However, the statements are only printed as expressions.
This commit is contained in:
Bill Currie 2011-01-19 08:38:09 +09:00
parent 33db650161
commit ff6e1b4d6c
3 changed files with 21 additions and 20 deletions

View file

@ -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);

View file

@ -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)

View file

@ -154,9 +154,18 @@ program
symtab_removesymbol (current_symtab, $1);
symtab_addsymbol (current_symtab, $1);
$<symtab>$ = 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 = $<symtab>3;
dstring_delete (str);
}
| subprogram_head ASSIGNOP '#' CONST ';'
{