Skip to content

Commit

Permalink
forgot to add symref value type (for calls)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander.nutz committed Dec 3, 2024
1 parent 4c48f39 commit fb812a2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ir/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ void vx_IrValue_dump(vx_IrValue value, FILE *out, const size_t indent) {
}
break;

case VX_IR_VAL_SYMREF: {
fprintf(out, "%s", value.symref);
}
break;

case VX_IR_VAL_BLOCK: {
const vx_IrBlock *block = value.block;

Expand Down
3 changes: 3 additions & 0 deletions ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ bool vx_IrValue_eq(vx_IrValue a, vx_IrValue b)

case VX_IR_VAL_X86_CC:
return !strcmp(a.x86_cc, b.x86_cc);

case VX_IR_VAL_SYMREF:
return !strcmp(a.symref, b.symref);
}
}

Expand Down
3 changes: 3 additions & 0 deletions ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ struct vx_IrValue {
VX_IR_VAL_VAR,
VX_IR_VAL_UNINIT,
VX_IR_VAL_BLOCKREF,
VX_IR_VAL_SYMREF,

// not storable
VX_IR_VAL_BLOCK,
Expand All @@ -329,6 +330,7 @@ struct vx_IrValue {
vx_IrBlock *block;
vx_IrType *ty;
size_t id;
const char * symref;

const char *x86_cc;
};
Expand All @@ -345,6 +347,7 @@ bool vx_IrValue_eq(vx_IrValue a, vx_IrValue b);
#define VX_IR_VALUE_BLK(blk) ((vx_IrValue) { .type = VX_IR_VAL_BLOCK, .block = blk })
#define VX_IR_VALUE_ID(idin) ((vx_IrValue) { .type = VX_IR_VAL_ID, .id = idin })
#define VX_IR_VALUE_X86_CC(cc) ((vx_IrValue) { .type = VX_IR_VAL_X86_CC, .x86_cc = cc })
#define VX_IR_VALUE_SYMREF(sy) ((vx_IrValue) { .type = VX_IR_VAL_SYMREF, .symref = sy })

void vx_IrValue_dump(vx_IrValue value, FILE *out, size_t indent);

Expand Down
25 changes: 24 additions & 1 deletion targets/x86/cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ typedef enum {
LOC_MEM,
LOC_IMM,
LOC_LABEL,
LOC_SYM,
LOC_INVALID,
} LocationType;

Expand Down Expand Up @@ -106,6 +107,10 @@ typedef struct Location {
const char * label;
} label;

struct {
const char * sym;
} sym;

struct {
struct Location* address;
} mem;
Expand All @@ -122,6 +127,8 @@ typedef struct Location {
((Location) { .bytesWidth = (width), .type = LOC_MEM, .v.mem.address = (eaa) })
#define LocLabel(str) \
((Location) { .type = LOC_LABEL, .v.label.label = (str) })
#define LocSym(str) \
((Location) { .type = LOC_SYM, .v.sym.sym = (str) })

Location* loc_opt_copy(Location* old) {
Location* new = fastalloc(sizeof(Location));
Expand Down Expand Up @@ -155,6 +162,11 @@ Location* loc_opt_copy(Location* old) {
return new;
}

case LOC_SYM: {
*new = LocSym(old->v.sym.sym);
return new;
}

case LOC_INVALID:
default: {
assert(false);
Expand Down Expand Up @@ -282,7 +294,11 @@ static void emit(Location* loc, FILE* out) {
fputs(loc->v.label.label, out);
break;

case LOC_INVALID:
case LOC_SYM:
fputs(loc->v.sym.sym, out);
break;

case LOC_INVALID:
assert(false);
break;
}
Expand Down Expand Up @@ -687,6 +703,13 @@ static Location* as_loc(size_t width, vx_IrValue val) {
return loc;
}

case VX_IR_VAL_SYMREF: {
Location* loc = fastalloc(sizeof(Location));
loc->type = LOC_SYM;
loc->v.sym.sym = val.symref;
return loc;
}

default:
assert(false);
return NULL;
Expand Down

0 comments on commit fb812a2

Please sign in to comment.