Class: LLVM::ExecutionEngine
- Inherits:
-
Object
- Object
- LLVM::ExecutionEngine
- Defined in:
- lib/llvm/execution_engine.rb
Class Method Summary collapse
-
.create_jit_compiler(mod, opt_level = 3) ⇒ Object
Create a JIT compiler with an LLVM::Module.
Instance Method Summary collapse
-
#initialize(ptr) ⇒ ExecutionEngine
constructor
A new instance of ExecutionEngine.
-
#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).
- #to_ptr ⇒ Object
Constructor Details
#initialize(ptr) ⇒ ExecutionEngine
Returns a new instance of ExecutionEngine.
59 60 61 |
# File 'lib/llvm/execution_engine.rb', line 59 def initialize(ptr) @ptr = ptr end |
Class Method Details
.create_jit_compiler(mod, opt_level = 3) ⇒ Object
Create a JIT compiler with an LLVM::Module.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/llvm/execution_engine.rb', line 69 def self.create_jit_compiler(mod, opt_level = 3) FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |ptr| error = FFI::MemoryPointer.new(FFI.type_size(:pointer)) status = C.LLVMCreateJITCompilerForModule(ptr, mod, opt_level, error) errorp = error.read_pointer = errorp.read_string unless errorp.null? if status.zero? return new(ptr.read_pointer) else C.LLVMDisposeMessage(error) error.autorelease=false raise RuntimeError, "Error creating JIT compiler: #{}" end end end |
Instance Method Details
#pointer_to_global(global) ⇒ Object
Obtain an FFI::Pointer to a global within the current module.
97 98 99 |
# File 'lib/llvm/execution_engine.rb', line 97 def pointer_to_global(global) C.LLVMGetPointerToGlobal(self, global) end |
#run_function(fun, *args) ⇒ Object
Execute the given LLVM::Function with the supplied args (as GenericValues).
88 89 90 91 92 93 94 |
# File 'lib/llvm/execution_engine.rb', line 88 def run_function(fun, *args) FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr| args_ptr.write_array_of_pointer(args.map { |arg| LLVM.GenericValue(arg).to_ptr }) return LLVM::GenericValue.from_ptr( C.LLVMRunFunction(self, fun, args.size, args_ptr)) end end |
#to_ptr ⇒ Object
64 65 66 |
# File 'lib/llvm/execution_engine.rb', line 64 def to_ptr @ptr end |