aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-18 20:26:52 +0100
committerlemon <lsof@mailbox.org>2025-12-18 20:26:52 +0100
commit80858d909be0915b2f0c0202dac33b9627c7a405 (patch)
tree8f27b4f0ba2566062fc7e61a2aa90c75817ff68e /ir
parentc4d20300e3b7d63bae20070e0d69af909b55d01b (diff)
ir: move cls2load to interface
There's plenty of code duplication like this around I'm looking to reduce.
Diffstat (limited to 'ir')
-rw-r--r--ir/ir.c9
-rw-r--r--ir/ir.h1
-rw-r--r--ir/regalloc.c4
3 files changed, 7 insertions, 7 deletions
diff --git a/ir/ir.c b/ir/ir.c
index 883e728..553885d 100644
--- a/ir/ir.c
+++ b/ir/ir.c
@@ -2,7 +2,11 @@
#include "../obj/obj.h"
uchar type2cls[NTYPETAG];
-uchar cls2siz[KF64+1];
+uchar cls2siz[] = { [KI32] = 4, [KI64] = 8, [KF32] = 4, [KF64] = 8 };
+uchar cls2load[] = {
+ [KI32] = Oloads32, [KI64] = Oloadi64,
+ [KF32] = Oloadf32, [KF64] = Oloadf64, [KPTR] = -1
+};
const uchar siz2intcls[] = { [1] = KI32, [2] = KI32, [4] = KI32, [8] = KI64 };
const char *opnames[] = {
@@ -61,9 +65,8 @@ irinit(struct function *fn)
type2cls[TYLDOUBLE] = KF64;
type2cls[TYPTR] = KPTR;
type2cls[TYARRAY] = KPTR;
- cls2siz[KI32] = cls2siz[KF32] = 4;
- cls2siz[KI64] = cls2siz[KF64] = 8;
cls2siz[KPTR] = targ_primsizes[TYPTR];
+ cls2load[KPTR] = targ_64bit ? Oloadi64 : Oloads32;
}
fn->entry = fn->curblk = allocz(fn->arena, sizeof(struct block), 0);
fn->nblk = 1;
diff --git a/ir/ir.h b/ir/ir.h
index 8c2990e..174cdab 100644
--- a/ir/ir.h
+++ b/ir/ir.h
@@ -224,6 +224,7 @@ enum { MAXINSTR = 1<<15 };
/** ir.c **/
extern uchar type2cls[];
extern uchar cls2siz[];
+extern uchar cls2load[];
extern const uchar siz2intcls[];
extern struct instr instrtab[];
extern struct use *instruse[];
diff --git a/ir/regalloc.c b/ir/regalloc.c
index 030dbf0..2176a02 100644
--- a/ir/regalloc.c
+++ b/ir/regalloc.c
@@ -1071,10 +1071,6 @@ devirt(struct rega *ra, struct block *blk)
assert(naddr < 2);
for (int i = 0; i < nargref; ++i) {
- static uchar cls2load[] = {
- [KI32] = Oloads32, [KI64] = Oloadi64, [KF32] = Oloadf32, [KF64] = Oloadf64, [KPTR] = 0
- };
- cls2load[KPTR] = targ_64bit ? Oloadi64 : Oloads32;
union ref *r = argref[i];
int tr;
if (r->t == RTMP) {