Class: LLVM::Module::GlobalCollection
- Inherits:
-
Object
- Object
- LLVM::Module::GlobalCollection
- Includes:
- Enumerable
- Defined in:
- lib/llvm/core/module.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the GlobalVariable with a name equal to key (symbol or string) or at key (integer).
-
#add(ty, name) ⇒ Object
Adds a GlobalVariable with the given type and name to the collection (symbol or string).
-
#delete(global) ⇒ Object
Deletes the GlobalVariable from the collection.
-
#each ⇒ Object
Iterates through each GlobalVariable in the collection.
-
#first ⇒ Object
Returns the first GlobalVariable in the collection.
-
#initialize(mod) ⇒ GlobalCollection
constructor
A new instance of GlobalCollection.
-
#last ⇒ Object
Returns the last GlobalVariable in the collection.
-
#named(name) ⇒ Object
Returns the GlobalVariable with the given name (symbol or string).
-
#next(global) ⇒ Object
Returns the next GlobalVariable in the collection after global.
-
#previous(global) ⇒ Object
Returns the previous GlobalVariable in the collection before global.
Constructor Details
#initialize(mod) ⇒ GlobalCollection
Returns a new instance of GlobalCollection.
95 96 97 |
# File 'lib/llvm/core/module.rb', line 95 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).
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/llvm/core/module.rb', line 137 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).
100 101 102 103 104 |
# File 'lib/llvm/core/module.rb', line 100 def add(ty, name) GlobalVariable.from_ptr(C.add_global(@module, LLVM::Type(ty), name.to_s)).tap do |gvar| yield gvar if block_given? end end |
#delete(global) ⇒ Object
Deletes the GlobalVariable from the collection.
132 133 134 |
# File 'lib/llvm/core/module.rb', line 132 def delete(global) C.delete_global(global) end |
#each ⇒ Object
Iterates through each GlobalVariable in the collection.
152 153 154 155 156 157 158 |
# File 'lib/llvm/core/module.rb', line 152 def each g = first until g.nil? yield g g = self.next(g) end end |
#first ⇒ Object
Returns the first GlobalVariable in the collection.
112 113 114 |
# File 'lib/llvm/core/module.rb', line 112 def first GlobalVariable.from_ptr(C.get_first_global(@module)) end |
#last ⇒ Object
Returns the last GlobalVariable in the collection.
117 118 119 |
# File 'lib/llvm/core/module.rb', line 117 def last GlobalVariable.from_ptr(C.get_last_global(@module)) end |
#named(name) ⇒ Object
Returns the GlobalVariable with the given name (symbol or string).
107 108 109 |
# File 'lib/llvm/core/module.rb', line 107 def named(name) GlobalVariable.from_ptr(C.get_named_global(@module, name.to_s)) end |
#next(global) ⇒ Object
Returns the next GlobalVariable in the collection after global.
122 123 124 |
# File 'lib/llvm/core/module.rb', line 122 def next(global) GlobalVariable.from_ptr(C.get_next_global(global)) end |
#previous(global) ⇒ Object
Returns the previous GlobalVariable in the collection before global.
127 128 129 |
# File 'lib/llvm/core/module.rb', line 127 def previous(global) GlobalVariable.from_ptr(C.get_previous_global(global)) end |