Class: RLTK::CG::Constant Abstract

Inherits:
User show all
Includes:
Filigree::AbstractClass
Defined in:
lib/rltk/cg/value.rb

Overview

This class is abstract.

All classes representing constant values inherit from this class.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from User

#operands

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.

Parameters:

  • overloaded (FFI::Pointer, Type)

    Pointer to existing constant or a Type.



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

Parameters:

  • type (Type)

    Type to cast to

Returns:



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.

Parameters:

  • type (Type)

    Type to cast to

Returns:



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.

Parameters:

  • indices (Array<Value>)

    A Ruby array of Value objects representing indicies into the constant value.

Returns:

  • (ConstantExpr)

    LLVM Value object representing a pointer to a LLVM Value object.



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.

Parameters:

  • indices (Array<Value>)

    A Ruby array of Value objects representing indicies into the constant value.

Returns:

  • (ConstantExpr)

    LLVM Value object representing a pointer to a LLVM Value object.



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