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



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/llvm/execution_engine.rb', line 188

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



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/llvm/execution_engine.rb', line 201

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

#run_function(fun, *args) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/llvm/execution_engine.rb', line 214

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)
  ret1 = f.call(*args)
  ret2 = LLVM.make_generic_value(fun.function_type.return_type, ret1)
  ret2
end