Class: RLTK::CG::Value
- Inherits:
-
Object
- Object
- RLTK::CG::Value
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/value.rb
Overview
This class represents LLVM IR “data”, including integer and float literals, functions, and constant arrays, structs, and vectors.
Direct Known Subclasses
Defined Under Namespace
Classes: AttrCollection
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare one Value to another.
-
#attributes ⇒ AttrCollection
(also: #attrs)
Proxy object for inspecing a value’s attributes.
-
#bitcast(type) ⇒ ConstantExpr
Bitcast a value to a given type.
-
#constant? ⇒ Boolean
If this value is a constant.
-
#dump ⇒ void
Print the LLVM IR representation of this value to standard error.
-
#hash ⇒ Fixnum
Hashed value of the pointer representing this value.
-
#initialize(ptr) ⇒ Value
constructor
Instantiate a Value object from a pointer.
-
#name ⇒ String
Name of this value in LLVM IR.
-
#name=(str) ⇒ String
Set the name of this value in LLVM IR.
-
#null? ⇒ Boolean
If the value is null or not.
-
#print ⇒ String
LLVM IR representation of this value.
-
#trunc(type) ⇒ ConstantExpr
Truncate a value to a given type.
-
#trunc_or_bitcast(type) ⇒ ConstantExpr
Truncate or bitcast a value to the given type as is appropriate.
-
#type ⇒ Type
Type of this value.
-
#undefined? ⇒ Boolean
If the value is undefined or not.
-
#zextend(type) ⇒ ConstantExpr
Zero extend the value to the length of type.
-
#zextend_or_bitcast(type) ⇒ ConstantExpr
Zero extend or bitcast the value to the given type as is appropriate.
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.
32 33 34 |
# File 'lib/rltk/cg/value.rb', line 32 def initialize(ptr) @ptr = check_type(ptr, FFI::Pointer, 'ptr') end |
Instance Method Details
#==(other) ⇒ Boolean
Compare one Value to another.
41 42 43 |
# File 'lib/rltk/cg/value.rb', line 41 def ==(other) other.is_a?(Value) and @ptr == other.ptr end |
#attributes ⇒ AttrCollection Also known as: attrs
Returns Proxy object for inspecing a value’s attributes.
46 47 48 |
# File 'lib/rltk/cg/value.rb', line 46 def attributes @attributes ||= AttrCollection.new(@ptr) end |
#bitcast(type) ⇒ ConstantExpr
Bitcast a value to a given type.
56 57 58 |
# File 'lib/rltk/cg/value.rb', line 56 def bitcast(type) ConstantExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type))) end |
#constant? ⇒ Boolean
Returns If this value is a constant.
61 62 63 |
# File 'lib/rltk/cg/value.rb', line 61 def constant? Bindings.is_constant(@ptr).to_bool end |
#dump ⇒ void
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.
72 73 74 |
# File 'lib/rltk/cg/value.rb', line 72 def dump Bindings.dump_value(@ptr) end |
#hash ⇒ Fixnum
Returns Hashed value of the pointer representing this value.
77 78 79 |
# File 'lib/rltk/cg/value.rb', line 77 def hash @ptr.address.hash end |
#name ⇒ String
Returns Name of this value in LLVM IR.
82 83 84 |
# File 'lib/rltk/cg/value.rb', line 82 def name Bindings.get_value_name(@ptr) end |
#name=(str) ⇒ String
Set the name of this value in LLVM IR.
91 92 93 |
# File 'lib/rltk/cg/value.rb', line 91 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.
96 97 98 |
# File 'lib/rltk/cg/value.rb', line 96 def null? Bindings.is_null(@ptr).to_bool end |
#print ⇒ String
Returns LLVM IR representation of this value.
101 102 103 |
# File 'lib/rltk/cg/value.rb', line 101 def print Bindings.print_value_to_string(@ptr) end |
#trunc(type) ⇒ ConstantExpr
Truncate a value to a given type.
110 111 112 |
# 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) ⇒ ConstantExpr
Truncate or bitcast a value to the given type as is appropriate.
119 120 121 |
# 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 ⇒ Type
Returns Type of this value.
124 125 126 |
# File 'lib/rltk/cg/value.rb', line 124 def type @type ||= Type.from_ptr(Bindings.type_of(@ptr)) end |
#undefined? ⇒ Boolean
Returns If the value is undefined or not.
129 130 131 |
# File 'lib/rltk/cg/value.rb', line 129 def undefined? Bindings.is_undef(@ptr).to_bool end |
#zextend(type) ⇒ ConstantExpr
Zero extend the value to the length of type.
138 139 140 |
# 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) ⇒ ConstantExpr
Zero extend or bitcast the value to the given type as is appropriate.
147 148 149 |
# 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 |