move mangler quote handling from asm printers to TargetAsmInfo.
[oota-llvm.git] / lib / Target / X86 / AsmPrinter / X86IntelAsmPrinter.cpp
index 1822c1f914a42eed9c820761a7251187532d5998..659934930d46c2f3d4b049a206770462f24f0113 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Assembly/Writer.h"
+#include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetOptions.h"
@@ -54,11 +55,11 @@ static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
     const Type* Ty = AI->getType();
 
     // 'Dereference' type in case of byval parameter attribute
-    if (F->paramHasAttr(argNum, ParamAttr::ByVal))
+    if (F->paramHasAttr(argNum, Attribute::ByVal))
       Ty = cast<PointerType>(Ty)->getElementType();
 
     // Size should be aligned to DWORD boundary
-    Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
+    Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4;
   }
 
   // We're not supporting tooooo huge arguments :)
@@ -117,16 +118,11 @@ void X86IntelAsmPrinter::decorateName(std::string &Name,
   }
 }
 
-
-std::string X86IntelAsmPrinter::getSectionForFunction(const Function &F) const {
-  // Intel asm always emits functions to _text.
-  return "_text";
-}
-
 /// runOnMachineFunction - This uses the printMachineInstruction()
 /// method to print assembly for each instruction.
 ///
 bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
+  this->MF = &MF;
   SetupMachineFunction(MF);
   O << "\n\n";
 
@@ -144,11 +140,14 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   decorateName(CurrentFnName, F);
 
-  SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
+  SwitchToTextSection("_text", F);
 
-  unsigned FnAlign = OptimizeForSize ? 1 : 4;
+  unsigned FnAlign = 4;
+  if (F->hasFnAttr(Attribute::OptimizeForSize))
+    FnAlign = 1;
   switch (F->getLinkage()) {
   default: assert(0 && "Unsupported linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:
     EmitAlignment(FnAlign);
     break;
@@ -183,6 +182,8 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   O << CurrentFnName << "\tendp\n";
 
+  O.flush();
+
   // We didn't modify anything.
   return false;
 }
@@ -237,11 +238,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
     if (!isMemOp) O << "OFFSET ";
     O << "[" << TAI->getPrivateGlobalPrefix() << "CPI"
       << getFunctionNumber() << "_" << MO.getIndex();
-    int Offset = MO.getOffset();
-    if (Offset > 0)
-      O << " + " << Offset;
-    else if (Offset < 0)
-      O << Offset;
+    printOffset(MO.getOffset());
     O << "]";
     return;
   }
@@ -260,11 +257,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
       O << "__imp_";
     }
     O << Name;
-    int Offset = MO.getOffset();
-    if (Offset > 0)
-      O << " + " << Offset;
-    else if (Offset < 0)
-      O << Offset;
+    printOffset(MO.getOffset());
     return;
   }
   case MachineOperand::MO_ExternalSymbol: {
@@ -278,10 +271,9 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
   }
 }
 
-void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
-                                           const char *Modifier) {
-  assert(isMem(MI, Op) && "Invalid memory reference!");
-
+void X86IntelAsmPrinter::printLeaMemReference(const MachineInstr *MI,
+                                              unsigned Op,
+                                              const char *Modifier) {
   const MachineOperand &BaseReg  = MI->getOperand(Op);
   int ScaleVal                   = MI->getOperand(Op+1).getImm();
   const MachineOperand &IndexReg = MI->getOperand(Op+2);
@@ -302,8 +294,8 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
     NeedPlus = true;
   }
 
-  if (DispSpec.isGlobalAddress() || DispSpec.isConstantPoolIndex() ||
-      DispSpec.isJumpTableIndex()) {
+  if (DispSpec.isGlobal() || DispSpec.isCPI() ||
+      DispSpec.isJTI()) {
     if (NeedPlus)
       O << " + ";
     printOp(DispSpec, "mem");
@@ -324,6 +316,17 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
   O << "]";
 }
 
+void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
+                                           const char *Modifier) {
+  assert(isMem(MI, Op) && "Invalid memory reference!");
+  MachineOperand Segment = MI->getOperand(Op+4);
+  if (Segment.getReg()) {
+      printOperand(MI, Op+4, Modifier);
+      O << ':';
+    }
+  printLeaMemReference(MI, Op, Modifier);
+}
+
 void X86IntelAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
                                            const MachineBasicBlock *MBB) const {
   if (!TAI->getSetDirective())
@@ -463,8 +466,10 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
 
     switch (I->getLinkage()) {
     case GlobalValue::CommonLinkage:
-    case GlobalValue::LinkOnceLinkage:
-    case GlobalValue::WeakLinkage:
+    case GlobalValue::LinkOnceAnyLinkage:
+    case GlobalValue::LinkOnceODRLinkage:
+    case GlobalValue::WeakAnyLinkage:
+    case GlobalValue::WeakODRLinkage:
       SwitchToDataSection("");
       O << name << "?\tsegment common 'COMMON'\n";
       bCustomSegment = true;
@@ -485,7 +490,7 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
       O << "\tpublic " << name << "\n";
       // FALL THROUGH
     case GlobalValue::InternalLinkage:
-      SwitchToDataSection(TAI->getDataSection(), I);
+      SwitchToSection(TAI->getDataSection());
       break;
     default:
       assert(0 && "Unknown linkage type!");
@@ -494,8 +499,11 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
     if (!bCustomSegment)
       EmitAlignment(Align, I);
 
-    O << name << ":\t\t\t\t" << TAI->getCommentString()
-      << " " << I->getName() << '\n';
+    O << name << ":";
+    if (VerboseAsm)
+      O << "\t\t\t\t" << TAI->getCommentString()
+        << " " << I->getName();
+    O << '\n';
 
     EmitGlobalConstant(C);
 
@@ -506,10 +514,14 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
     // Output linker support code for dllexported globals
   if (!DLLExportedGVs.empty() || !DLLExportedFns.empty()) {
     SwitchToDataSection("");
-    O << "; WARNING: The following code is valid only with MASM v8.x and (possible) higher\n"
-      << "; This version of MASM is usually shipped with Microsoft Visual Studio 2005\n"
-      << "; or (possible) further versions. Unfortunately, there is no way to support\n"
-      << "; dllexported symbols in the earlier versions of MASM in fully automatic way\n\n";
+    O << "; WARNING: The following code is valid only with MASM v8.x"
+      << "and (possible) higher\n"
+      << "; This version of MASM is usually shipped with Microsoft "
+      << "Visual Studio 2005\n"
+      << "; or (possible) further versions. Unfortunately, there is no "
+      << "way to support\n"
+      << "; dllexported symbols in the earlier versions of MASM in fully "
+      << "automatic way\n\n";
     O << "_drectve\t segment info alias('.drectve')\n";
   }