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.
This commit is contained in:
Quentin Carbonneaux 2022-11-22 21:44:44 +01:00
parent 04e2640901
commit cbee74bdb4
12 changed files with 68 additions and 58 deletions

21
all.h
View file

@ -20,6 +20,7 @@ typedef struct Ins Ins;
typedef struct Phi Phi;
typedef struct Blk Blk;
typedef struct Use Use;
typedef struct Sym Sym;
typedef struct Alias Alias;
typedef struct Tmp Tmp;
typedef struct Con Con;
@ -264,6 +265,14 @@ struct Use {
} u;
};
struct Sym {
enum {
SGlo,
SThr,
} type;
uint32_t id;
};
enum {
NoAlias,
MayAlias,
@ -283,10 +292,7 @@ struct Alias {
int base;
int64_t offset;
union {
struct {
uint32_t label;
int con;
} sym;
Sym sym;
struct {
int sz; /* -1 if > NBit */
bits m;
@ -329,16 +335,12 @@ struct Con {
CBits,
CAddr,
} type;
uint32_t label;
Sym sym;
union {
int64_t i;
double d;
float s;
} bits;
enum {
RelDef,
RelThr,
} reloc;
char flt; /* 1 to print as s, 2 to print as d */
};
@ -463,6 +465,7 @@ int clsmerge(short *, short);
int phicls(int, Tmp *);
Ref newtmp(char *, int, Fn *);
void chuse(Ref, int, Fn *);
int symeq(Sym, Sym);
Ref newcon(Con *, Fn *);
Ref getcon(int64_t, Fn *);
int addcon(Con *, Con *);