DwarfWriter reading basic type information from llvm-gcc4 code.
[oota-llvm.git] / lib / VMCore / Module.cpp
index 0c005494e15d8732e7a1765e02b7cdd5650e8160..b6761a616cd002c304fccb52f9d25b84be4540e2 100644 (file)
@@ -1,10 +1,10 @@
 //===-- Module.cpp - Implement the Module class ---------------------------===//
-// 
+//
 //                     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 implements the Module class for the VMCore library.
@@ -52,7 +52,7 @@ iplist<GlobalVariable> &ilist_traits<GlobalVariable>::getList(Module *M) {
 }
 
 // Explicit instantiations of SymbolTableListTraits since some of the methods
-// are not in the public header file...
+// are not in the public header file.
 template class SymbolTableListTraits<GlobalVariable, Module, Module>;
 template class SymbolTableListTraits<Function, Module, Module>;
 
@@ -174,7 +174,7 @@ Function *Module::getMainFunction() {
     if (Function *F = getFunction("main", FunctionType::get(Type::IntTy,
                                                             Params, false)))
       return F;
-    
+
     // void main(int argc, char **argv)...
     if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
                                                             Params, false)))
@@ -206,17 +206,17 @@ Function *Module::getNamedFunction(const std::string &Name) {
 //
 
 /// 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.
+/// symbol table.  If it does not exist, return null.  The type argument
+/// should be the underlying type of the global, i.e., it should not have
+/// the top-level PointerType, which represents the address of the global.
+/// If AllowInternal is set to true, this function will return types that
+/// have InternalLinkage. By default, these types are not returned.
 ///
-GlobalVariable *Module::getGlobalVariable(const std::string &Name, 
-                                          const Type *Ty) {
+GlobalVariable *Module::getGlobalVariable(const std::string &Name,
+                                          const Type *Ty, bool AllowInternal) {
   if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) {
     GlobalVariable *Result = cast<GlobalVariable>(V);
-    if (!Result->hasInternalLinkage())
+    if (AllowInternal || !Result->hasInternalLinkage())
       return Result;
   }
   return 0;
@@ -237,7 +237,7 @@ bool Module::addTypeName(const std::string &Name, const Type *Ty) {
   SymbolTable &ST = getSymbolTable();
 
   if (ST.lookupType(Name)) return true;  // Already in symtab...
-  
+
   // Not in symbol table?  Set the name with the Symtab as an argument so the
   // type knows what to update...
   ST.insert(Name, Ty);
@@ -286,7 +286,7 @@ void Module::dropAllReferences() {
   for(Module::iterator I = begin(), E = end(); I != E; ++I)
     I->dropAllReferences();
 
-  for(Module::giterator I = gbegin(), E = gend(); I != E; ++I)
+  for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
     I->dropAllReferences();
 }