class RLTK::CG::Value

This class represents LLVM IR “data”, including integer and float literals, functions, and constant arrays, structs, and vectors.

Public Class Methods

new(ptr) click to toggle source

Instantiate a Value object from a pointer. This should never be done by library users, and is only used internally.

@param [FFI::Pointer] ptr Pointer to an LLVM value.

# File lib/rltk/cg/value.rb, line 32
def initialize(ptr)
        @ptr = check_type(ptr, FFI::Pointer, 'ptr')
end

Public Instance Methods

==(other) click to toggle source

Compare one Value to another.

@param [Value] other Another value object.

@return [Boolean]

# File lib/rltk/cg/value.rb, line 41
def ==(other)
        other.is_a?(Value) and @ptr == other.ptr
end
attributes() click to toggle source

@return [AttrCollection] Proxy object for inspecing a value’s attributes.

# File lib/rltk/cg/value.rb, line 46
def attributes
        @attributes ||= AttrCollection.new(@ptr)
end
Also aliased as: attrs
attrs()
Alias for: attributes
bitcast(type) click to toggle source

Bitcast a value to a given type.

@param [Type] type Type to cast to.

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 56
def bitcast(type)
        ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type)))
end
constant?() click to toggle source

@return [Boolean] If this value is a constant.

# File lib/rltk/cg/value.rb, line 61
def constant?
        Bindings.is_constant(@ptr).to_bool
end
dump() click to toggle source

Print the LLVM IR representation of this value to standard error. This function is the debugging version of the more general purpose {#print} method.

@see print

@return [void]

# File lib/rltk/cg/value.rb, line 72
def dump
        Bindings.dump_value(@ptr)
end
hash() click to toggle source

@return [Fixnum] Hashed value of the pointer representing this value.

# File lib/rltk/cg/value.rb, line 77
def hash
        @ptr.address.hash
end
name() click to toggle source

@return [String] Name of this value in LLVM IR.

# File lib/rltk/cg/value.rb, line 82
def name
        Bindings.get_value_name(@ptr)
end
name=(str) click to toggle source

Set the name of this value in LLVM IR.

@param [String] str Name of the value in LLVM IR.

@return [String] str

# File lib/rltk/cg/value.rb, line 91
def name=(str)
        str.tap { Bindings.set_value_name(@ptr, check_type(str, String)) }
end
null?() click to toggle source

@return [Boolean] If the value is null or not.

# File lib/rltk/cg/value.rb, line 96
def null?
        Bindings.is_null(@ptr).to_bool
end
print() click to toggle source

@return [String] LLVM IR representation of this value

trunc(type) click to toggle source

Truncate a value to a given type.

@param [Type] type Type to truncate to.

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 110
def trunc(type)
        ConstantExpr.new(Bindings.const_trunc(check_cg_type(type)))
end
trunc_or_bitcast(type) click to toggle source

Truncate or bitcast a value to the given type as is appropriate.

@param [Type] type Type to cast or truncate to.

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 119
def trunc_or_bitcast(type)
        ConstantExpr.new(Bindings.const_trunc_or_bit_cast(check_cg_type(type)))
end
type() click to toggle source

@return [Type] Type of this value.

# File lib/rltk/cg/value.rb, line 124
def type
        @type ||= Type.from_ptr(Bindings.type_of(@ptr))
end
undefined?() click to toggle source

@return [Boolean] If the value is undefined or not.

# File lib/rltk/cg/value.rb, line 129
def undefined?
        Bindings.is_undef(@ptr).to_bool
end
zextend(type) click to toggle source

Zero extend the value to the length of type.

@param [Type] type Type to extend the value to.

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 138
def zextend(type)
        ConstantExpr.new(Bindings.const_z_ext(check_cg_type(type)))
end
zextend_or_bitcast(type) click to toggle source

Zero extend or bitcast the value to the given type as is appropriate.

@param [Type] type Type to cast or extend to.

@return [ConstantExpr]

# File lib/rltk/cg/value.rb, line 147
def zextend_or_bitcast(type)
        ConstantExpr.new(Bindings.const_z_ext_or_bit_cast(check_cg_type(type)))
end