Separate target specific asm properties from the asm printers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30126 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp
index 61534f6..98c3790 100644
--- a/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -23,6 +23,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
@@ -37,8 +38,8 @@
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  struct ARMAsmPrinter : public AsmPrinter {
-    ARMAsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {
+  struct VISIBILITY_HIDDEN ARMTargetAsmInfo : public TargetAsmInfo {
+    ARMTargetAsmInfo() {
       Data16bitsDirective = "\t.half\t";
       Data32bitsDirective = "\t.word\t";
       Data64bitsDirective = 0;
@@ -47,6 +48,12 @@
       ConstantPoolSection = "\t.text\n";
       AlignmentIsInBytes = false;
     }
+  };
+
+  struct VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter {
+    ARMAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T)
+      : AsmPrinter(O, TM, T) {
+    }
 
     /// We name each basic block in a Function with a unique number, so
     /// that we can consistently refer to them later. This is cleared
@@ -106,7 +113,8 @@
 ///
 FunctionPass *llvm::createARMCodePrinterPass(std::ostream &o,
                                                TargetMachine &tm) {
-  return new ARMAsmPrinter(o, tm);
+  ARMTargetAsmInfo *TAI = new ARMTargetAsmInfo();
+  return new ARMAsmPrinter(o, tm, TAI);
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
@@ -187,7 +195,7 @@
     abort();
     break;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber()
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
       << '_' << MO.getConstantPoolIndex();
     break;
   default:
diff --git a/lib/Target/Alpha/AlphaAsmPrinter.cpp b/lib/Target/Alpha/AlphaAsmPrinter.cpp
index 919552c..d709ed7 100644
--- a/lib/Target/Alpha/AlphaAsmPrinter.cpp
+++ b/lib/Target/Alpha/AlphaAsmPrinter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Type.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/ADT/Statistic.h"
@@ -27,17 +28,22 @@
 
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
+  
+  struct VISIBILITY_HIDDEN AlphaTargetAsmInfo : public TargetAsmInfo {
+    AlphaTargetAsmInfo() {
+      AlignmentIsInBytes = false;
+      PrivateGlobalPrefix = "$";
+    }
+  };
 
-  struct AlphaAsmPrinter : public AsmPrinter {
+  struct VISIBILITY_HIDDEN AlphaAsmPrinter : public AsmPrinter {
 
     /// Unique incrementer for label values for referencing Global values.
     ///
     unsigned LabelNumber;
 
-     AlphaAsmPrinter(std::ostream &o, TargetMachine &tm)
-       : AsmPrinter(o, tm), LabelNumber(0) {
-      AlignmentIsInBytes = false;
-      PrivateGlobalPrefix = "$";
+    AlphaAsmPrinter(std::ostream &o, TargetMachine &tm, TargetAsmInfo *T)
+       : AsmPrinter(o, tm, T), LabelNumber(0) {
     }
 
     /// We name each basic block in a Function with a unique number, so
@@ -76,7 +82,8 @@
 ///
 FunctionPass *llvm::createAlphaCodePrinterPass (std::ostream &o,
                                                   TargetMachine &tm) {
-  return new AlphaAsmPrinter(o, tm);
+  AlphaTargetAsmInfo *TAI = new AlphaTargetAsmInfo();
+  return new AlphaAsmPrinter(o, tm, TAI);
 }
 
 #include "AlphaGenAsmWriter.inc"
@@ -115,7 +122,7 @@
     return;
 
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex();
     return;
 
diff --git a/lib/Target/IA64/IA64AsmPrinter.cpp b/lib/Target/IA64/IA64AsmPrinter.cpp
index 2ebe010..1de1215 100644
--- a/lib/Target/IA64/IA64AsmPrinter.cpp
+++ b/lib/Target/IA64/IA64AsmPrinter.cpp
@@ -24,6 +24,7 @@
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/ADT/Statistic.h"
 #include <iostream>
@@ -32,10 +33,8 @@
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  struct IA64AsmPrinter : public AsmPrinter {
-    std::set<std::string> ExternalFunctionNames, ExternalObjectNames;
-
-    IA64AsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {
+  struct VISIBILITY_HIDDEN IA64TargetAsmInfo : public TargetAsmInfo {
+    IA64TargetAsmInfo() {
       CommentString = "//";
       Data8bitsDirective = "\tdata1\t";     // FIXME: check that we are
       Data16bitsDirective = "\tdata2.ua\t"; // disabling auto-alignment
@@ -52,6 +51,14 @@
       // FIXME: would be nice to have rodata (no 'w') when appropriate?
       ConstantPoolSection = "\n\t.section .data, \"aw\", \"progbits\"\n";
     }
+  };
+  
+  struct IA64AsmPrinter : public AsmPrinter {
+    std::set<std::string> ExternalFunctionNames, ExternalObjectNames;
+
+    IA64AsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T)
+      : AsmPrinter(O, TM, T) {
+    }
 
     virtual const char *getPassName() const {
       return "IA64 Assembly Printer";
@@ -185,7 +192,8 @@
     printBasicBlockLabel(MO.getMachineBasicBlock());
     return;
   case MachineOperand::MO_ConstantPoolIndex: {
-    O << "@gprel(" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+    O << "@gprel(" << TAI->getPrivateGlobalPrefix()
+      << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex() << ")";
     return;
   }
@@ -358,7 +366,8 @@
 ///
 FunctionPass *llvm::createIA64CodePrinterPass(std::ostream &o,
                                               IA64TargetMachine &tm) {
-  return new IA64AsmPrinter(o, tm);
+  IA64TargetAsmInfo *TAI = new IA64TargetAsmInfo();
+  return new IA64AsmPrinter(o, tm, TAI);
 }
 
 
diff --git a/lib/Target/PowerPC/PPC.h b/lib/Target/PowerPC/PPC.h
index 26439bd..4cd540b 100644
--- a/lib/Target/PowerPC/PPC.h
+++ b/lib/Target/PowerPC/PPC.h
@@ -26,7 +26,8 @@
 
 FunctionPass *createPPCBranchSelectionPass();
 FunctionPass *createPPCISelDag(PPCTargetMachine &TM);
-FunctionPass *createDarwinAsmPrinter(std::ostream &OS, PPCTargetMachine &TM);
+FunctionPass *createDarwinCodePrinterPass(std::ostream &OS,
+                                          PPCTargetMachine &TM);
 FunctionPass *createPPCCodeEmitterPass(PPCTargetMachine &TM,
                                        MachineCodeEmitter &MCE);
 void addPPCMachOObjectWriterPass(FunctionPassManager &FPM, std::ostream &o, 
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 1e15c2c..9ec7106 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetOptions.h"
@@ -46,12 +47,11 @@
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
-  public:
+  struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
     std::set<std::string> FnStubs, GVStubs;
     
-    PPCAsmPrinter(std::ostream &O, TargetMachine &TM)
-      : AsmPrinter(O, TM) {}
+    PPCAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T)
+      : AsmPrinter(O, TM, T) {}
 
     virtual const char *getPassName() const {
       return "PowerPC Assembly Printer";
@@ -151,7 +151,7 @@
           }
         }
         if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
-          std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+          std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
           FnStubs.insert(Name);
           O << "L" << Name << "$stub";
           return;
@@ -239,14 +239,28 @@
     
   };
 
-  /// DarwinDwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
-  ///
-  struct VISIBILITY_HIDDEN DarwinDwarfWriter : public DwarfWriter {
-    // Ctor.
-    DarwinDwarfWriter(std::ostream &o, AsmPrinter *ap)
-    : DwarfWriter(o, ap)
-    {
-      needsSet = true;
+  struct VISIBILITY_HIDDEN DarwinTargetAsmInfo : public TargetAsmInfo {
+    DarwinTargetAsmInfo(PPCTargetMachine &TM) {
+      bool isPPC64 = TM.getSubtargetImpl()->isPPC64();
+
+      CommentString = ";";
+      GlobalPrefix = "_";
+      PrivateGlobalPrefix = "L";
+      ZeroDirective = "\t.space\t";
+      SetDirective = "\t.set";
+      Data64bitsDirective = isPPC64 ? ".quad\t" : 0;  
+      AlignmentIsInBytes = false;
+      ConstantPoolSection = "\t.const\t";
+      JumpTableDataSection = ".const";
+      JumpTableTextSection = "\t.text";
+      LCOMMDirective = "\t.lcomm\t";
+      StaticCtorsSection = ".mod_init_func";
+      StaticDtorsSection = ".mod_term_func";
+      InlineAsmStart = "# InlineAsm Start";
+      InlineAsmEnd = "# InlineAsm End";
+      
+      NeedsSet = true;
+      AddressSize = isPPC64 ? 8 : 4;
       DwarfAbbrevSection = ".section __DWARF,__debug_abbrev";
       DwarfInfoSection = ".section __DWARF,__debug_info";
       DwarfLineSection = ".section __DWARF,__debug_line";
@@ -258,8 +272,6 @@
       DwarfARangesSection = ".section __DWARF,__debug_aranges";
       DwarfRangesSection = ".section __DWARF,__debug_ranges";
       DwarfMacInfoSection = ".section __DWARF,__debug_macinfo";
-      TextSection = ".text";
-      DataSection = ".data";
     }
   };
 
@@ -267,29 +279,11 @@
   /// X
   struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter {
   
-    DarwinDwarfWriter DW;
+    DwarfWriter DW;
 
-    DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM)
-      : PPCAsmPrinter(O, TM), DW(O, this) {
+    DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM, TargetAsmInfo *T)
+      : PPCAsmPrinter(O, TM, T), DW(O, this, T) {
       bool isPPC64 = TM.getSubtargetImpl()->isPPC64();
-      CommentString = ";";
-      GlobalPrefix = "_";
-      PrivateGlobalPrefix = "L";     // Marker for constant pool idxs
-      ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
-      SetDirective = "\t.set";
-      if (isPPC64)
-        Data64bitsDirective = ".quad\t";       // we can't emit a 64-bit unit
-      else
-        Data64bitsDirective = 0;       // we can't emit a 64-bit unit
-      AlignmentIsInBytes = false;    // Alignment is by power of 2.
-      ConstantPoolSection = "\t.const\t";
-      JumpTableDataSection = ".const";
-      JumpTableTextSection = "\t.text";
-      LCOMMDirective = "\t.lcomm\t";
-      StaticCtorsSection = ".mod_init_func";
-      StaticDtorsSection = ".mod_term_func";
-      InlineAsmStart = "# InlineAsm Start";
-      InlineAsmEnd = "# InlineAsm End";
     }
 
     virtual const char *getPassName() const {
@@ -309,13 +303,14 @@
   };
 } // end of anonymous namespace
 
-/// createDarwinAsmPrinterPass - Returns a pass that prints the PPC assembly
+/// createDarwinCodePrinterPass - Returns a pass that prints the PPC assembly
 /// code for a MachineFunction to the given output stream, in a format that the
 /// Darwin assembler can deal with.
 ///
-FunctionPass *llvm::createDarwinAsmPrinter(std::ostream &o,
-                                           PPCTargetMachine &tm) {
-  return new DarwinAsmPrinter(o, tm);
+FunctionPass *llvm::createDarwinCodePrinterPass(std::ostream &o,
+                                                PPCTargetMachine &tm) {
+  TargetAsmInfo *TAI = new DarwinTargetAsmInfo(tm);
+  return new DarwinAsmPrinter(o, tm, TAI);
 }
 
 // Include the auto-generated portion of the assembly writer
@@ -332,23 +327,23 @@
     printBasicBlockLabel(MO.getMachineBasicBlock());
     return;
   case MachineOperand::MO_JumpTableIndex:
-    O << PrivateGlobalPrefix << "JTI" << getFunctionNumber()
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
       << '_' << MO.getJumpTableIndex();
     // FIXME: PIC relocation model
     return;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber()
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
       << '_' << MO.getConstantPoolIndex();
     return;
   case MachineOperand::MO_ExternalSymbol:
     // Computing the address of an external symbol, not calling it.
     if (TM.getRelocationModel() != Reloc::Static) {
-      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+      std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
       GVStubs.insert(Name);
       O << "L" << Name << "$non_lazy_ptr";
       return;
     }
-    O << GlobalPrefix << MO.getSymbolName();
+    O << TAI->getGlobalPrefix() << MO.getSymbolName();
     return;
   case MachineOperand::MO_GlobalAddress: {
     // Computing the address of a global symbol, not calling it.
@@ -561,7 +556,7 @@
           << Size << ", " << Align;
       } else if (I->hasInternalLinkage()) {
         SwitchToDataSection("\t.data", I);
-        O << LCOMMDirective << name << "," << Size << "," << Align;
+        O << TAI->getLCOMMDirective() << name << "," << Size << "," << Align;
       } else {
         SwitchToDataSection("\t.data", I);
         O << ".comm " << name << "," << Size;
diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp
index 2e2fd28..91fc0a6 100644
--- a/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ b/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -117,7 +117,7 @@
 
 bool PPCTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
                                           std::ostream &Out) {
-  PM.add(createDarwinAsmPrinter(Out, *this));
+  PM.add(createDarwinCodePrinterPass(Out, *this));
   return false;
 }
 
diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp
index 0de7fb0..2bc6f63 100644
--- a/lib/Target/Sparc/SparcAsmPrinter.cpp
+++ b/lib/Target/Sparc/SparcAsmPrinter.cpp
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
@@ -36,8 +37,8 @@
 namespace {
   Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
 
-  struct SparcAsmPrinter : public AsmPrinter {
-    SparcAsmPrinter(std::ostream &O, TargetMachine &TM) : AsmPrinter(O, TM) {
+  struct VISIBILITY_HIDDEN SparcTargetAsmInfo : public TargetAsmInfo {
+    SparcTargetAsmInfo() {
       Data16bitsDirective = "\t.half\t";
       Data32bitsDirective = "\t.word\t";
       Data64bitsDirective = 0;  // .xword is only supported by V9.
@@ -45,6 +46,12 @@
       CommentString = "!";
       ConstantPoolSection = "\t.section \".rodata\",#alloc\n";
     }
+  };
+
+  struct VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter {
+    SparcAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T)
+      : AsmPrinter(O, TM, T) {
+    }
 
     /// We name each basic block in a Function with a unique number, so
     /// that we can consistently refer to them later. This is cleared
@@ -78,7 +85,8 @@
 ///
 FunctionPass *llvm::createSparcCodePrinterPass(std::ostream &o,
                                                TargetMachine &tm) {
-  return new SparcAsmPrinter(o, tm);
+  SparcTargetAsmInfo *TAI = new SparcTargetAsmInfo();
+  return new SparcAsmPrinter(o, tm, TAI);
 }
 
 /// runOnMachineFunction - This uses the printMachineInstruction()
@@ -167,7 +175,7 @@
     O << MO.getSymbolName();
     break;
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex();
     break;
   default:
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index 9a78fea..6c54d69 100755
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -43,11 +43,11 @@
   switch (F->getLinkage()) {
   default: assert(0 && "Unknown linkage type!");
   case Function::InternalLinkage:  // Symbols default to internal.
-    SwitchToTextSection(DefaultTextSection, F);
+    SwitchToTextSection(TAI->getTextSection(), F);
     EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
     break;
   case Function::ExternalLinkage:
-    SwitchToTextSection(DefaultTextSection, F);
+    SwitchToTextSection(TAI->getTextSection(), F);
     EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
     O << "\t.globl\t" << CurrentFnName << "\n";
     break;
@@ -101,7 +101,7 @@
   // lables that are used in jump table expressions (e.g. LBB1_1-LJT1_0).
   EmitJumpTableInfo(MF.getJumpTableInfo());
   
-  if (HasDotTypeDotSizeDirective)
+  if (TAI->hasDotTypeDotSizeDirective())
     O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
 
   if (Subtarget->isTargetDarwin()) {
@@ -144,7 +144,7 @@
   case MachineOperand::MO_JumpTableIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << '$';
-    O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << "_"
+    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
       << MO.getJumpTableIndex();
     if (Subtarget->isTargetDarwin() && 
         TM.getRelocationModel() == Reloc::PIC_)
@@ -154,7 +154,7 @@
   case MachineOperand::MO_ConstantPoolIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << '$';
-    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+    O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex();
     if (Subtarget->isTargetDarwin() && 
         TM.getRelocationModel() == Reloc::PIC_)
@@ -206,14 +206,14 @@
     if (isCallOp && 
         Subtarget->isTargetDarwin() && 
         TM.getRelocationModel() != Reloc::Static) {
-      std::string Name(GlobalPrefix);
+      std::string Name(TAI->getGlobalPrefix());
       Name += MO.getSymbolName();
       FnStubs.insert(Name);
       O << "L" << Name << "$stub";
       return;
     }
     if (!isCallOp) O << '$';
-    O << GlobalPrefix << MO.getSymbolName();
+    O << TAI->getGlobalPrefix() << MO.getSymbolName();
     return;
   }
   default:
@@ -388,7 +388,7 @@
       Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
     else
       Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
-    O << CommentString << " TRUNCATE ";
+    O << TAI->getCommentString() << " TRUNCATE ";
     if (Reg0 != Reg1)
       O << "\n\t";
     break;
diff --git a/lib/Target/X86/X86ATTAsmPrinter.h b/lib/Target/X86/X86ATTAsmPrinter.h
index 6139c3a..e060150 100755
--- a/lib/Target/X86/X86ATTAsmPrinter.h
+++ b/lib/Target/X86/X86ATTAsmPrinter.h
@@ -20,8 +20,8 @@
 namespace llvm {
 
 struct X86ATTAsmPrinter : public X86SharedAsmPrinter {
- X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM)
-    : X86SharedAsmPrinter(O, TM) { }
+ X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T)
+    : X86SharedAsmPrinter(O, TM, T) { }
 
   virtual const char *getPassName() const {
     return "X86 AT&T-Style Assembly Printer";
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index 9e862e8..3fdd7b1 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -26,10 +26,11 @@
 #include "llvm/Support/CommandLine.h"
 using namespace llvm;
 
+enum AsmWriterFlavorTy { att, intel };
+
 Statistic<> llvm::EmittedInsts("asm-printer",
                                "Number of machine instrs printed");
 
-enum AsmWriterFlavorTy { att, intel };
 cl::opt<AsmWriterFlavorTy>
 AsmWriterFlavor("x86-asm-syntax",
                 cl::desc("Choose style of code to emit from X86 backend:"),
@@ -44,16 +45,11 @@
 #endif
                 );
 
-// Out of line virtual function to home classes.
-void X86DwarfWriter::virtfn() {}
-
-
-/// doInitialization
-bool X86SharedAsmPrinter::doInitialization(Module &M) {
-  PrivateGlobalPrefix = ".L";
-  DefaultTextSection = ".text";
-  DefaultDataSection = ".data";
+X86TargetAsmInfo::X86TargetAsmInfo(X86TargetMachine &TM) {
+  const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
   
+  //FIXME - Should to be simplified.
+   
   switch (Subtarget->TargetType) {
   case X86Subtarget::isDarwin:
     AlignmentIsInBytes = false;
@@ -73,6 +69,19 @@
     InlineAsmStart = "# InlineAsm Start";
     InlineAsmEnd = "# InlineAsm End";
     SetDirective = "\t.set";
+    
+    NeedsSet = true;
+    DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
+    DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
+    DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
+    DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
+    DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
+    DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
+    DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
+    DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
+    DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
+    DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
+    DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
     break;
   case X86Subtarget::isCygwin:
     GlobalPrefix = "_";
@@ -88,6 +97,33 @@
   default: break;
   }
   
+  if (AsmWriterFlavor == intel) {
+    GlobalPrefix = "_";
+    CommentString = ";";
+  
+    PrivateGlobalPrefix = "$";
+    AlignDirective = "\talign\t";
+    ZeroDirective = "\tdb\t";
+    ZeroDirectiveSuffix = " dup(0)";
+    AsciiDirective = "\tdb\t";
+    AscizDirective = 0;
+    Data8bitsDirective = "\tdb\t";
+    Data16bitsDirective = "\tdw\t";
+    Data32bitsDirective = "\tdd\t";
+    Data64bitsDirective = "\tdq\t";
+    HasDotTypeDotSizeDirective = false;
+    
+    TextSection = "_text";
+    DataSection = "_data";
+    SwitchToSectionDirective = "";
+    TextSectionStartSuffix = "\tsegment 'CODE'";
+    DataSectionStartSuffix = "\tsegment 'DATA'";
+    SectionEndDirectiveSuffix = "\tends\n";
+  }
+}
+
+/// doInitialization
+bool X86SharedAsmPrinter::doInitialization(Module &M) {  
   if (Subtarget->isTargetDarwin()) {
     // Emit initial debug information.
     DW.BeginModule(&M);
@@ -127,25 +163,25 @@
           O << "\t.zerofill __DATA__, __common, " << name << ", "
             << Size << ", " << Align;
       } else {
-        SwitchToDataSection(DefaultDataSection, I);
-        if (LCOMMDirective != NULL) {
+        SwitchToDataSection(TAI->getDataSection(), I);
+        if (TAI->getLCOMMDirective() != NULL) {
           if (I->hasInternalLinkage()) {
-            O << LCOMMDirective << name << "," << Size;
+            O << TAI->getLCOMMDirective() << name << "," << Size;
             if (Subtarget->isTargetDarwin())
-              O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
+              O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
           } else
-            O << COMMDirective  << name << "," << Size;
+            O << TAI->getCOMMDirective()  << name << "," << Size;
         } else {
           if (Subtarget->TargetType != X86Subtarget::isCygwin) {
             if (I->hasInternalLinkage())
               O << "\t.local\t" << name << "\n";
           }
-          O << COMMDirective  << name << "," << Size;
-          if (COMMDirectiveTakesAlignment)
-            O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
+          O << TAI->getCOMMDirective()  << name << "," << Size;
+          if (TAI->getCOMMDirectiveTakesAlignment())
+            O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
         }
       }
-      O << "\t\t" << CommentString << " " << I->getName() << "\n";
+      O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
     } else {
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
@@ -170,16 +206,16 @@
         O << "\t.globl " << name << "\n";
         // FALL THROUGH
       case GlobalValue::InternalLinkage:
-        SwitchToDataSection(DefaultDataSection, I);
+        SwitchToDataSection(TAI->getDataSection(), I);
         break;
       default:
         assert(0 && "Unknown linkage type!");
       }
 
       EmitAlignment(Align, I);
-      O << name << ":\t\t\t\t" << CommentString << " " << I->getName()
+      O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
         << "\n";
-      if (HasDotTypeDotSizeDirective)
+      if (TAI->hasDotTypeDotSizeDirective())
         O << "\t.size " << name << ", " << Size << "\n";
 
       EmitGlobalConstant(C);
@@ -234,13 +270,13 @@
 /// machine description.
 ///
 FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
-                                             X86TargetMachine &tm){
+                                             X86TargetMachine &tm) {
+  TargetAsmInfo *TAI = new X86TargetAsmInfo(tm);
+
   switch (AsmWriterFlavor) {
   default:
     assert(0 && "Unknown asm flavor!");
-  case intel:
-    return new X86IntelAsmPrinter(o, tm);
-  case att:
-    return new X86ATTAsmPrinter(o, tm);
+  case intel: return new X86IntelAsmPrinter(o, tm, TAI);
+  case att: return new X86ATTAsmPrinter(o, tm, TAI);
   }
 }
diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/X86AsmPrinter.h
index 4bc5b2b..aa8129b 100755
--- a/lib/Target/X86/X86AsmPrinter.h
+++ b/lib/Target/X86/X86AsmPrinter.h
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/CodeGen/MachineDebugInfo.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Target/TargetAsmInfo.h"
 #include <set>
 
 
@@ -29,33 +30,16 @@
 
 extern Statistic<> EmittedInsts;
 
-/// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
-///
-struct X86DwarfWriter : public DwarfWriter {
-  X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) {
-      needsSet = true;
-      DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
-      DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
-      DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
-      DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
-      DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
-      DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
-      DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
-      DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
-      DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
-      DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
-      DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
-      TextSection = ".text";
-      DataSection = ".data";
-  }
-  virtual void virtfn();  // out of line virtual fn.
+struct VISIBILITY_HIDDEN X86TargetAsmInfo : public TargetAsmInfo {
+  X86TargetAsmInfo(X86TargetMachine &TM);
 };
 
-struct X86SharedAsmPrinter : public AsmPrinter {
-  X86DwarfWriter DW;
+struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
+  DwarfWriter DW;
 
-  X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
-    : AsmPrinter(O, TM), DW(O, this) {
+  X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
+                      TargetAsmInfo *T)
+    : AsmPrinter(O, TM, T), DW(O, this, T) {
     Subtarget = &TM.getSubtarget<X86Subtarget>();
   }
 
@@ -70,8 +54,6 @@
     MachineFunctionPass::getAnalysisUsage(AU);
   }
 
-  const char *DefaultTextSection;   // "_text" for MASM, ".text" for others.
-  const char *DefaultDataSection;   // "_data" for MASM, ".data" for others.
   const X86Subtarget *Subtarget;
 
   // Necessary for Darwin to print out the apprioriate types of linker stubs
diff --git a/lib/Target/X86/X86IntelAsmPrinter.cpp b/lib/Target/X86/X86IntelAsmPrinter.cpp
index c8bcc59..7be50e7 100755
--- a/lib/Target/X86/X86IntelAsmPrinter.cpp
+++ b/lib/Target/X86/X86IntelAsmPrinter.cpp
@@ -22,10 +22,6 @@
 #include "llvm/Target/TargetOptions.h"
 using namespace llvm;
 
-X86IntelAsmPrinter::X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM)
-    : X86SharedAsmPrinter(O, TM) {
-}
-
 /// runOnMachineFunction - This uses the printMachineInstruction()
 /// method to print assembly for each instruction.
 ///
@@ -106,8 +102,8 @@
   case MachineOperand::MO_ConstantPoolIndex: {
     bool isMemOp  = Modifier && !strcmp(Modifier, "mem");
     if (!isMemOp) O << "OFFSET ";
-    O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
-      << MO.getConstantPoolIndex();
+    O << "[" << TAI->getPrivateGlobalPrefix() << "CPI"
+      << getFunctionNumber() << "_" << MO.getConstantPoolIndex();
     int Offset = MO.getOffset();
     if (Offset > 0)
       O << " + " << Offset;
@@ -131,7 +127,7 @@
   case MachineOperand::MO_ExternalSymbol: {
     bool isCallOp = Modifier && !strcmp(Modifier, "call");
     if (!isCallOp) O << "OFFSET ";
-    O << GlobalPrefix << MO.getSymbolName();
+    O << TAI->getGlobalPrefix() << MO.getSymbolName();
     return;
   }
   default:
@@ -272,7 +268,7 @@
       Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
     else
       Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
-    O << CommentString << " TRUNCATE ";
+    O << TAI->getCommentString() << " TRUNCATE ";
     if (Reg0 != Reg1)
       O << "\n\t";
     break;
@@ -284,30 +280,9 @@
 }
 
 bool X86IntelAsmPrinter::doInitialization(Module &M) {
-  GlobalPrefix = "_";
-  CommentString = ";";
-
   X86SharedAsmPrinter::doInitialization(M);
-
-  PrivateGlobalPrefix = "$";
-  AlignDirective = "\talign\t";
-  ZeroDirective = "\tdb\t";
-  ZeroDirectiveSuffix = " dup(0)";
-  AsciiDirective = "\tdb\t";
-  AscizDirective = 0;
-  Data8bitsDirective = "\tdb\t";
-  Data16bitsDirective = "\tdw\t";
-  Data32bitsDirective = "\tdd\t";
-  Data64bitsDirective = "\tdq\t";
-  HasDotTypeDotSizeDirective = false;
-  Mang->markCharUnacceptable('.');
   
-  DefaultTextSection = "_text";
-  DefaultDataSection = "_data";
-  SwitchToSectionDirective = "";
-  TextSectionStartSuffix = "\tsegment 'CODE'";
-  DataSectionStartSuffix = "\tsegment 'DATA'";
-  SectionEndDirectiveSuffix = "\tends\n";
+  Mang->markCharUnacceptable('.');
 
   O << "\t.686\n\t.model flat\n\n";
 
@@ -365,7 +340,7 @@
       O << "\tpublic " << name << "\n";
       // FALL THROUGH
     case GlobalValue::InternalLinkage:
-      SwitchToDataSection(DefaultDataSection, I);
+      SwitchToDataSection(TAI->getDataSection(), I);
       break;
     default:
       assert(0 && "Unknown linkage type!");
@@ -374,7 +349,8 @@
     if (!bCustomSegment)
       EmitAlignment(Align, I);
 
-    O << name << ":\t\t\t\t" << CommentString << " " << I->getName() << '\n';
+    O << name << ":\t\t\t\t" << TAI->getCommentString()
+      << " " << I->getName() << '\n';
 
     EmitGlobalConstant(C);
 
diff --git a/lib/Target/X86/X86IntelAsmPrinter.h b/lib/Target/X86/X86IntelAsmPrinter.h
index c594e46..8e0e8ba 100755
--- a/lib/Target/X86/X86IntelAsmPrinter.h
+++ b/lib/Target/X86/X86IntelAsmPrinter.h
@@ -21,7 +21,9 @@
 namespace llvm {
 
 struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
-  X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM);
+  X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T)
+      : X86SharedAsmPrinter(O, TM, T) {
+  }
 
   virtual const char *getPassName() const {
     return "X86 Intel-Style Assembly Printer";