Class: RLTK::CG::TargetMachine
- Inherits:
-
Object
- Object
- RLTK::CG::TargetMachine
- 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.
Constant Summary collapse
- CLASS_FINALIZER =
The Proc object called by the garbage collector to free resources used by LLVM.
Proc.new { |id| Bindings.dispose_target_machine(ptr) if ptr = ObjectSpace._id2ref(id).ptr }
Instance Attribute Summary
Attributes included from BindingClass
Class Method Summary collapse
-
.host ⇒ TargetMachine
TargetMachine representation of the host machine.
Instance Method Summary collapse
-
#cpu ⇒ String
Name of the target machine’s CPU.
- #data ⇒ TargetData
-
#emit_module(mod, file_name, emit_type) ⇒ void
Emit assembly or object code for the given module to the file specified.
-
#feature_string ⇒ String
Feature string for this target machine.
-
#initialize(target, mcpu = '', features = '', opt_level = :none, reloc_mode = :default, code_model = :default) ⇒ TargetMachine
constructor
Create a new object describing a target machine.
- #target ⇒ Target
- #triple ⇒ Triple
-
#verbose_asm=(bool) ⇒ void
Set verbose ASM property.
-
#verbose_asm? ⇒ Boolean
If this target machine should print verbose ASM.
Methods included from BindingClass
Constructor Details
#initialize(target, mcpu = '', features = '', opt_level = :none, reloc_mode = :default, code_model = :default) ⇒ TargetMachine
Create a new object describing a target machine.
152 153 154 155 156 157 158 159 160 161 |
# 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 |
Class Method Details
.host ⇒ TargetMachine
Returns TargetMachine representation of the host machine.
137 138 139 |
# File 'lib/rltk/cg/target.rb', line 137 def self.host @host ||= self.new(Target.host) end |
Instance Method Details
#cpu ⇒ String
Returns Name of the target machine’s CPU.
164 165 166 |
# File 'lib/rltk/cg/target.rb', line 164 def cpu Bindings.get_target_machine_cpu(@ptr) end |
#data ⇒ TargetData
169 170 171 |
# 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) ⇒ void
This method returns an undefined value.
Emit assembly or object code for the given module to the file specified.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# 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 = errorp.null? ? 'Unknown' : errorp.read_string error.autorelease = false Bindings.(error) raise "Error emiting code for module: #{}" end end |
#feature_string ⇒ String
Returns Feature string for this target machine.
200 201 202 |
# File 'lib/rltk/cg/target.rb', line 200 def feature_string Bindings.get_target_machine_feature_string(@ptr) end |
#target ⇒ Target
205 206 207 |
# File 'lib/rltk/cg/target.rb', line 205 def target Target.new(Bindings.get_target_machine_target(@ptr)) end |
#triple ⇒ Triple
210 211 212 |
# File 'lib/rltk/cg/target.rb', line 210 def triple Triple.new(Bindings.get_target_machine_triple(@ptr)) end |
#verbose_asm=(bool) ⇒ void
This method returns an undefined value.
Set verbose ASM property.
219 220 221 222 223 |
# 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? ⇒ Boolean
Returns If this target machine should print verbose ASM.
226 227 228 |
# File 'lib/rltk/cg/target.rb', line 226 def verbose_asm? @verbose_asm ||= false end |