[hackers] [scc] [cc2] Create a enum for storage classes || Roberto E. Vargas Caballero
commit 8c13f50ab5ae9ca834cd32ed55faec745d1a96c6
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Mon Apr 18 03:15:35 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Mon Apr 18 03:15:35 2016 +0200
[cc2] Create a enum for storage classes
This is the enum for the different storage class, or in a general
form, for the different kind of symbols we are going to have in
the the compiler (not all the target willl use all the different kinds).
This patch foud several errors, and it created new bugs.
diff --git a/cc2/arch/amd64-sysv/code.c b/cc2/arch/amd64-sysv/code.c
index cc7a906..29617b8 100644
--- a/cc2/arch/amd64-sysv/code.c
+++ b/cc2/arch/amd64-sysv/code.c
_AT_@ -38,9 +38,9 @@ symname(Symbol *sym)
if (sym->name) {
switch (sym->kind) {
- case EXTRN:
- case GLOB:
- case PRIVAT:
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
return sym->name;
}
}
_AT_@ -155,11 +155,11 @@ label(Symbol *sym)
segment(seg);
switch (sym->kind) {
- case EXTRN:
+ case SEXTRN:
printf("\t.extern\t%s\n", name);
- case LOCAL:
+ case SLOCAL:
return;
- case GLOB:
+ case SGLOB:
printf("\t.global\t%s\n", name);
if (seg == BSSSEG) {
printf("\t.comm\t%s,%llu\n",
_AT_@ -169,7 +169,7 @@ label(Symbol *sym)
break;
}
if (sym->type.align != 1)
- printf("\t.align\t%d\n",sym->type.align );
+ printf("\t.align\t%lld\n", (long long) sym->type.align );
printf("%s:\n", name);
}
_AT_@ -177,7 +177,7 @@ void
defglobal(Symbol *sym)
{
label(sym);
- if (sym->kind == EXTRN || (sym->type.flags & INITF))
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
return;
size2asm(&sym->type);
puts("0");
diff --git a/cc2/arch/i386-sysv/code.c b/cc2/arch/i386-sysv/code.c
index c42256d..f55ff66 100644
--- a/cc2/arch/i386-sysv/code.c
+++ b/cc2/arch/i386-sysv/code.c
_AT_@ -38,9 +38,9 @@ symname(Symbol *sym)
if (sym->name) {
switch (sym->kind) {
- case EXTRN:
- case GLOB:
- case PRIVAT:
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
return sym->name;
}
}
_AT_@ -154,11 +154,11 @@ label(Symbol *sym)
segment(seg);
switch (sym->kind) {
- case EXTRN:
+ case SEXTRN:
printf("\t.extern\t%s\n", name);
- case LOCAL:
+ case SLOCAL:
return;
- case GLOB:
+ case SGLOB:
printf("\t.global\t%s\n", name);
if (seg == BSSSEG) {
printf("\t.comm\t%s,%llu\n",
_AT_@ -168,7 +168,7 @@ label(Symbol *sym)
break;
}
if (sym->type.align != 1)
- printf("\t.align\t%d\n",sym->type.align );
+ printf("\t.align\t%lld\n", (long long) sym->type.align );
printf("%s:\n", name);
}
_AT_@ -176,7 +176,7 @@ void
defglobal(Symbol *sym)
{
label(sym);
- if (sym->kind == EXTRN || (sym->type.flags & INITF))
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
return;
size2asm(&sym->type);
puts("0");
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index c4f503a..5b1e246 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -16,7 +16,7 @@ tmpnode(Node *np)
sym = getsym(TMPSYM);
sym->type = np->type;
- sym->kind = TMP;
+ sym->kind = STMP;
np->u.sym = sym;
np->op = OTMP;
np->flags |= ISTMP;
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index fbac10f..db41fb6 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -42,13 +42,14 @@ static char
sigil(Symbol *sym)
{
switch (sym->kind) {
- case EXTRN:
- case GLOB:
- case PRIVAT:
- case LOCAL:
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ case SLOCAL:
return '$';
- case AUTO:
- case REG:
+ case SAUTO:
+ case SREG:
+ case STMP:
return '%';
default:
abort();
_AT_@ -64,10 +65,10 @@ symname(Symbol *sym)
if (sym->name) {
switch (sym->kind) {
- case EXTRN:
- case GLOB:
- case PRIVAT:
- case AUTO:
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ case SAUTO:
sprintf(name, "%c%s", c, sym->name);
return name;
default:
_AT_@ -156,9 +157,9 @@ size2asm(Type *tp)
void
defglobal(Symbol *sym)
{
- if (sym->kind == EXTRN)
+ if (sym->kind == SEXTRN)
return;
- if (sym->kind == GLOB)
+ if (sym->kind == SGLOB)
fputs("export ", stdout);
printf("data %s = {\n", symname(sym));
if (sym->type.flags & INITF)
_AT_@ -193,7 +194,7 @@ writeout(void)
Type *tp;
char *sep;
- if (curfun->kind == GLOB)
+ if (curfun->kind == SGLOB)
fputs("export ", stdout);
printf("function %s %s(", size2asm(&curfun->rtype), symname(curfun));
_AT_@ -226,9 +227,9 @@ addr2txt(Addr *a)
static char buff[40];
switch (a->kind) {
- case AUTO:
- case LABEL:
- case TMP:
+ case SAUTO:
+ case SLABEL:
+ case STMP:
return symname(a->u.sym);
default:
abort();
diff --git a/cc2/arch/z80/code.c b/cc2/arch/z80/code.c
index 22a3f45..8b200fd 100644
--- a/cc2/arch/z80/code.c
+++ b/cc2/arch/z80/code.c
_AT_@ -39,11 +39,11 @@ symname(Symbol *sym)
if (sym->name) {
switch (sym->kind) {
- case GLOB:
- case EXTRN:
+ case SGLOB:
+ case SEXTRN:
snprintf(name, sizeof(name), "_%s", sym->name);
return name;
- case PRIVAT:
+ case SPRIV:
return sym->name;
}
}
_AT_@ -70,10 +70,10 @@ label(Symbol *sym)
segment(seg);
switch (sym->kind) {
- case EXTRN:
+ case SEXTRN:
printf("\tEXTRN\t%s\n", name);
return;
- case GLOB:
+ case SGLOB:
printf("\tPUBLIC\t%s\n", name);
break;
}
_AT_@ -168,7 +168,7 @@ defpar(Symbol *sym)
{
TSIZE align, size;
- if (sym->kind != REG && sym->kind != AUTO)
+ if (sym->kind != SREG && sym->kind != SAUTO)
return;
align = sym->type.align;
size = sym->type.size;
_AT_@ -176,7 +176,7 @@ defpar(Symbol *sym)
offpar -= align-1 & ~align;
sym->u.off = offpar;
offpar -= size;
- sym->kind = AUTO;
+ sym->kind = SAUTO;
}
void
_AT_@ -184,7 +184,7 @@ defvar(Symbol *sym)
{
TSIZE align, size;
- if (sym->kind != REG && sym->kind != AUTO)
+ if (sym->kind != SREG && sym->kind != SAUTO)
return;
align = sym->type.align;
size = sym->type.size;
_AT_@ -192,14 +192,14 @@ defvar(Symbol *sym)
offvar += align-1 & ~align;
sym->u.off = offvar;
offvar += size;
- sym->kind = AUTO;
+ sym->kind = SAUTO;
}
void
defglobal(Symbol *sym)
{
label(sym);
- if (sym->kind == EXTRN || (sym->type.flags & INITF))
+ if (sym->kind == SEXTRN || (sym->type.flags & INITF))
return;
size2asm(&sym->type);
puts("0");
diff --git a/cc2/cc2.h b/cc2/cc2.h
index f4d25f5..2b34008 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -9,6 +9,19 @@ enum tflags {
INITF = 128
};
+enum sclass {
+ SAUTO = 'A',
+ SREG = 'R',
+ SLABEL = 'L',
+ SINDEX = 'I',
+ STMP = 'N',
+ SGLOB = 'G',
+ SEXTRN = 'X',
+ SPRIV = 'Y',
+ SLOCAL = 'T',
+ SMEMB = 'M',
+};
+
enum op {
/* types */
ELLIPSIS = 'E',
_AT_@ -33,20 +46,8 @@ enum op {
ONAME = '"',
/* kind of operand */
NONE = 0,
- MEM = 'M',
- AUTO = 'A',
- REG = 'R',
CONST = '#',
STRING = '"',
- LABEL = 'L',
- INDEX = 'I',
- TMP = 'T',
- /* storage class */
- GLOB = 'G',
- EXTRN = 'X',
- PRIVAT = 'Y',
- LOCAL = 'T',
- MEMBER = 'M',
/* operands */
OMEM = 'M',
OTMP = 'T',
diff --git a/cc2/code.c b/cc2/code.c
index da2db80..fd60dc2 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -30,17 +30,15 @@ static void
addr(Node *np, Addr *addr)
{
switch (addr->kind = np->op) {
- case REG:
+ case SREG:
addr->u.reg = np->u.reg;
break;
case CONST:
abort();
break;
- case LABEL:
- addr->u.sym = np->u.sym;
- break;
- case AUTO:
- case TMP:
+ case SLABEL:
+ case SAUTO:
+ case STMP:
addr->u.sym = np->u.sym;
break;
default:
diff --git a/cc2/parser.c b/cc2/parser.c
index 6de47cb..d03f036 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -27,7 +27,7 @@ Type funtype = {
union tokenop {
void *arg;
- int op;
+ unsigned op;
};
typedef void parsefun(char *, union tokenop);
_AT_@ -44,14 +44,14 @@ static struct decoc {
void (*parse)(char *token, union tokenop);
union tokenop u;
} optbl[] = { /* eval parse args */
- ['A'] = { vardecl, symbol, .u.op = OAUTO},
- ['R'] = { vardecl, symbol, .u.op = OREG},
- ['G'] = { vardecl, symbol, .u.op = OMEM},
- ['X'] = { vardecl, symbol, .u.op = OMEM},
- ['Y'] = { vardecl, symbol, .u.op = OMEM},
- ['T'] = { vardecl, symbol, .u.op = OMEM},
- ['M'] = { flddecl, symbol, .u.op = OMEM},
- ['L'] = { labeldcl, symbol, .u.op = OLABEL},
+ ['A'] = { vardecl, symbol, .u.op = SAUTO<<8 | OAUTO},
+ ['R'] = { vardecl, symbol, .u.op = SREG<<8 | OREG},
+ ['G'] = { vardecl, symbol, .u.op = SGLOB<<8 | OMEM},
+ ['X'] = { vardecl, symbol, .u.op = SEXTRN<<8 | OMEM},
+ ['Y'] = { vardecl, symbol, .u.op = SPRIV<<8 | OMEM},
+ ['T'] = { vardecl, symbol, .u.op = SLOCAL<<8 | OMEM},
+ ['M'] = { flddecl, symbol, .u.op = SMEMB<<8 | OMEM},
+ ['L'] = { labeldcl, symbol, .u.op = SLABEL<<8 | OLABEL},
['C'] = { NULL, type, .u.arg = &int8type},
['I'] = { NULL, type, .u.arg = &int16type},
_AT_@ -182,10 +182,10 @@ symbol(char *token, union tokenop u)
{
Node *np;
- sclass = *token++;
+ sclass = u.op >> 8;
np = newnode();
- np->u.sym = getsym(atoi(token));
- np->op = u.op;
+ np->u.sym = getsym(atoi(token+1));
+ np->op = u.op & 0xFF;
push(np);
}
_AT_@ -492,14 +492,14 @@ decl(Symbol *sym)
curfun = sym;
} else {
switch (sym->kind) {
- case EXTRN:
- case GLOB:
- case PRIVAT:
- case LOCAL:
+ case SEXTRN:
+ case SGLOB:
+ case SPRIV:
+ case SLOCAL:
defglobal(sym);
break;
- case AUTO:
- case REG:
+ case SAUTO:
+ case SREG:
if (!curfun)
error(ESYNTAX);
((inpars) ? defpar : defvar)(sym);
Received on Mon Apr 18 2016 - 21:24:05 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 18 2016 - 21:24:41 CEST