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. --- fold.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'fold.c') diff --git a/fold.c b/fold.c index 2bb3a2f..75554bf 100644 --- a/fold.c +++ b/fold.c @@ -333,35 +333,31 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr) double fd; } l, r; uint64_t x; - uint32_t lab; - int typ, rel; + Sym sym; + int typ; + memset(&sym, 0, sizeof sym); typ = CBits; - rel = RelDef; - lab = 0; l.s = cl->bits.i; r.s = cr->bits.i; if (op == Oadd) { if (cl->type == CAddr) { if (cr->type == CAddr) return 1; - lab = cl->label; - rel = cl->reloc; typ = CAddr; + sym = cl->sym; } else if (cr->type == CAddr) { - lab = cr->label; - rel = cr->reloc; typ = CAddr; + sym = cr->sym; } } else if (op == Osub) { if (cl->type == CAddr) { if (cr->type != CAddr) { - lab = cl->label; - rel = cl->reloc; typ = CAddr; - } else if (cl->label != cr->label) + sym = cl->sym; + } else if (!symeq(cl->sym, cr->sym)) return 1; } else if (cr->type == CAddr) @@ -407,9 +403,8 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr) case Ocast: x = l.u; if (cl->type == CAddr) { - lab = cl->label; - rel = cl->reloc; typ = CAddr; + sym = cl->sym; } break; default: @@ -462,7 +457,7 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr) else die("unreachable"); } - *res = (Con){.type=typ, .label=lab, .reloc=rel, .bits={.i=x}}; + *res = (Con){.type=typ, .sym=sym, .bits={.i=x}}; return 0; } -- cgit v1.2.3