Update the .cvs files.
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.cpp
index ef8cbea590dcaf1a86915c4c6b49c68d8de2e39b..9f3f76956dd41e357a716ca3a075d5bcfa5a7af2 100644 (file)
@@ -102,13 +102,13 @@ void X86SharedAsmPrinter::decorateName(std::string &Name,
   case StdCall:
     // "Pure" variadic functions do not receive @0 suffix.
     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
-        (FT->getNumParams() == 1 && F->isStructReturn()))
+        (FT->getNumParams() == 1 && F->hasStructRetAttr()))
       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
     break;
   case FastCall:
     // "Pure" variadic functions do not receive @0 suffix.
     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
-        (FT->getNumParams() == 1 && F->isStructReturn()))
+        (FT->getNumParams() == 1 && F->hasStructRetAttr()))
       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
 
     if (Name[0] == '_') {
@@ -138,6 +138,15 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
   return Result;
 }
 
+/// PrintUnmangledNameSafely - Print out the printable characters in the name.
+/// Don't print things like \n or \0.
+static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
+  for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
+       Name != E; ++Name)
+    if (isprint(*Name))
+      OS << *Name;
+}
+
 bool X86SharedAsmPrinter::doFinalization(Module &M) {
   // Note: this code is not shared by the Intel printer as it is too different
   // from how MASM does things.  When making changes here don't forget to look
@@ -183,7 +192,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       if (I->hasExternalLinkage()) {
         if (const char *Directive = TAI->getZeroFillDirective()) {
           O << "\t.globl " << name << "\n";
-          O << Directive << "__DATA__, __common, " << name << ", "
+          O << Directive << "__DATA, __common, " << name << ", "
             << Size << ", " << Align << "\n";
           continue;
         }
@@ -191,7 +200,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       
       if (!I->isThreadLocal() &&
           (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-           I->hasLinkOnceLinkage())) {
+           I->hasLinkOnceLinkage() || I->hasCommonLinkage())) {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (!NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(TAI->getBSSSection(), I);
@@ -202,6 +211,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
             O << TAI->getLCOMMDirective() << name << "," << Size;
             if (Subtarget->isTargetDarwin())
               O << "," << Align;
+          } else if (Subtarget->isTargetDarwin() && !I->hasCommonLinkage()) {
+            O << "\t.globl " << name << "\n"
+              << TAI->getWeakDefDirective() << name << "\n";
+            SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
+            EmitAlignment(Align, I);
+            O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
+            PrintUnmangledNameSafely(I, O);
+            O << "\n";
+            EmitGlobalConstant(C);
+            continue;
           } else {
             O << TAI->getCOMMDirective()  << name << "," << Size;
             
@@ -218,18 +237,29 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
           if (TAI->getCOMMDirectiveTakesAlignment())
             O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
         }
-        O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
+        O << "\t\t" << TAI->getCommentString() << " ";
+        PrintUnmangledNameSafely(I, O);
+        O << "\n";
         continue;
       }
     }
 
     switch (I->getLinkage()) {
+    case GlobalValue::CommonLinkage:
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
       if (Subtarget->isTargetDarwin()) {
         O << "\t.globl " << name << "\n"
           << TAI->getWeakDefDirective() << name << "\n";
-        SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
+        if (!I->isConstant())
+          SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
+        else {
+          const ArrayType *AT = dyn_cast<ArrayType>(Type);
+          if (AT && AT->getElementType()==Type::Int8Ty)
+            SwitchToDataSection("\t.section __TEXT,__const_coal,coalesced", I);
+          else
+            SwitchToDataSection("\t.section __DATA,__const_coal,coalesced", I);
+        }
       } else if (Subtarget->isTargetCygMing()) {
         std::string SectionName(".section\t.data$linkonce." +
                                 name +
@@ -275,7 +305,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
           assert(!Subtarget->isTargetDarwin());
           SectionName += ",\"aw\",@progbits";
         }
-
+        SwitchToDataSection(SectionName.c_str());
+      } else if (I->hasSection() && Subtarget->isTargetDarwin()) {
+        // Honor all section names on Darwin; ObjC uses this
+        std::string SectionName = ".section " + I->getSection();
         SwitchToDataSection(SectionName.c_str());
       } else {
         if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
@@ -316,8 +349,9 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     }
 
     EmitAlignment(Align, I);
-    O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
-      << "\n";
+    O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
+    PrintUnmangledNameSafely(I, O);
+    O << "\n";
     if (TAI->hasDotTypeDotSizeDirective())
       O << "\t.size\t" << name << ", " << Size << "\n";
     // If the initializer is a extern weak symbol, remember to emit the weak
@@ -359,16 +393,18 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
          i != e; ++i, ++j) {
       SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
                           "self_modifying_code+pure_instructions,5", 0);
-      O << "L" << *i << "$stub:\n";
-      O << "\t.indirect_symbol " << *i << "\n";
+      std::string p = *i;
+      printSuffixedName(p, "$stub");
+      O << ":\n";
+      O << "\t.indirect_symbol " << p << "\n";
       O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
     }
 
     O << "\n";
 
-    if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI &&
-        !Subtarget->is64Bit()) {
+    if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
       // Add the (possibly multiple) personalities to the set of global values.
+      // Only referenced functions get into the Personalities list.
       const std::vector<Function *>& Personalities = MMI->getPersonalities();
 
       for (std::vector<Function *>::const_iterator I = Personalities.begin(),
@@ -382,8 +418,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
                     "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
     for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
          i != e; ++i) {
-      O << "L" << *i << "$non_lazy_ptr:\n";
-      O << "\t.indirect_symbol " << *i << "\n";
+      std::string p = *i;
+      printSuffixedName(p, "$non_lazy_ptr");
+      O << ":\n";
+      O << "\t.indirect_symbol " << p << "\n";
       O << "\t.long\t0\n";
     }