scc

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

commit bb043d47fd80b8aafdacb217ce4f48677c587df1
parent d6a0fc915b3162e6dc096a8987186ad432022e4b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 31 May 2016 08:30:36 +0200

[cc2] Simplify code.c:addr()

This function can be called with multiple different arguments, and
we where dealing the different symbols like different cases, but it
was the same case because we only had to use the storage class
already stored in the symbol by parser.c:vardecl().

Diffstat:
cc2/code.c | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/cc2/code.c b/cc2/code.c @@ -29,26 +29,31 @@ nextpc(void) static void addr(Node *np, Addr *addr) { + Symbol *sym; + switch (np->op) { case OREG: + /* TODO: + * At this moment this op is used also for register variables + */ addr->kind = SREG; addr->u.reg = np->u.reg; break; case OCONST: - addr->kind = OCONST; + addr->kind = SCONST; + /* TODO: Add support for more type of constants */ addr->u.i = np->u.i; break; + case OTMP: case OLABEL: - addr->kind = SLABEL; - goto symbol; case OAUTO: - addr->kind = SAUTO; - goto symbol; - case OTMP: - addr->kind = STMP;; - symbol: - addr->u.sym = np->u.sym; + case OMEM: + sym = np->u.sym; + addr->kind = sym->kind; + addr->u.sym = sym; break; + default: + abort(); } }