Class: LLVM::JITCompiler
- Inherits:
-
Object
- Object
- LLVM::JITCompiler
- Defined in:
- lib/llvm/execution_engine.rb
Instance Method Summary collapse
-
#initialize(mod, opt_level = 3) ⇒ JITCompiler
constructor
A new instance of JITCompiler.
-
#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(mod, opt_level = 3) ⇒ JITCompiler
Returns a new instance of JITCompiler.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/llvm/execution_engine.rb', line 56 def initialize(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? @ptr = ptr.read_pointer else C.LLVMDisposeMessage(error) error.autorelease=false raise RuntimeError, "Error creating JIT compiler: #{message}" end end end |
Instance Method Details
#pointer_to_global(global) ⇒ Object
Obtain an FFI::Pointer to a global within the current module.
91 92 93 |
# File 'lib/llvm/execution_engine.rb', line 91 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).
80 81 82 83 84 85 86 87 88 |
# File 'lib/llvm/execution_engine.rb', line 80 def run_function(fun, *args) FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr| args_ptr.write_array_of_pointer fun.params.zip(args).map { |p, a| a.kind_of?(GenericValue) ? a : LLVM.make_generic_value(p.type, a) } return LLVM::GenericValue.from_ptr( C.LLVMRunFunction(self, fun, args.size, args_ptr)) end end |
#to_ptr ⇒ Object
74 75 76 |
# File 'lib/llvm/execution_engine.rb', line 74 def to_ptr @ptr end |