aboutsummaryrefslogtreecommitdiff
path: root/ir.h
diff options
context:
space:
mode:
Diffstat (limited to 'ir.h')
-rw-r--r--ir.h32
1 files changed, 27 insertions, 5 deletions
diff --git a/ir.h b/ir.h
index b359d00..e732a3d 100644
--- a/ir.h
+++ b/ir.h
@@ -1,5 +1,6 @@
#pragma once
+#include <stdio.h>
#include <stdbool.h>
@@ -21,6 +22,7 @@ enum instype {
INS_JMP, // jmp name
INS_JCC, // if condcode, jmp name
INS_CALL, // call name
+ INS_CALLV, // r0 = call name
INS_RET, // return
INS_RETV, // return r1
INS_MOV, // r0 = r1
@@ -32,15 +34,31 @@ enum condcode {
enum reftype {
REF_REG, // reg
- REF_MEM, // [reg + offset + (rel_heap ? heap_base : 0)]
+ REF_MEM, // [reg + offset + {0, .data, heap base}[rel]]
REF_IMM, // imm
};
+enum refrel {
+ REFREL_ZERO,
+ REFREL_DATA,
+ REFREL_HEAP,
+};
+
+#define REG_UNUSED (-1)
+#define REG_A (-10)
+#define REG_B (-11)
+#define REG_C (-12)
+#define REG_D (-13)
+#define REG_X (-14)
+#define REG_Y (-15)
+#define REG_SP (-16)
+#define REG_BP (-17)
+
struct ref {
enum reftype type;
- int reg; // if -1 in a REF_MEM, unused
+ int reg; // >=0 for temporary or one of the REG_ constants
int offset;
- bool rel_heap; // whether the heap base address should be added to the offset
+ enum refrel rel;
int imm;
};
@@ -61,13 +79,17 @@ struct ir {
struct ir* ir_make(void);
void ir_delete(struct ir *ir);
-// returns offset
+void ir_print(struct ir *ir, FILE *f);
+void irins_print(struct irins *ins, FILE *f);
+
+// returns offset in .data segment
struct ref ir_reserve_global(struct ir *ir, int size);
void ir_append(struct ir *ir, struct irins *ins);
struct irins* irins_make(enum instype type);
struct irins* irins_make_name(enum instype type, char *name);
+struct irins* irins_make_0(enum instype type, struct ref r0);
struct irins* irins_make_01(enum instype type, struct ref r0, struct ref r1);
struct irins* irins_make_012(enum instype type, struct ref r0, struct ref r1, struct ref r2);
struct irins* irins_make_1(enum instype type, struct ref r1);
@@ -78,6 +100,6 @@ void irins_delete(struct irins *ins);
char* gen_label_name(void);
struct ref ref_reg(int reg);
-struct ref ref_mem(int reg, int offset, bool rel_heap);
+struct ref ref_mem(int reg, int offset, enum refrel rel);
struct ref ref_imm(int imm);
struct ref ref_next_register(void);