[llvm-commits] CVS: llvm/lib/VMCore/Module.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Dec 31 02:44:00 PST 2003
Changes in directory llvm/lib/VMCore:
Module.cpp updated: 1.46 -> 1.47
---
Log message:
Add some comments, add new getGlobalVariable method
---
Diffs of the changes: (+43 -1)
Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.46 llvm/lib/VMCore/Module.cpp:1.47
--- llvm/lib/VMCore/Module.cpp:1.46 Wed Dec 31 01:09:33 2003
+++ llvm/lib/VMCore/Module.cpp Wed Dec 31 02:43:01 2003
@@ -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 @@
};
}
+//===----------------------------------------------------------------------===//
+// Primitive Module methods.
+//
Module::Module(const std::string &MID)
: ModuleID(MID), Endian(AnyEndianness), PtrSize(AnyPointerSize) {
@@ -87,6 +94,10 @@
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 @@
}
-
// getFunction - Look up the specified function in the module symbol table.
// If it does not exist, return null.
//
@@ -201,6 +211,33 @@
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
@@ -243,6 +280,11 @@
return TI->first;
return ""; // Must not have found anything...
}
+
+
+//===----------------------------------------------------------------------===//
+// Other module related stuff.
+//
// dropAllReferences() - This function causes all the subelementss to "let go"
More information about the llvm-commits
mailing list