Class: LLVM::MCJITCompiler

Inherits:
ExecutionEngine show all
Defined in:
lib/llvm/execution_engine.rb

Instance Method Summary collapse

Methods inherited from ExecutionEngine

#data_layout, #dispose, #function_address, #functions, #modules, #pointer_to_global, #target_machine, #to_ptr

Constructor Details

#initialize(mod, options = {}) ⇒ ExecutionEngine

TODO:

Add :mcjmm option (MCJIT memory manager)

Note:

You should call ‘LLVM.init_jit(true)` before creating an execution engine.

Create a MCJIT execution engine.

Parameters:

  • mod (LLVM::Module)

    module

  • options (Hash{Symbol => Object}) (defaults to: {})

    options

Options Hash (options):

  • :opt_level (Integer) — default: 2

    Optimization level

  • :code_model (Integer) — default: 0

    Code model types

  • :no_frame_pointer_elim (Boolean) — default: false

    Disable frame pointer elimination optimization

  • :enable_fast_i_sel (Boolean) — default: false

    Enables fast-path instruction selection



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/llvm/execution_engine.rb', line 194

def initialize(mod, options = {})
  options = {
    :opt_level             => 2, # LLVMCodeGenLevelDefault
    :code_model            => 0,
    :no_frame_pointer_elim => false,
    :enable_fast_i_sel     => false,
    # TODO
    # :mcjmm                 => nil,
  }.merge(options)

  super
end

Instance Method Details

#convert_type(type) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/llvm/execution_engine.rb', line 207

def convert_type(type)
  case type.kind
  when :integer
    if type.width <= 8
      :int8
    else
      :"int#{type.width}"
    end
  else
    type.kind
  end
end

#run_function(fun, *args) ⇒ Object

: (Function, *untyped) -> GenericValue?



221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/llvm/execution_engine.rb', line 221

def run_function(fun, *args)
  args2 = fun.params.map {|e| convert_type(e.type)}
  ptr = FFI::Pointer.new(function_address(fun.name))
  raise "Couldn't find function" if ptr.null?

  return_type = convert_type(fun.function_type.return_type)
  f = FFI::Function.new(return_type, args2, ptr) #: as untyped
  ret1 = f.call(*args)
  begin
    LLVM.make_generic_value(fun.function_type.return_type, ret1)
  rescue ArgumentError
    nil
  end
end