[hackers] [scc] [cc2-qbe] Add support for integer constants || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 23 Apr 2016 22:20:26 +0200 (CEST)

commit 2faa69e787edb65a43a9d58c394adf27eb4dcbc8
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Sat Apr 23 01:16:30 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Sat Apr 23 01:16:30 2016 +0200

    [cc2-qbe] Add support for integer constants
    
    They are needed in a lot of different places.

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 502bfcd..c26723b 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -123,6 +123,7 @@ static struct opdata {
         [ASSLTOS]= {.fun = unary, .txt = "truncd", .letter = 's'},
 };
 
+static char buff[ADDR_LEN];
 /*
  * : is for user-defined Aggregate Types
  * $ is for globals (represented by a pointer)
_AT_@ -151,7 +152,6 @@ sigil(Symbol *sym)
 static char *
 symname(Symbol *sym)
 {
- static char name[ADDR_LEN];
         static unsigned id;
         char c = sigil(sym);
 
_AT_@ -159,12 +159,12 @@ symname(Symbol *sym)
                 switch (sym->kind) {
                 case SEXTRN:
                 case SGLOB:
- sprintf(name, "%c%s", c, sym->name);
- return name;
+ sprintf(buff, "%c%s", c, sym->name);
+ return buff;
                 case SPRIV:
                 case SAUTO:
- sprintf(name, "%c%s.%u", c, sym->name, sym->id);
- return name;
+ sprintf(buff, "%c%s.%u", c, sym->name, sym->id);
+ return buff;
                 default:
                         abort();
                 }
_AT_@ -172,9 +172,9 @@ symname(Symbol *sym)
 
         if (sym->numid == 0 && (sym->numid = ++id) == 0)
                 error(EIDOVER);
- sprintf(name, "%c.%u", c, sym->numid);
+ sprintf(buff, "%c.%u", c, sym->numid);
 
- return name;
+ return buff;
 }
 
 static void
_AT_@ -343,6 +343,9 @@ static char *
 addr2txt(Addr *a)
 {
         switch (a->kind) {
+ case SCONST:
+ sprintf(buff, "%llu", (unsigned long long) a->u.i);
+ return buff;
         case SAUTO:
         case SLABEL:
         case STMP:
diff --git a/cc2/code.c b/cc2/code.c
index be77fe1..c5ba26b 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -34,7 +34,7 @@ addr(Node *np, Addr *addr)
                 addr->u.reg = np->u.reg;
                 break;
         case SCONST:
- abort();
+ addr->u.i = np->u.i;
                 break;
         case SLABEL:
         case SAUTO:
_AT_@ -44,7 +44,6 @@ addr(Node *np, Addr *addr)
         default:
                 abort();
         }
-
 }
 
 void
Received on Sat Apr 23 2016 - 22:20:26 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 23 2016 - 22:24:14 CEST