commit 2faa69e787edb65a43a9d58c394adf27eb4dcbc8
parent 9b054a5140eadd3ee241af25dd86ae82ad608669
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date: Sat, 23 Apr 2016 01:16:30 +0200
[cc2-qbe] Add support for integer constants
They are needed in a lot of different places.
Diffstat:
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
@@ -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)
@@ -151,7 +152,6 @@ sigil(Symbol *sym)
static char *
symname(Symbol *sym)
{
- static char name[ADDR_LEN];
static unsigned id;
char c = sigil(sym);
@@ -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();
}
@@ -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
@@ -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
@@ -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:
@@ -44,7 +44,6 @@ addr(Node *np, Addr *addr)
default:
abort();
}
-
}
void