Class: RCGTK::Value

Inherits:
Object
  • Object
show all
Includes:
BindingClass
Defined in:
lib/rcgtk/value.rb

Overview

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

Direct Known Subclasses

Argument, BasicBlock, User

Defined Under Namespace

Classes: AttrCollection

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Value

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

Parameters:

  • ptr (FFI::Pointer)

    Pointer to an LLVM value.



33
34
35
# File 'lib/rcgtk/value.rb', line 33

def initialize(ptr)
	@ptr = check_type(ptr, FFI::Pointer, 'ptr')
end

Instance Method Details

#==(other) ⇒ Boolean

Compare one Value to another.

Parameters:

  • other (Value)

    Another value object.

Returns:

  • (Boolean)


42
43
44
# File 'lib/rcgtk/value.rb', line 42

def ==(other)
	other.is_a?(Value) and @ptr == other.ptr
end

#attributesAttrCollection Also known as: attrs

Returns Proxy object for inspecing a value’s attributes.

Returns:

  • (AttrCollection)

    Proxy object for inspecing a value’s attributes.



47
48
49
# File 'lib/rcgtk/value.rb', line 47

def attributes
	@attributes ||= AttrCollection.new(@ptr)
end

#bitcast(type) ⇒ ConstantExpr

Bitcast a value to a given type.

Parameters:

  • type (Type)

    Type to cast to.

Returns:



57
58
59
# File 'lib/rcgtk/value.rb', line 57

def bitcast(type)
	ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type)))
end

#constant?Boolean

Returns If this value is a constant.

Returns:

  • (Boolean)

    If this value is a constant.



62
63
64
# File 'lib/rcgtk/value.rb', line 62

def constant?
	Bindings.is_constant(@ptr).to_bool
end

#dumpvoid

This method returns an undefined value.

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 Also:



73
74
75
# File 'lib/rcgtk/value.rb', line 73

def dump
	Bindings.dump_value(@ptr)
end

#hashFixnum

Returns Hashed value of the pointer representing this value.

Returns:

  • (Fixnum)

    Hashed value of the pointer representing this value.



78
79
80
# File 'lib/rcgtk/value.rb', line 78

def hash
	@ptr.address.hash
end

#nameString

Returns Name of this value in LLVM IR.

Returns:

  • (String)

    Name of this value in LLVM IR.



83
84
85
# File 'lib/rcgtk/value.rb', line 83

def name
	Bindings.get_value_name(@ptr)
end

#name=(str) ⇒ String

Set the name of this value in LLVM IR.

Parameters:

  • str (String)

    Name of the value in LLVM IR.

Returns:

  • (String)

    str



92
93
94
# File 'lib/rcgtk/value.rb', line 92

def name=(str)
	str.tap { Bindings.set_value_name(@ptr, check_type(str, String)) }
end

#null?Boolean

Returns If the value is null or not.

Returns:

  • (Boolean)

    If the value is null or not.



97
98
99
# File 'lib/rcgtk/value.rb', line 97

def null?
	Bindings.is_null(@ptr).to_bool
end

Returns LLVM IR representation of this value.

Returns:

  • (String)

    LLVM IR representation of this value



102
103
104
# File 'lib/rcgtk/value.rb', line 102

def print
	Bindings.print_value_to_string(@ptr)
end

#trunc(type) ⇒ ConstantExpr

Truncate a value to a given type.

Parameters:

  • type (Type)

    Type to truncate to.

Returns:



111
112
113
# File 'lib/rcgtk/value.rb', line 111

def trunc(type)
	ConstantExpr.new(Bindings.const_trunc(check_cg_type(type)))
end

#trunc_or_bitcast(type) ⇒ ConstantExpr

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

Parameters:

  • type (Type)

    Type to cast or truncate to.

Returns:



120
121
122
# File 'lib/rcgtk/value.rb', line 120

def trunc_or_bitcast(type)
	ConstantExpr.new(Bindings.const_trunc_or_bit_cast(check_cg_type(type)))
end

#typeType

Returns Type of this value.

Returns:

  • (Type)

    Type of this value.



125
126
127
# File 'lib/rcgtk/value.rb', line 125

def type
	@type ||= Type.from_ptr(Bindings.type_of(@ptr))
end

#undefined?Boolean

Returns If the value is undefined or not.

Returns:

  • (Boolean)

    If the value is undefined or not.



130
131
132
# File 'lib/rcgtk/value.rb', line 130

def undefined?
	Bindings.is_undef(@ptr).to_bool
end

#zextend(type) ⇒ ConstantExpr

Zero extend the value to the length of type.

Parameters:

  • type (Type)

    Type to extend the value to.

Returns:



139
140
141
# File 'lib/rcgtk/value.rb', line 139

def zextend(type)
	ConstantExpr.new(Bindings.const_z_ext(check_cg_type(type)))
end

#zextend_or_bitcast(type) ⇒ ConstantExpr

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

Parameters:

  • type (Type)

    Type to cast or extend to.

Returns:



148
149
150
# File 'lib/rcgtk/value.rb', line 148

def zextend_or_bitcast(type)
	ConstantExpr.new(Bindings.const_z_ext_or_bit_cast(check_cg_type(type)))
end