@@ -3,159 +3,227 @@ import cllvm
3
3
#endif
4
4
5
5
/// Enumerates the opcodes of instructions available in the LLVM IR language.
6
- ///
7
- /// The raw values of this enumeration *must* match those in
8
- /// [llvm-c/Core.h](https://github.com/llvm-mirror/llvm/blob/master/include/llvm-c/Core.h)
9
- public enum OpCode : UInt32 {
6
+ public enum OpCode {
10
7
// MARK: Terminator Instructions
11
8
12
9
/// The opcode for the `ret` instruction.
13
- case ret = 1
10
+ case ret
14
11
/// The opcode for the `br` instruction.
15
- case br = 2
12
+ case br
16
13
/// The opcode for the `switch` instruction.
17
- case `switch` = 3
14
+ case `switch`
18
15
/// The opcode for the `indirectBr` instruction.
19
- case indirectBr = 4
16
+ case indirectBr
20
17
/// The opcode for the `invoke` instruction.
21
- case invoke = 5
18
+ case invoke
22
19
/// The opcode for the `unreachable` instruction.
23
- case unreachable = 7
20
+ case unreachable
24
21
25
22
// MARK: Standard Binary Operators
26
23
27
24
/// The opcode for the `add` instruction.
28
- case add = 8
25
+ case add
29
26
/// The opcode for the `fadd` instruction.
30
- case fadd = 9
27
+ case fadd
31
28
/// The opcode for the `sub` instruction.
32
- case sub = 10
29
+ case sub
33
30
/// The opcode for the `fsub` instruction.
34
- case fsub = 11
31
+ case fsub
35
32
/// The opcode for the `mul` instruction.
36
- case mul = 12
33
+ case mul
37
34
/// The opcode for the `fmul` instruction.
38
- case fmul = 13
35
+ case fmul
39
36
/// The opcode for the `udiv` instruction.
40
- case udiv = 14
37
+ case udiv
41
38
/// The opcode for the `sdiv` instruction.
42
- case sdiv = 15
39
+ case sdiv
43
40
/// The opcode for the `fdiv` instruction.
44
- case fdiv = 16
41
+ case fdiv
45
42
/// The opcode for the `urem` instruction.
46
- case urem = 17
43
+ case urem
47
44
/// The opcode for the `srem` instruction.
48
- case srem = 18
45
+ case srem
49
46
/// The opcode for the `frem` instruction.
50
- case frem = 19
47
+ case frem
51
48
52
49
// MARK: Logical Operators
53
50
54
51
/// The opcode for the `shl` instruction.
55
- case shl = 20
52
+ case shl
56
53
/// The opcode for the `lshr` instruction.
57
- case lshr = 21
54
+ case lshr
58
55
/// The opcode for the `ashr` instruction.
59
- case ashr = 22
56
+ case ashr
60
57
/// The opcode for the `and` instruction.
61
- case and = 23
58
+ case and
62
59
/// The opcode for the `or` instruction.
63
- case or = 24
60
+ case or
64
61
/// The opcode for the `xor` instruction.
65
- case xor = 25
62
+ case xor
66
63
67
64
// MARK: Memory Operators
68
65
69
66
/// The opcode for the `alloca` instruction.
70
- case alloca = 26
67
+ case alloca
71
68
/// The opcode for the `load` instruction.
72
- case load = 27
69
+ case load
73
70
/// The opcode for the `store` instruction.
74
- case store = 28
71
+ case store
75
72
/// The opcode for the `getElementPtr` instruction.
76
- case getElementPtr = 29
73
+ case getElementPtr
77
74
78
75
// MARK: Cast Operators
79
76
80
77
/// The opcode for the `trunc` instruction.
81
- case trunc = 30
78
+ case trunc
82
79
/// The opcode for the `zext` instruction.
83
- case zext = 31
80
+ case zext
84
81
/// The opcode for the `sext` instruction.
85
- case sext = 32
82
+ case sext
86
83
/// The opcode for the `fpToUI` instruction.
87
- case fpToUI = 33
84
+ case fpToUI
88
85
/// The opcode for the `fpToSI` instruction.
89
- case fpToSI = 34
86
+ case fpToSI
90
87
/// The opcode for the `uiToFP` instruction.
91
- case uiToFP = 35
88
+ case uiToFP
92
89
/// The opcode for the `siToFP` instruction.
93
- case siToFP = 36
90
+ case siToFP
94
91
/// The opcode for the `fpTrunc` instruction.
95
- case fpTrunc = 37
92
+ case fpTrunc
96
93
/// The opcode for the `fpExt` instruction.
97
- case fpExt = 38
94
+ case fpExt
98
95
/// The opcode for the `ptrToInt` instruction.
99
- case ptrToInt = 39
96
+ case ptrToInt
100
97
/// The opcode for the `intToPtr` instruction.
101
- case intToPtr = 40
98
+ case intToPtr
102
99
/// The opcode for the `bitCast` instruction.
103
- case bitCast = 41
100
+ case bitCast
104
101
/// The opcode for the `addrSpaceCast` instruction.
105
- case addrSpaceCast = 60
102
+ case addrSpaceCast
106
103
107
104
// MARK: Other Operators
108
105
109
106
/// The opcode for the `icmp` instruction.
110
- case icmp = 42
107
+ case icmp
111
108
/// The opcode for the `fcmp` instruction.
112
- case fcmp = 43
109
+ case fcmp
113
110
/// The opcode for the `PHI` instruction.
114
- case PHI = 44
111
+ case phi
115
112
/// The opcode for the `call` instruction.
116
- case call = 45
113
+ case call
117
114
/// The opcode for the `select` instruction.
118
- case select = 46
115
+ case select
119
116
/// The opcode for the `userOp1` instruction.
120
- case userOp1 = 47
117
+ case userOp1
121
118
/// The opcode for the `userOp2` instruction.
122
- case userOp2 = 48
119
+ case userOp2
123
120
/// The opcode for the `vaArg` instruction.
124
- case vaArg = 49
121
+ case vaArg
125
122
/// The opcode for the `extractElement` instruction.
126
- case extractElement = 50
123
+ case extractElement
127
124
/// The opcode for the `insertElement` instruction.
128
- case insertElement = 51
125
+ case insertElement
129
126
/// The opcode for the `shuffleVector` instruction.
130
- case shuffleVector = 52
127
+ case shuffleVector
131
128
/// The opcode for the `extractValue` instruction.
132
- case extractValue = 53
129
+ case extractValue
133
130
/// The opcode for the `insertValue` instruction.
134
- case insertValue = 54
131
+ case insertValue
135
132
136
133
// MARK: Atomic operators
137
134
138
135
/// The opcode for the `fence` instruction.
139
- case fence = 55
136
+ case fence
140
137
/// The opcode for the `atomicCmpXchg` instruction.
141
- case atomicCmpXchg = 56
138
+ case atomicCmpXchg
142
139
/// The opcode for the `atomicRMW` instruction.
143
- case atomicRMW = 57
140
+ case atomicRMW
144
141
145
142
// MARK: Exception Handling Operators
146
143
147
144
/// The opcode for the `resume` instruction.
148
- case resume = 58
145
+ case resume
149
146
/// The opcode for the `landingPad` instruction.
150
- case landingPad = 59
147
+ case landingPad
151
148
/// The opcode for the `cleanupRet` instruction.
152
- case cleanupRet = 61
149
+ case cleanupRet
153
150
/// The opcode for the `catchRet` instruction.
154
- case catchRet = 62
151
+ case catchRet
155
152
/// The opcode for the `catchPad` instruction.
156
- case catchPad = 63
153
+ case catchPad
157
154
/// The opcode for the `cleanupPad` instruction.
158
- case cleanupPad = 64
155
+ case cleanupPad
159
156
/// The opcode for the `catchSwitch` instruction.
160
- case catchSwitch = 65
157
+ case catchSwitch
158
+
159
+ /// Creates an `OpCode` from an `LLVMOpcode`
160
+ init ( rawValue: LLVMOpcode ) {
161
+ switch rawValue {
162
+ case LLVMRet: self = . ret
163
+ case LLVMBr: self = . br
164
+ case LLVMSwitch: self = . switch
165
+ case LLVMIndirectBr: self = . indirectBr
166
+ case LLVMInvoke: self = . invoke
167
+ case LLVMUnreachable: self = . unreachable
168
+ case LLVMAdd: self = . add
169
+ case LLVMFAdd: self = . fadd
170
+ case LLVMSub: self = . sub
171
+ case LLVMFSub: self = . fsub
172
+ case LLVMMul: self = . mul
173
+ case LLVMFMul: self = . fmul
174
+ case LLVMUDiv: self = . udiv
175
+ case LLVMSDiv: self = . sdiv
176
+ case LLVMFDiv: self = . fdiv
177
+ case LLVMURem: self = . urem
178
+ case LLVMSRem: self = . srem
179
+ case LLVMFRem: self = . frem
180
+ case LLVMShl: self = . shl
181
+ case LLVMLShr: self = . lshr
182
+ case LLVMAShr: self = . ashr
183
+ case LLVMAnd: self = . and
184
+ case LLVMOr: self = . or
185
+ case LLVMXor: self = . xor
186
+ case LLVMAlloca: self = . alloca
187
+ case LLVMLoad: self = . load
188
+ case LLVMStore: self = . store
189
+ case LLVMGetElementPtr: self = . getElementPtr
190
+ case LLVMTrunc: self = . trunc
191
+ case LLVMZExt: self = . zext
192
+ case LLVMSExt: self = . sext
193
+ case LLVMFPToUI: self = . fpToUI
194
+ case LLVMFPToSI: self = . fpToSI
195
+ case LLVMUIToFP: self = . uiToFP
196
+ case LLVMSIToFP: self = . siToFP
197
+ case LLVMFPTrunc: self = . fpTrunc
198
+ case LLVMFPExt: self = . fpExt
199
+ case LLVMPtrToInt: self = . ptrToInt
200
+ case LLVMIntToPtr: self = . intToPtr
201
+ case LLVMBitCast: self = . bitCast
202
+ case LLVMAddrSpaceCast: self = . addrSpaceCast
203
+ case LLVMICmp: self = . icmp
204
+ case LLVMFCmp: self = . fcmp
205
+ case LLVMPHI: self = . phi
206
+ case LLVMCall: self = . call
207
+ case LLVMSelect: self = . select
208
+ case LLVMUserOp1: self = . userOp1
209
+ case LLVMUserOp2: self = . userOp2
210
+ case LLVMVAArg: self = . vaArg
211
+ case LLVMExtractElement: self = . extractElement
212
+ case LLVMInsertElement: self = . insertElement
213
+ case LLVMShuffleVector: self = . shuffleVector
214
+ case LLVMExtractValue: self = . extractValue
215
+ case LLVMInsertValue: self = . insertValue
216
+ case LLVMFence: self = . fence
217
+ case LLVMAtomicCmpXchg: self = . atomicCmpXchg
218
+ case LLVMAtomicRMW: self = . atomicRMW
219
+ case LLVMResume: self = . resume
220
+ case LLVMLandingPad: self = . landingPad
221
+ case LLVMCleanupRet: self = . cleanupRet
222
+ case LLVMCatchRet: self = . catchRet
223
+ case LLVMCatchPad: self = . catchPad
224
+ case LLVMCleanupPad: self = . cleanupPad
225
+ case LLVMCatchSwitch: self = . catchSwitch
226
+ default : fatalError ( " invalid LLVMOpcode \( rawValue) " )
227
+ }
228
+ }
161
229
}
0 commit comments