summary refs log tree commit diff
path: root/util.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2022-11-22 21:44:44 +0100
committerQuentin Carbonneaux <quentin@c9x.me>2022-11-22 21:56:21 +0100
commitcbee74bdb4f85d6d8d4f192f0018ea023418e216 (patch)
tree4ea3eb41265e44336d81fecf719193c67540f3d3 /util.c
parent04e26409011389f7b5759114905195a4fb0b0286 (diff)
downloadroux-cbee74bdb4f85d6d8d4f192f0018ea023418e216.tar.gz
use a new struct for symbols
Symbols are a useful abstraction
that occurs in both Con and Alias.
In this patch they get their own
struct. This new struct packages
a symbol name and a type; the type
tells us where the symbol name
must be interpreted (currently, in
gobal memory or in thread-local
storage).

The refactor fixed a bug in
addcon(), proving the value of
packaging symbol names with their
type.
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/util.c b/util.c
index a4bdb29..41b2625 100644
--- a/util.c
+++ b/util.c
@@ -349,6 +349,12 @@ chuse(Ref r, int du, Fn *fn)
 		fn->tmp[r.val].nuse += du;
 }
 
+int
+symeq(Sym s0, Sym s1)
+{
+	return s0.type == s1.type && s0.id == s1.id;
+}
+
 Ref
 newcon(Con *c0, Fn *fn)
 {
@@ -358,9 +364,8 @@ newcon(Con *c0, Fn *fn)
 	for (i=0; i<fn->ncon; i++) {
 		c1 = &fn->con[i];
 		if (c0->type == c1->type
-		&& c0->label == c1->label
-		&& c0->bits.i == c1->bits.i
-		&& c0->reloc == c1->reloc)
+		&& symeq(c0->sym, c1->sym)
+		&& c0->bits.i == c1->bits.i)
 			return CON(i);
 	}
 	vgrow(&fn->con, ++fn->ncon);
@@ -391,7 +396,7 @@ addcon(Con *c0, Con *c1)
 			if (c0->type == CAddr)
 				return 0;
 			c0->type = CAddr;
-			c0->label = c1->label;
+			c0->sym = c1->sym;
 		}
 		c0->bits.i += c1->bits.i;
 	}