Class: RLTK::CG::Constant Abstract
- Includes:
- Filigree::AbstractClass
- Defined in:
- lib/rltk/cg/value.rb
Overview
All classes representing constant values inherit from this class.
Direct Known Subclasses
ConstantAggregate, ConstantExpr, ConstantNull, ConstantNullPtr, ConstantNumber, ConstantUndef, ConstantVector, GlobalValue
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#addr_space_cast(type) ⇒ ConstantExpr
Cast a constant to a given address space.
-
#bitcast_to(type) ⇒ ConstantExpr
Bitcast a constant to a given type.
-
#get_element_ptr(*indices) ⇒ ConstantExpr
(also: #gep)
Get a pointer to an element of a constant value.
-
#get_element_ptr_in_bounds(*indices) ⇒ ConstantExpr
(also: #inbounds_gep)
Get a pointer to an element of a constant value, ensuring that the pointer is within the bounds of the value.
-
#initialize(overloaded) ⇒ Constant
constructor
Create a new constant from a pointer or a type.
Methods inherited from User
Methods inherited from Value
#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast
Methods included from BindingClass
Constructor Details
#initialize(overloaded) ⇒ Constant
Create a new constant from a pointer or a type. As a library user you should never pass a pointer in here as that is only used internally.
283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/rltk/cg/value.rb', line 283 def initialize(overloaded) @ptr = case overloaded when FFI::Pointer overloaded when Type Bindings.send(@@initializer, @type = overloaded) else raise 'New must be passed either a Type or a FFI::Pointer.' end end |
Instance Method Details
#addr_space_cast(type) ⇒ ConstantExpr
Cast a constant to a given address space
301 302 303 |
# File 'lib/rltk/cg/value.rb', line 301 def addr_space_cast(type) ConstantExpr.new(Bindings.const_addr_space_cast(@ptr, check_cg_type(type))) end |
#bitcast_to(type) ⇒ ConstantExpr
Bitcast a constant to a given type.
310 311 312 |
# File 'lib/rltk/cg/value.rb', line 310 def bitcast_to(type) ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type))) end |
#get_element_ptr(*indices) ⇒ ConstantExpr Also known as: gep
Get a pointer to an element of a constant value.
319 320 321 322 323 324 |
# File 'lib/rltk/cg/value.rb', line 319 def get_element_ptr(*indices) indicies_ptr = FFI::MemoryPointer.new(:pointer, indices.length) indices_ptr.write_array_of_pointer(indices) ConstantExpr.new(Bindings.const_gep(@ptr, indices_ptr, indices.length)) end |
#get_element_ptr_in_bounds(*indices) ⇒ ConstantExpr Also known as: inbounds_gep
Get a pointer to an element of a constant value, ensuring that the pointer is within the bounds of the value.
333 334 335 336 337 338 |
# File 'lib/rltk/cg/value.rb', line 333 def get_element_ptr_in_bounds(*indices) indices_ptr = FFI::MemoryPointer.new(:pointer, indices.length) indices_ptr.write_array_of_pointer(indices) ConstantExpr.new(Bindings.const_in_bounds_gep(@ptr, indices_ptr, indices.length)) end |