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.
79 80 81 |
# File 'lib/llvm/core/module.rb', line 79 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).
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/llvm/core/module.rb', line 121 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).
84 85 86 87 88 |
# File 'lib/llvm/core/module.rb', line 84 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.
116 117 118 |
# File 'lib/llvm/core/module.rb', line 116 def delete(global) C.delete_global(global) end |
#each ⇒ Object
Iterates through each GlobalVariable in the collection.
136 137 138 139 140 141 142 |
# File 'lib/llvm/core/module.rb', line 136 def each g = first until g.nil? yield g g = self.next(g) end end |
#first ⇒ Object
Returns the first GlobalVariable in the collection.
96 97 98 |
# File 'lib/llvm/core/module.rb', line 96 def first GlobalValue.from_ptr(C.get_first_global(@module)) end |
#last ⇒ Object
Returns the last GlobalVariable in the collection.
101 102 103 |
# File 'lib/llvm/core/module.rb', line 101 def last GlobalValue.from_ptr(C.get_last_global(@module)) end |
#named(name) ⇒ Object
Returns the GlobalVariable with the given name (symbol or string).
91 92 93 |
# File 'lib/llvm/core/module.rb', line 91 def named(name) GlobalValue.from_ptr(C.get_named_global(@module, name.to_s)) end |
#next(global) ⇒ Object
Returns the next GlobalVariable in the collection after global.
106 107 108 |
# File 'lib/llvm/core/module.rb', line 106 def next(global) GlobalValue.from_ptr(C.get_next_global(global)) end |
#previous(global) ⇒ Object
Returns the previous GlobalVariable in the collection before global.
111 112 113 |
# File 'lib/llvm/core/module.rb', line 111 def previous(global) GlobalValue.from_ptr(C.get_previous_global(global)) end |