Class: LLVM::Module::FunctionCollection

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

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ FunctionCollection

Returns a new instance of FunctionCollection.



155
156
157
# File 'lib/llvm/core/module.rb', line 155

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).



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/llvm/core/module.rb', line 207

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).



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/llvm/core/module.rb', line 160

def add(name, *args)
  if args.first.kind_of? FunctionType
    type = args.first
  else
    type = Type.function(*args)
  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.



202
203
204
# File 'lib/llvm/core/module.rb', line 202

def delete(function)
  C.delete_function(function)
end

#eachObject

Iterates through each Function in the collection.



222
223
224
225
226
227
228
# File 'lib/llvm/core/module.rb', line 222

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

#firstObject

Returns the first Function in the collection.



182
183
184
# File 'lib/llvm/core/module.rb', line 182

def first
  Function.from_ptr(C.get_first_function(@module))
end

#lastObject

Returns the last Function in the collection.



187
188
189
# File 'lib/llvm/core/module.rb', line 187

def last
  Function.from_ptr(C.get_last_function(@module))
end

#named(name) ⇒ Object

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



177
178
179
# File 'lib/llvm/core/module.rb', line 177

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.



192
193
194
# File 'lib/llvm/core/module.rb', line 192

def next(function)
  Function.from_ptr(C.get_next_function(function))
end

#previous(function) ⇒ Object

Returns the previous Function in the collection before function.



197
198
199
# File 'lib/llvm/core/module.rb', line 197

def previous(function)
  Function.from_ptr(C.get_previous_function(function))
end