Class: LLVM::Module::GlobalCollection

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

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ GlobalCollection

Returns a new instance of GlobalCollection.



105
106
107
# File 'lib/llvm/core/module.rb', line 105

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



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/llvm/core/module.rb', line 153

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



110
111
112
113
114
# File 'lib/llvm/core/module.rb', line 110

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. : (GlobalVariable) -> void



148
149
150
# File 'lib/llvm/core/module.rb', line 148

def delete(global)
  C.delete_global(global)
end

#eachObject

Iterates through each GlobalVariable in the collection.



168
169
170
171
172
173
174
# File 'lib/llvm/core/module.rb', line 168

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

#firstObject

Returns the first GlobalVariable in the collection. : -> GlobalVariable



124
125
126
# File 'lib/llvm/core/module.rb', line 124

def first
  GlobalVariable.from_ptr(C.get_first_global(@module))
end

#lastObject

Returns the last GlobalVariable in the collection. : -> GlobalVariable



130
131
132
# File 'lib/llvm/core/module.rb', line 130

def last
  GlobalVariable.from_ptr(C.get_last_global(@module))
end

#named(name) ⇒ Object

Returns the GlobalVariable with the given name (symbol or string). : (untyped) -> GlobalVariable



118
119
120
# File 'lib/llvm/core/module.rb', line 118

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. : (GlobalVariable) -> GlobalVariable



136
137
138
# File 'lib/llvm/core/module.rb', line 136

def next(global)
  GlobalVariable.from_ptr(C.get_next_global(global))
end

#previous(global) ⇒ Object

Returns the previous GlobalVariable in the collection before global. : (GlobalVariable) -> GlobalVariable



142
143
144
# File 'lib/llvm/core/module.rb', line 142

def previous(global)
  GlobalVariable.from_ptr(C.get_previous_global(global))
end