scc

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

commit 61e2e3177d38dc8a7b798a370408d58901e3d550
parent 87dab1114c64c72d7a40b5f9c048c4e1a7541607
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  7 Jun 2016 09:19:17 +0200

[cc2-qbe] Add assign() in cgen.c

We need to do assigments like temporal step in some of the operations
of the nodes, so having this function can make the code simpler.

Diffstat:
Mcc2/arch/qbe/cgen.c | 45+++++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c @@ -289,6 +289,32 @@ abbrev(Node *np) return np->right = cgen(tmp); } +static Node * +assign(Node *to, Node *from) +{ + Type *tp = &to->type; + int op; + + switch (tp->size) { + case 1: + op = ASSTB; + break; + case 2: + op = ASSTH; + break; + case 4: + op = (tp->flags & INTF) ? ASSTW : ASSTS; + break; + case 8: + op = (tp->flags & INTF) ? ASSTL : ASSTD; + break; + default: + abort(); + } + code(op, to, from, NULL); + return from; +} + /* TODO: Fix "memory leaks" */ Node * cgen(Node *np) @@ -379,24 +405,7 @@ cgen(Node *np) abort(); case OASSIG: abbrev(np); - switch (tp->size) { - case 1: - op = ASSTB; - break; - case 2: - op = ASSTH; - break; - case 4: - op = (tp->flags & INTF) ? ASSTW : ASSTS; - break; - case 8: - op = (tp->flags & INTF) ? ASSTL : ASSTD; - break; - default: - abort(); - } - code(op, np->left, load(np, LOADR), NULL); - return np->right; + return assign(np->left, load(np, LOADR)); case OCOMMA: return np->right; case OCALL: