Class: RLTK::CG::TargetMachine

Inherits:
Object
  • Object
show all
Includes:
BindingClass
Defined in:
lib/rltk/cg/target.rb

Overview

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

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BindingClass

#==

Constructor Details

#initialize(target, mcpu = '', features = '', reloc_model = :default, code_model = :default) ⇒ TargetMachine

Create a new object describing a target machine.

Parameters:

  • target (Target)

    Target description.

  • mcpu (String) (defaults to: '')

    Specific CPU type to target.

  • features (Array<String>, String) (defaults to: '')

    Features present for this target machine.

  • reloc_model (Symbol) (defaults to: :default)

    Code relocation model.

  • code_model (Symbol) (defaults to: :default)

    Code generation model.

See Also:



89
90
91
92
93
94
95
96
97
98
# File 'lib/rltk/cg/target.rb', line 89

def initialize(target, mcpu = '', features = '', reloc_model = :default, code_model = :default)
	# Just to make things easier on developers.
	reloc_model = :default_rmodel if reloc_model == :default
	code_model  = :default_cmodel if 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, reloc_model, code_model)
end

Class Method Details

.build_feature_string(features) ⇒ String

Convert an array of strings representing features of a target machine into a single string.

Parameters:

  • features (Array<String>)

    Strings representing features of a target machine.

Returns:

  • (String)

    A single string representing all of the given features.



67
68
69
70
71
72
# File 'lib/rltk/cg/target.rb', line 67

def self.build_feature_string(features)
	strings_ptr = FFI::MemoryPointer.new(:pointer, features.length)
	strings_ptr.write_array_of_pointer(features.map { |str| FFI::MemoryPointer.from_string(str) })
	
	Bindings.build_features_string(strings_ptr, features.length)
end

.hostTargetMachine

Returns TargetMachine representation of the host machine.

Returns:

  • (TargetMachine)

    TargetMachine representation of the host machine.



75
76
77
# File 'lib/rltk/cg/target.rb', line 75

def self.host
	@host ||= self.new(Target.host)
end