From cbee74bdb4f85d6d8d4f192f0018ea023418e216 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Tue, 22 Nov 2022 21:44:44 +0100 Subject: 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. --- util.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'util.c') 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; incon; 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; } -- cgit 1.4.1