scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 27b3c745a4bbdf3c0e6ed5d482b2fd673ba0fd83
parent 797ee1ebf6f6949ded2a493fcd0ebd844f4463db
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 21 Apr 2014 06:59:50 +0200

Add symbol flag in Symbol

This flag help to detect when a node is a symbol.

Diffstat:
Mcc1.h | 1+
Mcode.c | 8++++++--
Mexpr.c | 2+-
3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/cc1.h b/cc1.h @@ -193,6 +193,7 @@ typedef struct node { uint8_t typeop; struct { bool lvalue : 1; + bool symbol: 1; } b; union unode { Symbol *sym; diff --git a/code.c b/code.c @@ -57,7 +57,7 @@ node(Inst code, Type *tp, union unode u, uint8_t nchilds) np->utype = UNQUAL(tp); np->typeop = np->utype->op; np->u = u; - np->b.lvalue = 0; + np->b.symbol = np->b.lvalue = 0; return np; } @@ -246,5 +246,9 @@ ternarycode(Node *cond, Node *ifyes, Node *ifno) Node * constcode(Symbol *sym) { - return node(emitconst, inttype, SYM(sym), 0); + Node *np; + + np = node(emitconst, inttype, SYM(sym), 0); + np->b.symbol = 1; + return np; } diff --git a/expr.c b/expr.c @@ -355,7 +355,7 @@ primary(void) if ((sym = yylval.sym) == NULL) error("'%s' undeclared", yytext); np = node(emitsym, sym->type, SYM(sym), 0); - np->b.lvalue = 1; + np->b.symbol = np->b.lvalue = 1; next(); break; case CONSTANT: