commit e5165d704e5d8d7c7ee23bb884f2aacf6cb722a4
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Fri Apr 15 15:55:11 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Apr 15 15:55:11 2016 +0200

    [cc2-qbe] Add emission of local variables
    
    Local variables must be allocated in the current stack of the defined
    function.

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index e8840ce..883f8a7 100644
--- 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("}");
 }
 

Reply via email to