Class: LLVM::Value

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

Direct Known Subclasses

Argument, BasicBlock, User

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Value

Returns a new instance of Value.



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

def initialize(ptr)
  @ptr = ptr
end

Class Method Details

.from_ptr(ptr) ⇒ Object



4
5
6
# File 'lib/llvm/core/value.rb', line 4

def self.from_ptr(ptr)
  new(ptr) unless ptr.null?
end

.to_ptrObject



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

def self.to_ptr
  type.to_ptr
end

.typeObject

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

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/llvm/core/value.rb', line 36

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

Instance Method Details

#==(other) ⇒ Object

Checks if the value is equal to other.



21
22
23
24
25
26
27
28
# File 'lib/llvm/core/value.rb', line 21

def ==(other)
  case other
  when LLVM::Value
    @ptr == other.to_ptr
  else
    false
  end
end

#add_attribute(attr) ⇒ Object

Adds attr to this value’s attributes.



90
91
92
# File 'lib/llvm/core/value.rb', line 90

def add_attribute(attr)
  C.LLVMAddAttribute(self, attr)
end

#constant?Boolean

Returns whether the value is constant.

Returns:

  • (Boolean)


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

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

#dumpObject

Print the value’s IR to stdout.



61
62
63
# File 'lib/llvm/core/value.rb', line 61

def dump
  C.LLVMDumpValue(self)
end

#eql?(other) ⇒ Boolean

Checks if the value is equal to other.

Returns:

  • (Boolean)


31
32
33
# File 'lib/llvm/core/value.rb', line 31

def eql?(other)
  other.instance_of?(self.class) && self == other
end

#nameObject

Returns the value’s name.



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

def name
  C.LLVMGetValueName(self)
end

#name=(str) ⇒ Object

Sets the value’s name to str.



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

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

#null?Boolean

Returns whether the value is null.

Returns:

  • (Boolean)


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

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

#to_ptrObject



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

def to_ptr
  @ptr
end

#typeObject

Returns the value’s type.



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

def type
  Type.from_ptr(C.LLVMTypeOf(self))
end

#undefined?Boolean

Returns whether the value is undefined.

Returns:

  • (Boolean)


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

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