scc

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

commit 5b8415def1c73c66509eb6ad3c0e5fa021cf6d19
parent 924e73fca9662a6295f2cb5c19be2eac1c2033c9
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
Date:   Fri, 15 Apr 2016 14:13:46 +0200

[cc2-qbe] Fix load() in cgen.c

This load has to load the symbol into a temporary, but it was
doing a bad job.

Diffstat:
Mcc2/arch/qbe/cgen.c | 34++++++++++++++++++++--------------
Mcc2/arch/qbe/code.c | 1+
Mcc2/cc2.h | 3++-
3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -10,19 +10,29 @@ enum sflags { }; static Node * -load(Node *np) +tmpnode(Node *np) { - Node *new; Symbol *sym; - new = newnode(); sym = getsym(TMPSYM); sym->type = np->type; - new->u.sym = sym; - new->op = OLOAD; + sym->kind = TMP; + np->u.sym = sym; + np->op = OTMP; + np->flags |= ISTMP; + return np; +} + +static Node * +load(Node *np) +{ + Node *new; + + new = tmpnode(newnode()); new->left = np; new->type = np->type; - new->flags |= ISTMP; + code(OLOAD, new, np, NULL); + return new; } @@ -67,15 +77,11 @@ cgen(Node *np) case OBXOR: case OCPL: if ((l->flags & (ISTMP|ISCONS)) == 0) - np->left = load(l); + l = np->left = load(l); if ((r->flags & (ISTMP|ISCONS)) == 0) - np->right = load(r); - sym = getsym(TMPSYM); - sym->type = np->type; - np->flags |= ISTMP; - np->u.sym = sym; - np->op = OTMP; - code(op, np, np->left, np->right); + r = np->right = load(r); + tmpnode(np); + code(op, np, l, r); return np; case ONOP: case OBLOOP: diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c @@ -223,6 +223,7 @@ addr2txt(Addr *a) switch (a->kind) { case AUTO: case LABEL: + case TMP: return symname(a->u.sym); default: abort(); diff --git a/cc2/cc2.h b/cc2/cc2.h @@ -40,7 +40,7 @@ enum op { STRING = '"', LABEL = 'L', INDEX = 'I', - OTMP = 'T', + TMP = 'T', /* storage class */ GLOB = 'G', EXTRN = 'X', @@ -49,6 +49,7 @@ enum op { MEMBER = 'M', /* operands */ OMEM = 'M', + OTMP = 'T', OAUTO = 'A', OREG = 'R', OCONST = '#',