aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'ir.c')
-rw-r--r--ir.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/ir.c b/ir.c
index cb4cc27..2f1c622 100644
--- a/ir.c
+++ b/ir.c
@@ -4,12 +4,12 @@ uchar type2cls[NTYPETAG];
uchar cls2siz[KF8+1];
const uchar siz2intcls[] = { [1] = KI4, [2] = KI4, [4] = KI4, [8] = KI8 };
-static vec_of(struct irdat) dats;
struct instr instrtab[1<<14];
static int ninstr;
static int instrfreelist;
struct calltab calltab;
struct phitab phitab;
+struct dattab dattab;
void
irinit(struct function *fn)
@@ -59,14 +59,6 @@ addcon(const struct xcon *con)
}
}
-/* union ref
-adddat(struct function *fn, const struct irdat *dat)
-{
- assert(dats.n < 1u<<29);
- vpush(&dats, *dat);
- return mkref(RDAT, dats.n - 1);
-} */
-
static void
targwrite2(uchar *d, ushort x)
{
@@ -163,6 +155,19 @@ mksymref(struct function *fn, const char *s)
return mkref(RXCON, addcon(&con));
}
+union ref
+mkdatref(struct function *fn, uint siz, uint align, const void *bytes, uint n)
+{
+ struct irdat dat = { align, 0, siz };
+ if (siz <= 8) memcpy(dat.sdat, bytes, n < siz ? n : siz);
+ else {
+ while (((uchar *)bytes)[n-1] == 0) --n; /* nip trailing zeroes */
+ vpushn(&dat.dat, bytes, n);
+ }
+ vpush(&dattab, dat);
+ return mkref(RDAT, dattab.n - 1);
+}
+
struct instr
mkalloca(uint siz, uint align)
{
@@ -220,6 +225,7 @@ insertinstr(struct block *blk, int idx, struct instr ins)
else {
assert(idx >= 0 && idx < blk->ins.n);
vpush_((void **)&blk->ins.p, &blk->ins._cap, &blk->ins.n, sizeof *blk->ins.p);
+ vresize(&blk->ins, blk->ins.n);
for (int i = blk->ins.n++; i > idx; --i)
blk->ins.p[i] = blk->ins.p[i - 1];
blk->ins.p[idx] = new;