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.



79
80
81
# File 'lib/llvm/core/module.rb', line 79

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



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/llvm/core/module.rb', line 119

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



84
85
86
# File 'lib/llvm/core/module.rb', line 84

def add(ty, name)
  GlobalVariable.from_ptr(C.LLVMAddGlobal(@module, LLVM::Type(ty), name.to_s))
end

#delete(global) ⇒ Object

Deletes the GlobalVariable from the collection.



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

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

#eachObject

Iterates through each GlobalVariable in the collection.



134
135
136
137
138
139
140
# File 'lib/llvm/core/module.rb', line 134

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

#firstObject

Returns the first GlobalVariable in the collection.



94
95
96
# File 'lib/llvm/core/module.rb', line 94

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

#lastObject

Returns the last GlobalVariable in the collection.



99
100
101
# File 'lib/llvm/core/module.rb', line 99

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

#named(name) ⇒ Object

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



89
90
91
# File 'lib/llvm/core/module.rb', line 89

def named(name)
  GlobalValue.from_ptr(C.LLVMGetNamedGlobal(@module, name.to_s))
end

#next(global) ⇒ Object

Returns the next GlobalVariable in the collection after global.



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

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

#previous(global) ⇒ Object

Returns the previous GlobalVariable in the collection before global.



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

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