Class: LLVM::Value
- Inherits:
-
Object
- Object
- LLVM::Value
- Includes:
- PointerIdentity
- Defined in:
- lib/llvm/core/value.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes included from PointerIdentity
Class Method Summary collapse
- .from_ptr(ptr) ⇒ Object
-
.from_ptr_kind(ptr) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- .to_ptr ⇒ Object
-
.type ⇒ Object
Returns the Value type.
Instance Method Summary collapse
-
#add_attribute(attr) ⇒ Object
Adds attr to this value’s attributes.
-
#allocated_type ⇒ Object
allocated type of alloca also works on geps of allocas.
-
#allocated_type? ⇒ Boolean
: -> bool.
-
#constant? ⇒ Boolean
Returns whether the value is constant.
-
#dump ⇒ Object
Print the value’s IR to stdout.
-
#gep_source_element_type ⇒ Object
element type of gep.
-
#gep_source_element_type? ⇒ Boolean
: -> bool.
-
#global_parent ⇒ Object
Get the parent module of a global variable, including functions.
-
#kind ⇒ Object
Returns the value’s kind.
-
#name ⇒ Object
Returns the value’s name.
-
#name=(str) ⇒ Object
Sets the value’s name to str.
-
#null? ⇒ Boolean
Returns whether the value is null.
-
#poison? ⇒ Boolean
: -> bool.
-
#remove_attribute(attr) ⇒ Object
Removes the given attribute from the function.
- #to_s ⇒ Object
-
#type ⇒ Object
Returns the value’s type.
-
#undef? ⇒ Boolean
(also: #undefined?)
Returns whether the value is undefined.
Methods included from PointerIdentity
Class Method Details
.from_ptr(ptr) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/llvm/core/value.rb', line 9 def self.from_ptr(ptr) return if ptr.null? val = allocate val.instance_variable_set(:@ptr, ptr) val end |
.from_ptr_kind(ptr) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/llvm/core/value.rb', line 16 def self.from_ptr_kind(ptr) # rubocop:disable Metrics/CyclomaticComplexity return if ptr.null? kind = C.get_value_kind(ptr) case kind when :instruction Instruction.from_ptr(ptr) when :const_int ConstantInt.from_ptr(ptr) when :const_fp ConstantReal.from_ptr(ptr) when :poison Poison.from_ptr(ptr) when :global_variable GlobalVariable.from_ptr(ptr) when :const_expr ConstantExpr.from_ptr(ptr) when :const_null ConstantNull.from_ptr(ptr) when :const_struct, :const_aggregregate_zero ConstantStruct.from_ptr(ptr) else raise "from_ptr_kind cannot handle: #{kind}" end end |
.to_ptr ⇒ Object
47 48 49 |
# File 'lib/llvm/core/value.rb', line 47 def self.to_ptr type.to_ptr end |
.type ⇒ Object
Returns the Value type. This is abstract and is overidden by its subclasses.
43 44 45 |
# File 'lib/llvm/core/value.rb', line 43 def self.type raise NotImplementedError, "#{name}.type() is abstract." end |
Instance Method Details
#add_attribute(attr) ⇒ Object
Adds attr to this value’s attributes.
141 142 143 144 145 146 147 148 149 |
# File 'lib/llvm/core/value.rb', line 141 def add_attribute(attr) fun = param_parent return unless fun index = param_index(fun) return unless index fun.add_attribute(attr, index) end |
#allocated_type ⇒ Object
allocated type of alloca also works on geps of allocas
74 75 76 77 78 79 80 81 |
# File 'lib/llvm/core/value.rb', line 74 def allocated_type return if !allocated_type? alloc_type = C.get_allocated_type(self) return nil if alloc_type.nil? Type.from_ptr(alloc_type) end |
#allocated_type? ⇒ Boolean
: -> bool
63 64 65 66 67 68 69 70 |
# File 'lib/llvm/core/value.rb', line 63 def allocated_type? case self when Instruction true else false end end |
#constant? ⇒ Boolean
Returns whether the value is constant. : -> bool
118 119 120 |
# File 'lib/llvm/core/value.rb', line 118 def constant? C.is_constant(self) end |
#dump ⇒ Object
Print the value’s IR to stdout.
106 107 108 109 110 |
# File 'lib/llvm/core/value.rb', line 106 def dump # :nocov: C.dump_value(self) # :nocov: end |
#gep_source_element_type ⇒ Object
element type of gep
89 90 91 92 93 |
# File 'lib/llvm/core/value.rb', line 89 def gep_source_element_type return if !gep_source_element_type? Type.from_ptr(C.get_gep_source_element_type(self)) end |
#gep_source_element_type? ⇒ Boolean
: -> bool
84 85 86 |
# File 'lib/llvm/core/value.rb', line 84 def gep_source_element_type? is_a?(Instruction) end |
#global_parent ⇒ Object
Get the parent module of a global variable, including functions
163 164 165 |
# File 'lib/llvm/core/value.rb', line 163 def global_parent LLVM::Module.from_ptr(C.get_global_parent(self)) end |
#kind ⇒ Object
Returns the value’s kind.
58 59 60 |
# File 'lib/llvm/core/value.rb', line 58 def kind C.get_value_kind(self) end |
#name ⇒ Object
Returns the value’s name.
96 97 98 |
# File 'lib/llvm/core/value.rb', line 96 def name C.get_value_name(self) end |
#name=(str) ⇒ Object
Sets the value’s name to str.
101 102 103 |
# File 'lib/llvm/core/value.rb', line 101 def name=(str) C.set_value_name(self, str) end |
#null? ⇒ Boolean
Returns whether the value is null. : -> bool
124 125 126 |
# File 'lib/llvm/core/value.rb', line 124 def null? C.is_null(self) end |
#poison? ⇒ Boolean
: -> bool
136 137 138 |
# File 'lib/llvm/core/value.rb', line 136 def poison? C.is_poison(self) end |
#remove_attribute(attr) ⇒ Object
Removes the given attribute from the function.
152 153 154 155 156 157 158 159 160 |
# File 'lib/llvm/core/value.rb', line 152 def remove_attribute(attr) fun = param_parent return unless fun index = param_index(fun) return unless index fun.remove_attribute(attr, index) end |
#to_s ⇒ Object
112 113 114 |
# File 'lib/llvm/core/value.rb', line 112 def to_s C.print_value_to_string(self) end |