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

From: <git_AT_suckless.org>
Date: Sat, 16 Apr 2016 09:42:19 +0200 (CEST)

commit 5b8415def1c73c66509eb6ad3c0e5fa021cf6d19
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Fri Apr 15 14:13:46 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Fri Apr 15 14:24:51 2016 +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.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 09ddc5c..0fa5fd0 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -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;
 }
 
_AT_@ -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
index 905325f..5455fcc 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -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
index 54214f3..f4d25f5 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -40,7 +40,7 @@ enum op {
         STRING = '"',
         LABEL = 'L',
         INDEX = 'I',
- OTMP = 'T',
+ TMP = 'T',
         /* storage class */
         GLOB = 'G',
         EXTRN = 'X',
_AT_@ -49,6 +49,7 @@ enum op {
         MEMBER = 'M',
         /* operands */
         OMEM = 'M',
+ OTMP = 'T',
         OAUTO = 'A',
         OREG = 'R',
         OCONST = '#',
Received on Sat Apr 16 2016 - 09:42:19 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 16 2016 - 09:48:29 CEST