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.
81 82 83 |
# File 'lib/llvm/core/module.rb', line 81 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).
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/llvm/core/module.rb', line 123 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).
86 87 88 89 90 |
# File 'lib/llvm/core/module.rb', line 86 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.
118 119 120 |
# File 'lib/llvm/core/module.rb', line 118 def delete(global) C.delete_global(global) end |
#each ⇒ Object
Iterates through each GlobalVariable in the collection.
138 139 140 141 142 143 144 |
# File 'lib/llvm/core/module.rb', line 138 def each g = first until g.nil? yield g g = self.next(g) end end |
#first ⇒ Object
Returns the first GlobalVariable in the collection.
98 99 100 |
# File 'lib/llvm/core/module.rb', line 98 def first GlobalValue.from_ptr(C.get_first_global(@module)) end |
#last ⇒ Object
Returns the last GlobalVariable in the collection.
103 104 105 |
# File 'lib/llvm/core/module.rb', line 103 def last GlobalValue.from_ptr(C.get_last_global(@module)) end |
#named(name) ⇒ Object
Returns the GlobalVariable with the given name (symbol or string).
93 94 95 |
# File 'lib/llvm/core/module.rb', line 93 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.
108 109 110 |
# File 'lib/llvm/core/module.rb', line 108 def next(global) GlobalValue.from_ptr(C.get_next_global(global)) end |
#previous(global) ⇒ Object
Returns the previous GlobalVariable in the collection before global.
113 114 115 |
# File 'lib/llvm/core/module.rb', line 113 def previous(global) GlobalValue.from_ptr(C.get_previous_global(global)) end |