Class: LLVM::Target
- Inherits:
-
Object
- Object
- LLVM::Target
- Includes:
- PointerIdentity
- Defined in:
- lib/llvm/target.rb
Overview
You need to call Target.init for a target to be usable.
Defined Under Namespace
Modules: TargetModule
Class Method Summary collapse
-
.by_name(name) ⇒ Target
Fetch a target by its name.
-
.each {|Target| ... } ⇒ Object
Enumerate all initialized targets.
- .from_ptr(ptr) ⇒ Object
- .init(target, asm_printer = false) ⇒ Object
-
.init_all(asm_printer = false) ⇒ Object
Initializes all available targets.
-
.init_native(asm_printer = true) ⇒ Object
Initializes native target.
Instance Method Summary collapse
-
#asm_backend? ⇒ Boolean
Returns if the target has an ASM backend (required for emitting output).
-
#create_machine(triple, cpu = "", features = "", opt_level = :default, reloc = :default, code_model = :default) ⇒ TargetMachine
Constructs a TargetMachine.
-
#description ⇒ String
Returns the description of the target.
-
#jit? ⇒ Boolean
Returns if the target has a JIT.
-
#name ⇒ String
Returns the name of the target.
-
#target_machine? ⇒ Boolean
Returns if the target has a TargetMachine associated.
Methods included from PointerIdentity
Class Method Details
.by_name(name) ⇒ Target
Fetch a target by its name.
108 109 110 111 112 |
# File 'lib/llvm/target.rb', line 108 def self.by_name(name) each do |target| return target if target.name == name end end |
.each {|Target| ... } ⇒ Object
Enumerate all initialized targets.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/llvm/target.rb', line 94 def self.each(&block) return to_enum(:each) if block.nil? target = C.get_first_target until target.null? yield from_ptr(target) target = C.get_next_target(target) end end |
.from_ptr(ptr) ⇒ Object
117 118 119 120 121 |
# File 'lib/llvm/target.rb', line 117 def self.from_ptr(ptr) target = allocate target.instance_variable_set :@ptr, ptr target end |
.init(target, asm_printer = false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/llvm/target.rb', line 37 def self.init(target, asm_printer = false) target_module = TargetModule.dup target_module.module_eval do attach_function :"initialize_target_info_#{target}", :"LLVMInitialize#{target}TargetInfo", [], :void attach_function :"initialize_target_#{target}", :"LLVMInitialize#{target}Target", [], :void attach_function :"initialize_target_#{target}_mc", :"LLVMInitialize#{target}TargetMC", [], :void if asm_printer attach_function(:"initialize_#{target}_asm_printer", :"LLVMInitialize#{target}AsmPrinter", [], :void) end safe_attach_function :"initialize_#{target}_asm_parser", :"LLVMInitialize#{target}AsmParser", [], :void safe_attach_function :"initialize_#{target}_disassembler", :"LLVMInitialize#{target}Disassembler", [], :void end C.extend(target_module) begin %W(initialize_target_info_#{target} initialize_target_#{target} initialize_target_#{target}_mc).each do |init| C.send init end rescue FFI::NotFoundError raise ArgumentError, "LLVM target #{target} is not linked in. Try `llvm-config-#{LLVM_VERSION} --targets-built'." end begin C.send :"initialize_#{target}_asm_printer" if asm_printer rescue FFI::NotFoundError => e raise ArgumentError, "LLVM target #{target} does not implement an ASM routime: #{e.}" end end |
.init_all(asm_printer = false) ⇒ Object
Initializes all available targets.
73 74 75 76 77 78 79 |
# File 'lib/llvm/target.rb', line 73 def self.init_all(asm_printer = false) Support::C.initialize_all_target_infos Support::C.initialize_all_targets Support::C.initialize_all_target_mcs Support::C.initialize_all_asm_printers if asm_printer end |
Instance Method Details
#asm_backend? ⇒ Boolean
Returns if the target has an ASM backend (required for emitting output).
148 149 150 |
# File 'lib/llvm/target.rb', line 148 def asm_backend? !C.target_has_asm_backend(self).zero? end |
#create_machine(triple, cpu = "", features = "", opt_level = :default, reloc = :default, code_model = :default) ⇒ TargetMachine
Constructs a TargetMachine.
161 162 163 164 165 |
# File 'lib/llvm/target.rb', line 161 def create_machine(triple, cpu = "", features = "", opt_level = :default, reloc = :default, code_model = :default) TargetMachine.from_ptr(C.create_target_machine(self, triple, cpu, features, opt_level, reloc, code_model)) end |
#description ⇒ String
Returns the description of the target.
133 134 135 |
# File 'lib/llvm/target.rb', line 133 def description C.get_target_description(self) end |
#jit? ⇒ Boolean
Returns if the target has a JIT.
138 139 140 |
# File 'lib/llvm/target.rb', line 138 def jit? !C.target_has_jit(self).zero? end |
#name ⇒ String
Returns the name of the target.
126 127 128 |
# File 'lib/llvm/target.rb', line 126 def name C.get_target_name(self) end |
#target_machine? ⇒ Boolean
Returns if the target has a TargetMachine associated.
143 144 145 |
# File 'lib/llvm/target.rb', line 143 def target_machine? !C.target_has_target_machine(self).zero? end |