ref: 85ebcbcd9fe786761fb9c16e01a015376b14ad5f
parent: 76d61787b88efc7692984fbb5779f5ca55a21691
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Apr 22 21:16:30 EDT 2016
[cc2-qbe] Add support for integer constants They are needed in a lot of different places.
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -123,6 +123,7 @@
[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)
@@ -151,7 +152,6 @@
static char *
symname(Symbol *sym)
{
- static char name[ADDR_LEN];
static unsigned id;
char c = sigil(sym);
@@ -159,12 +159,12 @@
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();
}
@@ -172,9 +172,9 @@
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
@@ -343,6 +343,9 @@
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:
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -34,7 +34,7 @@
addr->u.reg = np->u.reg;
break;
case SCONST:
- abort();
+ addr->u.i = np->u.i;
break;
case SLABEL:
case SAUTO:
@@ -44,7 +44,6 @@
default:
abort();
}
-
}
void