Function *ilist_traits<Function>::createSentinel() {
FunctionType *FTy =
- FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false,
- std::vector<FunctionType::ParameterAttributes>() );
+ FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
Function *Ret = new Function(FTy, GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
LeakDetector::removeGarbageObject(Ret);
return Ret;
}
+GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
+ GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, GlobalValue::ExternalLinkage);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
+}
iplist<Function> &ilist_traits<Function>::getList(Module *M) {
return M->getFunctionList();
iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) {
return M->getGlobalList();
}
+iplist<GlobalAlias> &ilist_traits<GlobalAlias>::getList(Module *M) {
+ return M->getAliasList();
+}
// Explicit instantiations of SymbolTableListTraits since some of the methods
// are not in the public header file.
-template class SymbolTableListTraits<GlobalVariable, Module, Module>;
-template class SymbolTableListTraits<Function, Module, Module>;
+template class SymbolTableListTraits<GlobalVariable, Module>;
+template class SymbolTableListTraits<Function, Module>;
+template class SymbolTableListTraits<GlobalAlias, Module>;
//===----------------------------------------------------------------------===//
// Primitive Module methods.
Module::Module(const std::string &MID)
: ModuleID(MID), DataLayout("") {
- FunctionList.setItemParent(this);
- FunctionList.setParent(this);
- GlobalList.setItemParent(this);
- GlobalList.setParent(this);
ValSymTab = new ValueSymbolTable();
TypeSymTab = new TypeSymbolTable();
}
Module::~Module() {
dropAllReferences();
GlobalList.clear();
- GlobalList.setParent(0);
FunctionList.clear();
- FunctionList.setParent(0);
+ AliasList.clear();
LibraryList.clear();
delete ValSymTab;
delete TypeSymTab;
ValueSymbolTable &SymTab = getValueSymbolTable();
// See if we have a definition for the specified function already.
- Function *F = dyn_cast_or_null<Function>(SymTab.lookup(Name));
+ GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
if (F == 0) {
// Nope, add it
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
// If the function exists but has the wrong type, return a bitcast to the
// right type.
- if (F->getFunctionType() != Ty)
+ if (F->getType() != PointerType::get(Ty))
return ConstantExpr::getBitCast(F, PointerType::get(Ty));
// Otherwise, we just found the existing function or a prototype.
return 0;
}
+//===----------------------------------------------------------------------===//
+// Methods for easy access to the global variables in the module.
+//
+
+// getNamedAlias - Look up the specified global in the module symbol table.
+// If it does not exist, return null.
+//
+GlobalAlias *Module::getNamedAlias(const std::string &Name) const {
+ const ValueSymbolTable &SymTab = getValueSymbolTable();
+ return dyn_cast_or_null<GlobalAlias>(SymTab.lookup(Name));
+}
+
//===----------------------------------------------------------------------===//
// Methods for easy access to the types in the module.
//
for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
I->dropAllReferences();
+
+ for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
+ I->dropAllReferences();
}
void Module::addLibrary(const std::string& Lib) {