class RLTK::CG::Constant

All classes representing constant values inherit from this class.

@abstract

Public Class Methods

new(overloaded) click to toggle source

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.

@param [FFI::Pointer, Type] overloaded Pointer to existing constant or a Type.

# 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

Public Instance Methods

addr_space_cast(type) click to toggle source

Cast a constant to a given address space

@param [Type] type Type to cast to

@return [ConstantExpr]

# 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) click to toggle source

Bitcast a constant to a given type.

@param [Type] type Type to cast to

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 310
def bitcast_to(type)
        ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type)))
end
gep(*indices)
Alias for: get_element_ptr
get_element_ptr(*indices) click to toggle source

Get a pointer to an element of a constant value.

@param [Array<Value>] indices A Ruby array of Value objects representing indicies into the constant value.

@return [ConstantExpr] LLVM Value object representing a pointer to a LLVM Value object.

# 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
Also aliased as: gep
get_element_ptr_in_bounds(*indices) click to toggle source

Get a pointer to an element of a constant value, ensuring that the pointer is within the bounds of the value.

@param [Array<Value>] indices A Ruby array of Value objects representing indicies into the constant value.

@return [ConstantExpr] LLVM Value object representing a pointer to a LLVM Value object.

# 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
Also aliased as: inbounds_gep
inbounds_gep(*indices)