Class: LLVM::GenericValue
- Inherits:
-
Object
- Object
- LLVM::GenericValue
- Defined in:
- lib/llvm/execution_engine.rb
Class Method Summary collapse
-
.from_b(b) ⇒ Object
Creates a GenericValue from a Ruby boolean.
- .from_d(val) ⇒ Object
-
.from_f(f) ⇒ Object
Creates a Generic Value from a Float.
-
.from_i(i, options = {}) ⇒ Object
Creates a Generic Value from an integer.
-
.from_ptr(ptr) ⇒ Object
Casts an FFI::Pointer pointing to a GenericValue to an instance.
-
.from_value_ptr(ptr) ⇒ Object
Creates a GenericValue from an FFI::Pointer pointing to some arbitrary value.
Instance Method Summary collapse
- #dispose ⇒ Object
-
#to_b ⇒ Object
Converts a GenericValue to a Ruby boolean.
-
#to_f(type = LLVM::Float.type) ⇒ Object
Converts a GenericValue to a Ruby Float.
-
#to_i(signed = true) ⇒ Object
Converts a GenericValue to a Ruby Integer.
- #to_ptr ⇒ Object
- #to_value_ptr ⇒ Object
Class Method Details
.from_b(b) ⇒ Object
Creates a GenericValue from a Ruby boolean.
112 113 114 |
# File 'lib/llvm/execution_engine.rb', line 112 def self.from_b(b) from_i(b ? 1 : 0, LLVM::Int1, false) end |
.from_d(val) ⇒ Object
107 108 109 |
# File 'lib/llvm/execution_engine.rb', line 107 def self.from_d(val) from_ptr(C.create_generic_value_of_float(LLVM::Double, val)) end |
.from_f(f) ⇒ Object
Creates a Generic Value from a Float.
103 104 105 |
# File 'lib/llvm/execution_engine.rb', line 103 def self.from_f(f) from_ptr(C.create_generic_value_of_float(LLVM::Float, f)) end |
.from_i(i, options = {}) ⇒ Object
Creates a Generic Value from an integer. Type is the size of integer to create (ex. Int32, Int8, etc.)
96 97 98 99 100 |
# File 'lib/llvm/execution_engine.rb', line 96 def self.from_i(i, = {}) type = .fetch(:type, LLVM::Int) signed = .fetch(:signed, true) from_ptr(C.create_generic_value_of_int(type, i, signed ? 1 : 0)) end |
.from_ptr(ptr) ⇒ Object
Casts an FFI::Pointer pointing to a GenericValue to an instance.
81 82 83 84 85 86 |
# File 'lib/llvm/execution_engine.rb', line 81 def self.from_ptr(ptr) return if ptr.null? val = allocate val.instance_variable_set(:@ptr, ptr) val end |
.from_value_ptr(ptr) ⇒ Object
Creates a GenericValue from an FFI::Pointer pointing to some arbitrary value.
117 118 119 |
# File 'lib/llvm/execution_engine.rb', line 117 def self.from_value_ptr(ptr) from_ptr(LLVM::C.create_generic_value_of_pointer(ptr)) end |
Instance Method Details
#dispose ⇒ Object
88 89 90 91 92 |
# File 'lib/llvm/execution_engine.rb', line 88 def dispose return if @ptr.nil? C.dispose_generic_value(@ptr) @ptr = nil end |
#to_b ⇒ Object
Converts a GenericValue to a Ruby boolean.
134 135 136 |
# File 'lib/llvm/execution_engine.rb', line 134 def to_b to_i(false) != 0 end |
#to_f(type = LLVM::Float.type) ⇒ Object
Converts a GenericValue to a Ruby Float.
129 130 131 |
# File 'lib/llvm/execution_engine.rb', line 129 def to_f(type = LLVM::Float.type) C.generic_value_to_float(type, self) end |
#to_i(signed = true) ⇒ Object
Converts a GenericValue to a Ruby Integer.
122 123 124 125 126 |
# File 'lib/llvm/execution_engine.rb', line 122 def to_i(signed = true) v = C.generic_value_to_int(self, signed ? 1 : 0) v -= 2**64 if signed and v >= 2**63 v end |
#to_ptr ⇒ Object
76 77 78 |
# File 'lib/llvm/execution_engine.rb', line 76 def to_ptr @ptr end |
#to_value_ptr ⇒ Object
138 139 140 |
# File 'lib/llvm/execution_engine.rb', line 138 def to_value_ptr C.generic_value_to_pointer(self) end |