//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include <algorithm>
#include <cstdarg>
#include <cstdlib>
-#include <map>
using namespace llvm;
//===----------------------------------------------------------------------===//
Function *ilist_traits<Function>::createSentinel() {
FunctionType *FTy =
- FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false,
- std::vector<FunctionType::ParameterAttributes>() );
- Function *Ret = new Function(FTy, GlobalValue::ExternalLinkage);
+ FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
+ Function *Ret = Function::Create(FTy, GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return 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;
GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
if (F == 0) {
// Nope, add it
- Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
+ Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
FunctionList.push_back(New);
return New; // Return the new prototype.
}
// If the function exists but has the wrong type, return a bitcast to the
// right type.
- if (F->getType() != PointerType::get(Ty))
- return ConstantExpr::getBitCast(F, PointerType::get(Ty));
+ if (F->getType() != PointerType::getUnqual(Ty))
+ return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
// Otherwise, we just found the existing function or a prototype.
return F;
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) {