scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit e5165d704e5d8d7c7ee23bb884f2aacf6cb722a4
parent 6e1706f9eb1bc7e9fd6669ed256da1233d44c554
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 15 Apr 2016 15:55:11 +0200

[cc2-qbe] Add emission of local variables

Local variables must be allocated in the current stack of the defined
function.

Diffstat:
cc2/arch/qbe/code.c | 15++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -164,15 +164,24 @@ void writeout(void) { Symbol *p; + Type *tp; if (curfun->kind == GLOB) fputs("export ", stdout); - printf("function %s $%s(", size2asm(&curfun->rtype), symname(curfun)); + printf("function %s %s(\n", size2asm(&curfun->rtype), symname(curfun)); for (p = locals; p && p->type.flags & PARF; p = p->next) - printf("%s %s,", size2asm(&p->type), symname(p)); + printf("\t%s %s,\n", size2asm(&p->type), symname(p)); + + puts(")\n{"); + + for ( ; p; p = p->next) { + tp = &p->type; + printf("\t%s %s= alloc%d %d\n", + symname(p), size2asm(tp), tp->size, tp->align); + } + - puts("){"); puts("}"); }