[hackers] [scc] [cc2] Add newlabel() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 7 Jun 2016 08:42:56 +0200 (CEST)

commit 19f5c0a15f0e21510092ded91507a7a6e5feb9cf
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jun 7 08:40:34 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jun 7 08:40:34 2016 +0200

    [cc2] Add newlabel()
    
    This function is going to be useful in different targets and in a lot of
    different situations, so it is a good idea to have it in cc2/code.c.

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index 472b81a..3541a25 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -410,11 +410,8 @@ cgen(Node *np)
         case OBRANCH:
                 next = np->next;
                 load(np, LOADL);
- if (next->label) {
- sym = getsym(TMPSYM);
- sym->kind = SLABEL;
- next->label = sym;
- }
+ if (!next->label)
+ next->label = newlabel();
                 ifyes = label2node(np->u.sym);
                 ifno = label2node(next->label);
                 op = ASBRANCH;
diff --git a/cc2/cc2.h b/cc2/cc2.h
index 4a44b55..00528da 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -207,6 +207,7 @@ extern void code(int op, Node *to, Node *from1, Node *from2);
 extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
 extern void setlabel(Symbol *sym);
 extern Node *label2node(Symbol *sym);
+extern Symbol *newlabel(void);
 
 /* node.c */
 #define SETCUR 1
diff --git a/cc2/code.c b/cc2/code.c
index 829a695..ba7c616 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -57,6 +57,15 @@ addr(Node *np, Addr *addr)
         }
 }
 
+Symbol *
+newlabel(void)
+{
+ Symbol *sym = getsym(TMPSYM);
+
+ sym->kind = SLABEL;
+ return sym;
+}
+
 Node *
 label2node(Symbol *sym)
 {
Received on Tue Jun 07 2016 - 08:42:56 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 07 2016 - 08:48:13 CEST