Class: LLVM::Module::GlobalCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/llvm/core/module.rb

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ GlobalCollection

Returns a new instance of GlobalCollection.



74
75
76
# File 'lib/llvm/core/module.rb', line 74

def initialize(mod)
  @module = mod
end

Instance Method Details

#[](key) ⇒ Object

Returns the GlobalVariable with a name equal to key (symbol or string) or at key (integer).



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/llvm/core/module.rb', line 114

def [](key)
  case key
  when String, Symbol then named(key)
  when Integer then
    i = 0
    g = first
    until i >= key || g.nil?
      g = self.next(g)
      i += 1
    end
    g
  end
end

#add(ty, name) ⇒ Object

Adds a GlobalVariable with the given type and name to the collection (symbol or string).



79
80
81
# File 'lib/llvm/core/module.rb', line 79

def add(ty, name)
  GlobalVariable.from_ptr(C.LLVMAddGlobal(@module, LLVM::Type(ty), name.to_s))
end

#delete(global) ⇒ Object

Deletes the GlobalVariable from the collection.



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

def delete(global)
  C.LLVMDeleteGlobal(global)
end

#eachObject

Iterates through each GlobalVariable in the collection.



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

def each
  g = first
  until g.nil?
    yield g
    g = self.next(g)
  end
end

#firstObject

Returns the first GlobalVariable in the collection.



89
90
91
# File 'lib/llvm/core/module.rb', line 89

def first
  GlobalValue.from_ptr(C.LLVMGetFirstGlobal(@module))
end

#lastObject

Returns the last GlobalVariable in the collection.



94
95
96
# File 'lib/llvm/core/module.rb', line 94

def last
  GlobalValue.from_ptr(C.LLVMGetLastGlobal(@module))
end

#named(name) ⇒ Object

Returns the GlobalVariable with the given name (symbol or string).



84
85
86
# File 'lib/llvm/core/module.rb', line 84

def named(name)
  GlobalValue.from_ptr(C.LLVMGetNamedGlobal(@module, name.to_s))
end

#next(global) ⇒ Object

Returns the next GlobalVariable in the collection after global.



99
100
101
# File 'lib/llvm/core/module.rb', line 99

def next(global)
  GlobalValue.from_ptr(C.LLVMGetNextGlobal(global))
end

#previous(global) ⇒ Object

Returns the previous GlobalVariable in the collection before global.



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

def previous(global)
  GlobalValue.from_ptr(C.LLVMGetPreviousGlobal(global))
end