scc

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

commit ee745a15aaf58a70f4dd922e610c665d030f30a0
parent d2d85525987cfb0822d2cb0163a7323acbbadd1e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  3 Jul 2017 10:45:46 +0100

[cc1] Add support for union designators in emit

Union is similar to struct, but in this case we only emit the last
designated element.

Diffstat:
Mcc1/code.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/cc1/code.c b/cc1/code.c @@ -337,7 +337,7 @@ static void emitdesig(Node *np, Type *tp) { Symbol *sym; - size_t n; + size_t n; /* TODO: This should be SIZET */ Node *aux; Type *p; @@ -362,7 +362,11 @@ emitdesig(Node *np, Type *tp) aux = (sym) ? *sym->u.init : convert(constnode(zero), tp, 0); emitexp(OEXPR, aux); break; - /* TODO: case UNION: */ + case UNION: + n = tp->n.elem-1; + aux = (sym) ? sym->u.init[n] : NULL; + emitdesig(aux, tp->p.fields[n]->type); + break; case STRUCT: case ARY: for (n = 0; n < tp->n.elem; ++n) {