Class: LLVM::Value

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

Direct Known Subclasses

Argument, BasicBlock, 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

.to_ptrObject



20
21
22
# File 'lib/llvm/core/value.rb', line 20

def self.to_ptr
  type.to_ptr
end

.typeObject

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

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/llvm/core/value.rb', line 16

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

Instance Method Details

#add_attribute(attr) ⇒ Object

Adds attr to this value’s attributes.



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

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



29
30
31
# File 'lib/llvm/core/value.rb', line 29

def allocated_type
  Type.from_ptr(C.get_allocated_type(self), nil)
end

#constant?Boolean

Returns whether the value is constant.

Returns:

  • (Boolean)


54
55
56
57
58
59
# File 'lib/llvm/core/value.rb', line 54

def constant?
  case C.is_constant(self)
  when 0 then false
  when 1 then true
  end
end

#dumpObject

Print the value’s IR to stdout.



45
46
47
# File 'lib/llvm/core/value.rb', line 45

def dump
  C.dump_value(self)
end

#nameObject

Returns the value’s name.



34
35
36
# File 'lib/llvm/core/value.rb', line 34

def name
  C.get_value_name(self)
end

#name=(str) ⇒ Object

Sets the value’s name to str.



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

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

#null?Boolean

Returns whether the value is null.

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/llvm/core/value.rb', line 62

def null?
  case C.is_null(self)
  when 0 then false
  when 1 then true
  end
end

#remove_attribute(attr) ⇒ Object

Removes the given attribute from the function.



89
90
91
92
93
94
95
96
97
# File 'lib/llvm/core/value.rb', line 89

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



49
50
51
# File 'lib/llvm/core/value.rb', line 49

def to_s
  C.print_value_to_string(self)
end

#typeObject

Returns the value’s type.



25
26
27
# File 'lib/llvm/core/value.rb', line 25

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

#undefined?Boolean

Returns whether the value is undefined.

Returns:

  • (Boolean)


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

def undefined?
  case C.is_undef(self)
  when 0 then false
  when 1 then true
  end
end