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.



91
92
93
# File 'lib/llvm/core/module.rb', line 91

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



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/llvm/core/module.rb', line 133

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



96
97
98
99
100
# File 'lib/llvm/core/module.rb', line 96

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.



128
129
130
# File 'lib/llvm/core/module.rb', line 128

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

#eachObject

Iterates through each GlobalVariable in the collection.



148
149
150
151
152
153
154
# File 'lib/llvm/core/module.rb', line 148

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

#firstObject

Returns the first GlobalVariable in the collection.



108
109
110
# File 'lib/llvm/core/module.rb', line 108

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

#lastObject

Returns the last GlobalVariable in the collection.



113
114
115
# File 'lib/llvm/core/module.rb', line 113

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

#named(name) ⇒ Object

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



103
104
105
# File 'lib/llvm/core/module.rb', line 103

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.



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

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

#previous(global) ⇒ Object

Returns the previous GlobalVariable in the collection before global.



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

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