aboutsummaryrefslogtreecommitdiffstats
path: root/src/ir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir.c')
-rw-r--r--src/ir.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/ir.c b/src/ir.c
new file mode 100644
index 0000000..4c85792
--- /dev/null
+++ b/src/ir.c
@@ -0,0 +1,85 @@
1typedef enum Operator {
2 // Arithmetic ops.
3 OP_ADD,
4 OP_SUB,
5 OP_MUL,
6 OP_DIV,
7 OP_MOD,
8
9 // Load/store/copy operations.
10 OP_LD8,
11 OP_LD16,
12 OP_LD32,
13 OP_LD64,
14 OP_ST8,
15 OP_ST16,
16 OP_ST32,
17 OP_ST64,
18 OP_CP8,
19 OP_CP16,
20 OP_CP32,
21 OP_CP64,
22
23 // Bit fiddling operations.
24 OP_NOT,
25 OP_AND,
26 OP_OR,
27 OP_XOR,
28 OP_LSHIFT,
29 OP_RSHIFT,
30 OP_LROT,
31 OP_RROT,
32
33 // (Un)conditional jump operations.
34 OP_LABEL,
35 OP_JMP,
36 OP_JMP_EQ,
37 OP_JMP_NEQ,
38 OP_JMP_GT,
39 OP_JMP_LT,
40 OP_JMP_GE,
41 OP_JMP_LE,
42} Operator;
43
44typedef enum OperandType {
45 OP_TYPE_REG,
46 OP_TYPE_CONST,
47 OP_TYPE_LABEL,
48} OperandType;
49
50typedef struct Operand {
51 OperandType type;
52 union {
53 struct {
54 size_t num;
55 } reg;
56
57 struct {
58 size_t num;
59 } label;
60
61 struct {
62 union {
63 u64 uval;
64 s64 sval;
65 };
66 } const;
67 };
68} Operand;
69
70typedef struct Instruction {
71 Operator op;
72 Operand dst;
73 Operand src_a;
74 Operand src_b;
75} Instruction;
76
77typedef struct LineInfo {
78 size_t line;
79 size_t col;
80} LineInfo;
81
82typedef struct ProgramBASM {
83 Instruction *inst;
84 LineInfo *lines;
85} ProgramBASM;