Class: RLTK::CG::Target

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

Overview

Class binding for the LLVM Triple class.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BindingClass

#==

Constructor Details

#initialize(overloaded) ⇒ Target

Create an object representing a particular code generation target. You can create a target either from a string or a Triple.

Parameters:

  • overloaded (Triple, String)

    Object describing the target.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rltk/cg/target.rb', line 51

def initialize(overloaded)
	@ptr, @triple = 
	case overloaded
	when String
		[Bindings.get_target_from_name(overloaded), Triple.new(overloaded)]
		
	when RLTK::CG::Triple
		ptr    = FFI::MemoryPointer.new(:pointer)
		error  = FFI::MemoryPointer.new(:pointer)
		status = Bindings.get_target_from_triple(overloaded.to_s, ptr, error)
		
		if status.zero?
			[ptr, overloaded]
		
		else
			errorp  = error.read_pointer
			message = errorp.null? ? 'Unknown' : errorp.read_string

			error.autorelease = false

			Bindings.dispose_message(error)

			raise "Error creating target: #{message}"
		end
		
	when RLTK::CG::Bindings::Triple
		[overloaded, nil]
	end
end

Class Method Details

.firstTarget

Returns First target in the target list.

Returns:

  • (Target)

    First target in the target list



29
30
31
# File 'lib/rltk/cg/target.rb', line 29

def self.first
	@first ||= self.new(Bindings.get_first_target)
end

.hostTarget

Returns Target object for the host architecture.

Returns:

  • (Target)

    Target object for the host architecture.



34
35
36
# File 'lib/rltk/cg/target.rb', line 34

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

.next_target(target) ⇒ Target

Returns Next target in the target list.

Returns:

  • (Target)

    Next target in the target list



39
40
41
# File 'lib/rltk/cg/target.rb', line 39

def self.next_target(target)
	self.new(Bindings.get_next_target(target))
end

Instance Method Details

#asm_backend?Boolean

Returns Whether or not the target has an ASM backend.

Returns:

  • (Boolean)

    Whether or not the target has an ASM backend



82
83
84
# File 'lib/rltk/cg/target.rb', line 82

def asm_backend?
	Bindings.target_has_asm_backend(@ptr).to_bool
end

#describeString

Returns Description of the target.

Returns:

  • (String)

    Description of the target



97
98
99
# File 'lib/rltk/cg/target.rb', line 97

def describe
	Bindings.get_target_description(@ptr)
end

#jit?Boolean

Returns Whether or not the target has a JIT.

Returns:

  • (Boolean)

    Whether or not the target has a JIT



87
88
89
# File 'lib/rltk/cg/target.rb', line 87

def jit?
	Bindings.target_has_jit(@ptr).to_bool
end

#target_machine?Boolean

Returns Whether or not the target has a TargetMachine.

Returns:

  • (Boolean)

    Whether or not the target has a TargetMachine



92
93
94
# File 'lib/rltk/cg/target.rb', line 92

def target_machine?
	Bindings.target_has_target_machine(@ptr).to_bool
end

#tripleTriple

Returns Triple object for this target.

Returns:

  • (Triple)

    Triple object for this target



102
103
104
# File 'lib/rltk/cg/target.rb', line 102

def triple
	@triple ||= Triple.new(Bindings.get_target_name(@ptr))
end