ruby-llvm-next 10.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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +30 -0
  3. data/README.md +67 -0
  4. data/ext/ruby-llvm-support/Rakefile +110 -0
  5. data/ext/ruby-llvm-support/support.cpp +32 -0
  6. data/lib/llvm.rb +29 -0
  7. data/lib/llvm/analysis.rb +49 -0
  8. data/lib/llvm/analysis_ffi.rb +77 -0
  9. data/lib/llvm/config.rb +10 -0
  10. data/lib/llvm/core.rb +97 -0
  11. data/lib/llvm/core/bitcode.rb +84 -0
  12. data/lib/llvm/core/bitcode_ffi.rb +132 -0
  13. data/lib/llvm/core/builder.rb +944 -0
  14. data/lib/llvm/core/context.rb +24 -0
  15. data/lib/llvm/core/module.rb +240 -0
  16. data/lib/llvm/core/pass_manager.rb +80 -0
  17. data/lib/llvm/core/type.rb +210 -0
  18. data/lib/llvm/core/value.rb +1005 -0
  19. data/lib/llvm/core_ffi.rb +6021 -0
  20. data/lib/llvm/execution_engine.rb +323 -0
  21. data/lib/llvm/execution_engine_ffi.rb +421 -0
  22. data/lib/llvm/linker.rb +16 -0
  23. data/lib/llvm/linker_ffi.rb +44 -0
  24. data/lib/llvm/support.rb +38 -0
  25. data/lib/llvm/target.rb +318 -0
  26. data/lib/llvm/target_ffi.rb +628 -0
  27. data/lib/llvm/transforms/builder.rb +107 -0
  28. data/lib/llvm/transforms/builder_ffi.rb +117 -0
  29. data/lib/llvm/transforms/ipo.rb +78 -0
  30. data/lib/llvm/transforms/ipo_ffi.rb +127 -0
  31. data/lib/llvm/transforms/scalar.rb +152 -0
  32. data/lib/llvm/transforms/scalar_ffi.rb +344 -0
  33. data/lib/llvm/transforms/vectorize.rb +22 -0
  34. data/lib/llvm/transforms/vectorize_ffi.rb +38 -0
  35. data/lib/llvm/version.rb +5 -0
  36. data/test/array_test.rb +38 -0
  37. data/test/basic_block_test.rb +87 -0
  38. data/test/binary_operations_test.rb +58 -0
  39. data/test/bitcode_test.rb +24 -0
  40. data/test/branch_test.rb +57 -0
  41. data/test/call_test.rb +82 -0
  42. data/test/comparisons_test.rb +66 -0
  43. data/test/conversions_test.rb +92 -0
  44. data/test/double_test.rb +34 -0
  45. data/test/equality_test.rb +89 -0
  46. data/test/function_test.rb +100 -0
  47. data/test/generic_value_test.rb +22 -0
  48. data/test/instruction_test.rb +30 -0
  49. data/test/ipo_test.rb +53 -0
  50. data/test/linker_test.rb +37 -0
  51. data/test/mcjit_test.rb +94 -0
  52. data/test/memory_access_test.rb +38 -0
  53. data/test/module_test.rb +93 -0
  54. data/test/parameter_collection_test.rb +28 -0
  55. data/test/pass_manager_builder_test.rb +53 -0
  56. data/test/phi_test.rb +33 -0
  57. data/test/select_test.rb +22 -0
  58. data/test/struct_test.rb +98 -0
  59. data/test/target_test.rb +113 -0
  60. data/test/test_helper.rb +62 -0
  61. data/test/type_test.rb +15 -0
  62. data/test/vector_test.rb +64 -0
  63. metadata +240 -0
@@ -0,0 +1,323 @@
1
+ require 'llvm'
2
+ require 'llvm/core'
3
+ require 'llvm/target'
4
+ require 'llvm/analysis'
5
+ require 'llvm/execution_engine_ffi'
6
+
7
+ module LLVM
8
+ # @abstract Subclass and override {#create_execution_engine_for_module}.
9
+ class ExecutionEngine
10
+ # Create a JIT execution engine for module with the given options.
11
+ #
12
+ # @note Important: Call #dispose to free backend memory after use. Do not call #dispose on mod any more.
13
+ #
14
+ # @param [LLVM::Module] mod module
15
+ # @param [Hash{Symbol => Object}] options options
16
+ # @return [ExecutionEngine] JIT execution engine
17
+ def initialize(mod, options)
18
+ FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |ptr|
19
+ error = FFI::MemoryPointer.new(FFI.type_size(:pointer))
20
+ status = create_execution_engine_for_module(ptr, mod, error, options)
21
+ errorp = error.read_pointer
22
+ message = errorp.read_string unless errorp.null?
23
+
24
+ if status.zero?
25
+ @ptr = ptr.read_pointer
26
+ else
27
+ C.dispose_message(error)
28
+ error.autorelease = false
29
+ raise "Error creating JIT compiler: #{message}"
30
+ end
31
+ end
32
+ end
33
+
34
+ def dispose
35
+ return if @ptr.nil?
36
+ C.dispose_execution_engine(@ptr)
37
+ @ptr = nil
38
+ end
39
+
40
+ # @private
41
+ def to_ptr
42
+ @ptr
43
+ end
44
+
45
+ # Get the associated data layout.
46
+ #
47
+ # @return [TargetDataLayout]
48
+ def data_layout
49
+ TargetDataLayout.from_ptr(C.get_execution_engine_target_data(self))
50
+ end
51
+
52
+ # Get the associated target machine.
53
+ #
54
+ # @return [TargetMachine]
55
+ def target_machine
56
+ TargetMachine.from_ptr(C.get_execution_engine_target_machine(self))
57
+ end
58
+
59
+ # Execute the given LLVM::Function with the supplied args (as
60
+ # GenericValues).
61
+ # Important: Call #dispose on the returned GenericValue to
62
+ # free backend memory after use.
63
+ def run_function(fun, *args)
64
+ FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr|
65
+ new_values = []
66
+ args_ptr.write_array_of_pointer(fun.params.zip(args).map do |p, a|
67
+ if a.kind_of?(GenericValue)
68
+ a
69
+ else
70
+ value = LLVM.make_generic_value(p.type, a)
71
+ new_values << value
72
+ value
73
+ end
74
+ end)
75
+ result = LLVM::GenericValue.from_ptr(
76
+ C.run_function(self, fun, args.size, args_ptr))
77
+ new_values.each(&:dispose)
78
+ return result
79
+ end
80
+ end
81
+
82
+ # Obtain an FFI::Pointer to a global within the current module.
83
+ def pointer_to_global(global)
84
+ C.get_pointer_to_global(self, global)
85
+ end
86
+
87
+ def function_address(name)
88
+ C.get_function_address(self, name)
89
+ end
90
+
91
+ # Returns a ModuleCollection of all the Modules in the engine.
92
+ # @return [ModuleCollection]
93
+ def modules
94
+ @modules ||= ModuleCollection.new(self)
95
+ end
96
+
97
+ # Returns a FunctionCollection of all the Functions in the engine.
98
+ # @return [FunctionCollection]
99
+ def functions
100
+ @functions ||= FunctionCollection.new(self)
101
+ end
102
+
103
+ class ModuleCollection
104
+ # @param [ExecutionEngine] engine
105
+ def initialize(engine)
106
+ @engine = engine
107
+ end
108
+
109
+ # @param [LLVM::Module] mod
110
+ # @return [ModuleCollection]
111
+ def add(mod)
112
+ tap { C.add_module(@engine, mod) }
113
+ end
114
+
115
+ # @param [LLVM::Module] mod
116
+ # @return [LLVM::Module] deleted module
117
+ def delete(mod)
118
+ error = FFI::MemoryPointer.new(:pointer)
119
+ out_mod = FFI::MemoryPointer.new(:pointer)
120
+
121
+ status = C.remove_module(@engine, mod, out_mod, error)
122
+
123
+ if status.zero?
124
+ LLVM::Module.from_ptr(out_mod.read_pointer)
125
+ else
126
+ errorp = error.read_pointer
127
+ message = errorp.read_string unless errorp.null?
128
+
129
+ C.dispose_message(error)
130
+ error.autorelease = false
131
+
132
+ raise "Error removing module: #{message}"
133
+ end
134
+ end
135
+
136
+ alias_method :<<, :add
137
+ end
138
+
139
+ class FunctionCollection
140
+ # @param [ExecutionEngine] engine
141
+ def initialize(engine)
142
+ @engine = engine
143
+ end
144
+
145
+ # @param [String, Symbol] name function name
146
+ # @return [Function]
147
+ def named(name)
148
+ out_fun = FFI::MemoryPointer.new(:pointer)
149
+
150
+ status = C.find_function(@engine, name.to_s, out_fun)
151
+ return unless status.zero?
152
+
153
+ Function.from_ptr(out_fun.read_pointer)
154
+ end
155
+
156
+ alias_method :[], :named
157
+ end
158
+
159
+ protected
160
+
161
+ # Create a JIT execution engine for module with the given options.
162
+ #
163
+ # @param [FFI::Pointer(*ExecutionEngineRef)] out_ee execution engine
164
+ # @param [LLVM::Module] mod module
165
+ # @param [FFI::Pointer(**CharS)] out_error error message
166
+ # @param [Hash{Symbol => Object}] options options. `:opt_level => 3` for example.
167
+ # @return [Integer] 0 for success, non- zero to indicate an error
168
+ def create_execution_engine_for_module(out_ee, mod, out_error, options)
169
+ raise NotImplementedError, "override in subclass"
170
+ end
171
+ end
172
+
173
+ class MCJITCompiler < ExecutionEngine
174
+ # Create a MCJIT execution engine.
175
+ #
176
+ # @note You should call `LLVM.init_jit(true)` before creating an execution engine.
177
+ # @todo Add :mcjmm option (MCJIT memory manager)
178
+ #
179
+ # @param [LLVM::Module] mod module
180
+ # @param [Hash{Symbol => Object}] options options
181
+ # @option options [Integer] :opt_level (2) Optimization level
182
+ # @option options [Integer] :code_model (0) Code model types
183
+ # @option options [Boolean] :no_frame_pointer_elim (false) Disable frame pointer elimination optimization
184
+ # @option options [Boolean] :enable_fast_i_sel (false) Enables fast-path instruction selection
185
+ # @return [ExecutionEngine] Execution engine
186
+ def initialize(mod, options = {})
187
+ options = {
188
+ :opt_level => 2, # LLVMCodeGenLevelDefault
189
+ :code_model => 0,
190
+ :no_frame_pointer_elim => false,
191
+ :enable_fast_i_sel => false,
192
+ # TODO
193
+ #:mcjmm => nil,
194
+ }.merge(options)
195
+
196
+ super
197
+ end
198
+
199
+ def convert_type(type)
200
+ case type.kind
201
+ when :integer
202
+ if type.width <= 8
203
+ :int8
204
+ else
205
+ "int#{type.width}".to_sym
206
+ end
207
+ else
208
+ type.kind
209
+ end
210
+ end
211
+
212
+ def run_function(fun, *args)
213
+ args2 = fun.params.map {|e| convert_type(e.type)}
214
+ ptr = FFI::Pointer.new(function_address(fun.name))
215
+ raise "Couldn't find function" if ptr.null?
216
+
217
+ return_type = convert_type(fun.function_type.return_type)
218
+ f = FFI::Function.new(return_type, args2, ptr)
219
+ ret1 = f.call(*args)
220
+ ret2 = LLVM.make_generic_value(fun.function_type.return_type, ret1)
221
+ ret2
222
+ end
223
+
224
+ protected
225
+
226
+ def create_execution_engine_for_module(out_ee, mod, out_error, options)
227
+ mcopts = LLVM::C::MCJITCompilerOptions.new
228
+
229
+ LLVM::C.initialize_mcjit_compiler_options(mcopts, mcopts.size)
230
+
231
+ mcopts[:opt_level] = options[:opt_level]
232
+ mcopts[:code_model] = options[:code_model]
233
+ mcopts[:no_frame_pointer_elim] = options[:no_frame_pointer_elim] ? 1 : 0
234
+ mcopts[:enable_fast_i_sel] = options[:enable_fast_i_sel] ? 1 : 0
235
+
236
+ C.create_mcjit_compiler_for_module(out_ee, mod, mcopts, mcopts.size, out_error)
237
+ end
238
+ end
239
+
240
+ JITCompiler = MCJITCompiler
241
+
242
+ class GenericValue
243
+ # @private
244
+ def to_ptr
245
+ @ptr
246
+ end
247
+
248
+ # Casts an FFI::Pointer pointing to a GenericValue to an instance.
249
+ def self.from_ptr(ptr)
250
+ return if ptr.null?
251
+ val = allocate
252
+ val.instance_variable_set(:@ptr, ptr)
253
+ val
254
+ end
255
+
256
+ def dispose
257
+ return if @ptr.nil?
258
+ C.dispose_generic_value(@ptr)
259
+ @ptr = nil
260
+ end
261
+
262
+ # Creates a Generic Value from an integer. Type is the size of integer to
263
+ # create (ex. Int32, Int8, etc.)
264
+ def self.from_i(i, options = {})
265
+ type = options.fetch(:type, LLVM::Int)
266
+ signed = options.fetch(:signed, true)
267
+ from_ptr(C.create_generic_value_of_int(type, i, signed ? 1 : 0))
268
+ end
269
+
270
+ # Creates a Generic Value from a Float.
271
+ def self.from_f(f)
272
+ from_ptr(C.create_generic_value_of_float(LLVM::Float, f))
273
+ end
274
+
275
+ def self.from_d(val)
276
+ from_ptr(C.create_generic_value_of_float(LLVM::Double, val))
277
+ end
278
+
279
+ # Creates a GenericValue from a Ruby boolean.
280
+ def self.from_b(b)
281
+ from_i(b ? 1 : 0, LLVM::Int1, false)
282
+ end
283
+
284
+ # Creates a GenericValue from an FFI::Pointer pointing to some arbitrary value.
285
+ def self.from_value_ptr(ptr)
286
+ from_ptr(LLVM::C.create_generic_value_of_pointer(ptr))
287
+ end
288
+
289
+ # Converts a GenericValue to a Ruby Integer.
290
+ def to_i(signed = true)
291
+ v = C.generic_value_to_int(self, signed ? 1 : 0)
292
+ v -= 2**64 if signed and v >= 2**63
293
+ v
294
+ end
295
+
296
+ # Converts a GenericValue to a Ruby Float.
297
+ def to_f(type = LLVM::Float.type)
298
+ C.generic_value_to_float(type, self)
299
+ end
300
+
301
+ # Converts a GenericValue to a Ruby boolean.
302
+ def to_b
303
+ to_i(false) != 0
304
+ end
305
+
306
+ def to_value_ptr
307
+ C.generic_value_to_pointer(self)
308
+ end
309
+ end
310
+
311
+ # @private
312
+ def make_generic_value(ty, val)
313
+ case ty.kind
314
+ when :double then GenericValue.from_d(val)
315
+ when :float then GenericValue.from_f(val)
316
+ when :pointer then GenericValue.from_value_ptr(val)
317
+ when :integer then GenericValue.from_i(val, :type => ty)
318
+ else
319
+ raise "Unsupported type #{ty.kind}."
320
+ end
321
+ end
322
+ module_function :make_generic_value
323
+ end
@@ -0,0 +1,421 @@
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 ["libLLVM-10.so.1", "LLVM-10"]
8
+
9
+ def self.attach_function(name, *_)
10
+ begin; super; rescue FFI::NotFoundError => e
11
+ (class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
12
+ end
13
+ end
14
+
15
+ # @defgroup LLVMCExecutionEngine Execution Engine
16
+ # @ingroup LLVMC
17
+ #
18
+ # @{
19
+ #
20
+ # @method link_in_mcjit()
21
+ # @return [nil]
22
+ # @scope class
23
+ attach_function :link_in_mcjit, :LLVMLinkInMCJIT, [], :void
24
+
25
+ # (Not documented)
26
+ #
27
+ # @method link_in_interpreter()
28
+ # @return [nil]
29
+ # @scope class
30
+ attach_function :link_in_interpreter, :LLVMLinkInInterpreter, [], :void
31
+
32
+ # (Not documented)
33
+ class OpaqueGenericValue < FFI::Struct
34
+ layout :dummy, :char
35
+ end
36
+
37
+ # (Not documented)
38
+ class OpaqueExecutionEngine < FFI::Struct
39
+ layout :dummy, :char
40
+ end
41
+
42
+ # (Not documented)
43
+ class OpaqueMCJITMemoryManager < FFI::Struct
44
+ layout :dummy, :char
45
+ end
46
+
47
+ # (Not documented)
48
+ #
49
+ # = Fields:
50
+ # :opt_level ::
51
+ # (Integer)
52
+ # :code_model ::
53
+ # (unknown)
54
+ # :no_frame_pointer_elim ::
55
+ # (Integer)
56
+ # :enable_fast_i_sel ::
57
+ # (Integer)
58
+ # :mcjmm ::
59
+ # (OpaqueMCJITMemoryManager)
60
+ class MCJITCompilerOptions < FFI::Struct
61
+ layout :opt_level, :uint,
62
+ :code_model, :char,
63
+ :no_frame_pointer_elim, :int,
64
+ :enable_fast_i_sel, :int,
65
+ :mcjmm, OpaqueMCJITMemoryManager
66
+ end
67
+
68
+ # ===-- Operations on generic values --------------------------------------===
69
+ #
70
+ # @method create_generic_value_of_int(ty, n, is_signed)
71
+ # @param [FFI::Pointer(TypeRef)] ty
72
+ # @param [Integer] n
73
+ # @param [Integer] is_signed
74
+ # @return [OpaqueGenericValue]
75
+ # @scope class
76
+ attach_function :create_generic_value_of_int, :LLVMCreateGenericValueOfInt, [:pointer, :ulong_long, :int], OpaqueGenericValue
77
+
78
+ # (Not documented)
79
+ #
80
+ # @method create_generic_value_of_pointer(p)
81
+ # @param [FFI::Pointer(*Void)] p
82
+ # @return [OpaqueGenericValue]
83
+ # @scope class
84
+ attach_function :create_generic_value_of_pointer, :LLVMCreateGenericValueOfPointer, [:pointer], OpaqueGenericValue
85
+
86
+ # (Not documented)
87
+ #
88
+ # @method create_generic_value_of_float(ty, n)
89
+ # @param [FFI::Pointer(TypeRef)] ty
90
+ # @param [Float] n
91
+ # @return [OpaqueGenericValue]
92
+ # @scope class
93
+ attach_function :create_generic_value_of_float, :LLVMCreateGenericValueOfFloat, [:pointer, :double], OpaqueGenericValue
94
+
95
+ # (Not documented)
96
+ #
97
+ # @method generic_value_int_width(gen_val_ref)
98
+ # @param [OpaqueGenericValue] gen_val_ref
99
+ # @return [Integer]
100
+ # @scope class
101
+ attach_function :generic_value_int_width, :LLVMGenericValueIntWidth, [OpaqueGenericValue], :uint
102
+
103
+ # (Not documented)
104
+ #
105
+ # @method generic_value_to_int(gen_val, is_signed)
106
+ # @param [OpaqueGenericValue] gen_val
107
+ # @param [Integer] is_signed
108
+ # @return [Integer]
109
+ # @scope class
110
+ attach_function :generic_value_to_int, :LLVMGenericValueToInt, [OpaqueGenericValue, :int], :ulong_long
111
+
112
+ # (Not documented)
113
+ #
114
+ # @method generic_value_to_pointer(gen_val)
115
+ # @param [OpaqueGenericValue] gen_val
116
+ # @return [FFI::Pointer(*Void)]
117
+ # @scope class
118
+ attach_function :generic_value_to_pointer, :LLVMGenericValueToPointer, [OpaqueGenericValue], :pointer
119
+
120
+ # (Not documented)
121
+ #
122
+ # @method generic_value_to_float(ty_ref, gen_val)
123
+ # @param [FFI::Pointer(TypeRef)] ty_ref
124
+ # @param [OpaqueGenericValue] gen_val
125
+ # @return [Float]
126
+ # @scope class
127
+ attach_function :generic_value_to_float, :LLVMGenericValueToFloat, [:pointer, OpaqueGenericValue], :double
128
+
129
+ # (Not documented)
130
+ #
131
+ # @method dispose_generic_value(gen_val)
132
+ # @param [OpaqueGenericValue] gen_val
133
+ # @return [nil]
134
+ # @scope class
135
+ attach_function :dispose_generic_value, :LLVMDisposeGenericValue, [OpaqueGenericValue], :void
136
+
137
+ # ===-- Operations on execution engines -----------------------------------===
138
+ #
139
+ # @method create_execution_engine_for_module(out_ee, m, out_error)
140
+ # @param [FFI::Pointer(*ExecutionEngineRef)] out_ee
141
+ # @param [FFI::Pointer(ModuleRef)] m
142
+ # @param [FFI::Pointer(**CharS)] out_error
143
+ # @return [Integer]
144
+ # @scope class
145
+ attach_function :create_execution_engine_for_module, :LLVMCreateExecutionEngineForModule, [:pointer, :pointer, :pointer], :int
146
+
147
+ # (Not documented)
148
+ #
149
+ # @method create_interpreter_for_module(out_interp, m, out_error)
150
+ # @param [FFI::Pointer(*ExecutionEngineRef)] out_interp
151
+ # @param [FFI::Pointer(ModuleRef)] m
152
+ # @param [FFI::Pointer(**CharS)] out_error
153
+ # @return [Integer]
154
+ # @scope class
155
+ attach_function :create_interpreter_for_module, :LLVMCreateInterpreterForModule, [:pointer, :pointer, :pointer], :int
156
+
157
+ # (Not documented)
158
+ #
159
+ # @method create_jit_compiler_for_module(out_jit, m, opt_level, out_error)
160
+ # @param [FFI::Pointer(*ExecutionEngineRef)] out_jit
161
+ # @param [FFI::Pointer(ModuleRef)] m
162
+ # @param [Integer] opt_level
163
+ # @param [FFI::Pointer(**CharS)] out_error
164
+ # @return [Integer]
165
+ # @scope class
166
+ attach_function :create_jit_compiler_for_module, :LLVMCreateJITCompilerForModule, [:pointer, :pointer, :uint, :pointer], :int
167
+
168
+ # (Not documented)
169
+ #
170
+ # @method initialize_mcjit_compiler_options(options, size_of_options)
171
+ # @param [MCJITCompilerOptions] options
172
+ # @param [Integer] size_of_options
173
+ # @return [nil]
174
+ # @scope class
175
+ attach_function :initialize_mcjit_compiler_options, :LLVMInitializeMCJITCompilerOptions, [MCJITCompilerOptions, :ulong], :void
176
+
177
+ # Create an MCJIT execution engine for a module, with the given options. It is
178
+ # the responsibility of the caller to ensure that all fields in Options up to
179
+ # the given SizeOfOptions are initialized. It is correct to pass a smaller
180
+ # value of SizeOfOptions that omits some fields. The canonical way of using
181
+ # this is:
182
+ #
183
+ # LLVMMCJITCompilerOptions options;
184
+ # LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
185
+ # ... fill in those options you care about
186
+ # LLVMCreateMCJITCompilerForModule(&jit, mod, &options, sizeof(options),
187
+ # &error);
188
+ #
189
+ # Note that this is also correct, though possibly suboptimal:
190
+ #
191
+ # LLVMCreateMCJITCompilerForModule(&jit, mod, 0, 0, &error);
192
+ #
193
+ # @method create_mcjit_compiler_for_module(out_jit, m, options, size_of_options, out_error)
194
+ # @param [FFI::Pointer(*ExecutionEngineRef)] out_jit
195
+ # @param [FFI::Pointer(ModuleRef)] m
196
+ # @param [MCJITCompilerOptions] options
197
+ # @param [Integer] size_of_options
198
+ # @param [FFI::Pointer(**CharS)] out_error
199
+ # @return [Integer]
200
+ # @scope class
201
+ attach_function :create_mcjit_compiler_for_module, :LLVMCreateMCJITCompilerForModule, [:pointer, :pointer, MCJITCompilerOptions, :ulong, :pointer], :int
202
+
203
+ # (Not documented)
204
+ #
205
+ # @method dispose_execution_engine(ee)
206
+ # @param [OpaqueExecutionEngine] ee
207
+ # @return [nil]
208
+ # @scope class
209
+ attach_function :dispose_execution_engine, :LLVMDisposeExecutionEngine, [OpaqueExecutionEngine], :void
210
+
211
+ # (Not documented)
212
+ #
213
+ # @method run_static_constructors(ee)
214
+ # @param [OpaqueExecutionEngine] ee
215
+ # @return [nil]
216
+ # @scope class
217
+ attach_function :run_static_constructors, :LLVMRunStaticConstructors, [OpaqueExecutionEngine], :void
218
+
219
+ # (Not documented)
220
+ #
221
+ # @method run_static_destructors(ee)
222
+ # @param [OpaqueExecutionEngine] ee
223
+ # @return [nil]
224
+ # @scope class
225
+ attach_function :run_static_destructors, :LLVMRunStaticDestructors, [OpaqueExecutionEngine], :void
226
+
227
+ # (Not documented)
228
+ #
229
+ # @method run_function_as_main(ee, f, arg_c, arg_v, env_p)
230
+ # @param [OpaqueExecutionEngine] ee
231
+ # @param [FFI::Pointer(ValueRef)] f
232
+ # @param [Integer] arg_c
233
+ # @param [FFI::Pointer(**CharS)] arg_v
234
+ # @param [FFI::Pointer(**CharS)] env_p
235
+ # @return [Integer]
236
+ # @scope class
237
+ attach_function :run_function_as_main, :LLVMRunFunctionAsMain, [OpaqueExecutionEngine, :pointer, :uint, :pointer, :pointer], :int
238
+
239
+ # (Not documented)
240
+ #
241
+ # @method run_function(ee, f, num_args, args)
242
+ # @param [OpaqueExecutionEngine] ee
243
+ # @param [FFI::Pointer(ValueRef)] f
244
+ # @param [Integer] num_args
245
+ # @param [FFI::Pointer(*GenericValueRef)] args
246
+ # @return [OpaqueGenericValue]
247
+ # @scope class
248
+ attach_function :run_function, :LLVMRunFunction, [OpaqueExecutionEngine, :pointer, :uint, :pointer], OpaqueGenericValue
249
+
250
+ # (Not documented)
251
+ #
252
+ # @method free_machine_code_for_function(ee, f)
253
+ # @param [OpaqueExecutionEngine] ee
254
+ # @param [FFI::Pointer(ValueRef)] f
255
+ # @return [nil]
256
+ # @scope class
257
+ attach_function :free_machine_code_for_function, :LLVMFreeMachineCodeForFunction, [OpaqueExecutionEngine, :pointer], :void
258
+
259
+ # (Not documented)
260
+ #
261
+ # @method add_module(ee, m)
262
+ # @param [OpaqueExecutionEngine] ee
263
+ # @param [FFI::Pointer(ModuleRef)] m
264
+ # @return [nil]
265
+ # @scope class
266
+ attach_function :add_module, :LLVMAddModule, [OpaqueExecutionEngine, :pointer], :void
267
+
268
+ # (Not documented)
269
+ #
270
+ # @method remove_module(ee, m, out_mod, out_error)
271
+ # @param [OpaqueExecutionEngine] ee
272
+ # @param [FFI::Pointer(ModuleRef)] m
273
+ # @param [FFI::Pointer(*ModuleRef)] out_mod
274
+ # @param [FFI::Pointer(**CharS)] out_error
275
+ # @return [Integer]
276
+ # @scope class
277
+ attach_function :remove_module, :LLVMRemoveModule, [OpaqueExecutionEngine, :pointer, :pointer, :pointer], :int
278
+
279
+ # (Not documented)
280
+ #
281
+ # @method find_function(ee, name, out_fn)
282
+ # @param [OpaqueExecutionEngine] ee
283
+ # @param [String] name
284
+ # @param [FFI::Pointer(*ValueRef)] out_fn
285
+ # @return [Integer]
286
+ # @scope class
287
+ attach_function :find_function, :LLVMFindFunction, [OpaqueExecutionEngine, :string, :pointer], :int
288
+
289
+ # (Not documented)
290
+ #
291
+ # @method recompile_and_relink_function(ee, fn)
292
+ # @param [OpaqueExecutionEngine] ee
293
+ # @param [FFI::Pointer(ValueRef)] fn
294
+ # @return [FFI::Pointer(*Void)]
295
+ # @scope class
296
+ attach_function :recompile_and_relink_function, :LLVMRecompileAndRelinkFunction, [OpaqueExecutionEngine, :pointer], :pointer
297
+
298
+ # (Not documented)
299
+ #
300
+ # @method get_execution_engine_target_data(ee)
301
+ # @param [OpaqueExecutionEngine] ee
302
+ # @return [FFI::Pointer(TargetDataRef)]
303
+ # @scope class
304
+ attach_function :get_execution_engine_target_data, :LLVMGetExecutionEngineTargetData, [OpaqueExecutionEngine], :pointer
305
+
306
+ # (Not documented)
307
+ #
308
+ # @method get_execution_engine_target_machine(ee)
309
+ # @param [OpaqueExecutionEngine] ee
310
+ # @return [FFI::Pointer(TargetMachineRef)]
311
+ # @scope class
312
+ attach_function :get_execution_engine_target_machine, :LLVMGetExecutionEngineTargetMachine, [OpaqueExecutionEngine], :pointer
313
+
314
+ # (Not documented)
315
+ #
316
+ # @method add_global_mapping(ee, global, addr)
317
+ # @param [OpaqueExecutionEngine] ee
318
+ # @param [FFI::Pointer(ValueRef)] global
319
+ # @param [FFI::Pointer(*Void)] addr
320
+ # @return [nil]
321
+ # @scope class
322
+ attach_function :add_global_mapping, :LLVMAddGlobalMapping, [OpaqueExecutionEngine, :pointer, :pointer], :void
323
+
324
+ # (Not documented)
325
+ #
326
+ # @method get_pointer_to_global(ee, global)
327
+ # @param [OpaqueExecutionEngine] ee
328
+ # @param [FFI::Pointer(ValueRef)] global
329
+ # @return [FFI::Pointer(*Void)]
330
+ # @scope class
331
+ attach_function :get_pointer_to_global, :LLVMGetPointerToGlobal, [OpaqueExecutionEngine, :pointer], :pointer
332
+
333
+ # (Not documented)
334
+ #
335
+ # @method get_global_value_address(ee, name)
336
+ # @param [OpaqueExecutionEngine] ee
337
+ # @param [String] name
338
+ # @return [Integer]
339
+ # @scope class
340
+ attach_function :get_global_value_address, :LLVMGetGlobalValueAddress, [OpaqueExecutionEngine, :string], :ulong
341
+
342
+ # (Not documented)
343
+ #
344
+ # @method get_function_address(ee, name)
345
+ # @param [OpaqueExecutionEngine] ee
346
+ # @param [String] name
347
+ # @return [Integer]
348
+ # @scope class
349
+ attach_function :get_function_address, :LLVMGetFunctionAddress, [OpaqueExecutionEngine, :string], :ulong
350
+
351
+ # ===-- Operations on memory managers -------------------------------------===
352
+ #
353
+ # <em>This entry is only for documentation and no real method.</em>
354
+ #
355
+ # @method _callback_memory_manager_allocate_code_section_callback_(uint8_t, opaque, size, alignment, section_id, section_name)
356
+ # @param [Integer] uint8_t
357
+ # @param [FFI::Pointer(*Void)] opaque
358
+ # @param [Integer] size
359
+ # @param [Integer] alignment
360
+ # @param [Integer] section_id
361
+ # @param [String] section_name
362
+ # @return [Integer]
363
+ # @scope class
364
+ callback :memory_manager_allocate_code_section_callback, [:uchar, :pointer, :ulong, :uint, :uint, :string], :uchar
365
+
366
+ # (Not documented)
367
+ #
368
+ # <em>This entry is only for documentation and no real method.</em>
369
+ #
370
+ # @method _callback_memory_manager_allocate_data_section_callback_(uint8_t, opaque, size, alignment, section_id, section_name, is_read_only)
371
+ # @param [Integer] uint8_t
372
+ # @param [FFI::Pointer(*Void)] opaque
373
+ # @param [Integer] size
374
+ # @param [Integer] alignment
375
+ # @param [Integer] section_id
376
+ # @param [String] section_name
377
+ # @param [Integer] is_read_only
378
+ # @return [Integer]
379
+ # @scope class
380
+ callback :memory_manager_allocate_data_section_callback, [:uchar, :pointer, :ulong, :uint, :uint, :string, :int], :uchar
381
+
382
+ # (Not documented)
383
+ #
384
+ # <em>This entry is only for documentation and no real method.</em>
385
+ #
386
+ # @method _callback_memory_manager_finalize_memory_callback_(bool, opaque, err_msg)
387
+ # @param [Integer] bool
388
+ # @param [FFI::Pointer(*Void)] opaque
389
+ # @param [FFI::Pointer(**CharS)] err_msg
390
+ # @return [Integer]
391
+ # @scope class
392
+ callback :memory_manager_finalize_memory_callback, [:int, :pointer, :pointer], :int
393
+
394
+ # Create a simple custom MCJIT memory manager. This memory manager can
395
+ # intercept allocations in a module-oblivious way. This will return NULL
396
+ # if any of the passed functions are NULL.
397
+ #
398
+ # @param Opaque An opaque client object to pass back to the callbacks.
399
+ # @param AllocateCodeSection Allocate a block of memory for executable code.
400
+ # @param AllocateDataSection Allocate a block of memory for data.
401
+ # @param FinalizeMemory Set page permissions and flush cache. Return 0 on
402
+ # success, 1 on error.
403
+ #
404
+ # @method create_simple_mcjit_memory_manager(opaque, allocate_code_section, allocate_data_section, finalize_memory, destroy)
405
+ # @param [FFI::Pointer(*Void)] opaque
406
+ # @param [Proc(_callback_memory_manager_allocate_code_section_callback_)] allocate_code_section
407
+ # @param [Proc(_callback_memory_manager_allocate_data_section_callback_)] allocate_data_section
408
+ # @param [Proc(_callback_memory_manager_finalize_memory_callback_)] finalize_memory
409
+ # @param [FFI::Pointer(MemoryManagerDestroyCallback)] destroy
410
+ # @return [OpaqueMCJITMemoryManager]
411
+ # @scope class
412
+ attach_function :create_simple_mcjit_memory_manager, :LLVMCreateSimpleMCJITMemoryManager, [:pointer, :memory_manager_allocate_code_section_callback, :memory_manager_allocate_data_section_callback, :memory_manager_finalize_memory_callback, :pointer], OpaqueMCJITMemoryManager
413
+
414
+ # (Not documented)
415
+ #
416
+ # @method dispose_mcjit_memory_manager(mm)
417
+ # @param [OpaqueMCJITMemoryManager] mm
418
+ # @return [nil]
419
+ # @scope class
420
+ attach_function :dispose_mcjit_memory_manager, :LLVMDisposeMCJITMemoryManager, [OpaqueMCJITMemoryManager], :void
421
+ end