scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit f118bda209b47d84d74d5e5fe50b1f97d9a368d4
parent 738ceb3db836a394105b82b4bf57ee37b90cb05f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  3 Feb 2018 21:31:54 +0100

[as] Remove FNTYPE and FMASK

We can use only one bit for every type of symbol.

Diffstat:
Mas/as.h | 17+++++++----------
Mas/myro.c | 6++----
Mas/parser.c | 2+-
Mas/symbol.c | 6++----
4 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/as/as.h b/as/as.h @@ -3,16 +3,13 @@ * type of segment */ enum symflags { - FTMASK = 0x3, - FNTYPE = 0, - FREG = 1, - FSECT = 2, - FSYM = 3, - - FCOMMON = 1 << 2, - FEXTERN = 1 << 3, - FDEF = 1 << 4, - FGLOBAL = 1 << 5, + FREG = 1 << 0, + FSECT = 1 << 1, + FSYM = 1 << 2, + FCOMMON = 1 << 3, + FEXTERN = 1 << 4, + FDEF = 1 << 5, + FGLOBAL = 1 << 6, FABS = 1 << 7, }; diff --git a/as/myro.c b/as/myro.c @@ -27,7 +27,7 @@ writestrings(FILE *fp) off = sizeof(FORMAT); for (sym = symlist; sym; sym = sym->next) { - if ((sym->flags & FTMASK) == FREG) + if (sym->flags & FREG) continue; str = &sym->name; len = strlen(str->buf) + 1; @@ -100,14 +100,12 @@ getsymflags(Symbol *sym) static size_t writesymbols(FILE *fp) { - int type; Symbol *sym; size_t off = 0; struct myrosym symbol; for (sym = symlist; sym; sym = sym->next) { - type = sym->flags & FTMASK; - if (type == FREG || type == FSECT) + if (sym->flags & (FREG|FSECT)) continue; symbol.name = sym->name.offset; symbol.type = -1; diff --git a/as/parser.c b/as/parser.c @@ -84,7 +84,7 @@ out_loop: tok2str(); yylval.sym = lookup(yytext); - return ((yylval.sym->flags & FTMASK) == FREG) ? REG : IDEN; + return (yylval.sym->flags & FREG) ? REG : IDEN; } static int diff --git a/as/symbol.c b/as/symbol.c @@ -64,7 +64,7 @@ lookup(char *name) sym = xmalloc(sizeof(*sym)); sym->name = newstring(name); - sym->flags = FNTYPE; + sym->flags = 0; sym->size = sym->value = 0; sym->section = cursec; sym->hash = *list; @@ -190,12 +190,10 @@ setsec(char *name, char *attr) { Section *sec; Symbol *sym; - int flags, type; cursec = NULL; sym = lookup(name); - type = sym->flags & FTMASK; - if (type != FNTYPE && type != FSECT) + if (sym->flags & ~FSECT) error("invalid section name '%s'", name); if ((sec = sym->section) == NULL) {