ruby-llvm 2.9.0 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -5
- data/lib/llvm.rb +1 -0
- data/lib/llvm/analysis.rb +1 -0
- data/lib/llvm/core.rb +1 -0
- data/lib/llvm/core/builder.rb +161 -19
- data/lib/llvm/core/context.rb +7 -4
- data/lib/llvm/core/module.rb +42 -15
- data/lib/llvm/core/pass_manager.rb +7 -1
- data/lib/llvm/core/type.rb +27 -3
- data/lib/llvm/core/value.rb +130 -16
- data/lib/llvm/execution_engine.rb +24 -7
- data/lib/llvm/target.rb +1 -0
- data/lib/llvm/transforms/ipo.rb +2 -0
- data/lib/llvm/transforms/scalar.rb +22 -0
- metadata +5 -21
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= LLVM
|
2
2
|
|
3
3
|
Author:: Jeremy Voorhis
|
4
|
-
Contributors:: Evan Phoenix, Takanori Ishikawa, Ronaldo M. Ferraz
|
4
|
+
Contributors:: Evan Phoenix, David Holroyd, Takanori Ishikawa, Ronaldo M. Ferraz, Mac Malone
|
5
5
|
Copyright:: Copyright (c) 2010-2011 Jeremy Voorhis
|
6
6
|
License:: BSD 3-clause (see LICENSE)
|
7
7
|
|
@@ -10,18 +10,17 @@ make use of LLVM's optimization passes and JIT compilation for
|
|
10
10
|
implementing compiled DSLs, callback functions, or fast Ruby method
|
11
11
|
implementations.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
13
|
ruby-llvm has been tested on Mac OS X 10.6 using the following Ruby interpreters:
|
16
14
|
|
17
15
|
* MRI 1.8.7-p174
|
18
16
|
* MRI 1.9.2-p180
|
19
17
|
* JRuby 1.4.0
|
20
18
|
|
21
|
-
If using MRI, ffi >= 1.0.7 is recommended.
|
19
|
+
If using MRI, ffi >= 1.0.7 is recommended (only ffi >= 1.0.0 is required).
|
22
20
|
|
23
21
|
== Requirements
|
24
|
-
* LLVM 2.9, including libLLVM-2.9 (compile LLVM with --enable-shared)
|
22
|
+
* LLVM 2.9, including libLLVM-2.9 (compile LLVM with --enable-shared).
|
23
|
+
* In order to ensure the usability of JIT features (i.e. create_jit_compiler), compile LLVM with --enable-jit as well.
|
25
24
|
|
26
25
|
== About version numbers
|
27
26
|
|
data/lib/llvm.rb
CHANGED
data/lib/llvm/analysis.rb
CHANGED
data/lib/llvm/core.rb
CHANGED
data/lib/llvm/core/builder.rb
CHANGED
@@ -2,50 +2,60 @@ module LLVM
|
|
2
2
|
class Builder
|
3
3
|
private_class_method :new
|
4
4
|
|
5
|
-
|
5
|
+
# @private
|
6
|
+
def initialize(ptr)
|
6
7
|
@ptr = ptr
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
|
+
# @private
|
11
|
+
def to_ptr
|
10
12
|
@ptr
|
11
13
|
end
|
12
14
|
|
15
|
+
# Creates a Builder.
|
13
16
|
def self.create
|
14
17
|
new(C.LLVMCreateBuilder())
|
15
18
|
end
|
16
19
|
|
20
|
+
# Positions the builder at the given Instruction in the given BasicBlock.
|
17
21
|
def position(block, instruction)
|
18
|
-
raise "
|
22
|
+
raise "Block must not be nil" if block.nil?
|
19
23
|
C.LLVMPositionBuilder(self, block, instruction)
|
20
24
|
self
|
21
25
|
end
|
22
26
|
|
27
|
+
# Positions the builder before the given Instruction.
|
23
28
|
def position_before(instruction)
|
24
|
-
raise "
|
29
|
+
raise "Instruction must not be nil" if instruction.nil?
|
25
30
|
C.LLVMPositionBuilderBefore(self, instruction)
|
26
31
|
self
|
27
32
|
end
|
28
33
|
|
34
|
+
# Positions the builder at the end of the given BasicBlock.
|
29
35
|
def position_at_end(block)
|
30
|
-
raise "
|
36
|
+
raise "Block must not be nil" if block.nil?
|
31
37
|
C.LLVMPositionBuilderAtEnd(self, block)
|
32
38
|
self
|
33
39
|
end
|
34
40
|
|
35
|
-
|
41
|
+
# The BasicBlock at which the Builder is currently positioned.
|
42
|
+
def insert_block
|
36
43
|
BasicBlock.from_ptr(C.LLVMGetInsertBlock(self))
|
37
44
|
end
|
38
45
|
|
39
|
-
# Terminators
|
40
46
|
|
47
|
+
# @LLVMinst ret
|
41
48
|
def ret_void
|
42
49
|
Instruction.from_ptr(C.LLVMBuildRetVoid(self))
|
43
50
|
end
|
44
51
|
|
52
|
+
# @LLVMinst ret
|
45
53
|
def ret(val)
|
46
54
|
Instruction.from_ptr(C.LLVMBuildRet(self, val))
|
47
55
|
end
|
48
56
|
|
57
|
+
# Builds a ret instruction returning multiple values.
|
58
|
+
# @LLVMinst ret
|
49
59
|
def aggregate_ret(*vals)
|
50
60
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * vals.size) do |vals_ptr|
|
51
61
|
vals_ptr.write_array_of_pointer(vals)
|
@@ -53,154 +63,206 @@ module LLVM
|
|
53
63
|
end
|
54
64
|
end
|
55
65
|
|
66
|
+
# Unconditional branching (i.e. goto)
|
67
|
+
# @LLVMinst br
|
56
68
|
def br(block)
|
57
69
|
Instruction.from_ptr(
|
58
70
|
C.LLVMBuildBr(self, block))
|
59
71
|
end
|
60
72
|
|
73
|
+
# Conditional branching (i.e. if)
|
74
|
+
# @LLVMinst br
|
61
75
|
def cond(cond, iftrue, iffalse)
|
62
76
|
Instruction.from_ptr(
|
63
77
|
C.LLVMBuildCondBr(self, cond, iftrue, iffalse))
|
64
78
|
end
|
65
79
|
|
66
|
-
|
67
|
-
|
80
|
+
# @LLVMinst switch
|
81
|
+
def switch(val, default, ncases)
|
82
|
+
SwitchInst.from_ptr(C.LLVMBuildSwitch(self, val, default, ncases))
|
68
83
|
end
|
69
84
|
|
85
|
+
# Invoke a function which may potentially unwind
|
86
|
+
# @LLVMinst invoke
|
70
87
|
def invoke(fun, args, _then, _catch, name = "")
|
71
88
|
Instruction.from_ptr(
|
72
89
|
C.LLVMBuildInvoke(self,
|
73
90
|
fun, args, args.size, _then, _catch, name))
|
74
91
|
end
|
75
92
|
|
93
|
+
# Builds an unwind Instruction.
|
94
|
+
# @LLVMinst unwind
|
76
95
|
def unwind
|
77
96
|
Instruction.from_ptr(C.LLVMBuildUnwind(self))
|
78
97
|
end
|
79
98
|
|
99
|
+
# @LLVMinst unreachable
|
80
100
|
def unreachable
|
81
101
|
Instruction.from_ptr(C.LLVMBuildUnreachable(self))
|
82
102
|
end
|
83
103
|
|
84
|
-
#
|
85
|
-
|
104
|
+
# @LLVMinst add
|
86
105
|
def add(lhs, rhs, name = "")
|
87
106
|
Instruction.from_ptr(C.LLVMBuildAdd(self, lhs, rhs, name))
|
88
107
|
end
|
89
108
|
|
109
|
+
# No signed wrap addition.
|
110
|
+
# @LLVMinst add
|
90
111
|
def nsw_add(lhs, rhs, name = "")
|
91
112
|
Instruction.from_ptr(C.LLVMBuildNSWAdd(self, lhs, rhs, name))
|
92
113
|
end
|
93
114
|
|
115
|
+
# @LLVMinst fadd
|
94
116
|
def fadd(lhs, rhs, name = "")
|
95
117
|
Instruction.from_ptr(C.LLVMBuildFAdd(self, lhs, rhs, name))
|
96
118
|
end
|
97
119
|
|
120
|
+
# @LLVMinst sub
|
98
121
|
def sub(lhs, rhs, name = "")
|
99
122
|
Instruction.from_ptr(C.LLVMBuildSub(self, lhs, rhs, name))
|
100
123
|
end
|
101
124
|
|
125
|
+
# @LLVMinst fsub
|
102
126
|
def fsub(lhs, rhs, name = "")
|
103
127
|
Instruction.from_ptr(C.LLVMBuildFSub(self, lhs, rhs, name))
|
104
128
|
end
|
105
129
|
|
130
|
+
# @LLVMinst mul
|
106
131
|
def mul(lhs, rhs, name = "")
|
107
132
|
Instruction.from_ptr(C.LLVMBuildMul(self, lhs, rhs, name))
|
108
133
|
end
|
109
134
|
|
135
|
+
# @LLVMinst fmul
|
110
136
|
def fmul(lhs, rhs, name = "")
|
111
137
|
Instruction.from_ptr(C.LLVMBuildFMul(self, lhs, rhs, name))
|
112
138
|
end
|
113
139
|
|
140
|
+
# Unsigned integer division
|
141
|
+
# @LLVMinst udiv
|
114
142
|
def udiv(lhs, rhs, name = "")
|
115
143
|
Instruction.from_ptr(C.LLVMBuildUDiv(self, lhs, rhs, name))
|
116
144
|
end
|
117
145
|
|
146
|
+
# Signed division
|
147
|
+
# @LLVMinst sdiv
|
118
148
|
def sdiv(lhs, rhs, name = "")
|
119
149
|
Instruction.from_ptr(C.LLVMBuildSDiv(self, lhs, rhs, name))
|
120
150
|
end
|
121
151
|
|
152
|
+
# Signed exact division
|
153
|
+
# @LLVMinst sdiv
|
122
154
|
def exact_sdiv(lhs, rhs, name = "")
|
123
155
|
Instruction.from_ptr(C.LLVMBuildExactSDiv(self, lhs, rhs, name))
|
124
156
|
end
|
125
157
|
|
158
|
+
# @LLVMinst fdiv
|
126
159
|
def fdiv(lhs, rhs, name = "")
|
127
160
|
Instruction.from_ptr(C.LLVMBuildFDiv(self, lhs, rhs, name))
|
128
161
|
end
|
129
162
|
|
163
|
+
# @LLVMinst urem
|
130
164
|
def urem(lhs, rhs, name = "")
|
131
165
|
Instruction.from_ptr(C.LLVMBuildURem(self, lhs, rhs, name))
|
132
166
|
end
|
133
167
|
|
168
|
+
# @LLVMinst srem
|
134
169
|
def srem(lhs, rhs, name = "")
|
135
170
|
Instruction.from_ptr(C.LLVMBuildSRem(self, lhs, rhs, name))
|
136
171
|
end
|
137
172
|
|
173
|
+
# @LLVMinst frem
|
138
174
|
def frem(lhs, rhs, name = "")
|
139
175
|
Instruction.from_ptr(C.LLVMBuildFRem(self, lhs, rhs, name))
|
140
176
|
end
|
141
177
|
|
178
|
+
# @LLVMinst shl
|
142
179
|
def shl(lhs, rhs, name = "")
|
143
180
|
Instruction.from_ptr(C.LLVMBuildShl(self, lhs, rhs, name))
|
144
181
|
end
|
145
182
|
|
183
|
+
# Shifts right with zero fill.
|
184
|
+
# @LLVMinst lshr
|
146
185
|
def lshr(lhs, rhs, name = "")
|
147
186
|
Instruction.from_ptr(C.LLVMBuildLShr(self, lhs, rhs, name))
|
148
187
|
end
|
149
188
|
|
189
|
+
# Arithmatic shift right.
|
190
|
+
# @LLVMinst ashr
|
150
191
|
def ashr(lhs, rhs, name = "")
|
151
192
|
Instruction.from_ptr(C.LLVMBuildAShr(self, lhs, rhs, name))
|
152
193
|
end
|
153
194
|
|
195
|
+
# @LLVMinst and
|
154
196
|
def and(lhs, rhs, name = "")
|
155
197
|
Instruction.from_ptr(C.LLVMBuildAnd(self, lhs, rhs, name))
|
156
198
|
end
|
157
199
|
|
200
|
+
# @LLVMinst or
|
158
201
|
def or(lhs, rhs, name = "")
|
159
202
|
Instruction.from_ptr(C.LLVMBuildOr(self, lhs, rhs, name))
|
160
203
|
end
|
161
204
|
|
205
|
+
# @LLVMinst xor
|
162
206
|
def xor(lhs, rhs, name = "")
|
163
207
|
Instruction.from_ptr(C.LLVMBuildXor(self, lhs, rhs, name))
|
164
208
|
end
|
165
209
|
|
210
|
+
# Integer negation (i.e. multiplication by -1).
|
166
211
|
def neg(arg, name = "")
|
167
212
|
Instruction.from_ptr(C.LLVMBuildNeg(self, arg, name))
|
168
213
|
end
|
169
214
|
|
215
|
+
# Boolean negation.
|
170
216
|
def not(arg, name = "")
|
171
217
|
Instruction.from_ptr(C.LLVMBuildNot(self, arg, name))
|
172
218
|
end
|
173
219
|
|
174
|
-
#
|
175
|
-
|
220
|
+
# Builds a malloc Instruction for the given type.
|
176
221
|
def malloc(ty, name = "")
|
177
222
|
Instruction.from_ptr(C.LLVMBuildMalloc(self, LLVM::Type(ty), name))
|
178
223
|
end
|
179
224
|
|
225
|
+
# Builds a malloc Instruction for the given array type.
|
180
226
|
def array_malloc(ty, val, name = "")
|
181
227
|
Instruction.from_ptr(C.LLVMBuildArrayMalloc(self, LLVM::Type(ty), val, name))
|
182
228
|
end
|
183
229
|
|
230
|
+
# Stack allocation.
|
231
|
+
# @LLVMinst alloca
|
184
232
|
def alloca(ty, name = "")
|
185
233
|
Instruction.from_ptr(C.LLVMBuildAlloca(self, LLVM::Type(ty), name))
|
186
234
|
end
|
187
235
|
|
236
|
+
# Array stack allocation
|
237
|
+
# @param LLVM::Value used to initialize each element.
|
238
|
+
# @LLVMinst alloca
|
188
239
|
def array_alloca(ty, val, name = "")
|
189
240
|
Instruction.from_ptr(C.LLVMBuildArrayAlloca(self, LLVM::Type(ty), val, name))
|
190
241
|
end
|
191
242
|
|
243
|
+
# Builds a free Instruction. Frees the given pointer (an Instruction).
|
192
244
|
def free(pointer)
|
193
245
|
Instruction.from_ptr(C.LLVMBuildFree(self, pointer))
|
194
246
|
end
|
195
247
|
|
248
|
+
# Builds a load Instruction with the given name. Loads the value of the
|
249
|
+
# given pointer (an Instruction).
|
250
|
+
# @LLVMinst load
|
196
251
|
def load(pointer, name = "")
|
197
252
|
Instruction.from_ptr(C.LLVMBuildLoad(self, pointer, name))
|
198
253
|
end
|
199
254
|
|
255
|
+
# Builds a store Instruction. Stores the given Value into the given
|
256
|
+
# pointer (an Instruction).
|
257
|
+
# @LLVMinst store
|
200
258
|
def store(val, pointer)
|
201
259
|
Instruction.from_ptr(C.LLVMBuildStore(self, val, pointer))
|
202
260
|
end
|
203
261
|
|
262
|
+
# Builds a getelementptr Instruction with the given name. Retrieves the
|
263
|
+
# element pointer at the given indices of the pointer (an Instruction).
|
264
|
+
# @LLVMinst gep
|
265
|
+
# @see http://llvm.org/docs/GetElementPtr.html
|
204
266
|
def gep(pointer, indices, name = "")
|
205
267
|
indices = Array(indices)
|
206
268
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
|
@@ -210,6 +272,12 @@ module LLVM
|
|
210
272
|
end
|
211
273
|
end
|
212
274
|
|
275
|
+
# Builds a inbounds getelementptr Instruction with the given name.
|
276
|
+
# Retrieves the element pointer at the given indices of the pointer (an
|
277
|
+
# Instruction). If the indices are outside the allocated pointer the
|
278
|
+
# retrieved value is undefined.
|
279
|
+
# @LLVMinst gep
|
280
|
+
# @see http://llvm.org/docs/GetElementPtr.html
|
213
281
|
def inbounds_gep(pointer, indices, name = "")
|
214
282
|
indices = Array(indices)
|
215
283
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
|
@@ -219,104 +287,164 @@ module LLVM
|
|
219
287
|
end
|
220
288
|
end
|
221
289
|
|
290
|
+
# Builds a struct getelementptr Instruction with the given name.
|
291
|
+
# Retrieves the element pointer at the given indices (idx) of the pointer
|
292
|
+
# (an Instruction). See http://llvm.org/docs/GetElementPtr.html for
|
293
|
+
# discussion.
|
294
|
+
# @LLVMinst gep
|
295
|
+
# @see http://llvm.org/docs/GetElementPtr.html
|
222
296
|
def struct_gep(pointer, idx, name = "")
|
223
297
|
Instruction.from_ptr(C.LLVMBuildStructGEP(self, pointer, idx, name))
|
224
298
|
end
|
225
299
|
|
300
|
+
# Builds a global string Instruction with the given name. Creates a global
|
301
|
+
# string.
|
226
302
|
def global_string(string, name = "")
|
227
303
|
Instruction.from_ptr(C.LLVMBuildGlobalString(self, string, name))
|
228
304
|
end
|
229
305
|
|
306
|
+
# Builds a global string Instruction with the given name. Creates a global
|
307
|
+
# string pointer.
|
230
308
|
def global_string_pointer(string, name = "")
|
231
309
|
Instruction.from_ptr(C.LLVMBuildGlobalStringPtr(self, string, name))
|
232
310
|
end
|
233
311
|
|
234
|
-
#
|
235
|
-
|
312
|
+
# @LLVMinst trunc
|
236
313
|
def trunc(val, ty, name = "")
|
237
314
|
Instruction.from_ptr(C.LLVMBuildTrunc(self, val, LLVM::Type(ty), name))
|
238
315
|
end
|
239
316
|
|
317
|
+
# @LLVMinst zext
|
240
318
|
def zext(val, ty, name = "")
|
241
319
|
Instruction.from_ptr(C.LLVMBuildZExt(self, val, LLVM::Type(ty), name))
|
242
320
|
end
|
243
321
|
|
322
|
+
# @LLVMinst sext
|
244
323
|
def sext(val, ty, name = "")
|
245
324
|
Instruction.from_ptr(C.LLVMBuildSExt(self, val, LLVM::Type(ty), name))
|
246
325
|
end
|
247
326
|
|
327
|
+
# @LLVMinst fptoui
|
248
328
|
def fp2ui(val, ty, name = "")
|
249
329
|
Instruction.from_ptr(C.LLVMBuildFPToUI(self, val, LLVM::Type(ty), name))
|
250
330
|
end
|
251
331
|
|
332
|
+
# @LLVMinst fptosi
|
252
333
|
def fp2si(val, ty, name = "")
|
253
334
|
Instruction.from_ptr(C.LLVMBuildFPToSI(self, val, LLVM::Type(ty), name))
|
254
335
|
end
|
255
336
|
|
337
|
+
# @LLVMinst uitofp
|
256
338
|
def ui2fp(val, ty, name = "")
|
257
339
|
Instruction.from_ptr(C.LLVMBuildUIToFP(self, val, LLVM::Type(ty), name))
|
258
340
|
end
|
259
341
|
|
342
|
+
# @LLVMinst sitofp
|
260
343
|
def si2fp(val, ty, name = "")
|
261
344
|
Instruction.from_ptr(C.LLVMBuildSIToFP(self, val, LLVM::Type(ty), name))
|
262
345
|
end
|
263
346
|
|
347
|
+
# @LLVMinst fptrunc
|
264
348
|
def fp_trunc(val, ty, name = "")
|
265
349
|
Instruction.from_ptr(C.LLVMBuildFPTrunc(self, val, LLVM::Type(ty), name))
|
266
350
|
end
|
267
351
|
|
352
|
+
# @LLVMinst fpext
|
268
353
|
def fp_ext(val, ty, name = "")
|
269
354
|
Instruction.from_ptr(C.LLVMBuildFPExt(self, val, LLVM::Type(ty), name))
|
270
355
|
end
|
271
356
|
|
357
|
+
# Cast a pointer to an int. Useful for pointer arithmetic.
|
358
|
+
# @LLVMinst ptrtoint
|
272
359
|
def ptr2int(val, ty, name = "")
|
273
360
|
Instruction.from_ptr(C.LLVMBuildPtrToInt(self, val, LLVM::Type(ty), name))
|
274
361
|
end
|
275
362
|
|
363
|
+
# @LLVMinst inttoptr
|
276
364
|
def int2ptr(val, ty, name = "")
|
277
365
|
Instruction.from_ptr(C.LLVMBuildIntToPtr(self, val, LLVM::Type(ty), name))
|
278
366
|
end
|
279
367
|
|
368
|
+
# @LLVMinst bitcast
|
280
369
|
def bit_cast(val, ty, name = "")
|
281
370
|
Instruction.from_ptr(C.LLVMBuildBitCast(self, val, LLVM::Type(ty), name))
|
282
371
|
end
|
283
372
|
|
373
|
+
# @LLVMinst zext
|
374
|
+
# @LLVMinst bitcast
|
284
375
|
def zext_or_bit_cast(val, ty, name = "")
|
285
376
|
Instruction.from_ptr(C.LLVMBuildZExtOrBitCast(self, val, LLVM::Type(ty), name))
|
286
377
|
end
|
287
378
|
|
379
|
+
# @LLVMinst sext
|
380
|
+
# @LLVMinst bitcast
|
288
381
|
def sext_or_bit_cast(val, ty, name = "")
|
289
382
|
Instruction.from_ptr(C.LLVMBuildSExtOrBitCast(self, val, LLVM::Type(ty), name))
|
290
383
|
end
|
291
384
|
|
385
|
+
# @LLVMinst trunc
|
386
|
+
# @LLVMinst bitcast
|
292
387
|
def trunc_or_bit_cast(val, ty, name = "")
|
293
388
|
Instruction.from_ptr(C.LLVMBuildTruncOrBitCast(self, val, LLVM::Type(ty), name))
|
294
389
|
end
|
295
390
|
|
391
|
+
# Builds a pointer cast Instruction with the given name.
|
296
392
|
def pointer_cast(val, ty, name = "")
|
297
393
|
Instruction.from_ptr(C.LLVMBuildPointerCast(self, val, LLVM::Type(ty), name))
|
298
394
|
end
|
299
395
|
|
396
|
+
# Builds a int cast Instruction with the given name.
|
300
397
|
def int_cast(val, ty, name = "")
|
301
398
|
Instruction.from_ptr(C.LLVMBuildIntCast(self, val, LLVM::Type(ty), name))
|
302
399
|
end
|
303
400
|
|
401
|
+
# Builds a fp cast Instruction with the given name.
|
304
402
|
def fp_cast(val, ty, name = "")
|
305
403
|
Instruction.from_ptr(C.LLVMBuildFPCast(self, val, LLVM::Type(ty), name))
|
306
404
|
end
|
307
405
|
|
308
|
-
#
|
309
|
-
|
406
|
+
# Builds an icmp Instruction. Compares lhs to rhs (Instructions)
|
407
|
+
# using the given symbol predicate (pred):
|
408
|
+
# :eq - equal to
|
409
|
+
# :ne - not equal to
|
410
|
+
# :ugt - unsigned greater than
|
411
|
+
# :uge - unsigned greater than or equal to
|
412
|
+
# :ult - unsigned less than
|
413
|
+
# :ule - unsigned less than or equal to
|
414
|
+
# :sgt - signed greater than
|
415
|
+
# :sge - signed greater than or equal to
|
416
|
+
# :slt - signed less than
|
417
|
+
# :sle - signed less than or equal to
|
418
|
+
# @LLVMinst icmp
|
310
419
|
def icmp(pred, lhs, rhs, name = "")
|
311
420
|
Instruction.from_ptr(C.LLVMBuildICmp(self, pred, lhs, rhs, name))
|
312
421
|
end
|
313
422
|
|
423
|
+
# Builds an fcmp Instruction. Compares lhs to rhs (Instructions) as Reals
|
424
|
+
# using the given symbol predicate (pred):
|
425
|
+
# :ord - ordered
|
426
|
+
# :uno - unordered: isnan(X) | isnan(Y)
|
427
|
+
# :oeq - ordered and equal to
|
428
|
+
# :oeq - unordered and equal to
|
429
|
+
# :one - ordered and not equal to
|
430
|
+
# :one - unordered and not equal to
|
431
|
+
# :ogt - ordered and greater than
|
432
|
+
# :uge - unordered and greater than or equal to
|
433
|
+
# :olt - ordered and less than
|
434
|
+
# :ule - unordered and less than or equal to
|
435
|
+
# :oge - ordered and greater than or equal to
|
436
|
+
# :sge - unordered and greater than or equal to
|
437
|
+
# :ole - ordered and less than or equal to
|
438
|
+
# :sle - unordered and less than or equal to
|
439
|
+
# :true - always true and folded
|
440
|
+
# :false - always false and folded
|
441
|
+
# @LLVMinst fcmp
|
314
442
|
def fcmp(pred, lhs, rhs, name = "")
|
315
443
|
Instruction.from_ptr(C.LLVMBuildFCmp(self, pred, lhs, rhs, name))
|
316
444
|
end
|
317
445
|
|
318
|
-
#
|
319
|
-
|
446
|
+
# Builds a Phi node of the given Type with the given incoming branches.
|
447
|
+
# @LLVMinst phi
|
320
448
|
def phi(ty, *incoming)
|
321
449
|
if incoming.last.kind_of? String
|
322
450
|
name = incoming.pop
|
@@ -329,6 +457,9 @@ module LLVM
|
|
329
457
|
phi
|
330
458
|
end
|
331
459
|
|
460
|
+
# Builds a call Instruction. Calls the given Function with the given
|
461
|
+
# args (Instructions).
|
462
|
+
# @LLVMinst call
|
332
463
|
def call(fun, *args)
|
333
464
|
raise "No fun" if fun.nil?
|
334
465
|
if args.last.kind_of? String
|
@@ -342,46 +473,57 @@ module LLVM
|
|
342
473
|
CallInst.from_ptr(C.LLVMBuildCall(self, fun, args_ptr, args.size, name))
|
343
474
|
end
|
344
475
|
|
476
|
+
# @LLVMinst select
|
345
477
|
def select(_if, _then, _else, name = "")
|
346
478
|
Instruction.from_ptr(C.LLVMBuildSelect(self, _if, _then, _else, name))
|
347
479
|
end
|
348
480
|
|
481
|
+
# @LLVMinst va_arg
|
349
482
|
def va_arg(list, ty, name = "")
|
350
483
|
Instruction.from_ptr(C.LLVMBuildVAArg(self, list, LLVM::Type(ty), name))
|
351
484
|
end
|
352
485
|
|
486
|
+
# @LLVMinst extractelement
|
353
487
|
def extract_element(vector, index, name = "")
|
354
488
|
Instruction.from_ptr(C.LLVMBuildExtractElement(self, vector, index, name))
|
355
489
|
end
|
356
490
|
|
491
|
+
# @LLVMinst insertelement
|
357
492
|
def insert_element(vector, elem, index, name = "")
|
358
493
|
Instruction.from_ptr(C.LLVMBuildInsertElement(self, vector, elem, index, name))
|
359
494
|
end
|
360
495
|
|
496
|
+
# @LLVMinst shufflevector
|
361
497
|
def shuffle_vector(vec1, vec2, mask, name = "")
|
362
498
|
Instruction.from_ptr(C.LLVMBuildShuffleVector(self, vec1, vec2, mask, name))
|
363
499
|
end
|
364
500
|
|
501
|
+
# LLVMinst extractvalue
|
365
502
|
def extract_value(aggregate, index, name = "")
|
366
503
|
Instruction.from_ptr(C.LLVMBuildExtractValue(self, aggregate, index, name))
|
367
504
|
end
|
368
505
|
|
506
|
+
# @LLVMinst insertvalue
|
369
507
|
def insert_value(aggregate, elem, index, name = "")
|
370
508
|
Instruction.from_ptr(C.LLVMBuildInsertValue(self, aggregate, elem, index, name))
|
371
509
|
end
|
372
510
|
|
511
|
+
# Check if a value is null.
|
373
512
|
def is_null(val, name = "")
|
374
513
|
Instruction.from_ptr(C.LLVMBuildIsNull(self, val, name))
|
375
514
|
end
|
376
515
|
|
516
|
+
# Check if a value is not null.
|
377
517
|
def is_not_null(val, name = "")
|
378
518
|
Instruction.from_ptr(C.LLVMBuildIsNotNull(self, val, name))
|
379
519
|
end
|
380
520
|
|
521
|
+
# Retrieves the pointer difference between the given lhs and rhs.
|
381
522
|
def ptr_diff(lhs, rhs, name = "")
|
382
523
|
Instruction.from_ptr(C.LLVMBuildPtrDiff(lhs, rhs, name))
|
383
524
|
end
|
384
525
|
|
526
|
+
# Disposes the builder.
|
385
527
|
def dispose
|
386
528
|
C.LLVMDisposeBuilder(@ptr)
|
387
529
|
end
|