scc

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

commit 4d656cc381de1f2573bfc90a74a878a00f95148d
parent 5ee0c779060595407f6042414f4bf9c1165634b9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 17 Mar 2015 06:25:43 +0000

Remove payload in Node

This payload should be part of the symbol attached to the node.
In other case we have duplicated values in the node and in the
symbol.

Diffstat:
cc2/cc2.h | 12++++++------
cc2/cgen.c | 41+++++++++++++++++++++++------------------
cc2/code.c | 8++++----
cc2/parser.c | 6+++---
4 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -62,6 +62,10 @@ struct symbol { short off; } v; struct { + /* TODO: Admit inmediate of other type */ + TINT imm; + } i; + struct { short addr; } l; struct { @@ -78,12 +82,8 @@ struct node { Type type; uint8_t complex; uint8_t addable; - union { - Symbol *sym; - /* TODO: Admit inmediate of other type */ - TINT imm; - uint8_t reg; - } u; + uint8_t reg; + Symbol *sym; struct node *left, *right; }; diff --git a/cc2/cgen.c b/cc2/cgen.c @@ -22,63 +22,63 @@ static char pair[] = { Node reg_E = { .op = REG, - .u.reg = E + .reg = E }, reg_D = { .op = REG, - .u.reg = D + .reg = D }, reg_H = { .op = REG, - .u.reg = H + .reg = H }, reg_L = { .op = REG, - .u.reg = L + .reg = L }, reg_C = { .op= REG, - .u.reg = C + .reg = C }, reg_B = { .op= REG, - .u.reg = B + .reg = B }, reg_A = { .op= REG, - .u.reg = A + .reg = A }, reg_IYL = { .op = REG, - .u.reg = IYL + .reg = IYL }, reg_IYH = { .op = REG, - .u.reg = IYH + .reg = IYH }, reg_DE = { .op = REG, - .u.reg = DE + .reg = DE }, reg_HL = { .op = REG, - .u.reg = HL + .reg = HL }, reg_BC = { .op = REG, - .u.reg = BC + .reg = BC }, reg_IX = { .op = REG, - .u.reg = IX + .reg = IX }, reg_IY = { .op = REG, - .u.reg = IY + .reg = IY }, reg_SP = { .op = REG, - .u.reg = SP + .reg = SP }; Node *regs[] = { @@ -140,7 +140,7 @@ moveto(Node *np, uint8_t reg) } break; case AUTO: - sym = np->u.sym; + sym = np->sym; switch (np->type.size) { case 1: code(LDL, regs[reg], np); @@ -266,7 +266,7 @@ add(Node *np) accum(lp); break; case REG: - if (lp->u.reg != A) + if (lp->reg != A) moveto(lp, A); switch (rp->op) { case REG: @@ -285,7 +285,7 @@ add(Node *np) add_A: code(ADD, lp, rp); np->op = REG; - np->u.reg = A; + np->reg = A; break; case 2: case 4: @@ -306,7 +306,12 @@ assign(Node *np) code(LDL, lp, rp); break; case REG: + code(MOV, lp, rp); + break; case MEM: + index(lp); + code(LDL, lp, rp); + break; default: abort(); } diff --git a/cc2/code.c b/cc2/code.c @@ -91,16 +91,16 @@ addr(char op, Node *np, Addr *addr) { switch (addr->kind = np->op) { case REG: - addr->u.reg = np->u.reg; + addr->u.reg = np->reg; break; case CONST: - addr->u.i = np->u.imm; + /* TODO: Take the immediate from some place */ break; case AUTO: - addr->u.i = np->u.sym->u.v.off; + addr->u.i = np->sym->u.v.off; break; case MEM: - addr->u.sym = np->u.sym; + addr->u.sym = np->sym; break; case INDEX: break; diff --git a/cc2/parser.c b/cc2/parser.c @@ -235,7 +235,7 @@ imm(TINT i, Type *tp) np->op = CONST; np->type = *tp; - np->u.imm = i; + /* TODO: assign the integer to something */ np->left = np->right = NULL; } @@ -299,7 +299,7 @@ variable(uint8_t t, char *token) Node *np = newnode(); Symbol *sym = symbol(t, token); - np->u.sym = sym; + np->sym = sym; np->op = sym->u.v.sclass; np->type = sym->u.v.type; np->left = np->right = NULL; @@ -361,7 +361,7 @@ label(char *token) np->left = np->right = NULL; np->op = LABEL; - np->u.sym = local(token); + np->sym = local(token); push(np); }