[hackers] [scc] [cc2-qbe] Add assign() in cgen.c || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 7 Jun 2016 09:34:12 +0200 (CEST)

commit 61e2e3177d38dc8a7b798a370408d58901e3d550
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jun 7 09:19:17 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_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
_AT_@ -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)
_AT_@ -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:
Received on Tue Jun 07 2016 - 09:34:12 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 07 2016 - 09:36:15 CEST