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. : (bool) -> GenericValue



298
299
300
# File 'lib/llvm/execution_engine.rb', line 298

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

.from_d(val) ⇒ Object

: (Numeric) -> GenericValue



292
293
294
# File 'lib/llvm/execution_engine.rb', line 292

def self.from_d(val)
  from_ptr(C.create_generic_value_of_float(LLVM::Double, val.to_f)) #: as !nil
end

.from_f(f) ⇒ Object

Creates a Generic Value from a Float. : (Numeric) -> GenericValue



287
288
289
# File 'lib/llvm/execution_engine.rb', line 287

def self.from_f(f)
  from_ptr(C.create_generic_value_of_float(LLVM::Float, f.to_f)) #: as !nil
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.) : (Numeric, ?Hash[untyped, untyped]) -> GenericValue



279
280
281
282
283
# File 'lib/llvm/execution_engine.rb', line 279

def self.from_i(i, options = {})
  type   = options.fetch(:type, LLVM::Int)
  signed = options.fetch(:signed, true)
  from_ptr(C.create_generic_value_of_int(type, i.to_i, signed ? 1 : 0)) #: as !nil
end

.from_ptr(ptr) ⇒ Object

Casts an FFI::Pointer pointing to a GenericValue to an instance. : (FFI::Pointer?) -> GenericValue?



262
263
264
265
266
267
# File 'lib/llvm/execution_engine.rb', line 262

def self.from_ptr(ptr)
  return if ptr.nil? || 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.



303
304
305
# File 'lib/llvm/execution_engine.rb', line 303

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

Instance Method Details

#disposeObject

: -> void



270
271
272
273
274
# File 'lib/llvm/execution_engine.rb', line 270

def dispose
  return if @ptr.nil?
  C.dispose_generic_value(@ptr)
  @ptr = nil
end

#to_bObject

Converts a GenericValue to a Ruby boolean. : -> bool



329
330
331
# File 'lib/llvm/execution_engine.rb', line 329

def to_b
  to_i(false) != 0
end

#to_dObject

Converts a GenericValue to a Ruby Float. : -> ::Float



323
324
325
# File 'lib/llvm/execution_engine.rb', line 323

def to_d
  C.generic_value_to_float(LLVM.double, self)
end

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

Converts a GenericValue to a Ruby Float. : (?LLVM::Type) -> ::Float



317
318
319
# File 'lib/llvm/execution_engine.rb', line 317

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. : (?bool) -> Integer



309
310
311
312
313
# File 'lib/llvm/execution_engine.rb', line 309

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_ptrObject



256
257
258
# File 'lib/llvm/execution_engine.rb', line 256

def to_ptr
  @ptr
end

#to_value_ptrObject



333
334
335
# File 'lib/llvm/execution_engine.rb', line 333

def to_value_ptr
  C.generic_value_to_pointer(self)
end