class RLTK::CG::TargetMachine

This class represents a specific architecture that wil be targeted by LLVM’s compilation process.

Constants

CLASS_FINALIZER

The Proc object called by the garbage collector to free resources used by LLVM.

Public Class Methods

host() click to toggle source

@return [TargetMachine] TargetMachine representation of the host machine.

# File lib/rltk/cg/target.rb, line 137
def self.host
        @host ||= self.new(Target.host)
end
new(target, mcpu = '', features = '', opt_level = :none, reloc_mode = :default, code_model = :default) click to toggle source

Create a new object describing a target machine.

@see Bindings.enum_reloc_model @see Bindings.enum_code_model

@param [Target] target Target description @param [String] mcpu Specific CPU type to target @param [Array<String>, String] features Features present for this target machine @param [Symbol from enum_code_gen_opt_level] opt_level Optimization level @param [Symbol from enum_reloc_mode] reloc_mode Code relocation model @param [Symbol from enum_code_model] code_model Code generation model

# File lib/rltk/cg/target.rb, line 152
def initialize(target, mcpu = '', features = '', opt_level = :none, reloc_mode = :default, code_model = :default)
        # Convert the features parameter if necessary.
        features = TargetMachine.build_feature_string(features) if features.is_a?(Array)

        @ptr = Bindings.create_target_machine(target, target.triple.to_s, mcpu, features, opt_level, reloc_mode, code_model)

        # Define a finalizer to free the memory used by LLVM for
        # this target machine.
        ObjectSpace.define_finalizer(self, CLASS_FINALIZER)
end

Public Instance Methods

cpu() click to toggle source

@return [String] Name of the target machine’s CPU

# File lib/rltk/cg/target.rb, line 164
def cpu
        Bindings.get_target_machine_cpu(@ptr)
end
data() click to toggle source

@return [TargetData]

# File lib/rltk/cg/target.rb, line 169
def data
        TargetData.new(Bindings.get_target_machine_data(@pt))
end
emit_module(mod, file_name, emit_type) click to toggle source

Emit assembly or object code for the given module to the file specified.

@param [Module] mod Module to emit code for @param [String] file_name File to emit code to @param [:assembly, :object] emit_type Type of code to emit

@return [void]

@raise LLVM error message if unable to emite code for module

# File lib/rltk/cg/target.rb, line 183
def emit_module(mod, file_name, emit_type)
        error  = FFI::MemoryPointer.new(:pointer)
        status = Bindings.target_machine_emit_to_file(@ptr, mod, file_name, emit_type, error)

        if not status.zero?
                errorp  = error.read_pointer
                message = errorp.null? ? 'Unknown' : errorp.read_string

                error.autorelease = false

                Bindings.dispose_message(error)

                raise "Error emiting code for module: #{message}"
        end
end
feature_string() click to toggle source

@return [String] Feature string for this target machine

# File lib/rltk/cg/target.rb, line 200
def feature_string
        Bindings.get_target_machine_feature_string(@ptr)
end
target() click to toggle source

@return [Target]

# File lib/rltk/cg/target.rb, line 205
def target
        Target.new(Bindings.get_target_machine_target(@ptr))
end
triple() click to toggle source

@return [Triple]

# File lib/rltk/cg/target.rb, line 210
def triple
        Triple.new(Bindings.get_target_machine_triple(@ptr))
end
verbose_asm=(bool) click to toggle source

Set verbose ASM property.

@param [Boolean] bool Verbose ASM or not

@return [void]

# File lib/rltk/cg/target.rb, line 219
def verbose_asm=(bool)
        @verbose_asm = bool

        Bindings.set_target_machine_asm_verbosity(@ptr, bool.to_i)
end
verbose_asm?() click to toggle source

@return [Boolean] If this target machine should print verbose ASM

# File lib/rltk/cg/target.rb, line 226
def verbose_asm?
        @verbose_asm ||= false
end