Class: RLTK::CG::Constant Abstract
- Includes:
- 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
-
#bitcast_to(type) ⇒ ConstExpr
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 included from AbstractClass
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.
296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/rltk/cg/value.rb', line 296 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
#bitcast_to(type) ⇒ ConstExpr
Bitcast a constant to a given type.
314 315 316 |
# File 'lib/rltk/cg/value.rb', line 314 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.
323 324 325 326 327 328 |
# File 'lib/rltk/cg/value.rb', line 323 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.
337 338 339 340 341 342 |
# File 'lib/rltk/cg/value.rb', line 337 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 |