scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit a5becc37677b6c86a026ce0ef9819e821d2d046a
parent 4dca54568291a99779209f6b381435a6a62a232d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 14 Aug 2015 15:37:16 +0200

Fix emit field

There were several errors in TEST002:

,
2,$c

The field operator was not emited, so TEST002 was failing.

Diffstat:
cc1/code.c | 17++++-------------
cc1/expr.c | 3+--
cc1/tests/test002.c | 5++---
3 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -9,7 +9,7 @@ static void emitbin(unsigned, void *), emitcast(unsigned, void *), emitswitch(unsigned, void *), - emitsym(unsigned, void *), emitfield(unsigned, void *), + emitsym(unsigned, void *), emitexp(unsigned, void *), emitsymid(unsigned, void *), emittext(unsigned, void *), emitfun(unsigned, void *), @@ -62,7 +62,8 @@ char *optxt[] = { [OELOOP] = "\tb", [OBLOOP] = "\td", [OPAR] = "p", - [OCALL] = "c" + [OCALL] = "c", + [OFIELD] = "." }; void (*opcode[])(unsigned, void *) = { @@ -106,7 +107,7 @@ void (*opcode[])(unsigned, void *) = { [OSYM] = emitsym, [OASK] = emitbin, [OCOLON] = emitbin, - [OFIELD]= emitfield, + [OFIELD]= emitbin, [OEXPR] = emitexp, [OLABEL] = emitsymid, [ODEFAULT] = emitsymid, @@ -368,16 +369,6 @@ emitswitch(unsigned op, void *arg) printf("\teI\t#%0x", lcase->nr); } -void -emitfield(unsigned op, void *arg) -{ - Node *np = arg; - - emitnode(np->left); - putchar('\t'); - emitvar(np->sym); -} - Node * node(unsigned op, Type *tp, Node *lp, Node *rp) { diff --git a/cc1/expr.c b/cc1/expr.c @@ -590,9 +590,8 @@ field(Node *np) if ((sym = yylval.sym) == NULL) error("incorrect field in struct/union"); next(); - np = node(OFIELD, sym->type, np, NULL); + np = node(OFIELD, sym->type, np, varnode(sym)); np->lvalue = 1; - np->sym = sym; return np; default: error("struct or union expected"); diff --git a/cc1/tests/test002.c b/cc1/tests/test002.c @@ -2,18 +2,17 @@ name: TEST002 description: Test forward references before definition of types output: -S2 S G4 P x F1 X6 F1 main G6 F1 main { - S2 S ( -M5 I +M5 I i ) A2 S2 y A2 M5 .I #I0 :I - G4 @S2 A2 :S + G4 @S2 A2 :S2 } */