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,7 +1,7 @@
1
1
  module LLVM
2
2
  class Context
3
3
  def initialize(ptr = nil)
4
- @ptr = ptr || C.LLVMContextCreate()
4
+ @ptr = ptr || C.context_create()
5
5
  end
6
6
 
7
7
  # @private
@@ -11,12 +11,14 @@ module LLVM
11
11
 
12
12
  # Obtains a reference to the global Context.
13
13
  def self.global
14
- new(C.LLVMGetGlobalContext())
14
+ new(C.get_global_context())
15
15
  end
16
16
 
17
17
  # Diposes the Context.
18
18
  def dispose
19
- C.LLVMContextDispose(@ptr)
19
+ return if @ptr.nil?
20
+ C.context_dispose(@ptr)
21
+ @ptr = nil
20
22
  end
21
23
  end
22
24
  end
@@ -8,8 +8,15 @@ module LLVM
8
8
  mod
9
9
  end
10
10
 
11
+ # Important: Call #dispose to free backend memory after use, but not when using JITCompiler with this module.
11
12
  def initialize(name)
12
- @ptr = C.LLVMModuleCreateWithName(name)
13
+ @ptr = C.module_create_with_name(name)
14
+ end
15
+
16
+ def dispose
17
+ return if @ptr.nil?
18
+ C.dispose_module(@ptr)
19
+ @ptr = nil
13
20
  end
14
21
 
15
22
  # @private
@@ -44,7 +51,7 @@ module LLVM
44
51
 
45
52
  # Returns the Type with the given name (symbol or string).
46
53
  def named(name)
47
- Type.from_ptr(C.LLVMGetTypeByName(@module, name.to_s))
54
+ Type.from_ptr(C.get_type_by_name(@module, name.to_s), nil)
48
55
  end
49
56
 
50
57
  # Returns the Type with the a name equal to key (symbol or string).
@@ -72,37 +79,37 @@ module LLVM
72
79
 
73
80
  # Adds a GlobalVariable with the given type and name to the collection (symbol or string).
74
81
  def add(ty, name)
75
- GlobalVariable.from_ptr(C.LLVMAddGlobal(@module, LLVM::Type(ty), name.to_s))
82
+ GlobalVariable.from_ptr(C.add_global(@module, LLVM::Type(ty), name.to_s))
76
83
  end
77
84
 
78
85
  # Returns the GlobalVariable with the given name (symbol or string).
79
86
  def named(name)
80
- GlobalValue.from_ptr(C.LLVMGetNamedGlobal(@module, name.to_s))
87
+ GlobalValue.from_ptr(C.get_named_global(@module, name.to_s))
81
88
  end
82
89
 
83
90
  # Returns the first GlobalVariable in the collection.
84
91
  def first
85
- GlobalValue.from_ptr(C.LLVMGetFirstGlobal(@module))
92
+ GlobalValue.from_ptr(C.get_first_global(@module))
86
93
  end
87
94
 
88
95
  # Returns the last GlobalVariable in the collection.
89
96
  def last
90
- GlobalValue.from_ptr(C.LLVMGetLastGlobal(@module))
97
+ GlobalValue.from_ptr(C.get_last_global(@module))
91
98
  end
92
99
 
93
100
  # Returns the next GlobalVariable in the collection after global.
94
101
  def next(global)
95
- GlobalValue.from_ptr(C.LLVMGetNextGlobal(global))
102
+ GlobalValue.from_ptr(C.get_next_global(global))
96
103
  end
97
104
 
98
105
  # Returns the previous GlobalVariable in the collection before global.
99
106
  def previous(global)
100
- GlobalValue.from_ptr(C.LLVMGetPreviousGlobal(global))
107
+ GlobalValue.from_ptr(C.get_previous_global(global))
101
108
  end
102
109
 
103
110
  # Deletes the GlobalVariable from the collection.
104
111
  def delete(global)
105
- C.LLVMDeleteGlobal(global)
112
+ C.delete_global(global)
106
113
  end
107
114
 
108
115
  # Returns the GlobalVariable with a name equal to key (symbol or string) or at key (integer).
@@ -149,7 +156,7 @@ module LLVM
149
156
  else
150
157
  type = Type.function(*args)
151
158
  end
152
- function = Function.from_ptr(C.LLVMAddFunction(@module, name.to_s, type))
159
+ function = Function.from_ptr(C.add_function(@module, name.to_s, type))
153
160
 
154
161
  if block_given?
155
162
  params = (0...function.params.size).map { |i| function.params[i] }
@@ -161,32 +168,32 @@ module LLVM
161
168
 
162
169
  # Returns the Function with the given name (symbol or string).
163
170
  def named(name)
164
- Function.from_ptr(C.LLVMGetNamedFunction(@module, name.to_s))
171
+ Function.from_ptr(C.get_named_function(@module, name.to_s))
165
172
  end
166
173
 
167
174
  # Returns the first Function in the collection.
168
175
  def first
169
- Function.from_ptr(C.LLVMGetFirstFunction(@module))
176
+ Function.from_ptr(C.get_first_function(@module))
170
177
  end
171
178
 
172
179
  # Returns the last Function in the collection.
173
180
  def last
174
- Function.from_ptr(C.LLVMGetLastFunction(@module))
181
+ Function.from_ptr(C.get_last_function(@module))
175
182
  end
176
183
 
177
184
  # Returns the next Function in the collection after function.
178
185
  def next(function)
179
- Function.from_ptr(C.LLVMGetNextFunction(function))
186
+ Function.from_ptr(C.get_next_function(function))
180
187
  end
181
188
 
182
189
  # Returns the previous Function in the collection before function.
183
190
  def previous(function)
184
- Function.from_ptr(C.LLVMGetPreviousFunction(function))
191
+ Function.from_ptr(C.get_previous_function(function))
185
192
  end
186
193
 
187
194
  # Deletes the Function from the collection.
188
195
  def delete(function)
189
- C.LLVMDeleteFunction(function)
196
+ C.delete_function(function)
190
197
  end
191
198
 
192
199
  # Returns the Function with a name equal to key (symbol or string) or at key (integer).
@@ -216,12 +223,7 @@ module LLVM
216
223
 
217
224
  # Print the module's IR to stdout.
218
225
  def dump
219
- C.LLVMDumpModule(self)
220
- end
221
-
222
- # Dispose the module.
223
- def dispose
224
- C.LLVMDisposeModule(@ptr)
226
+ C.dump_module(self)
225
227
  end
226
228
  end
227
229
  end
@@ -4,9 +4,9 @@ module LLVM
4
4
  class PassManager
5
5
  # Creates a new pass manager on the given ExecutionEngine.
6
6
  def initialize(execution_engine)
7
- ptr = C.LLVMCreatePassManager()
8
- C.LLVMAddTargetData(
9
- C.LLVMGetExecutionEngineTargetData(execution_engine), ptr)
7
+ ptr = C.create_pass_manager()
8
+ C.add_target_data(
9
+ C.get_execution_engine_target_data(execution_engine), ptr)
10
10
  @ptr = ptr
11
11
 
12
12
  do_initialization
@@ -29,13 +29,15 @@ module LLVM
29
29
  # @param [LLVM::Module]
30
30
  # @return [true, false] Indicates whether the module was modified.
31
31
  def run(mod)
32
- C.LLVMRunPassManager(self, mod) != 0
32
+ C.run_pass_manager(self, mod) != 0
33
33
  end
34
34
 
35
35
  # Disposes the pass manager.
36
36
  def dispose
37
+ return if @ptr.nil?
37
38
  do_finalization
38
- C.LLVMDisposePassManager(self)
39
+ C.dispose_pass_manager(@ptr)
40
+ @ptr = nil
39
41
  end
40
42
 
41
43
  protected
@@ -50,9 +52,9 @@ module LLVM
50
52
  class FunctionPassManager < PassManager
51
53
  # Creates a new pass manager on the given ExecutionEngine and Module.
52
54
  def initialize(execution_engine, mod)
53
- ptr = C.LLVMCreateFunctionPassManagerForModule(mod)
54
- C.LLVMAddTargetData(
55
- C.LLVMGetExecutionEngineTargetData(execution_engine), ptr)
55
+ ptr = C.create_function_pass_manager_for_module(mod)
56
+ C.add_target_data(
57
+ C.get_execution_engine_target_data(execution_engine), ptr)
56
58
  @ptr = ptr
57
59
  end
58
60
 
@@ -60,17 +62,17 @@ module LLVM
60
62
  # @param [LLVM::Function]
61
63
  # @return [true, false] indicates whether the function was modified.
62
64
  def run(fn)
63
- C.LLVMRunFunctionPassManager(self, fn) != 0
65
+ C.run_function_pass_manager(self, fn) != 0
64
66
  end
65
67
 
66
68
  protected
67
69
 
68
70
  def do_initialization
69
- C.LLVMInitializeFunctionPassManager(self) != 0
71
+ C.initialize_function_pass_manager(self) != 0
70
72
  end
71
73
 
72
74
  def do_finalization
73
- C.LLVMFinalizeFunctionPassManager(self) != 0
75
+ C.finalize_function_pass_manager(self) != 0
74
76
  end
75
77
  end
76
78
  end
@@ -14,7 +14,11 @@ module LLVM
14
14
  false
15
15
  end
16
16
  end
17
-
17
+
18
+ def hash
19
+ @ptr.address.hash
20
+ end
21
+
18
22
  # Checks if the type is equal to other.
19
23
  def eql?(other)
20
24
  other.instance_of?(self.class) && self == other
@@ -22,34 +26,34 @@ module LLVM
22
26
 
23
27
  # Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.)
24
28
  def kind
25
- C.LLVMGetTypeKind(self)
29
+ @kind
26
30
  end
27
31
 
28
32
  # Returns the size of the type.
29
33
  def size
30
- LLVM::Int64.from_ptr(C.LLVMSizeOf(self))
34
+ LLVM::Int64.from_ptr(C.size_of(self))
31
35
  end
32
36
 
33
37
  def align
34
- LLVM::Int64.from_ptr(C.LLVMAlignOf(self))
38
+ LLVM::Int64.from_ptr(C.align_of(self))
35
39
  end
36
40
 
37
41
  # Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
38
42
  def element_type
39
43
  case self.kind
40
44
  when :pointer, :vector, :array
41
- Type.from_ptr(C.LLVMGetElementType(self))
45
+ Type.from_ptr(C.get_element_type(self), nil)
42
46
  end
43
47
  end
44
48
 
45
49
  # Returns a null pointer ConstantExpr of this type.
46
50
  def null_pointer
47
- ConstantExpr.from_ptr(C.LLVMConstPointerNull(self))
51
+ ConstantExpr.from_ptr(C.const_pointer_null(self))
48
52
  end
49
53
 
50
54
  # Returns a null ConstantExpr of this type.
51
55
  def null
52
- ConstantExpr.from_ptr(C.LLVMConstNull(self))
56
+ ConstantExpr.from_ptr(C.const_null(self))
53
57
  end
54
58
 
55
59
  # Creates a pointer type with this type and the given address space.
@@ -57,32 +61,34 @@ module LLVM
57
61
  Type.pointer(self, address_space)
58
62
  end
59
63
 
60
- # Returns the name of the struct type.
61
- def name
62
- C.LLVMGetStructName(self)
63
- end
64
-
65
64
  # @private
66
- def self.from_ptr(ptr)
65
+ def self.from_ptr(ptr, kind)
67
66
  return if ptr.null?
68
- ty = allocate
67
+ kind ||= C.get_type_kind(ptr)
68
+ ty = case kind
69
+ when :integer then IntType.allocate
70
+ when :function then FunctionType.allocate
71
+ when :struct then StructType.allocate
72
+ else allocate
73
+ end
69
74
  ty.instance_variable_set(:@ptr, ptr)
75
+ ty.instance_variable_set(:@kind, kind)
70
76
  ty
71
77
  end
72
78
 
73
79
  # Creates an array type of Type with the given size.
74
80
  def self.array(ty, sz = 0)
75
- from_ptr(C.LLVMArrayType(LLVM::Type(ty), sz))
81
+ from_ptr(C.array_type(LLVM::Type(ty), sz), :array)
76
82
  end
77
83
 
78
84
  # Creates the pointer type of Type with the given address space.
79
85
  def self.pointer(ty, address_space = 0)
80
- from_ptr(C.LLVMPointerType(LLVM::Type(ty), address_space))
86
+ from_ptr(C.pointer_type(LLVM::Type(ty), address_space), :pointer)
81
87
  end
82
88
 
83
89
  # Creates a vector type of Type with the given element count.
84
90
  def self.vector(ty, element_count)
85
- from_ptr(C.LLVMVectorType(LLVM::Type(ty), element_count))
91
+ from_ptr(C.vector_type(LLVM::Type(ty), element_count), :vector)
86
92
  end
87
93
 
88
94
  # Creates a function type. Takes an array of argument Types and the result Type. The only option is <tt>:varargs</tt>,
@@ -91,7 +97,7 @@ module LLVM
91
97
  arg_types.map! { |ty| LLVM::Type(ty) }
92
98
  arg_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * arg_types.size)
93
99
  arg_types_ptr.write_array_of_pointer(arg_types)
94
- FunctionType.from_ptr(C.LLVMFunctionType(LLVM::Type(result_type), arg_types_ptr, arg_types.size, options[:varargs] ? 1 : 0))
100
+ from_ptr(C.function_type(LLVM::Type(result_type), arg_types_ptr, arg_types.size, options[:varargs] ? 1 : 0), :function)
95
101
  end
96
102
 
97
103
  # Creates a struct type with the given array of element types.
@@ -100,17 +106,17 @@ module LLVM
100
106
  elt_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * elt_types.size)
101
107
  elt_types_ptr.write_array_of_pointer(elt_types)
102
108
  if name
103
- struct = from_ptr(C.LLVMStructCreateNamed(Context.global, name))
104
- C.LLVMStructSetBody(struct, elt_types_ptr, elt_types.size, is_packed ? 1 : 0)
109
+ struct = from_ptr(C.struct_create_named(Context.global, name), :struct)
110
+ C.struct_set_body(struct, elt_types_ptr, elt_types.size, is_packed ? 1 : 0) unless elt_types.empty?
105
111
  struct
106
112
  else
107
- from_ptr(C.LLVMStructType(elt_types_ptr, elt_types.size, is_packed ? 1 : 0))
113
+ from_ptr(C.struct_type(elt_types_ptr, elt_types.size, is_packed ? 1 : 0), :struct)
108
114
  end
109
115
  end
110
116
 
111
117
  # Creates a void type.
112
118
  def self.void
113
- from_ptr(C.LLVMVoidType)
119
+ from_ptr(C.void_type, :void)
114
120
  end
115
121
 
116
122
  def self.rec
@@ -123,13 +129,39 @@ module LLVM
123
129
 
124
130
  class IntType < Type
125
131
  def width
126
- C.LLVMGetIntTypeWidth(self)
132
+ C.get_int_type_width(self)
127
133
  end
128
134
  end
129
135
 
130
136
  class FunctionType < Type
131
137
  def return_type
132
- LLVM::Type.from_ptr(C.LLVMGetReturnType(self))
138
+ Type.from_ptr(C.get_return_type(self), nil)
139
+ end
140
+ end
141
+
142
+ class StructType < Type
143
+ # Returns the name of the struct.
144
+ def name
145
+ C.get_struct_name(self)
146
+ end
147
+
148
+ # Returns the element types of the struct.
149
+ def element_types
150
+ count = C.count_struct_element_types(self)
151
+ elt_types = nil
152
+ FFI::MemoryPointer.new(FFI.type_size(:pointer) * count) do |types_ptr|
153
+ C.get_struct_element_types(self, types_ptr)
154
+ elt_types = types_ptr.read_array_of_pointer(count).map { |type_ptr| Type.from_ptr(type_ptr, nil) }
155
+ end
156
+ elt_types
157
+ end
158
+
159
+ # Sets the struct body.
160
+ def element_types=(elt_types)
161
+ elt_types.map! { |ty| LLVM::Type(ty) }
162
+ elt_types_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * elt_types.size)
163
+ elt_types_ptr.write_array_of_pointer(elt_types)
164
+ C.struct_set_body(self, elt_types_ptr, elt_types.size, 0)
133
165
  end
134
166
  end
135
167
 
@@ -43,28 +43,28 @@ module LLVM
43
43
 
44
44
  # Returns the value's type.
45
45
  def type
46
- Type.from_ptr(C.LLVMTypeOf(self))
46
+ Type.from_ptr(C.type_of(self), nil)
47
47
  end
48
48
 
49
49
  # Returns the value's name.
50
50
  def name
51
- C.LLVMGetValueName(self)
51
+ C.get_value_name(self)
52
52
  end
53
53
 
54
54
  # Sets the value's name to str.
55
55
  def name=(str)
56
- C.LLVMSetValueName(self, str)
56
+ C.set_value_name(self, str)
57
57
  str
58
58
  end
59
59
 
60
60
  # Print the value's IR to stdout.
61
61
  def dump
62
- C.LLVMDumpValue(self)
62
+ C.dump_value(self)
63
63
  end
64
64
 
65
65
  # Returns whether the value is constant.
66
66
  def constant?
67
- case C.LLVMIsConstant(self)
67
+ case C.is_constant(self)
68
68
  when 0 then false
69
69
  when 1 then true
70
70
  end
@@ -72,7 +72,7 @@ module LLVM
72
72
 
73
73
  # Returns whether the value is null.
74
74
  def null?
75
- case C.LLVMIsNull(self)
75
+ case C.is_null(self)
76
76
  when 0 then false
77
77
  when 1 then true
78
78
  end
@@ -80,7 +80,7 @@ module LLVM
80
80
 
81
81
  # Returns whether the value is undefined.
82
82
  def undefined?
83
- case C.LLVMIsUndef(self)
83
+ case C.is_undef(self)
84
84
  when 0 then false
85
85
  when 1 then true
86
86
  end
@@ -88,7 +88,7 @@ module LLVM
88
88
 
89
89
  # Adds attr to this value's attributes.
90
90
  def add_attribute(attr)
91
- C.LLVMAddAttribute(self, attr)
91
+ C.add_attribute(self, attr)
92
92
  end
93
93
  end
94
94
 
@@ -98,38 +98,37 @@ module LLVM
98
98
  class BasicBlock < Value
99
99
  # Creates a basic block for the given function with the given name.
100
100
  def self.create(fun = nil, name = "")
101
- self.from_ptr(C.LLVMAppendBasicBlock(fun, name))
101
+ self.from_ptr(C.append_basic_block(fun, name))
102
102
  end
103
103
 
104
104
  # Build the basic block with the given builder. Creates a new one if nil. Yields the builder.
105
105
  def build(builder = nil)
106
106
  if builder.nil?
107
107
  builder = Builder.new
108
- islocal = true
108
+ builder.position_at_end(self)
109
+ yield builder
110
+ builder.dispose
109
111
  else
110
- islocal = false
112
+ builder.position_at_end(self)
113
+ yield builder
111
114
  end
112
- builder.position_at_end(self)
113
- yield builder
114
- ensure
115
- builder.dispose if islocal
116
115
  end
117
116
 
118
117
  # Returns the parent of this basic block (a Function).
119
118
  def parent
120
- fp = C.LLVMGetBasicBlockParent(self)
119
+ fp = C.get_basic_block_parent(self)
121
120
  LLVM::Function.from_ptr(fp) unless fp.null?
122
121
  end
123
122
 
124
123
  # Returns the next basic block in the sequence.
125
124
  def next
126
- ptr = C.LLVMGetNextBasicBlock(self)
125
+ ptr = C.get_next_basic_block(self)
127
126
  BasicBlock.from_ptr(ptr) unless ptr.null?
128
127
  end
129
128
 
130
129
  # Returns the previous basic block in the sequence.
131
130
  def previous
132
- ptr = C.LLVMGetPreviousBasicBlock(self)
131
+ ptr = C.get_previous_basic_block(self)
133
132
  BasicBlock.from_ptr(ptr) unless ptr.null?
134
133
  end
135
134
 
@@ -170,13 +169,13 @@ module LLVM
170
169
 
171
170
  # Returns the first Instruction in the collection.
172
171
  def first
173
- ptr = C.LLVMGetFirstInstruction(@block)
172
+ ptr = C.get_first_instruction(@block)
174
173
  LLVM::Instruction.from_ptr(ptr) unless ptr.null?
175
174
  end
176
175
 
177
176
  # Returns the last Instruction in the collection.
178
177
  def last
179
- ptr = C.LLVMGetLastInstruction(@block)
178
+ ptr = C.get_last_instruction(@block)
180
179
  LLVM::Instruction.from_ptr(ptr) unless ptr.null?
181
180
  end
182
181
  end
@@ -198,18 +197,18 @@ module LLVM
198
197
 
199
198
  # Get a reference to an operand by index.
200
199
  def [](i)
201
- ptr = C.LLVMGetOperand(@user, i)
200
+ ptr = C.get_operand(@user, i)
202
201
  Value.from_ptr(ptr) unless ptr.null?
203
202
  end
204
203
 
205
204
  # Set or replace an operand by index.
206
205
  def []=(i, v)
207
- C.LLVMSetOperand(@user, i, v)
206
+ C.set_operand(@user, i, v)
208
207
  end
209
208
 
210
209
  # Returns the number of operands in the collection.
211
210
  def size
212
- C.LLVMGetNumOperands(@user)
211
+ C.get_num_operands(@user)
213
212
  end
214
213
 
215
214
  # Iterates through each operand in the collection.
@@ -224,22 +223,22 @@ module LLVM
224
223
  class Constant < User
225
224
  # Creates a null constant of Type.
226
225
  def self.null(type)
227
- from_ptr(C.LLVMConstNull(type))
226
+ from_ptr(C.const_null(type))
228
227
  end
229
228
 
230
229
  # Creates a undefined constant of Type.
231
230
  def self.undef(type)
232
- from_ptr(C.LLVMGetUndef(type))
231
+ from_ptr(C.get_undef(type))
233
232
  end
234
233
 
235
234
  # Creates a null pointer constant of Type.
236
235
  def self.null_ptr(type)
237
- from_ptr(C.LLVMConstPointerNull(type))
236
+ from_ptr(C.const_pointer_null(type))
238
237
  end
239
238
 
240
239
  # Bitcast this constant to Type.
241
240
  def bitcast_to(type)
242
- ConstantExpr.from_ptr(C.LLVMConstBitCast(self, type))
241
+ ConstantExpr.from_ptr(C.const_bit_cast(self, type))
243
242
  end
244
243
 
245
244
  # Returns the element pointer at the given indices of the constant.
@@ -249,7 +248,7 @@ module LLVM
249
248
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
250
249
  indices_ptr.write_array_of_pointer(indices)
251
250
  return ConstantExpr.from_ptr(
252
- C.LLVMConstGEP(self, indices_ptr, indices.size))
251
+ C.const_gep(self, indices_ptr, indices.size))
253
252
  end
254
253
  end
255
254
  end
@@ -272,14 +271,14 @@ module LLVM
272
271
 
273
272
  class ConstantArray < Constant
274
273
  def self.string(str, null_terminate = true)
275
- from_ptr(C.LLVMConstString(str, str.length, null_terminate ? 0 : 1))
274
+ from_ptr(C.const_string(str, str.length, null_terminate ? 0 : 1))
276
275
  end
277
276
 
278
277
  # ConstantArray.const(type, 3) {|i| ... } or
279
278
  # ConstantArray.const(type, [...])
280
279
  def self.const(type, size_or_values, &block)
281
280
  vals = LLVM::Support.allocate_pointers(size_or_values, &block)
282
- from_ptr C.LLVMConstArray(type, vals, vals.size / vals.type_size)
281
+ from_ptr C.const_array(type, vals, vals.size / vals.type_size)
283
282
  end
284
283
  end
285
284
 
@@ -288,77 +287,77 @@ module LLVM
288
287
 
289
288
  class ConstantInt < Constant
290
289
  def self.all_ones
291
- from_ptr(C.LLVMConstAllOnes(type))
290
+ from_ptr(C.const_all_ones(type))
292
291
  end
293
292
 
294
293
  # Creates a ConstantInt from an integer.
295
294
  def self.from_i(n, signed = true)
296
- from_ptr(C.LLVMConstInt(type, n, signed ? 1 : 0))
295
+ from_ptr(C.const_int(type, n, signed ? 1 : 0))
297
296
  end
298
297
 
299
298
  def self.parse(str, radix = 10)
300
- from_ptr(C.LLVMConstIntOfString(type, str, radix))
299
+ from_ptr(C.const_int_of_string(type, str, radix))
301
300
  end
302
301
 
303
302
  # Negation.
304
303
  def -@
305
- self.class.from_ptr(C.LLVMConstNeg(self))
304
+ self.class.from_ptr(C.const_neg(self))
306
305
  end
307
306
 
308
307
  # Boolean negation.
309
308
  def not
310
- self.class.from_ptr(C.LLVMConstNot(self))
309
+ self.class.from_ptr(C.const_not(self))
311
310
  end
312
311
 
313
312
  # Addition.
314
313
  def +(rhs)
315
- self.class.from_ptr(C.LLVMConstAdd(self, rhs))
314
+ self.class.from_ptr(C.const_add(self, rhs))
316
315
  end
317
316
 
318
317
  # "No signed wrap" addition. See
319
318
  # http://llvm.org/docs/LangRef.html#i_add for discusison.
320
319
  def nsw_add(rhs)
321
- self.class.from_ptr(C.LLVMConstNSWAdd(self, rhs))
320
+ self.class.from_ptr(C.const_nsw_add(self, rhs))
322
321
  end
323
322
 
324
323
  # Multiplication.
325
324
  def *(rhs)
326
- self.class.from_ptr(C.LLVMConstMul(self, rhs))
325
+ self.class.from_ptr(C.const_mul(self, rhs))
327
326
  end
328
327
 
329
328
  # Unsigned division.
330
329
  def udiv(rhs)
331
- self.class.from_ptr(C.LLVMConstUDiv(self, rhs))
330
+ self.class.from_ptr(C.const_u_div(self, rhs))
332
331
  end
333
332
 
334
333
  # Signed division.
335
334
  def /(rhs)
336
- self.class.from_ptr(C.LLVMConstSDiv(self, rhs))
335
+ self.class.from_ptr(C.const_s_div(self, rhs))
337
336
  end
338
337
 
339
338
  # Unsigned remainder.
340
339
  def urem(rhs)
341
- self.class.from_ptr(C.LLVMConstURem(self, rhs))
340
+ self.class.from_ptr(C.const_u_rem(self, rhs))
342
341
  end
343
342
 
344
343
  # Signed remainder.
345
344
  def rem(rhs)
346
- self.class.from_ptr(C.LLVMConstSRem(self, rhs))
345
+ self.class.from_ptr(C.const_s_rem(self, rhs))
347
346
  end
348
347
 
349
348
  # Integer AND.
350
349
  def and(rhs)
351
- self.class.from_ptr(C.LLVMConstAnd(self, rhs))
350
+ self.class.from_ptr(C.const_and(self, rhs))
352
351
  end
353
352
 
354
353
  # Integer OR.
355
354
  def or(rhs)
356
- self.class.from_ptr(C.LLVMConstOr(self, rhs))
355
+ self.class.from_ptr(C.const_or(self, rhs))
357
356
  end
358
357
 
359
358
  # Integer XOR.
360
359
  def xor(rhs)
361
- self.class.from_ptr(C.LLVMConstXor(self, rhs))
360
+ self.class.from_ptr(C.const_xor(self, rhs))
362
361
  end
363
362
 
364
363
  # Integer comparison using the predicate specified via the first parameter.
@@ -374,22 +373,22 @@ module LLVM
374
373
  # :slt - signed less than
375
374
  # :sle - signed less than or equal to
376
375
  def icmp(pred, rhs)
377
- self.class.from_ptr(C.LLVMConstICmp(pred, self, rhs))
376
+ self.class.from_ptr(C.const_i_cmp(pred, self, rhs))
378
377
  end
379
378
 
380
379
  # Shift left.
381
380
  def <<(bits)
382
- self.class.from_ptr(C.LLVMConstShl(self, bits))
381
+ self.class.from_ptr(C.const_shl(self, bits))
383
382
  end
384
383
 
385
384
  # Shift right.
386
385
  def >>(bits)
387
- self.class.from_ptr(C.LLVMConstLShr(self, bits))
386
+ self.class.from_ptr(C.const_l_shr(self, bits))
388
387
  end
389
388
 
390
389
  # Arithmatic shift right.
391
390
  def ashr(bits)
392
- self.class.from_ptr(C.LLVMConstAShr(self, bits))
391
+ self.class.from_ptr(C.const_a_shr(self, bits))
393
392
  end
394
393
  end
395
394
 
@@ -401,7 +400,7 @@ module LLVM
401
400
  eval <<-KLASS
402
401
  class #{name} < ConstantInt
403
402
  def self.type
404
- IntType.from_ptr(C.LLVMIntType(#{width}))
403
+ Type.from_ptr(C.int_type(#{width}), :integer)
405
404
  end
406
405
  end
407
406
  KLASS
@@ -430,36 +429,36 @@ module LLVM
430
429
  class ConstantReal < Constant
431
430
  # Creates a ConstantReal from a float of Type.
432
431
  def self.from_f(n)
433
- from_ptr(C.LLVMConstReal(type, n))
432
+ from_ptr(C.const_real(type, n))
434
433
  end
435
434
 
436
435
  def self.parse(type, str)
437
- from_ptr(C.LLVMConstRealOfString(type, str))
436
+ from_ptr(C.const_real_of_string(type, str))
438
437
  end
439
438
 
440
439
  # Negation.
441
440
  def -@
442
- self.class.from_ptr(C.LLVMConstFNeg(self))
441
+ self.class.from_ptr(C.const_f_neg(self))
443
442
  end
444
443
 
445
444
  # Returns the result of adding this ConstantReal to rhs.
446
445
  def +(rhs)
447
- self.class.from_ptr(C.LLVMConstFAdd(self, rhs))
446
+ self.class.from_ptr(C.const_f_add(self, rhs))
448
447
  end
449
448
 
450
449
  # Returns the result of multiplying this ConstantReal by rhs.
451
450
  def *(rhs)
452
- self.class.from_ptr(C.LLVMConstFMul(self, rhs))
451
+ self.class.from_ptr(C.const_f_mul(self, rhs))
453
452
  end
454
453
 
455
454
  # Returns the result of dividing this ConstantReal by rhs.
456
455
  def /(rhs)
457
- self.class.from_ptr(C.LLVMConstFDiv(self, rhs))
456
+ self.class.from_ptr(C.const_f_div(self, rhs))
458
457
  end
459
458
 
460
459
  # Remainder.
461
460
  def rem(rhs)
462
- self.class.from_ptr(C.LLVMConstFRem(self, rhs))
461
+ self.class.from_ptr(C.const_f_rem(self, rhs))
463
462
  end
464
463
 
465
464
  # Floating point comparison using the predicate specified via the first
@@ -481,14 +480,14 @@ module LLVM
481
480
  # :true - always true
482
481
  # :false- always false
483
482
  def fcmp(pred, rhs)
484
- self.class.from_ptr(C.LLMVConstFCmp(pred, self, rhs))
483
+ self.class.from_ptr(C.llmv_const_f_cmp(pred, self, rhs))
485
484
  end
486
485
  end
487
486
 
488
487
  class Float < ConstantReal
489
488
  # Return a Type representation of the float.
490
489
  def self.type
491
- Type.from_ptr(C.LLVMFloatType)
490
+ Type.from_ptr(C.float_type, :float)
492
491
  end
493
492
  end
494
493
 
@@ -499,7 +498,7 @@ module LLVM
499
498
 
500
499
  class Double < ConstantReal
501
500
  def self.type
502
- Type.from_ptr(C.LLVMDoubleType)
501
+ Type.from_ptr(C.double_type, :double)
503
502
  end
504
503
  end
505
504
 
@@ -512,90 +511,90 @@ module LLVM
512
511
  # ConstantStruct.const([...])
513
512
  def self.const(size_or_values, packed = false, &block)
514
513
  vals = LLVM::Support.allocate_pointers(size_or_values, &block)
515
- from_ptr C.LLVMConstStruct(vals, vals.size / vals.type_size, packed ? 1 : 0)
514
+ from_ptr C.const_struct(vals, vals.size / vals.type_size, packed ? 1 : 0)
516
515
  end
517
516
  end
518
517
 
519
518
  class ConstantVector < Constant
520
519
  def self.all_ones
521
- from_ptr(C.LLVMConstAllOnes(type))
520
+ from_ptr(C.const_all_ones(type))
522
521
  end
523
522
 
524
523
  def self.const(size_or_values, &block)
525
524
  vals = LLVM::Support.allocate_pointers(size_or_values, &block)
526
- from_ptr(C.LLVMConstVector(vals, vals.size / vals.type_size))
525
+ from_ptr(C.const_vector(vals, vals.size / vals.type_size))
527
526
  end
528
527
  end
529
528
 
530
529
  class GlobalValue < Constant
531
530
  def declaration?
532
- C.LLVMIsDeclaration(self)
531
+ C.is_declaration(self)
533
532
  end
534
533
 
535
534
  def linkage
536
- C.LLVMGetLinkage(self)
535
+ C.get_linkage(self)
537
536
  end
538
537
 
539
538
  def linkage=(linkage)
540
- C.LLVMSetLinkage(self, linkage)
539
+ C.set_linkage(self, linkage)
541
540
  end
542
541
 
543
542
  def section
544
- C.LLVMGetSection(self)
543
+ C.get_section(self)
545
544
  end
546
545
 
547
546
  def section=(section)
548
- C.LLVMSetSection(self, section)
547
+ C.set_section(self, section)
549
548
  end
550
549
 
551
550
  def visibility
552
- C.LLVMGetVisibility(self)
551
+ C.get_visibility(self)
553
552
  end
554
553
 
555
554
  def visibility=(viz)
556
- C.LLVMSetVisibility(self, viz)
555
+ C.set_visibility(self, viz)
557
556
  end
558
557
 
559
558
  def alignment
560
- C.LLVMGetAlignment(self)
559
+ C.get_alignment(self)
561
560
  end
562
561
 
563
562
  def alignment=(bytes)
564
- C.LLVMSetAlignment(self, bytes)
563
+ C.set_alignment(self, bytes)
565
564
  end
566
565
 
567
566
  def initializer
568
- Value.from_ptr(C.LLVMGetInitializer(self))
567
+ Value.from_ptr(C.get_initializer(self))
569
568
  end
570
569
 
571
570
  def initializer=(val)
572
- C.LLVMSetInitializer(self, val)
571
+ C.set_initializer(self, val)
573
572
  end
574
573
 
575
574
  def global_constant?
576
- C.LLVMIsGlobalConstant(self)
575
+ C.is_global_constant(self)
577
576
  end
578
577
 
579
578
  def global_constant=(flag)
580
- C.LLVMSetGlobalConstant(self, flag)
579
+ C.set_global_constant(self, flag)
581
580
  end
582
581
  end
583
582
 
584
583
  class Function < GlobalValue
585
584
  # Sets the function's calling convention and returns it.
586
585
  def call_conv=(conv)
587
- C.LLVMSetFunctionCallConv(self, conv)
586
+ C.set_function_call_conv(self, conv)
588
587
  conv
589
588
  end
590
589
 
591
590
  # Adds the given attribute to the function.
592
591
  def add_attribute(attr)
593
- C.LLVMAddFunctionAttr(self, attr)
592
+ C.add_function_attr(self, attr)
594
593
  end
595
594
 
596
595
  # Removes the given attribute from the function.
597
596
  def remove_attribute(attr)
598
- C.LLVMRemoveFunctionAttr(self, attr)
597
+ C.remove_function_attr(self, attr)
599
598
  end
600
599
 
601
600
  # Returns an Enumerable of the BasicBlocks in this function.
@@ -604,7 +603,7 @@ module LLVM
604
603
  end
605
604
 
606
605
  def type
607
- FunctionType.from_ptr(C.LLVMTypeOf(self))
606
+ Type.from_ptr(C.type_of(self), :function)
608
607
  end
609
608
 
610
609
  # @private
@@ -617,17 +616,17 @@ module LLVM
617
616
 
618
617
  # Returns the number of BasicBlocks in the collection.
619
618
  def size
620
- C.LLVMCountBasicBlocks(@fun)
619
+ C.count_basic_blocks(@fun)
621
620
  end
622
621
 
623
622
  # Iterates through each BasicBlock in the collection.
624
623
  def each
625
624
  return to_enum :each unless block_given?
626
625
 
627
- ptr = C.LLVMGetFirstBasicBlock(@fun)
626
+ ptr = C.get_first_basic_block(@fun)
628
627
  0.upto(size-1) do |i|
629
628
  yield BasicBlock.from_ptr(ptr)
630
- ptr = C.LLVMGetNextBasicBlock(ptr)
629
+ ptr = C.get_next_basic_block(ptr)
631
630
  end
632
631
 
633
632
  self
@@ -641,18 +640,18 @@ module LLVM
641
640
  # Returns the entry BasicBlock in the collection. This is the block the
642
641
  # function starts on.
643
642
  def entry
644
- BasicBlock.from_ptr(C.LLVMGetEntryBasicBlock(@fun))
643
+ BasicBlock.from_ptr(C.get_entry_basic_block(@fun))
645
644
  end
646
645
 
647
646
  # Returns the first BasicBlock in the collection.
648
647
  def first
649
- ptr = C.LLVMGetFirstBasicBlock(@fun)
648
+ ptr = C.get_first_basic_block(@fun)
650
649
  BasicBlock.from_ptr(ptr) unless ptr.null?
651
650
  end
652
651
 
653
652
  # Returns the last BasicBlock in the collection.
654
653
  def last
655
- ptr = C.LLVMGetLastBasicBlock(@fun)
654
+ ptr = C.get_last_basic_block(@fun)
656
655
  BasicBlock.from_ptr(ptr) unless ptr.null?
657
656
  end
658
657
  end
@@ -673,12 +672,12 @@ module LLVM
673
672
  sz = self.size
674
673
  i = sz + i if i < 0
675
674
  return unless 0 <= i && i < sz
676
- Value.from_ptr(C.LLVMGetParam(@fun, i))
675
+ Value.from_ptr(C.get_param(@fun, i))
677
676
  end
678
677
 
679
678
  # Returns the number of paramters in the collection.
680
679
  def size
681
- C.LLVMCountParams(@fun)
680
+ C.count_params(@fun)
682
681
  end
683
682
 
684
683
  include Enumerable
@@ -697,41 +696,41 @@ module LLVM
697
696
 
698
697
  class GlobalVariable < GlobalValue
699
698
  def initializer
700
- Value.from_ptr(C.LLVMGetInitializer(self))
699
+ Value.from_ptr(C.get_initializer(self))
701
700
  end
702
701
 
703
702
  def initializer=(val)
704
- C.LLVMSetInitializer(self, val)
703
+ C.set_initializer(self, val)
705
704
  end
706
705
 
707
706
  def thread_local?
708
- case C.LLVMIsThreadLocal(self)
707
+ case C.is_thread_local(self)
709
708
  when 0 then false
710
709
  else true
711
710
  end
712
711
  end
713
712
 
714
713
  def thread_local=(local)
715
- C.LLVMSetThreadLocal(self, local ? 1 : 0)
714
+ C.set_thread_local(self, local ? 1 : 0)
716
715
  end
717
716
  end
718
717
 
719
718
  class Instruction < User
720
719
  # Returns the parent of the instruction (a BasicBlock).
721
720
  def parent
722
- ptr = C.LLVMGetInstructionParent(self)
721
+ ptr = C.get_instruction_parent(self)
723
722
  LLVM::BasicBlock.from_ptr(ptr) unless ptr.null?
724
723
  end
725
724
 
726
725
  # Returns the next instruction after this one.
727
726
  def next
728
- ptr = C.LLVMGetNextInstruction(self)
727
+ ptr = C.get_next_instruction(self)
729
728
  LLVM::Instruction.from_ptr(ptr) unless ptr.null?
730
729
  end
731
730
 
732
731
  # Returns the previous instruction before this one.
733
732
  def previous
734
- ptr = C.LLVMGetPreviousInstruction(self)
733
+ ptr = C.get_previous_instruction(self)
735
734
  LLVM::Instruction.from_ptr(ptr) unless ptr.null?
736
735
  end
737
736
  end
@@ -739,13 +738,13 @@ module LLVM
739
738
  class CallInst < Instruction
740
739
  # Sets the call convention to conv.
741
740
  def call_conv=(conv)
742
- C.LLVMSetInstructionCallConv(self, conv)
741
+ C.set_instruction_call_conv(self, conv)
743
742
  conv
744
743
  end
745
744
 
746
745
  # Returns the call insatnce's call convention.
747
746
  def call_conv
748
- C.LLVMGetInstructionCallConv(self)
747
+ C.get_instruction_call_conv(self)
749
748
  end
750
749
  end
751
750
 
@@ -763,7 +762,7 @@ module LLVM
763
762
  vals_ptr.write_array_of_pointer(vals)
764
763
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * size) do |blks_ptr|
765
764
  blks_ptr.write_array_of_pointer(blks)
766
- C.LLVMAddIncoming(self, vals_ptr, blks_ptr, vals.size)
765
+ C.add_incoming(self, vals_ptr, blks_ptr, vals.size)
767
766
  end
768
767
  end
769
768
 
@@ -776,7 +775,7 @@ module LLVM
776
775
  # Adds a case to a switch instruction. First the value to match on, then
777
776
  # the basic block.
778
777
  def add_case(val, block)
779
- C.LLVMAddCase(self, val, block)
778
+ C.add_case(self, val, block)
780
779
  end
781
780
  end
782
781
  end