This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
irbuild.cc
121 lines (105 loc) · 2.42 KB
/
irbuild.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "ir.h"
using namespace IR;
using namespace std;
Inst *Build::nop() {
Inst *i = new Inst();
i->type = TYPE_VOID;
i->opcode = OP_NOP;
return i;
}
Inst *Build::move(Type type, int rdst, int rsrc) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_MOVE;
i->rdst = rdst;
i->rsrc1 = rsrc;
return i;
}
Inst *Build::loadimm(Type type, int rdst, int vsrc) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_LOADIMM;
i->rdst = rdst;
i->vsrc = vsrc;
return i;
}
Inst *Build::load(Type type, int rdst, string lsrc) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_LOAD;
i->rdst = rdst;
i->lsrc = lsrc;
return i;
}
Inst *Build::store(Type type, string ldst, int rsrc) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_STORE;
i->ldst = ldst;
i->rsrc1 = rsrc;
return i;
}
Inst *Build::add(Type type, int rdst, int rsrc1, int rsrc2) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_ADD;
i->rdst = rdst;
i->rsrc1 = rsrc1;
i->rsrc2 = rsrc2;
return i;
}
Inst *Build::sub(Type type, int rdst, int rsrc1, int rsrc2) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_SUB;
i->rdst = rdst;
i->rsrc1 = rsrc1;
i->rsrc2 = rsrc2;
return i;
}
Inst *Build::mult(Type type, int rdst, int rsrc1, int rsrc2) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_MULT;
i->rdst = rdst;
i->rsrc1 = rsrc1;
i->rsrc2 = rsrc2;
return i;
}
Inst *Build::div(Type type, int rdst, int rsrc1, int rsrc2) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_DIV;
i->rdst = rdst;
i->rsrc1 = rsrc1;
i->rsrc2 = rsrc2;
return i;
}
Inst *Build::ret() {
Inst *i = new Inst();
i->type = TYPE_VOID;
i->opcode = OP_RET;
return i;
}
Inst *Build::ret(Type type, int rsrc1) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_RET;
i->rsrc1 = rsrc1;
return i;
}
Inst *Build::call(string lsrc) {
Inst *i = new Inst();
i->type = TYPE_VOID;
i->opcode = OP_CALL;
i->lsrc = lsrc;
return i;
}
Inst *Build::call(Type type, VirtualReg rdst, string lsrc) {
Inst *i = new Inst();
i->type = type;
i->opcode = OP_CALL;
i->rdst = rdst;
i->lsrc = lsrc;
return i;
}