Class: LLVM::Value

Inherits:
Object
  • Object
show all
Includes:
PointerIdentity
Defined in:
lib/llvm/core/value.rb

Direct Known Subclasses

Argument, BasicBlock, Poison, User

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PointerIdentity

#==, #eql?, #hash, #to_ptr

Class Method Details

.from_ptr(ptr) ⇒ Object



8
9
10
11
12
13
# File 'lib/llvm/core/value.rb', line 8

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/llvm/core/value.rb', line 15

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)
  else
    raise "from_ptr_kind cannot handle: #{kind}"
  end
end

.to_ptrObject



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

def self.to_ptr
  type.to_ptr
end

.typeObject

Returns the Value type. This is abstract and is overidden by its subclasses.

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/llvm/core/value.rb', line 38

def self.type
  raise NotImplementedError, "#{name}.type() is abstract."
end

Instance Method Details

#add_attribute(attr) ⇒ Object

Adds attr to this value’s attributes.



129
130
131
132
133
134
135
136
137
# File 'lib/llvm/core/value.rb', line 129

def add_attribute(attr)
  fun = param_parent
  return unless fun

  index = param_index(fun)
  return unless index

  fun.add_attribute(attr, index)
end

#allocated_typeObject

allocated type of alloca also works on geps of allocas



67
68
69
70
71
72
73
74
# File 'lib/llvm/core/value.rb', line 67

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, nil)
end

#allocated_type?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
# File 'lib/llvm/core/value.rb', line 56

def allocated_type?
  case self
  when Instruction
    true
  else
    false
  end
end

#constant?Boolean

Returns whether the value is constant.

Returns:

  • (Boolean)


109
110
111
# File 'lib/llvm/core/value.rb', line 109

def constant?
  C.is_constant(self)
end

#dumpObject

Print the value’s IR to stdout.



98
99
100
101
102
# File 'lib/llvm/core/value.rb', line 98

def dump
  # :nocov:
  C.dump_value(self)
  # :nocov:
end

#gep_source_element_typeObject

element type of gep



81
82
83
84
85
# File 'lib/llvm/core/value.rb', line 81

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

Returns:

  • (Boolean)


76
77
78
# File 'lib/llvm/core/value.rb', line 76

def gep_source_element_type?
  is_a?(Instruction)
end

#global_parentObject

Get the parent module of a global variable, including functions



151
152
153
# File 'lib/llvm/core/value.rb', line 151

def global_parent
  LLVM::Module.from_ptr(C.get_global_parent(self))
end

#kindObject

Returns the value’s kind.



52
53
54
# File 'lib/llvm/core/value.rb', line 52

def kind
  C.get_value_kind(self)
end

#nameObject

Returns the value’s name.



88
89
90
# File 'lib/llvm/core/value.rb', line 88

def name
  C.get_value_name(self)
end

#name=(str) ⇒ Object

Sets the value’s name to str.



93
94
95
# File 'lib/llvm/core/value.rb', line 93

def name=(str)
  C.set_value_name(self, str)
end

#null?Boolean

Returns whether the value is null.

Returns:

  • (Boolean)


114
115
116
# File 'lib/llvm/core/value.rb', line 114

def null?
  C.is_null(self)
end

#poison?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/llvm/core/value.rb', line 124

def poison?
  C.is_poison(self)
end

#remove_attribute(attr) ⇒ Object

Removes the given attribute from the function.



140
141
142
143
144
145
146
147
148
# File 'lib/llvm/core/value.rb', line 140

def remove_attribute(attr)
  fun = param_parent
  return unless fun

  index = param_index(fun)
  return unless index

  fun.remove_attribute(attr, index)
end

#to_sObject



104
105
106
# File 'lib/llvm/core/value.rb', line 104

def to_s
  C.print_value_to_string(self)
end

#typeObject

Returns the value’s type.



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

def type
  Type.from_ptr(C.type_of(self), nil)
end

#undef?Boolean Also known as: undefined?

Returns whether the value is undefined.

Returns:

  • (Boolean)


119
120
121
# File 'lib/llvm/core/value.rb', line 119

def undef?
  C.is_undef(self)
end