(wrong string) ä-Ollila

From: <git_AT_suckless.org>
Date: Fri, 15 Apr 2016 12:29:15 +0200 (CEST)

commit 11111b2afe6b8510fdd8cf21a6058f7a60820117
Author: Pekka Jylhä-Ollila <pekka.jylha.ollila_AT_gmail.com>
AuthorDate: Thu Apr 14 15:15:14 2016 +0300
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Apr 15 09:51:30 2016 +0200

    [cc2-qbe] Print function parameter types and names
    
    Print out function parameter names and types in the qbe writeout function.
    I changed the 'locals' variable to global so it could be referenced,
    and the size2asm function to return a pointer instead of printing.
    
    I had to disable the calls to apply(sethi) and apply(cgen) in cc2/main.c
    while testing because they were causing segfaults.
    
    Example output:
    
    $ cat test.c
    int test(char a, int b, long c)
    {
            return a * b * c;
    }
    
    int main(int argc, char **argv)
    {
            int a = 1;
            int b = 2;
            int c = 3;
    
            return test(a, b, c);
    }
    $ ./cc1/cc1 test.c | ./cc2/cc2
    export function $test(b %.1, w %.2, l %.3){
    }
    export function $main(w %.4, l %.5){
    }

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 56d2def..52e606e 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -103,34 +103,25 @@ emittree(Node *np)
         }
 }
 
-static void
+static char *
 size2asm(Type *tp)
 {
- char *s;
-
- /* In qbe we can ignore the aligment because it handles it */
-
         if (tp->flags & STRF) {
- s = "b\t";
+ return "b";
         } else {
                 switch (tp->size) {
                 case 1:
- s = "b\t";
- break;
+ return "b";
                 case 2:
- s = "h\t";
- break;
+ return "h";
                 case 4:
- s = "w\t";
- break;
+ return "w";
                 case 8:
- s = "l\t";
- break;
+ return "l";
                 default:
                         abort();
                 }
         }
- fputs(s, stdout);
 }
 
 void
_AT_@ -149,6 +140,7 @@ defglobal(Symbol *sym)
 void
 defpar(Symbol *sym)
 {
+ sym->type.flags |= PARF;
 }
 
 void
_AT_@ -159,8 +151,7 @@ defvar(Symbol *sym)
 void
 data(Node *np)
 {
- putchar('\t');
- size2asm(&np->type);
+ printf("\t%s\t", size2asm(&np->type));
         emittree(np);
         putchar(',');
         putchar('\n');
_AT_@ -169,9 +160,15 @@ data(Node *np)
 void
 writeout(void)
 {
+ Symbol *p;
+
         if (curfun->kind == GLOB)
                 fputs("export ", stdout);
         printf("function %s(", symname(curfun));
+
+ for (p = locals; p && p->type.flags & PARF; p = p->next)
+ printf("%s %s,", size2asm(&p->type), symname(p));
+
         puts("){");
         puts("}");
 }
diff --git a/cc2/cc2.h b/cc2/cc2.h
index e0de200..eb63665 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -5,6 +5,7 @@ enum tflags {
         STRF = 8,
         UNIONF = 16,
         FUNF = 32,
+ PARF = 64,
         INITF = 128
 };
 
_AT_@ -211,3 +212,6 @@ extern Symbol *getsym(unsigned id);
 extern void popctx(void);
 extern void pushctx(void);
 extern void freesym(Symbol *sym);
+
+/* globals */
+extern Symbol *locals;
diff --git a/cc2/symbol.c b/cc2/symbol.c
index 0a54ae1..a761abf 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -11,8 +11,9 @@
 
 #define NR_SYMHASH 64
 
+Symbol *locals;
+
 static Symbol *symtab[NR_SYMHASH], *curlocal;
-static Symbol *locals;
 static int infunction;
 
 
Received on Fri Apr 15 2016 - 12:29:15 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 15 2016 - 12:36:21 CEST