shithub: scc

Download patch

ref: e3598b4df463df725281f103d0fe37108517dbd3
parent: cf7e9ca4944f5a8433c851a01b2539be1dcfd4a5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jun 7 04:40:34 EDT 2016

[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.

--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -410,11 +410,8 @@
 	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;
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -207,6 +207,7 @@
 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
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -57,6 +57,15 @@
 	}
 }
 
+Symbol *
+newlabel(void)
+{
+	Symbol *sym = getsym(TMPSYM);
+
+	sym->kind = SLABEL;
+	return sym;
+}
+
 Node *
 label2node(Symbol *sym)
 {