Class: LLVM::Module::FunctionCollection
- Inherits:
-
Object
- Object
- LLVM::Module::FunctionCollection
- Includes:
- Enumerable
- Defined in:
- lib/llvm/core/module.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the Function with a name equal to key (symbol or string) or at key (integer).
-
#add(name, *args) ⇒ Object
Adds a Function with the given name (symbol or string) and args (Types).
-
#delete(function) ⇒ Object
Deletes the Function from the collection.
-
#each ⇒ Object
Iterates through each Function in the collection.
-
#first ⇒ Object
Returns the first Function in the collection.
-
#initialize(mod) ⇒ FunctionCollection
constructor
A new instance of FunctionCollection.
-
#last ⇒ Object
Returns the last Function in the collection.
-
#named(name) ⇒ Object
Returns the Function with the given name (symbol or string).
-
#next(function) ⇒ Object
Returns the next Function in the collection after function.
-
#previous(function) ⇒ Object
Returns the previous Function in the collection before function.
Constructor Details
#initialize(mod) ⇒ FunctionCollection
Returns a new instance of FunctionCollection.
186 187 188 |
# File 'lib/llvm/core/module.rb', line 186 def initialize(mod) @module = mod end |
Instance Method Details
#[](key) ⇒ Object
Returns the Function with a name equal to key (symbol or string) or at key (integer).
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/llvm/core/module.rb', line 240 def [](key) case key when String, Symbol then named(key) when Integer i = 0 f = first until i >= key || f.nil? f = self.next(f) i += 1 end f end end |
#add(name, *args) ⇒ Object
Adds a Function with the given name (symbol or string) and args (Types).
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/llvm/core/module.rb', line 191 def add(name, *args) if args.first.kind_of? FunctionType type = args.first else type = Type.function( *args #: as untyped ) end function = Function.from_ptr(C.add_function(@module, name.to_s, type)) if block_given? params = (0...function.params.size).map { |i| function.params[i] } yield function, *params end function end |
#delete(function) ⇒ Object
Deletes the Function from the collection.
235 236 237 |
# File 'lib/llvm/core/module.rb', line 235 def delete(function) C.delete_function(function) end |
#each ⇒ Object
Iterates through each Function in the collection.
255 256 257 258 259 260 261 |
# File 'lib/llvm/core/module.rb', line 255 def each(&) f = first until f.nil? yield f f = self.next(f) end end |
#first ⇒ Object
Returns the first Function in the collection.
215 216 217 |
# File 'lib/llvm/core/module.rb', line 215 def first Function.from_ptr(C.get_first_function(@module)) end |
#last ⇒ Object
Returns the last Function in the collection.
220 221 222 |
# File 'lib/llvm/core/module.rb', line 220 def last Function.from_ptr(C.get_last_function(@module)) end |
#named(name) ⇒ Object
Returns the Function with the given name (symbol or string).
210 211 212 |
# File 'lib/llvm/core/module.rb', line 210 def named(name) Function.from_ptr(C.get_named_function(@module, name.to_s)) end |
#next(function) ⇒ Object
Returns the next Function in the collection after function.
225 226 227 |
# File 'lib/llvm/core/module.rb', line 225 def next(function) Function.from_ptr(C.get_next_function(function)) end |
#previous(function) ⇒ Object
Returns the previous Function in the collection before function.
230 231 232 |
# File 'lib/llvm/core/module.rb', line 230 def previous(function) Function.from_ptr(C.get_previous_function(function)) end |