diff options
| author | Quentin Carbonneaux <[email protected]> | 2022-11-22 21:44:44 +0100 |
|---|---|---|
| committer | Quentin Carbonneaux <[email protected]> | 2022-11-22 21:56:21 +0100 |
| commit | cbee74bdb4f85d6d8d4f192f0018ea023418e216 (patch) | |
| tree | 4ea3eb41265e44336d81fecf719193c67540f3d3 /fold.c | |
| parent | 04e26409011389f7b5759114905195a4fb0b0286 (diff) | |
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 'fold.c')
| -rw-r--r-- | fold.c | 23 |
1 files changed, 9 insertions, 14 deletions
@@ -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; } |
