[hackers] [scc] Revert "[cc2] Remove sigil function from qbe" || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 14 Apr 2016 08:05:15 +0200 (CEST)

commit df8e77f218a09fa630992c262d652586ac18ac95
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Thu Apr 14 08:01:55 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
CommitDate: Thu Apr 14 08:01:55 2016 +0200

    Revert "[cc2] Remove sigil function from qbe"
    
    This reverts commit 669131252b1f35c13e32a47e22e84026ac69d1a8.

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 38e9390..037b1ab 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -6,24 +6,49 @@
 #include "../../cc2.h"
 #include "../../../inc/sizes.h"
 
+/*
+ * : is for user-defined Aggregate Types
+ * $ is for globals (represented by a pointer)
+ * % is for function-scope temporaries
+ * _AT_ is for block labels
+ */
+static char
+sigil(Symbol *sym)
+{
+ switch (sym->kind) {
+ case EXTRN:
+ case GLOB:
+ case PRIVAT:
+ case LOCAL:
+ return '$';
+ case AUTO:
+ case REG:
+ return '%';
+ default:
+ abort();
+ }
+}
+
 static char *
 symname(Symbol *sym)
 {
- static char name[IDENTSIZ+1];
+ static char name[IDENTSIZ+2];
         static unsigned short id;
+ char c = sigil(sym);
 
         if (sym->name) {
                 switch (sym->kind) {
                 case EXTRN:
                 case GLOB:
                 case PRIVAT:
+ sprintf(name, "%c%s", c, sym->name);
                         return sym->name;
                 }
         }
 
         if (sym->numid == 0 && (sym->numid = ++id) == 0)
                 error(EIDOVER);
- sprintf(name, ".L%d", sym->numid);
+ sprintf(name, "%c.%d", c, sym->numid);
 
         return name;
 }
_AT_@ -115,7 +140,7 @@ defglobal(Symbol *sym)
                 return;
         if (sym->kind == GLOB)
                 fputs("export ", stdout);
- printf("data $%s = {\n", symname(sym));
+ printf("data %s = {\n", symname(sym));
         if (sym->type.flags & INITF)
                 return;
         printf("\tz\t%llu\n}\n", (unsigned long long) sym->type.size);
_AT_@ -146,7 +171,7 @@ writeout(void)
 {
         if (curfun->kind == GLOB)
                 fputs("export ", stdout);
- printf("function $%s(", symname(curfun));
+ printf("function %s(", symname(curfun));
         puts("){");
         puts("}");
 }
Received on Thu Apr 14 2016 - 08:05:15 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 14 2016 - 08:12:29 CEST