commit 61e2e3177d38dc8a7b798a370408d58901e3d550 Author: Roberto E. Vargas Caballero <k...@shike2.com> AuthorDate: Tue Jun 7 09:19:17 2016 +0200 Commit: Roberto E. Vargas Caballero <k...@shike2.com> CommitDate: Tue Jun 7 09:19:17 2016 +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. diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c index 3541a25..d8b0821 100644 --- 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: