Class: LLVM::GenericValue

Inherits:
Object
  • Object
show all
Defined in:
lib/llvm/execution_engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_b(b) ⇒ Object

Creates a GenericValue from a Ruby boolean.



128
129
130
# File 'lib/llvm/execution_engine.rb', line 128

def self.from_b(b)
  from_i(b ? 1 : 0, LLVM::Int1, false)
end

.from_d(val) ⇒ Object



123
124
125
# File 'lib/llvm/execution_engine.rb', line 123

def self.from_d(val)
  from_ptr(C.LLVMCreateGenericValueOfFloat(LLVM::Double, val))
end

.from_f(f) ⇒ Object

Creates a Generic Value from a Float.



119
120
121
# File 'lib/llvm/execution_engine.rb', line 119

def self.from_f(f)
  from_ptr(C.LLVMCreateGenericValueOfFloat(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.)



112
113
114
115
116
# File 'lib/llvm/execution_engine.rb', line 112

def self.from_i(i, options = {})
  type   = options.fetch(:type, LLVM::Int)
  signed = options.fetch(:signed, true)
  from_ptr(C.LLVMCreateGenericValueOfInt(type, i, signed ? 1 : 0))
end

.from_ptr(ptr) ⇒ Object

Casts an FFI::Pointer pointing to a GenericValue to an instance.



103
104
105
106
107
108
# File 'lib/llvm/execution_engine.rb', line 103

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.



133
134
135
# File 'lib/llvm/execution_engine.rb', line 133

def self.from_value_ptr(ptr)
  from_ptr(LLVM::C.LLVMCreateGenericValueOfPointer(ptr))
end

Instance Method Details

#to_bObject

Converts a GenericValue to a Ruby boolean.



148
149
150
# File 'lib/llvm/execution_engine.rb', line 148

def to_b
  to_i(false) != 0
end

#to_f(type = LLVM::Float.type) ⇒ Object

Converts a GenericValue to a Ruby Float.



143
144
145
# File 'lib/llvm/execution_engine.rb', line 143

def to_f(type = LLVM::Float.type)
  C.LLVMGenericValueToFloat(type, self)
end

#to_i(signed = true) ⇒ Object

Converts a GenericValue to a Ruby Integer.



138
139
140
# File 'lib/llvm/execution_engine.rb', line 138

def to_i(signed = true)
  C.LLVMGenericValueToInt(self, signed ? 1 : 0)
end

#to_ptrObject



98
99
100
# File 'lib/llvm/execution_engine.rb', line 98

def to_ptr
  @ptr
end

#to_value_ptrObject



152
153
154
# File 'lib/llvm/execution_engine.rb', line 152

def to_value_ptr
  C.LLVMGenericValueToPointer(self)
end