Class: 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) ⇒ ConstExpr
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(io = $stdout) ⇒ void
Print the LLVM IR representation of this value to a file.
-
#trunc(type) ⇒ ConstExpr
Truncate a value to a given type.
-
#trunc_or_bitcast(type) ⇒ ConstExpr
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) ⇒ ConstExpr
Zero extend the value to the length of type.
-
#zextend_or_bitcast(type) ⇒ ConstExpr
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.
30 31 32 |
# File 'lib/rltk/cg/value.rb', line 30 def initialize(ptr) @ptr = check_type(ptr, FFI::Pointer, 'ptr') end |
Instance Method Details
#==(other) ⇒ Boolean
Compare one Value to another.
39 40 41 |
# File 'lib/rltk/cg/value.rb', line 39 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.
44 45 46 |
# File 'lib/rltk/cg/value.rb', line 44 def attributes @attributes ||= AttrCollection.new(@ptr) end |
#bitcast(type) ⇒ ConstExpr
Bitcast a value to a given type.
54 55 56 |
# File 'lib/rltk/cg/value.rb', line 54 def bitcast(type) ConstExpr.new(Bindings.const_bit_cast(@ptr, check_cg_type(type))) end |
#constant? ⇒ Boolean
Returns If this value is a constant.
59 60 61 |
# File 'lib/rltk/cg/value.rb', line 59 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.
70 71 72 |
# File 'lib/rltk/cg/value.rb', line 70 def dump Bindings.dump_value(@ptr) end |
#hash ⇒ Fixnum
Returns Hashed value of the pointer representing this value.
75 76 77 |
# File 'lib/rltk/cg/value.rb', line 75 def hash @ptr.address.hash end |
#name ⇒ String
Returns Name of this value in LLVM IR.
80 81 82 |
# File 'lib/rltk/cg/value.rb', line 80 def name Bindings.get_value_name(@ptr) end |
#name=(str) ⇒ String
Set the name of this value in LLVM IR.
89 90 91 |
# File 'lib/rltk/cg/value.rb', line 89 def name=(str) returning(str) { Bindings.set_value_name(@ptr, check_type(str, String)) } end |
#null? ⇒ Boolean
Returns If the value is null or not.
94 95 96 |
# File 'lib/rltk/cg/value.rb', line 94 def null? Bindings.is_null(@ptr).to_bool end |
#print(io = $stdout) ⇒ void
This method returns an undefined value.
Print the LLVM IR representation of this value to a file. The file may be specified via a file name (which will be created or truncated) or an object that responds to #fileno.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rltk/cg/value.rb', line 107 def print(io = $stdout) case io when String File.open(io, 'w') do |f| Bindings.print_value(@ptr, f.fileno) end else Bindings.print_value(@ptr, io.fileno) end end |
#trunc(type) ⇒ ConstExpr
Truncate a value to a given type.
123 124 125 |
# File 'lib/rltk/cg/value.rb', line 123 def trunc(type) ConstExpr.new(Bindings.const_trunc(check_cg_type(type))) end |
#trunc_or_bitcast(type) ⇒ ConstExpr
Truncate or bitcast a value to the given type as is appropriate.
132 133 134 |
# File 'lib/rltk/cg/value.rb', line 132 def trunc_or_bitcast(type) ConstExpr.new(Bindings.const_trunc_or_bit_cast(check_cg_type(type))) end |
#type ⇒ Type
Returns Type of this value.
137 138 139 |
# File 'lib/rltk/cg/value.rb', line 137 def type @type ||= Type.from_ptr(Bindings.type_of(@ptr)) end |
#undefined? ⇒ Boolean
Returns If the value is undefined or not.
142 143 144 |
# File 'lib/rltk/cg/value.rb', line 142 def undefined? Bindings.is_undef(@ptr).to_bool end |
#zextend(type) ⇒ ConstExpr
Zero extend the value to the length of type.
151 152 153 |
# File 'lib/rltk/cg/value.rb', line 151 def zextend(type) ConstExpr.new(Bindings.const_z_ext(check_cg_type(type))) end |
#zextend_or_bitcast(type) ⇒ ConstExpr
Zero extend or bitcast the value to the given type as is appropriate.
160 161 162 |
# File 'lib/rltk/cg/value.rb', line 160 def zextend_or_bitcast(type) ConstExpr.new(Bindings.const_z_ext_or_bit_cast(check_cg_type(type))) end |