From 8b1b4e20a98fd621ebcc3a7a2783c3e25e63ff4a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 Jul 2002 18:35:16 +0000 Subject: [PATCH] * Make global variables with external linkage get emitted correctly * Do NOT add a prefix to global variables that are external * Add newline after emitting a constpointerref git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2925 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/SparcV9/SparcV9AsmPrinter.cpp | 27 ++++++++++++------------ 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index 940b72205fe..34d80b1e865 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -87,12 +87,10 @@ public: void endModule() { } - // Check if a name is external or accessible from external code. - // Only functions can currently be external. "main" is the only name - // that is visible externally. + // Check if a value is external or accessible from external code. bool isExternal(const Value* V) { - const Function *F = dyn_cast(V); - return F && (F->isExternal() || F->getName() == "main"); + const GlobalValue *GV = dyn_cast(V); + return GV && GV->hasExternalLinkage(); } // enterSection - Use this method to enter a different section of the output @@ -148,7 +146,7 @@ public: string getID(const Value *V, const char *Prefix, const char *FPrefix = 0) { string Result = FPrefix ? FPrefix : ""; // "Forced prefix" - Result = Result + (V->hasName()? V->getName() : string(Prefix)); + Result += V->hasName() ? V->getName() : string(Prefix); // Qualify all internal names with a unique id. if (!isExternal(V)) { @@ -174,11 +172,19 @@ public: return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str()); } string getID(const GlobalVariable *GV) { - return getID(GV, "LLVMGlobal_", ".G_"); + return getID(GV, "LLVMGlobal_"); } string getID(const Constant *CV) { return getID(CV, "LLVMConst_", ".C_"); } + string getID(const GlobalValue *GV) { + if (const GlobalVariable *V = dyn_cast(GV)) + return getID(V); + else if (const Function *F = dyn_cast(GV)) + return getID(F); + assert(0 && "Unexpected type of GlobalValue!"); + return ""; + } }; @@ -661,12 +667,7 @@ SparcModuleAsmPrinter::printSingleConstant(const Constant* CV) else if (const ConstantPointerRef* CPR = dyn_cast(CV)) { // This is a constant address for a global variable or method. // Use the name of the variable or method as the address value. - if (const GlobalVariable* GV = dyn_cast(CPR->getValue())) - toAsm << getID(GV); - else if (const Function* F = dyn_cast(CPR->getValue())) - toAsm << getID(F); - else - assert(0 && "Unexpected constant reference type"); + toAsm << getID(CPR->getValue()) << "\n"; } else if (const ConstantPointer* CPP = dyn_cast(CV)) {