ref: 691c29076baa1983116d4a26b3adfbc30bf68d43
parent: c6c9ed1a15c4682ae04f2f867cad16f0eaae03a7
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 15 11:55:11 EDT 2016
[cc2-qbe] Add emission of local variables Local variables must be allocated in the current stack of the defined function.
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -164,15 +164,24 @@
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("){");
+ 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("}");
}