Class: LLVM::ExecutionEngine Abstract
- Inherits:
-
Object
- Object
- LLVM::ExecutionEngine
- Defined in:
- lib/llvm/execution_engine.rb
Overview
Subclass and override #create_execution_engine_for_module.
Direct Known Subclasses
Defined Under Namespace
Classes: FunctionCollection, ModuleCollection
Instance Method Summary collapse
-
#data_layout ⇒ TargetDataLayout
Get the associated data layout.
- #dispose ⇒ Object
- #function_address(name) ⇒ Object
-
#functions ⇒ FunctionCollection
Returns a FunctionCollection of all the Functions in the engine.
-
#initialize(mod, options) ⇒ ExecutionEngine
constructor
Create a JIT execution engine for module with the given options.
-
#modules ⇒ ModuleCollection
Returns a ModuleCollection of all the Modules in the engine.
-
#pointer_to_global(global) ⇒ Object
Obtain an FFI::Pointer to a global within the current module.
-
#run_function(fun, *args) ⇒ Object
Execute the given LLVM::Function with the supplied args (as GenericValues).
-
#target_machine ⇒ TargetMachine
Get the associated target machine.
- #to_ptr ⇒ Object
Constructor Details
#initialize(mod, options) ⇒ ExecutionEngine
Important: Call #dispose to free backend memory after use. Do not call #dispose on mod any more.
Create a JIT execution engine for module with the given options.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/llvm/execution_engine.rb', line 19 def initialize(mod, ) FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |ptr| error = FFI::MemoryPointer.new(FFI.type_size(:pointer)) status = create_execution_engine_for_module(ptr, mod, error, ) errorp = error.read_pointer = errorp.read_string unless errorp.null? if status.zero? @ptr = ptr.read_pointer else C.(error) error.autorelease = false raise "Error creating JIT compiler: #{}" end end end |
Instance Method Details
#data_layout ⇒ TargetDataLayout
Get the associated data layout.
50 51 52 |
# File 'lib/llvm/execution_engine.rb', line 50 def data_layout TargetDataLayout.from_ptr(C.get_execution_engine_target_data(self)) end |
#dispose ⇒ Object
36 37 38 39 40 |
# File 'lib/llvm/execution_engine.rb', line 36 def dispose return if @ptr.nil? C.dispose_execution_engine(@ptr) @ptr = nil end |
#function_address(name) ⇒ Object
89 90 91 |
# File 'lib/llvm/execution_engine.rb', line 89 def function_address(name) C.get_function_address(self, name) end |
#functions ⇒ FunctionCollection
Returns a FunctionCollection of all the Functions in the engine.
101 102 103 |
# File 'lib/llvm/execution_engine.rb', line 101 def functions @functions ||= FunctionCollection.new(self) end |
#modules ⇒ ModuleCollection
Returns a ModuleCollection of all the Modules in the engine.
95 96 97 |
# File 'lib/llvm/execution_engine.rb', line 95 def modules @modules ||= ModuleCollection.new(self) end |
#pointer_to_global(global) ⇒ Object
Obtain an FFI::Pointer to a global within the current module.
85 86 87 |
# File 'lib/llvm/execution_engine.rb', line 85 def pointer_to_global(global) C.get_pointer_to_global(self, global) end |
#run_function(fun, *args) ⇒ Object
Execute the given LLVM::Function with the supplied args (as GenericValues). Important: Call #dispose on the returned GenericValue to free backend memory after use.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/llvm/execution_engine.rb', line 65 def run_function(fun, *args) FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr| new_values = [] args_ptr.write_array_of_pointer(fun.params.zip(args).map do |p, a| if a.kind_of?(GenericValue) a else value = LLVM.make_generic_value(p.type, a) new_values << value value end end) result = LLVM::GenericValue.from_ptr( C.run_function(self, fun, args.size, args_ptr)) new_values.each(&:dispose) return result end end |
#target_machine ⇒ TargetMachine
Get the associated target machine.
57 58 59 |
# File 'lib/llvm/execution_engine.rb', line 57 def target_machine TargetMachine.from_ptr(C.get_execution_engine_target_machine(self)) end |
#to_ptr ⇒ Object
43 44 45 |
# File 'lib/llvm/execution_engine.rb', line 43 def to_ptr @ptr end |