scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit a0b3a0df6a6a6ff2c2e5cdc190428bb5e1e47f4c
parent 9abe992c8b535e5c2f5cb574016d7dcdced33870
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  7 Jul 2016 16:26:32 +0200

[cc2-qbe] Add basic function definition support

With this small commit we can begin to do tests, because
we can parse full functions and see what is the code generated.

Diffstat:
Mcc2/arch/qbe/cgen.c | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -130,12 +130,40 @@ bool(Node *np, Node *new, Symbol *true, Symbol *false) } static Node * +function(void) +{ + Symbol *p; + + /* allocate stack space for parameters */ + for (p = locals; p && (p->type.flags & PARF) != 0; p = p->next) + code(ASALLOC, label2node(p), NULL, NULL); + + /* allocate stack space for local variables) */ + for ( ; p && p->id != TMPSYM; p = p->next) { + if (p->kind != SAUTO) + continue; + code(ASALLOC, label2node(p), NULL, NULL); + } + /* store formal parameters in parameters */ + for (p = locals; p; p = p->next) { + if ((p->type.flags & PARF) == 0) + break; + code(ASFORM, label2node(p), NULL, NULL); + } + return NULL; +} + +static Node * rhs(Node *np, Node *new) { Node aux; Symbol *label1, *label2; switch (np->op) { + case OBFUN: + return function(); + case OEFUN: + return NULL; case OMEM: case OAUTO: return load(np, new);