ruby-llvm 3.0.0.beta → 3.0.0

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.
@@ -1,12 +1,6 @@
1
- module LLVM
2
- # @private
3
- module C
4
- attach_function :LLVMParseBitcode, [:pointer, :buffer_out, :buffer_out], :int
5
- attach_function :LLVMParseBitcodeInContext, [:pointer, :pointer, :buffer_out, :buffer_out], :int
6
- attach_function :LLVMWriteBitcodeToFile, [:pointer, :string], :int
7
- attach_function :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int
8
- end
1
+ require 'llvm/core/bitcode_ffi'
9
2
 
3
+ module LLVM
10
4
  class Module
11
5
  # Parse a module from a memory buffer
12
6
  # @param [String, LLVM::MemoryBuffer] path_or_memory_buffer
@@ -18,7 +12,7 @@ module LLVM
18
12
  end
19
13
  FFI::MemoryPointer.new(:pointer) do |mod_ref|
20
14
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
21
- status = C.LLVMParseBitcode(memory_buffer, mod_ref, msg_ref)
15
+ status = C.parse_bitcode(memory_buffer, mod_ref, msg_ref)
22
16
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
23
17
  return from_ptr(mod_ref.get_pointer(0))
24
18
  end
@@ -30,13 +24,13 @@ module LLVM
30
24
  # @return [true, false] Success
31
25
  def write_bitcode(path_or_io)
32
26
  status = if path_or_io.respond_to?(:path)
33
- C.LLVMWriteBitcodeToFile(self, path_or_io.path)
27
+ C.write_bitcode_to_file(self, path_or_io.path)
34
28
  elsif path_or_io.respond_to?(:fileno)
35
- C.LLVMWriteBitcodeToFD(self, path_or_io.fileno, 0, 1)
29
+ C.write_bitcode_to_fd(self, path_or_io.fileno, 0, 1)
36
30
  elsif path_or_io.kind_of?(Integer)
37
- C.LLVMWriteBitcodeToFD(self, path_or_io, 0, 1)
31
+ C.write_bitcode_to_fd(self, path_or_io, 0, 1)
38
32
  else
39
- C.LLVMWriteBitcodeToFile(self, path_or_io.to_str)
33
+ C.write_bitcode_to_file(self, path_or_io.to_str)
40
34
  end
41
35
  return status == 0
42
36
  end
@@ -62,7 +56,7 @@ module LLVM
62
56
  def self.from_file(path)
63
57
  FFI::MemoryPointer.new(:pointer) do |buf_ref|
64
58
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
65
- status = C.LLVMCreateMemoryBufferWithContentsOfFile(path.to_str, buf_ref, msg_ref)
59
+ status = C.create_memory_buffer_with_contents_of_file(path.to_str, buf_ref, msg_ref)
66
60
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
67
61
  return new(buf_ref.get_pointer(0))
68
62
  end
@@ -74,7 +68,7 @@ module LLVM
74
68
  def self.from_stdin
75
69
  FFI::Buffer.new(:pointer) do |buf_ref|
76
70
  FFI::Buffer.new(:pointer) do |msg_ref|
77
- status = C.LLVMCreateMemoryBufferWithSTDIN(buf_ref, msg_ref)
71
+ status = C.create_memory_buffer_with_stdin(buf_ref, msg_ref)
78
72
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
79
73
  return new(buf_ref.get_pointer(0))
80
74
  end
@@ -82,7 +76,9 @@ module LLVM
82
76
  end
83
77
 
84
78
  def dispose
85
- C.LLVMDisposeMemoryBuffer(@ptr)
79
+ return if @ptr.nil?
80
+ C.dispose_memory_buffer(@ptr)
81
+ @ptr = nil
86
82
  end
87
83
  end
88
84
  end
@@ -0,0 +1,104 @@
1
+ # Generated by ffi_gen. Please do not change this file by hand.
2
+
3
+ require 'ffi'
4
+
5
+ module LLVM::C
6
+ extend FFI::Library
7
+ ffi_lib 'LLVM-3.0'
8
+
9
+ # (Not documented)
10
+ #
11
+ # @method parse_bitcode(mem_buf, out_module, out_message)
12
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
13
+ # @param [FFI::Pointer(*ModuleRef)] out_module
14
+ # @param [FFI::Pointer(**Char_S)] out_message
15
+ # @return [Integer]
16
+ # @scope class
17
+ attach_function :parse_bitcode, :LLVMParseBitcode, [:pointer, :pointer, :pointer], :int
18
+
19
+ # (Not documented)
20
+ #
21
+ # @method parse_bitcode_in_context(context_ref, mem_buf, out_module, out_message)
22
+ # @param [FFI::Pointer(ContextRef)] context_ref
23
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
24
+ # @param [FFI::Pointer(*ModuleRef)] out_module
25
+ # @param [FFI::Pointer(**Char_S)] out_message
26
+ # @return [Integer]
27
+ # @scope class
28
+ attach_function :parse_bitcode_in_context, :LLVMParseBitcodeInContext, [:pointer, :pointer, :pointer, :pointer], :int
29
+
30
+ # Reads a module from the specified path, returning via the OutMP parameter
31
+ # a module provider which performs lazy deserialization. Returns 0 on success.
32
+ # Optionally returns a human-readable error message via OutMessage.
33
+ #
34
+ # @method get_bitcode_module_in_context(context_ref, mem_buf, out_m, out_message)
35
+ # @param [FFI::Pointer(ContextRef)] context_ref
36
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
37
+ # @param [FFI::Pointer(*ModuleRef)] out_m
38
+ # @param [FFI::Pointer(**Char_S)] out_message
39
+ # @return [Integer]
40
+ # @scope class
41
+ attach_function :get_bitcode_module_in_context, :LLVMGetBitcodeModuleInContext, [:pointer, :pointer, :pointer, :pointer], :int
42
+
43
+ # (Not documented)
44
+ #
45
+ # @method get_bitcode_module(mem_buf, out_m, out_message)
46
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
47
+ # @param [FFI::Pointer(*ModuleRef)] out_m
48
+ # @param [FFI::Pointer(**Char_S)] out_message
49
+ # @return [Integer]
50
+ # @scope class
51
+ attach_function :get_bitcode_module, :LLVMGetBitcodeModule, [:pointer, :pointer, :pointer], :int
52
+
53
+ # Deprecated: Use LLVMGetBitcodeModuleInContext instead.
54
+ #
55
+ # @method get_bitcode_module_provider_in_context(context_ref, mem_buf, out_mp, out_message)
56
+ # @param [FFI::Pointer(ContextRef)] context_ref
57
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
58
+ # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
59
+ # @param [FFI::Pointer(**Char_S)] out_message
60
+ # @return [Integer]
61
+ # @scope class
62
+ attach_function :get_bitcode_module_provider_in_context, :LLVMGetBitcodeModuleProviderInContext, [:pointer, :pointer, :pointer, :pointer], :int
63
+
64
+ # Deprecated: Use LLVMGetBitcodeModule instead.
65
+ #
66
+ # @method get_bitcode_module_provider(mem_buf, out_mp, out_message)
67
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
68
+ # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
69
+ # @param [FFI::Pointer(**Char_S)] out_message
70
+ # @return [Integer]
71
+ # @scope class
72
+ attach_function :get_bitcode_module_provider, :LLVMGetBitcodeModuleProvider, [:pointer, :pointer, :pointer], :int
73
+
74
+ # (Not documented)
75
+ #
76
+ # @method write_bitcode_to_file(m, path)
77
+ # @param [FFI::Pointer(ModuleRef)] m
78
+ # @param [String] path
79
+ # @return [Integer]
80
+ # @scope class
81
+ attach_function :write_bitcode_to_file, :LLVMWriteBitcodeToFile, [:pointer, :string], :int
82
+
83
+ # Writes a module to an open file descriptor. Returns 0 on success.
84
+ #
85
+ # @method write_bitcode_to_fd(m, fd, should_close, unbuffered)
86
+ # @param [FFI::Pointer(ModuleRef)] m
87
+ # @param [Integer] fd
88
+ # @param [Integer] should_close
89
+ # @param [Integer] unbuffered
90
+ # @return [Integer]
91
+ # @scope class
92
+ attach_function :write_bitcode_to_fd, :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int
93
+
94
+ # Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file
95
+ # descriptor. Returns 0 on success. Closes the Handle.
96
+ #
97
+ # @method write_bitcode_to_file_handle(m, handle)
98
+ # @param [FFI::Pointer(ModuleRef)] m
99
+ # @param [Integer] handle
100
+ # @return [Integer]
101
+ # @scope class
102
+ attach_function :write_bitcode_to_file_handle, :LLVMWriteBitcodeToFileHandle, [:pointer, :int], :int
103
+
104
+ end
@@ -1,7 +1,14 @@
1
1
  module LLVM
2
2
  class Builder
3
+ # Important: Call #dispose to free backend memory after use.
3
4
  def initialize
4
- @ptr = C.LLVMCreateBuilder()
5
+ @ptr = C.create_builder()
6
+ end
7
+
8
+ def dispose
9
+ return if @ptr.nil?
10
+ C.dispose_builder(@ptr)
11
+ @ptr = nil
5
12
  end
6
13
 
7
14
  # @private
@@ -15,7 +22,7 @@ module LLVM
15
22
  # @return [LLVM::Builder]
16
23
  def position(block, instruction)
17
24
  raise "Block must not be nil" if block.nil?
18
- C.LLVMPositionBuilder(self, block, instruction)
25
+ C.position_builder(self, block, instruction)
19
26
  self
20
27
  end
21
28
 
@@ -24,7 +31,7 @@ module LLVM
24
31
  # @return [LLVM::Builder]
25
32
  def position_before(instruction)
26
33
  raise "Instruction must not be nil" if instruction.nil?
27
- C.LLVMPositionBuilderBefore(self, instruction)
34
+ C.position_builder_before(self, instruction)
28
35
  self
29
36
  end
30
37
 
@@ -33,27 +40,27 @@ module LLVM
33
40
  # @return [LLVM::Builder]
34
41
  def position_at_end(block)
35
42
  raise "Block must not be nil" if block.nil?
36
- C.LLVMPositionBuilderAtEnd(self, block)
43
+ C.position_builder_at_end(self, block)
37
44
  self
38
45
  end
39
46
 
40
47
  # The BasicBlock at which the Builder is currently positioned.
41
48
  # @return [LLVM::BasicBlock]
42
49
  def insert_block
43
- BasicBlock.from_ptr(C.LLVMGetInsertBlock(self))
50
+ BasicBlock.from_ptr(C.get_insert_block(self))
44
51
  end
45
52
 
46
53
  # @return [LLVM::Instruction]
47
54
  # @LLVMinst ret
48
55
  def ret_void
49
- Instruction.from_ptr(C.LLVMBuildRetVoid(self))
56
+ Instruction.from_ptr(C.build_ret_void(self))
50
57
  end
51
58
 
52
59
  # @param [LLVM::Value] val The value to return
53
60
  # @return [LLVM::Instruction]
54
61
  # @LLVMinst ret
55
62
  def ret(val)
56
- Instruction.from_ptr(C.LLVMBuildRet(self, val))
63
+ Instruction.from_ptr(C.build_ret(self, val))
57
64
  end
58
65
 
59
66
  # Builds a ret instruction returning multiple values.
@@ -63,7 +70,7 @@ module LLVM
63
70
  def aggregate_ret(*vals)
64
71
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * vals.size) do |vals_ptr|
65
72
  vals_ptr.write_array_of_pointer(vals)
66
- Instruction.from_ptr(C.LLVMBuildAggregateRet(self, vals_ptr, vals.size))
73
+ Instruction.from_ptr(C.build_aggregate_ret(self, vals_ptr, vals.size))
67
74
  end
68
75
  end
69
76
 
@@ -73,7 +80,7 @@ module LLVM
73
80
  # @LLVMinst br
74
81
  def br(block)
75
82
  Instruction.from_ptr(
76
- C.LLVMBuildBr(self, block))
83
+ C.build_br(self, block))
77
84
  end
78
85
 
79
86
  # Conditional branching (i.e. if)
@@ -84,7 +91,7 @@ module LLVM
84
91
  # @LLVMinst br
85
92
  def cond(cond, iftrue, iffalse)
86
93
  Instruction.from_ptr(
87
- C.LLVMBuildCondBr(self, cond, iftrue, iffalse))
94
+ C.build_cond_br(self, cond, iftrue, iffalse))
88
95
  end
89
96
 
90
97
  # @LLVMinst switch
@@ -95,7 +102,7 @@ module LLVM
95
102
  # to the corresponding basic block.
96
103
  # @return [LLVM::Instruction]
97
104
  def switch(val, default, cases)
98
- inst = SwitchInst.from_ptr(C.LLVMBuildSwitch(self, val, default, cases.size))
105
+ inst = SwitchInst.from_ptr(C.build_switch(self, val, default, cases.size))
99
106
  cases.each do |(val, block)|
100
107
  inst.add_case(val, block)
101
108
  end
@@ -113,7 +120,7 @@ module LLVM
113
120
  # @LLVMinst invoke
114
121
  def invoke(fun, args, normal, exception, name = "")
115
122
  Instruction.from_ptr(
116
- C.LLVMBuildInvoke(self,
123
+ C.build_invoke(self,
117
124
  fun, args, args.size, normal, exception, name))
118
125
  end
119
126
 
@@ -122,7 +129,7 @@ module LLVM
122
129
  # @return [LLVM::Instruction]
123
130
  # @LLVMinst unreachable
124
131
  def unreachable
125
- Instruction.from_ptr(C.LLVMBuildUnreachable(self))
132
+ Instruction.from_ptr(C.build_unreachable(self))
126
133
  end
127
134
 
128
135
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -131,7 +138,7 @@ module LLVM
131
138
  # @return [LLVM::Instruction] The integer sum of the two operands
132
139
  # @LLVMinst add
133
140
  def add(lhs, rhs, name = "")
134
- Instruction.from_ptr(C.LLVMBuildAdd(self, lhs, rhs, name))
141
+ Instruction.from_ptr(C.build_add(self, lhs, rhs, name))
135
142
  end
136
143
 
137
144
  # No signed wrap addition.
@@ -141,7 +148,7 @@ module LLVM
141
148
  # @return [LLVM::Instruction] The integer sum of the two operands
142
149
  # @LLVMinst add
143
150
  def nsw_add(lhs, rhs, name = "")
144
- Instruction.from_ptr(C.LLVMBuildNSWAdd(self, lhs, rhs, name))
151
+ Instruction.from_ptr(C.build_nsw_add(self, lhs, rhs, name))
145
152
  end
146
153
 
147
154
  # @param [LLVM::Value] lhs Floating point or vector of floating points
@@ -150,7 +157,7 @@ module LLVM
150
157
  # @return [LLVM::Instruction] The floating point sum of the two operands
151
158
  # @LLVMinst fadd
152
159
  def fadd(lhs, rhs, name = "")
153
- Instruction.from_ptr(C.LLVMBuildFAdd(self, lhs, rhs, name))
160
+ Instruction.from_ptr(C.build_f_add(self, lhs, rhs, name))
154
161
  end
155
162
 
156
163
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -159,7 +166,7 @@ module LLVM
159
166
  # @return [LLVM::Instruction] The integer difference of the two operands
160
167
  # @LLVMinst sub
161
168
  def sub(lhs, rhs, name = "")
162
- Instruction.from_ptr(C.LLVMBuildSub(self, lhs, rhs, name))
169
+ Instruction.from_ptr(C.build_sub(self, lhs, rhs, name))
163
170
  end
164
171
 
165
172
  # @param [LLVM::Value] lhs Floating point or vector of floating points
@@ -169,7 +176,7 @@ module LLVM
169
176
  # operands
170
177
  # @LLVMinst fsub
171
178
  def fsub(lhs, rhs, name = "")
172
- Instruction.from_ptr(C.LLVMBuildFSub(self, lhs, rhs, name))
179
+ Instruction.from_ptr(C.build_f_sub(self, lhs, rhs, name))
173
180
  end
174
181
 
175
182
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -178,7 +185,7 @@ module LLVM
178
185
  # @return [LLVM::Instruction] The integer product of the two operands
179
186
  # @LLVMinst mul
180
187
  def mul(lhs, rhs, name = "")
181
- Instruction.from_ptr(C.LLVMBuildMul(self, lhs, rhs, name))
188
+ Instruction.from_ptr(C.build_mul(self, lhs, rhs, name))
182
189
  end
183
190
 
184
191
  # @param [LLVM::Value] lhs Floating point or vector of floating points
@@ -188,7 +195,7 @@ module LLVM
188
195
  # operands
189
196
  # @LLVMinst fmul
190
197
  def fmul(lhs, rhs, name = "")
191
- Instruction.from_ptr(C.LLVMBuildFMul(self, lhs, rhs, name))
198
+ Instruction.from_ptr(C.build_f_mul(self, lhs, rhs, name))
192
199
  end
193
200
 
194
201
  # Unsigned integer division
@@ -198,7 +205,7 @@ module LLVM
198
205
  # @return [LLVM::Instruction] The integer quotient of the two operands
199
206
  # @LLVMinst udiv
200
207
  def udiv(lhs, rhs, name = "")
201
- Instruction.from_ptr(C.LLVMBuildUDiv(self, lhs, rhs, name))
208
+ Instruction.from_ptr(C.build_u_div(self, lhs, rhs, name))
202
209
  end
203
210
 
204
211
  # Signed division
@@ -208,7 +215,7 @@ module LLVM
208
215
  # @return [LLVM::Instruction] The integer quotient of the two operands
209
216
  # @LLVMinst sdiv
210
217
  def sdiv(lhs, rhs, name = "")
211
- Instruction.from_ptr(C.LLVMBuildSDiv(self, lhs, rhs, name))
218
+ Instruction.from_ptr(C.build_s_div(self, lhs, rhs, name))
212
219
  end
213
220
 
214
221
  # Signed exact division
@@ -218,7 +225,7 @@ module LLVM
218
225
  # @return [LLVM::Instruction] The integer quotient of the two operands
219
226
  # @LLVMinst sdiv
220
227
  def exact_sdiv(lhs, rhs, name = "")
221
- Instruction.from_ptr(C.LLVMBuildExactSDiv(self, lhs, rhs, name))
228
+ Instruction.from_ptr(C.build_exact_s_div(self, lhs, rhs, name))
222
229
  end
223
230
 
224
231
  # @param [LLVM::Value] lhs Floating point or vector of floating points
@@ -228,7 +235,7 @@ module LLVM
228
235
  # operands
229
236
  # @LLVMinst fdiv
230
237
  def fdiv(lhs, rhs, name = "")
231
- Instruction.from_ptr(C.LLVMBuildFDiv(self, lhs, rhs, name))
238
+ Instruction.from_ptr(C.build_f_div(self, lhs, rhs, name))
232
239
  end
233
240
 
234
241
  # Unsigned remainder
@@ -238,7 +245,7 @@ module LLVM
238
245
  # @return [LLVM::Instruction] The integer remainder
239
246
  # @LLVMinst urem
240
247
  def urem(lhs, rhs, name = "")
241
- Instruction.from_ptr(C.LLVMBuildURem(self, lhs, rhs, name))
248
+ Instruction.from_ptr(C.build_u_rem(self, lhs, rhs, name))
242
249
  end
243
250
 
244
251
  # Signed remainder
@@ -248,7 +255,7 @@ module LLVM
248
255
  # @return [LLVM::Instruction] The integer remainder
249
256
  # @LLVMinst srem
250
257
  def srem(lhs, rhs, name = "")
251
- Instruction.from_ptr(C.LLVMBuildSRem(self, lhs, rhs, name))
258
+ Instruction.from_ptr(C.build_s_rem(self, lhs, rhs, name))
252
259
  end
253
260
 
254
261
  # @param [LLVM::Value] lhs Floating point or vector of floating points
@@ -257,7 +264,7 @@ module LLVM
257
264
  # @return [LLVM::Instruction] The floating point remainder
258
265
  # @LLVMinst frem
259
266
  def frem(lhs, rhs, name = "")
260
- Instruction.from_ptr(C.LLVMBuildFRem(self, lhs, rhs, name))
267
+ Instruction.from_ptr(C.build_f_rem(self, lhs, rhs, name))
261
268
  end
262
269
 
263
270
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -266,7 +273,7 @@ module LLVM
266
273
  # @return [LLVM::Instruction] An integer instruction
267
274
  # @LLVMinst shl
268
275
  def shl(lhs, rhs, name = "")
269
- Instruction.from_ptr(C.LLVMBuildShl(self, lhs, rhs, name))
276
+ Instruction.from_ptr(C.build_shl(self, lhs, rhs, name))
270
277
  end
271
278
 
272
279
  # Shifts right with zero fill.
@@ -276,7 +283,7 @@ module LLVM
276
283
  # @return [LLVM::Instruction] An integer instruction
277
284
  # @LLVMinst lshr
278
285
  def lshr(lhs, rhs, name = "")
279
- Instruction.from_ptr(C.LLVMBuildLShr(self, lhs, rhs, name))
286
+ Instruction.from_ptr(C.build_l_shr(self, lhs, rhs, name))
280
287
  end
281
288
 
282
289
  # Arithmatic shift right.
@@ -286,7 +293,7 @@ module LLVM
286
293
  # @return [LLVM::Instruction] An integer instruction
287
294
  # @LLVMinst ashr
288
295
  def ashr(lhs, rhs, name = "")
289
- Instruction.from_ptr(C.LLVMBuildAShr(self, lhs, rhs, name))
296
+ Instruction.from_ptr(C.build_a_shr(self, lhs, rhs, name))
290
297
  end
291
298
 
292
299
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -295,7 +302,7 @@ module LLVM
295
302
  # @return [LLVM::Instruction] An integer instruction
296
303
  # @LLVMinst and
297
304
  def and(lhs, rhs, name = "")
298
- Instruction.from_ptr(C.LLVMBuildAnd(self, lhs, rhs, name))
305
+ Instruction.from_ptr(C.build_and(self, lhs, rhs, name))
299
306
  end
300
307
 
301
308
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -304,7 +311,7 @@ module LLVM
304
311
  # @return [LLVM::Instruction] An integer instruction
305
312
  # @LLVMinst or
306
313
  def or(lhs, rhs, name = "")
307
- Instruction.from_ptr(C.LLVMBuildOr(self, lhs, rhs, name))
314
+ Instruction.from_ptr(C.build_or(self, lhs, rhs, name))
308
315
  end
309
316
 
310
317
  # @param [LLVM::Value] lhs Integer or vector of integers
@@ -313,7 +320,7 @@ module LLVM
313
320
  # @return [LLVM::Instruction] An integer instruction
314
321
  # @LLVMinst xor
315
322
  def xor(lhs, rhs, name = "")
316
- Instruction.from_ptr(C.LLVMBuildXor(self, lhs, rhs, name))
323
+ Instruction.from_ptr(C.build_xor(self, lhs, rhs, name))
317
324
  end
318
325
 
319
326
  # Integer negation. Implemented as a shortcut to the equivalent sub
@@ -323,7 +330,7 @@ module LLVM
323
330
  # @return [LLVM::Instruction] The negated operand
324
331
  # @LLVMinst sub
325
332
  def neg(arg, name = "")
326
- Instruction.from_ptr(C.LLVMBuildNeg(self, arg, name))
333
+ Instruction.from_ptr(C.build_neg(self, arg, name))
327
334
  end
328
335
 
329
336
  # Boolean negation.
@@ -331,7 +338,7 @@ module LLVM
331
338
  # @param [String] name The name of the result in LLVM IR
332
339
  # @return [LLVM::Instruction] The negated operand
333
340
  def not(arg, name = "")
334
- Instruction.from_ptr(C.LLVMBuildNot(self, arg, name))
341
+ Instruction.from_ptr(C.build_not(self, arg, name))
335
342
  end
336
343
 
337
344
  # @param [LLVM::Type, #type] ty The type or value whose type
@@ -339,7 +346,7 @@ module LLVM
339
346
  # @param [String] name The name of the result in LLVM IR
340
347
  # @return [LLVM::Instruction] A pointer to the malloced bytes
341
348
  def malloc(ty, name = "")
342
- Instruction.from_ptr(C.LLVMBuildMalloc(self, LLVM::Type(ty), name))
349
+ Instruction.from_ptr(C.build_malloc(self, LLVM::Type(ty), name))
343
350
  end
344
351
 
345
352
  # @param [LLVM::Type, #type] ty The type or value whose type will be the
@@ -348,7 +355,7 @@ module LLVM
348
355
  # @param [String] name The name of the result in LLVM IR
349
356
  # @return [LLVM::Instruction] A pointer to the malloced array
350
357
  def array_malloc(ty, sz, name = "")
351
- Instruction.from_ptr(C.LLVMBuildArrayMalloc(self, LLVM::Type(ty), sz, name))
358
+ Instruction.from_ptr(C.build_array_malloc(self, LLVM::Type(ty), sz, name))
352
359
  end
353
360
 
354
361
  # Stack allocation.
@@ -358,7 +365,7 @@ module LLVM
358
365
  # @return [LLVM::Instruction] A pointer to the allocad bytes
359
366
  # @LLVMinst alloca
360
367
  def alloca(ty, name = "")
361
- Instruction.from_ptr(C.LLVMBuildAlloca(self, LLVM::Type(ty), name))
368
+ Instruction.from_ptr(C.build_alloca(self, LLVM::Type(ty), name))
362
369
  end
363
370
 
364
371
  # Array stack allocation
@@ -369,13 +376,13 @@ module LLVM
369
376
  # @return [LLVM::Instruction] A pointer to the allocad array
370
377
  # @LLVMinst alloca
371
378
  def array_alloca(ty, sz, name = "")
372
- Instruction.from_ptr(C.LLVMBuildArrayAlloca(self, LLVM::Type(ty), sz, name))
379
+ Instruction.from_ptr(C.build_array_alloca(self, LLVM::Type(ty), sz, name))
373
380
  end
374
381
 
375
382
  # @param [LLVM::Value] ptr The pointer to be freed
376
383
  # @return [LLVM::Instruction] The result of the free instruction
377
384
  def free(ptr)
378
- Instruction.from_ptr(C.LLVMBuildFree(self, ptr))
385
+ Instruction.from_ptr(C.build_free(self, ptr))
379
386
  end
380
387
 
381
388
  # Load the value of a given pointer
@@ -385,7 +392,7 @@ module LLVM
385
392
  # a value of the pointer's type.
386
393
  # @LLVMinst load
387
394
  def load(ptr, name = "")
388
- Instruction.from_ptr(C.LLVMBuildLoad(self, ptr, name))
395
+ Instruction.from_ptr(C.build_load(self, ptr, name))
389
396
  end
390
397
 
391
398
  # Store a value at a given pointer
@@ -394,7 +401,7 @@ module LLVM
394
401
  # @return [LLVM::Instruction] The result of the store operation
395
402
  # @LLVMinst store
396
403
  def store(val, ptr)
397
- Instruction.from_ptr(C.LLVMBuildStore(self, val, ptr))
404
+ Instruction.from_ptr(C.build_store(self, val, ptr))
398
405
  end
399
406
 
400
407
  # Obtain a pointer to the element at the given indices
@@ -410,7 +417,7 @@ module LLVM
410
417
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
411
418
  indices_ptr.write_array_of_pointer(indices)
412
419
  return Instruction.from_ptr(
413
- C.LLVMBuildGEP(self, ptr, indices_ptr, indices.size, name))
420
+ C.build_gep(self, ptr, indices_ptr, indices.size, name))
414
421
  end
415
422
  end
416
423
 
@@ -428,7 +435,7 @@ module LLVM
428
435
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
429
436
  indices_ptr.write_array_of_pointer(indices)
430
437
  return Instruction.from_ptr(
431
- C.LLVMBuildInBoundsGEP(self, ptr, indices_ptr, indices.size, name))
438
+ C.build_in_bounds_gep(self, ptr, indices_ptr, indices.size, name))
432
439
  end
433
440
  end
434
441
 
@@ -441,7 +448,7 @@ module LLVM
441
448
  # @LLVMinst gep
442
449
  # @see http://llvm.org/docs/GetElementPtr.html
443
450
  def struct_gep(pointer, idx, name = "")
444
- Instruction.from_ptr(C.LLVMBuildStructGEP(self, pointer, idx, name))
451
+ Instruction.from_ptr(C.build_struct_gep(self, pointer, idx, name))
445
452
  end
446
453
 
447
454
  # Creates a global string initialized to a given value.
@@ -449,7 +456,7 @@ module LLVM
449
456
  # @param [Name] name Name of the result in LLVM IR
450
457
  # @return [LLVM::Instruction] Reference to the global string
451
458
  def global_string(string, name = "")
452
- Instruction.from_ptr(C.LLVMBuildGlobalString(self, string, name))
459
+ Instruction.from_ptr(C.build_global_string(self, string, name))
453
460
  end
454
461
 
455
462
  # Creates a pointer to a global string initialized to a given value.
@@ -457,7 +464,7 @@ module LLVM
457
464
  # @param [String] name The name of the result in LLVM IR
458
465
  # @return [LLVM::Instruction] Reference to the global string pointer
459
466
  def global_string_pointer(string, name = "")
460
- Instruction.from_ptr(C.LLVMBuildGlobalStringPtr(self, string, name))
467
+ Instruction.from_ptr(C.build_global_string_ptr(self, string, name))
461
468
  end
462
469
 
463
470
  # Truncates its operand to the given type. The size of the value type must
@@ -469,7 +476,7 @@ module LLVM
469
476
  # @return [LLVM::Instruction] The truncated value
470
477
  # @LLVMinst trunc
471
478
  def trunc(val, ty, name = "")
472
- Instruction.from_ptr(C.LLVMBuildTrunc(self, val, LLVM::Type(ty), name))
479
+ Instruction.from_ptr(C.build_trunc(self, val, LLVM::Type(ty), name))
473
480
  end
474
481
 
475
482
  # Zero extends its operand to the given type. The size of the value type
@@ -481,7 +488,7 @@ module LLVM
481
488
  # @return [LLVM::Instruction] The extended value
482
489
  # @LLVMinst zext
483
490
  def zext(val, ty, name = "")
484
- Instruction.from_ptr(C.LLVMBuildZExt(self, val, LLVM::Type(ty), name))
491
+ Instruction.from_ptr(C.build_z_ext(self, val, LLVM::Type(ty), name))
485
492
  end
486
493
 
487
494
  # Sign extension by copying the sign bit (highest order bit) of the value
@@ -493,7 +500,7 @@ module LLVM
493
500
  # @return [LLVM::Instruction] The extended value
494
501
  # @LLVMinst sext
495
502
  def sext(val, ty, name = "")
496
- Instruction.from_ptr(C.LLVMBuildSExt(self, val, LLVM::Type(ty), name))
503
+ Instruction.from_ptr(C.build_s_ext(self, val, LLVM::Type(ty), name))
497
504
  end
498
505
 
499
506
  # Convert a floating point to an unsigned integer
@@ -504,7 +511,7 @@ module LLVM
504
511
  # @return [LLVM::Instruction] The converted value
505
512
  # @LLVMinst fptoui
506
513
  def fp2ui(val, ty, name = "")
507
- Instruction.from_ptr(C.LLVMBuildFPToUI(self, val, LLVM::Type(ty), name))
514
+ Instruction.from_ptr(C.build_fp_to_ui(self, val, LLVM::Type(ty), name))
508
515
  end
509
516
 
510
517
  # Convert a floating point to a signed integer
@@ -515,7 +522,7 @@ module LLVM
515
522
  # @return [LLVM::Instruction] The converted value
516
523
  # @LLVMinst fptosi
517
524
  def fp2si(val, ty, name = "")
518
- Instruction.from_ptr(C.LLVMBuildFPToSI(self, val, LLVM::Type(ty), name))
525
+ Instruction.from_ptr(C.build_fp_to_si(self, val, LLVM::Type(ty), name))
519
526
  end
520
527
 
521
528
  # Convert an unsigned integer to a floating point
@@ -527,7 +534,7 @@ module LLVM
527
534
  # @return [LLVM::Instruction] The converted value
528
535
  # @LLVMinst uitofp
529
536
  def ui2fp(val, ty, name = "")
530
- Instruction.from_ptr(C.LLVMBuildUIToFP(self, val, LLVM::Type(ty), name))
537
+ Instruction.from_ptr(C.build_ui_to_fp(self, val, LLVM::Type(ty), name))
531
538
  end
532
539
 
533
540
  # Convert a signed integer to a floating point
@@ -539,7 +546,7 @@ module LLVM
539
546
  # @return [LLVM::Instruction] The converted value
540
547
  # @LLVMinst sitofp
541
548
  def si2fp(val, ty, name = "")
542
- Instruction.from_ptr(C.LLVMBuildSIToFP(self, val, LLVM::Type(ty), name))
549
+ Instruction.from_ptr(C.build_si_to_fp(self, val, LLVM::Type(ty), name))
543
550
  end
544
551
 
545
552
  # Truncate a floating point value
@@ -550,7 +557,7 @@ module LLVM
550
557
  # @return [LLVM::Instruction] The truncated value
551
558
  # @LLVMinst fptrunc
552
559
  def fp_trunc(val, ty, name = "")
553
- Instruction.from_ptr(C.LLVMBuildFPTrunc(self, val, LLVM::Type(ty), name))
560
+ Instruction.from_ptr(C.build_fp_trunc(self, val, LLVM::Type(ty), name))
554
561
  end
555
562
 
556
563
  # Extend a floating point value
@@ -561,7 +568,7 @@ module LLVM
561
568
  # @return [LLVM::Instruction] The extended value
562
569
  # @LLVMinst fpext
563
570
  def fp_ext(val, ty, name = "")
564
- Instruction.from_ptr(C.LLVMBuildFPExt(self, val, LLVM::Type(ty), name))
571
+ Instruction.from_ptr(C.build_fp_ext(self, val, LLVM::Type(ty), name))
565
572
  end
566
573
 
567
574
  # Cast a pointer to an int. Useful for pointer arithmetic.
@@ -572,7 +579,7 @@ module LLVM
572
579
  # the pointer's address
573
580
  # @LLVMinst ptrtoint
574
581
  def ptr2int(val, ty, name = "")
575
- Instruction.from_ptr(C.LLVMBuildPtrToInt(self, val, LLVM::Type(ty), name))
582
+ Instruction.from_ptr(C.build_ptr_to_int(self, val, LLVM::Type(ty), name))
576
583
  end
577
584
 
578
585
  # Cast an int to a pointer
@@ -583,7 +590,7 @@ module LLVM
583
590
  # held in val
584
591
  # @LLVMinst inttoptr
585
592
  def int2ptr(val, ty, name = "")
586
- Instruction.from_ptr(C.LLVMBuildIntToPtr(self, val, LLVM::Type(ty), name))
593
+ Instruction.from_ptr(C.build_int_to_ptr(self, val, LLVM::Type(ty), name))
587
594
  end
588
595
 
589
596
  # Cast a value to the given type without changing any bits
@@ -593,7 +600,7 @@ module LLVM
593
600
  # @return [LLVM::Instruction] A value of the target type
594
601
  # @LLVMinst bitcast
595
602
  def bit_cast(val, ty, name = "")
596
- Instruction.from_ptr(C.LLVMBuildBitCast(self, val, LLVM::Type(ty), name))
603
+ Instruction.from_ptr(C.build_bit_cast(self, val, LLVM::Type(ty), name))
597
604
  end
598
605
 
599
606
  # @param [LLVM::Value] val
@@ -603,7 +610,7 @@ module LLVM
603
610
  # @LLVMinst zext
604
611
  # @LLVMinst bitcast
605
612
  def zext_or_bit_cast(val, ty, name = "")
606
- Instruction.from_ptr(C.LLVMBuildZExtOrBitCast(self, val, LLVM::Type(ty), name))
613
+ Instruction.from_ptr(C.build_z_ext_or_bit_cast(self, val, LLVM::Type(ty), name))
607
614
  end
608
615
 
609
616
  # @param [LLVM::Value] val
@@ -613,7 +620,7 @@ module LLVM
613
620
  # @LLVMinst sext
614
621
  # @LLVMinst bitcast
615
622
  def sext_or_bit_cast(val, ty, name = "")
616
- Instruction.from_ptr(C.LLVMBuildSExtOrBitCast(self, val, LLVM::Type(ty), name))
623
+ Instruction.from_ptr(C.build_s_ext_or_bit_cast(self, val, LLVM::Type(ty), name))
617
624
  end
618
625
 
619
626
  # @param [LLVM::Value] val
@@ -623,7 +630,7 @@ module LLVM
623
630
  # @LLVMinst trunc
624
631
  # @LLVMinst bitcast
625
632
  def trunc_or_bit_cast(val, ty, name = "")
626
- Instruction.from_ptr(C.LLVMBuildTruncOrBitCast(self, val, LLVM::Type(ty), name))
633
+ Instruction.from_ptr(C.build_trunc_or_bit_cast(self, val, LLVM::Type(ty), name))
627
634
  end
628
635
 
629
636
  # @param [LLVM::Value] val
@@ -631,7 +638,7 @@ module LLVM
631
638
  # @param [String] name The name of the result in LLVM IR
632
639
  # @return [LLVM::Instruction]
633
640
  def pointer_cast(val, ty, name = "")
634
- Instruction.from_ptr(C.LLVMBuildPointerCast(self, val, LLVM::Type(ty), name))
641
+ Instruction.from_ptr(C.build_pointer_cast(self, val, LLVM::Type(ty), name))
635
642
  end
636
643
 
637
644
  # @param [LLVM::Value] val
@@ -639,7 +646,7 @@ module LLVM
639
646
  # @param [String] name The name of the result in LLVM IR
640
647
  # @return [LLVM::Instruction]
641
648
  def int_cast(val, ty, name = "")
642
- Instruction.from_ptr(C.LLVMBuildIntCast(self, val, LLVM::Type(ty), name))
649
+ Instruction.from_ptr(C.build_int_cast(self, val, LLVM::Type(ty), name))
643
650
  end
644
651
 
645
652
  # @param [LLVM::Value] val
@@ -647,7 +654,7 @@ module LLVM
647
654
  # @param [String] name The name of the result in LLVM IR
648
655
  # @return [LLVM::Instruction]
649
656
  def fp_cast(val, ty, name = "")
650
- Instruction.from_ptr(C.LLVMBuildFPCast(self, val, LLVM::Type(ty), name))
657
+ Instruction.from_ptr(C.build_fp_cast(self, val, LLVM::Type(ty), name))
651
658
  end
652
659
 
653
660
  # Builds an icmp Instruction. Compares lhs to rhs (Instructions)
@@ -671,7 +678,7 @@ module LLVM
671
678
  # @return [LLVM::Instruction] A boolean represented as i1
672
679
  # @LLVMinst icmp
673
680
  def icmp(pred, lhs, rhs, name = "")
674
- Instruction.from_ptr(C.LLVMBuildICmp(self, pred, lhs, rhs, name))
681
+ Instruction.from_ptr(C.build_i_cmp(self, pred, lhs, rhs, name))
675
682
  end
676
683
 
677
684
  # Builds an fcmp Instruction. Compares lhs to rhs (Instructions) as Reals
@@ -701,7 +708,7 @@ module LLVM
701
708
  # @return [LLVM::Instruction] A boolean represented as i1
702
709
  # @LLVMinst fcmp
703
710
  def fcmp(pred, lhs, rhs, name = "")
704
- Instruction.from_ptr(C.LLVMBuildFCmp(self, pred, lhs, rhs, name))
711
+ Instruction.from_ptr(C.build_f_cmp(self, pred, lhs, rhs, name))
705
712
  end
706
713
 
707
714
  # Build a Phi node of the given type with the given incoming branches
@@ -715,7 +722,7 @@ module LLVM
715
722
  # @LLVMinst phi
716
723
  def phi(ty, incoming, name = "")
717
724
 
718
- phi = Phi.from_ptr(C.LLVMBuildPhi(self, LLVM::Type(ty), name))
725
+ phi = Phi.from_ptr(C.build_phi(self, LLVM::Type(ty), name))
719
726
  phi.add_incoming(incoming)
720
727
  phi
721
728
  end
@@ -736,7 +743,7 @@ module LLVM
736
743
 
737
744
  args_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size)
738
745
  args_ptr.write_array_of_pointer(args)
739
- CallInst.from_ptr(C.LLVMBuildCall(self, fun, args_ptr, args.size, name))
746
+ CallInst.from_ptr(C.build_call(self, fun, args_ptr, args.size, name))
740
747
  end
741
748
 
742
749
  # Return a value based on a condition. This differs from 'cond' in that
@@ -751,7 +758,7 @@ module LLVM
751
758
  # _else
752
759
  # @LLVMinst select
753
760
  def select(_if, _then, _else, name = "")
754
- Instruction.from_ptr(C.LLVMBuildSelect(self, _if, _then, _else, name))
761
+ Instruction.from_ptr(C.build_select(self, _if, _then, _else, name))
755
762
  end
756
763
 
757
764
  # Extract an element from a vector
@@ -762,7 +769,7 @@ module LLVM
762
769
  # @return [LLVM::Instruction] The extracted element
763
770
  # @LLVMinst extractelement
764
771
  def extract_element(vector, idx, name = "")
765
- Instruction.from_ptr(C.LLVMBuildExtractElement(self, vector, idx, name))
772
+ Instruction.from_ptr(C.build_extract_element(self, vector, idx, name))
766
773
  end
767
774
 
768
775
  # Insert an element into a vector
@@ -773,7 +780,7 @@ module LLVM
773
780
  # @return [LLVM::Instruction] A vector the same type as 'vector'
774
781
  # @LLVMinst insertelement
775
782
  def insert_element(vector, elem, idx, name = "")
776
- Instruction.from_ptr(C.LLVMBuildInsertElement(self, vector, elem, idx, name))
783
+ Instruction.from_ptr(C.build_insert_element(self, vector, elem, idx, name))
777
784
  end
778
785
 
779
786
  # Shuffle two vectors according to a given mask
@@ -785,7 +792,7 @@ module LLVM
785
792
  # @return [LLVM::Instruction] The shuffled vector
786
793
  # @LLVMinst shufflevector
787
794
  def shuffle_vector(vec1, vec2, mask, name = "")
788
- Instruction.from_ptr(C.LLVMBuildShuffleVector(self, vec1, vec2, mask, name))
795
+ Instruction.from_ptr(C.build_shuffle_vector(self, vec1, vec2, mask, name))
789
796
  end
790
797
 
791
798
  # Extract the value of a member field from an aggregate value
@@ -795,7 +802,7 @@ module LLVM
795
802
  # @return [LLVM::Instruction] The extracted value
796
803
  # @LLVMinst extractvalue
797
804
  def extract_value(aggregate, idx, name = "")
798
- Instruction.from_ptr(C.LLVMBuildExtractValue(self, aggregate, idx, name))
805
+ Instruction.from_ptr(C.build_extract_value(self, aggregate, idx, name))
799
806
  end
800
807
 
801
808
  # Insert a value into an aggregate value's member field
@@ -806,7 +813,7 @@ module LLVM
806
813
  # @return [LLVM::Instruction] An aggregate value of the same type as 'aggregate'
807
814
  # @LLVMinst insertvalue
808
815
  def insert_value(aggregate, elem, idx, name = "")
809
- Instruction.from_ptr(C.LLVMBuildInsertValue(self, aggregate, elem, idx, name))
816
+ Instruction.from_ptr(C.build_insert_value(self, aggregate, elem, idx, name))
810
817
  end
811
818
 
812
819
  # Check if a value is null
@@ -814,7 +821,7 @@ module LLVM
814
821
  # @param [String] name The name of the result in LLVM IR
815
822
  # @return [LLVM::Instruction] An i1
816
823
  def is_null(val, name = "")
817
- Instruction.from_ptr(C.LLVMBuildIsNull(self, val, name))
824
+ Instruction.from_ptr(C.build_is_null(self, val, name))
818
825
  end
819
826
 
820
827
  # Check if a value is not null
@@ -822,7 +829,7 @@ module LLVM
822
829
  # @param [String] name The name of the result in LLVM IR
823
830
  # @return [LLVM::Instruction] An i1
824
831
  def is_not_null(val, name = "")
825
- Instruction.from_ptr(C.LLVMBuildIsNotNull(self, val, name))
832
+ Instruction.from_ptr(C.build_is_not_null(self, val, name))
826
833
  end
827
834
 
828
835
  # Calculate the difference between two pointers
@@ -832,13 +839,7 @@ module LLVM
832
839
  # @return [LLVM::Instruction] The integer difference between the two
833
840
  # pointers
834
841
  def ptr_diff(lhs, rhs, name = "")
835
- Instruction.from_ptr(C.LLVMBuildPtrDiff(lhs, rhs, name))
836
- end
837
-
838
- # Disposes the builder.
839
- # @return nil
840
- def dispose
841
- C.LLVMDisposeBuilder(@ptr)
842
+ Instruction.from_ptr(C.build_ptr_diff(lhs, rhs, name))
842
843
  end
843
844
  end
844
845
  end