[llvm-commits] CVS: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp X86ATTAsmPrinter.h X86AsmPrinter.cpp X86AsmPrinter.h X86IntelAsmPrinter.cpp X86IntelAsmPrinter.h

Jim Laskey jlaskey at apple.com
Wed Sep 6 11:35:06 PDT 2006



Changes in directory llvm/lib/Target/X86:

X86ATTAsmPrinter.cpp updated: 1.58 -> 1.59
X86ATTAsmPrinter.h updated: 1.13 -> 1.14
X86AsmPrinter.cpp updated: 1.192 -> 1.193
X86AsmPrinter.h updated: 1.27 -> 1.28
X86IntelAsmPrinter.cpp updated: 1.52 -> 1.53
X86IntelAsmPrinter.h updated: 1.21 -> 1.22
---
Log message:

Separate target specific asm properties from the asm printers.


---
Diffs of the changes:  (+92 -96)

 X86ATTAsmPrinter.cpp   |   16 ++++----
 X86ATTAsmPrinter.h     |    4 +-
 X86AsmPrinter.cpp      |   90 ++++++++++++++++++++++++++++++++++---------------
 X86AsmPrinter.h        |   34 ++++--------------
 X86IntelAsmPrinter.cpp |   40 ++++-----------------
 X86IntelAsmPrinter.h   |    4 +-
 6 files changed, 92 insertions(+), 96 deletions(-)


Index: llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.58 llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.59
--- llvm/lib/Target/X86/X86ATTAsmPrinter.cpp:1.58	Tue Aug 29 17:13:10 2006
+++ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp	Wed Sep  6 13:34:40 2006
@@ -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;


Index: llvm/lib/Target/X86/X86ATTAsmPrinter.h
diff -u llvm/lib/Target/X86/X86ATTAsmPrinter.h:1.13 llvm/lib/Target/X86/X86ATTAsmPrinter.h:1.14
--- llvm/lib/Target/X86/X86ATTAsmPrinter.h:1.13	Fri Apr 28 18:19:39 2006
+++ llvm/lib/Target/X86/X86ATTAsmPrinter.h	Wed Sep  6 13:34:40 2006
@@ -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";


Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.192 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.193
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.192	Sat Aug 12 16:29:52 2006
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp	Wed Sep  6 13:34:40 2006
@@ -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);
   }
 }


Index: llvm/lib/Target/X86/X86AsmPrinter.h
diff -u llvm/lib/Target/X86/X86AsmPrinter.h:1.27 llvm/lib/Target/X86/X86AsmPrinter.h:1.28
--- llvm/lib/Target/X86/X86AsmPrinter.h:1.27	Tue Aug 29 17:14:48 2006
+++ llvm/lib/Target/X86/X86AsmPrinter.h	Wed Sep  6 13:34:40 2006
@@ -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


Index: llvm/lib/Target/X86/X86IntelAsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.52 llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.53
--- llvm/lib/Target/X86/X86IntelAsmPrinter.cpp:1.52	Wed May 31 17:34:26 2006
+++ llvm/lib/Target/X86/X86IntelAsmPrinter.cpp	Wed Sep  6 13:34:40 2006
@@ -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);
 


Index: llvm/lib/Target/X86/X86IntelAsmPrinter.h
diff -u llvm/lib/Target/X86/X86IntelAsmPrinter.h:1.21 llvm/lib/Target/X86/X86IntelAsmPrinter.h:1.22
--- llvm/lib/Target/X86/X86IntelAsmPrinter.h:1.21	Thu May  4 13:05:43 2006
+++ llvm/lib/Target/X86/X86IntelAsmPrinter.h	Wed Sep  6 13:34:40 2006
@@ -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";






More information about the llvm-commits mailing list