diff options
author | Chris Lattner <sabre@nondot.org> | 2003-12-31 08:43:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-12-31 08:43:01 +0000 |
commit | 60837821e2bb179c6dd239ecb4d72df37560d3bb (patch) | |
tree | ed88a2d8b0e8f1cdb2d9d52ef7457006a2537a92 /lib | |
parent | 3f804530c737b74a7417c215ac32f76c4672e370 (diff) | |
download | external_llvm-60837821e2bb179c6dd239ecb4d72df37560d3bb.zip external_llvm-60837821e2bb179c6dd239ecb4d72df37560d3bb.tar.gz external_llvm-60837821e2bb179c6dd239ecb4d72df37560d3bb.tar.bz2 |
Add some comments, add new getGlobalVariable method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10671 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Module.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index 83e0a6e..f481a0d 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -23,6 +23,10 @@ #include <map> using namespace llvm; +//===----------------------------------------------------------------------===// +// Stuff to implement the globals and functions lists. +// + Function *ilist_traits<Function>::createNode() { FunctionType *FTy = FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false); @@ -62,6 +66,9 @@ namespace llvm { }; } +//===----------------------------------------------------------------------===// +// Primitive Module methods. +// Module::Module(const std::string &MID) : ModuleID(MID), Endian(AnyEndianness), PtrSize(AnyPointerSize) { @@ -87,6 +94,10 @@ void Module::dump() const { print(std::cerr); } +//===----------------------------------------------------------------------===// +// Methods for easy access to the functions in the module. +// + // getOrInsertFunction - Look up the specified function in the module symbol // table. If it does not exist, add a prototype for the function and return // it. This is nice because it allows most passes to get away with not handling @@ -128,7 +139,6 @@ Function *Module::getOrInsertFunction(const std::string &Name, } - // getFunction - Look up the specified function in the module symbol table. // If it does not exist, return null. // @@ -201,6 +211,33 @@ Function *Module::getNamedFunction(const std::string &Name) { return Found; // Non-external function not found... } +//===----------------------------------------------------------------------===// +// Methods for easy access to the global variables in the module. +// + +/// getGlobalVariable - Look up the specified global variable in the module +/// symbol table. If it does not exist, return null. Note that this only +/// returns a global variable if it does not have internal linkage. The type +/// argument should be the underlying type of the global, ie, it should not +/// have the top-level PointerType, which represents the address of the +/// global. +/// +GlobalVariable *Module::getGlobalVariable(const std::string &Name, + const Type *Ty) { + if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) { + GlobalVariable *Result = cast<GlobalVariable>(V); + if (!Result->hasInternalLinkage()) + return Result; + } + return 0; +} + + + +//===----------------------------------------------------------------------===// +// Methods for easy access to the types in the module. +// + // addTypeName - Insert an entry in the symbol table mapping Str to Type. If // there is already an entry for this name, true is returned and the symbol @@ -245,6 +282,11 @@ std::string Module::getTypeName(const Type *Ty) const { } +//===----------------------------------------------------------------------===// +// Other module related stuff. +// + + // dropAllReferences() - This function causes all the subelementss to "let go" // of all references that they are maintaining. This allows one to 'delete' a // whole module at a time, even though there may be circular references... first |