fix an ugly wart in the MCInstPrinter api where the
authorChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 05:04:31 +0000 (05:04 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 05:04:31 +0000 (05:04 +0000)
raw_ostream to print an instruction to had to be specified
at MCInstPrinter construction time instead of being able
to pick at each call to printInstruction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100307 91177308-0d34-0410-b5e6-96231b3b80d8

18 files changed:
include/llvm/MC/MCInstPrinter.h
include/llvm/Target/TargetRegistry.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/MC/MCAsmStreamer.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/ARM/AsmPrinter/ARMInstPrinter.cpp
lib/Target/ARM/AsmPrinter/ARMInstPrinter.h
lib/Target/MSP430/AsmPrinter/MSP430AsmPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.cpp
lib/Target/MSP430/AsmPrinter/MSP430InstPrinter.h
lib/Target/X86/AsmPrinter/X86ATTInstPrinter.cpp
lib/Target/X86/AsmPrinter/X86ATTInstPrinter.h
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelInstPrinter.cpp
lib/Target/X86/AsmPrinter/X86IntelInstPrinter.h
tools/edis/EDDisassembler.cpp
tools/llvm-mc/Disassembler.cpp
tools/llvm-mc/llvm-mc.cpp

index d2ddc5bb42b2460933e7ec42bfdd2f54fa435e71..4839a83dba5cd65db057e8434c6ec7a213b36ee1 100644 (file)
@@ -20,26 +20,23 @@ class StringRef;
 /// that converts an MCInst to valid target assembly syntax.
 class MCInstPrinter {
 protected:
-  /// O - The main stream to emit instruction text to.
-  raw_ostream &O;
-  
   /// CommentStream - a stream that comments can be emitted to if desired.
   /// Each comment must end with a newline.  This will be null if verbose
   /// assembly emission is disable.
   raw_ostream *CommentStream;
   const MCAsmInfo &MAI;
 public:
-  MCInstPrinter(raw_ostream &o, const MCAsmInfo &mai)
-    : O(o), CommentStream(0), MAI(mai) {}
+  MCInstPrinter(const MCAsmInfo &mai)
+    : CommentStream(0), MAI(mai) {}
   
   virtual ~MCInstPrinter();
 
   /// setCommentStream - Specify a stream to emit comments to.
   void setCommentStream(raw_ostream &OS) { CommentStream = &OS; }
   
-  /// printInst - Print the specified MCInst to the current raw_ostream.
+  /// printInst - Print the specified MCInst to the specified raw_ostream.
   ///
-  virtual void printInst(const MCInst *MI) = 0;
+  virtual void printInst(const MCInst *MI, raw_ostream &OS) = 0;
   
   /// getOpcodeName - Return the name of the specified opcode enum (e.g.
   /// "MOV32ri") or empty if we can't resolve it.
index 6b6dad8185b0e016eb4b600db16c1f55fc639a0f..272205ab12eccc49bf7212672ccb95201d9bbae3 100644 (file)
@@ -71,8 +71,7 @@ namespace llvm {
     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
                                                   unsigned SyntaxVariant,
-                                                  const MCAsmInfo &MAI,
-                                                  raw_ostream &O);
+                                                  const MCAsmInfo &MAI);
     typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
                                                 TargetMachine &TM,
                                                 MCContext &Ctx);
@@ -248,11 +247,10 @@ namespace llvm {
     }
 
     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
-                                       const MCAsmInfo &MAI,
-                                       raw_ostream &O) const {
+                                       const MCAsmInfo &MAI) const {
       if (!MCInstPrinterCtorFn)
         return 0;
-      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, O);
+      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
     }
 
 
index 75e45efe4de143657e05f26b0d4b694811dcc97c..4b9095494dad0d6b0239b42f936a38da47bcb094 100644 (file)
@@ -128,7 +128,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
   default: return true;
   case CGFT_AssemblyFile: {
     MCInstPrinter *InstPrinter =
-      getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI, Out);
+      getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI);
     AsmStreamer.reset(createAsmStreamer(*Context, Out,
                                         getTargetData()->isLittleEndian(),
                                         getVerboseAsm(), InstPrinter,
index 757eaddcf2d54a02a445308bbef3adaf668c16a4..2c7e1c4c90d1eeb475ea093a928e373490065a05 100644 (file)
@@ -635,7 +635,7 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
   
   // If we have an AsmPrinter, use that to print, otherwise print the MCInst.
   if (InstPrinter)
-    InstPrinter->printInst(&Inst);
+    InstPrinter->printInst(&Inst, OS);
   else
     Inst.print(OS, &MAI);
   EmitEOL();
index 486ab00d66494adc86ba2a4333fc9b81d31b3407..feb2db8bb8e211498dde348e4b4559fc815d3d93 100644 (file)
@@ -1385,10 +1385,9 @@ void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
 
 static MCInstPrinter *createARMMCInstPrinter(const Target &T,
                                              unsigned SyntaxVariant,
-                                             const MCAsmInfo &MAI,
-                                             raw_ostream &O) {
+                                             const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new ARMInstPrinter(O, MAI, false);
+    return new ARMInstPrinter(MAI, false);
   return 0;
 }
 
index f0fcafbf81fce228607bc5d45321f235fbb79187..ef5ead6e473b65c1695b9ac594e606c1823e2c37 100644 (file)
@@ -98,7 +98,7 @@ static unsigned NextReg(unsigned Reg) {
   }
 }
 
-void ARMInstPrinter::printInst(const MCInst *MI) {
+void ARMInstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
   // Check for MOVs and print canonical forms, instead.
   if (MI->getOpcode() == ARM::MOVs) {
     const MCOperand &Dst = MI->getOperand(0);
index c2b32c1352e2f45122dcfce2b17433f16429bc4c..dd006fc52e74762101ddb1f84dd189c44a35a7fb 100644 (file)
@@ -22,10 +22,10 @@ namespace llvm {
 class ARMInstPrinter : public MCInstPrinter {
   bool VerboseAsm;
 public:
-  ARMInstPrinter(raw_ostream &O, const MCAsmInfo &MAI, bool verboseAsm)
-    : MCInstPrinter(O, MAI), VerboseAsm(verboseAsm) {}
+  ARMInstPrinter(const MCAsmInfo &MAI, bool verboseAsm)
+    : MCInstPrinter(MAI), VerboseAsm(verboseAsm) {}
 
-  virtual void printInst(const MCInst *MI);
+  virtual void printInst(const MCInst *MI, raw_ostream &O);
   
   // Autogenerated by tblgen.
   void printInstruction(const MCInst *MI, raw_ostream &O);
index 5d5e2e2474cfd0e3be9fbd6ce6f6e84e65fedc01..f40299079ebf5b98eb0b444d3b43ff4710922ba1 100644 (file)
@@ -51,7 +51,7 @@ namespace {
     }
 
     void printMCInst(const MCInst *MI) {
-      MSP430InstPrinter(O, *MAI).printInstruction(MI, O);
+      MSP430InstPrinter(*MAI).printInstruction(MI, O);
     }
     void printOperand(const MachineInstr *MI, int OpNum,
                       const char* Modifier = 0);
@@ -191,10 +191,9 @@ void MSP430AsmPrinter::EmitInstruction(const MachineInstr *MI) {
 
 static MCInstPrinter *createMSP430MCInstPrinter(const Target &T,
                                                 unsigned SyntaxVariant,
-                                                const MCAsmInfo &MAI,
-                                                raw_ostream &O) {
+                                                const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new MSP430InstPrinter(O, MAI);
+    return new MSP430InstPrinter(MAI);
   return 0;
 }
 
index 6b99645d23d544b7162c5f5311ab4f4ac4a1010c..c15d4085bc8b78be07a56656674de971e5d85577 100644 (file)
@@ -28,7 +28,7 @@ using namespace llvm;
 #include "MSP430GenAsmWriter.inc"
 #undef MachineInstr
 
-void MSP430InstPrinter::printInst(const MCInst *MI) {
+void MSP430InstPrinter::printInst(const MCInst *MI, raw_ostream &O) {
   printInstruction(MI, O);
 }
 
index a802cd2bae3681d123784c0a4c629249a5e5fac4..f0e1ce22841b5ce20697413a0b210775f68d4460 100644 (file)
 
 #include "llvm/MC/MCInstPrinter.h"
 
-namespace llvm
-{
-
+namespace llvm {
   class MCOperand;
 
   class MSP430InstPrinter : public MCInstPrinter {
   public:
-    MSP430InstPrinter(raw_ostream &O, const MCAsmInfo &MAI) :
-      MCInstPrinter(O, MAI) {
+    MSP430InstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {
     }
 
-    virtual void printInst(const MCInst *MI);
+    virtual void printInst(const MCInst *MI, raw_ostream &O);
 
     // Autogenerated by tblgen.
     void printInstruction(const MCInst *MI, raw_ostream &O);
index 93f3dc1eff08a3a328c6f7513da87e5fe2ab804d..0b64cb4f28282b134dadc77204bdf3637cb378b5 100644 (file)
@@ -29,8 +29,8 @@ using namespace llvm;
 #include "X86GenAsmWriter.inc"
 #undef MachineInstr
 
-void X86ATTInstPrinter::printInst(const MCInst *MI) {
-  printInstruction(MI, O);
+void X86ATTInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) {
+  printInstruction(MI, OS);
 }
 StringRef X86ATTInstPrinter::getOpcodeName(unsigned Opcode) const {
   return getInstructionName(Opcode);
index 3450a057f83a71cf5bf37e60a7be88791d177faa..8d5d50832d4921e362f09c36b483759161b89a1f 100644 (file)
@@ -21,11 +21,10 @@ namespace llvm {
   
 class X86ATTInstPrinter : public MCInstPrinter {
 public:
-  X86ATTInstPrinter(raw_ostream &O, const MCAsmInfo &MAI)
-    : MCInstPrinter(O, MAI) {}
+  X86ATTInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {}
 
   
-  virtual void printInst(const MCInst *MI);
+  virtual void printInst(const MCInst *MI, raw_ostream &OS);
   virtual StringRef getOpcodeName(unsigned Opcode) const;
 
   // Autogenerated by tblgen.
index 5f758db9456dde6d68e678f6a3bd87fabe31df81..311908abe5c91ce7430b4e8c50ee7702f89f1ad3 100644 (file)
@@ -636,12 +636,11 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
 
 static MCInstPrinter *createX86MCInstPrinter(const Target &T,
                                              unsigned SyntaxVariant,
-                                             const MCAsmInfo &MAI,
-                                             raw_ostream &O) {
+                                             const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new X86ATTInstPrinter(O, MAI);
+    return new X86ATTInstPrinter(MAI);
   if (SyntaxVariant == 1)
-    return new X86IntelInstPrinter(O, MAI);
+    return new X86IntelInstPrinter(MAI);
   return 0;
 }
 
index e12b1485730d0904c7f4f1ad688c12180aa2c9ed..7e0a9bb891fa77dd52504295bf04a57c3642f5cb 100644 (file)
@@ -28,8 +28,8 @@ using namespace llvm;
 #include "X86GenAsmWriter1.inc"
 #undef MachineInstr
 
-void X86IntelInstPrinter::printInst(const MCInst *MI) {
-  printInstruction(MI, O);
+void X86IntelInstPrinter::printInst(const MCInst *MI, raw_ostream &OS) {
+  printInstruction(MI, OS);
 }
 StringRef X86IntelInstPrinter::getOpcodeName(unsigned Opcode) const {
   return getInstructionName(Opcode);
index c2d02745110ea6e9b6c1f0f7087f4d1b5e75175d..a0beeb202e72bdef72b4da225d0b954a795f27c1 100644 (file)
@@ -22,10 +22,10 @@ namespace llvm {
   
 class X86IntelInstPrinter : public MCInstPrinter {
 public:
-  X86IntelInstPrinter(raw_ostream &O, const MCAsmInfo &MAI)
-    : MCInstPrinter(O, MAI) {}
+  X86IntelInstPrinter(const MCAsmInfo &MAI)
+    : MCInstPrinter(MAI) {}
   
-  virtual void printInst(const MCInst *MI);
+  virtual void printInst(const MCInst *MI, raw_ostream &OS);
   virtual StringRef getOpcodeName(unsigned Opcode) const;
   
   // Autogenerated by tblgen.
index f2b2f91577542ba0e6abed7833cf9239c18c7c76..8729b4998fda3df0bca0d52e4f476293bdec7d56 100644 (file)
@@ -195,10 +195,7 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
   
   InstString.reset(new std::string);
   InstStream.reset(new raw_string_ostream(*InstString));
-  
-  InstPrinter.reset(Tgt->createMCInstPrinter(syntaxVariant,
-                                                *AsmInfo,
-                                                *InstStream));
+  InstPrinter.reset(Tgt->createMCInstPrinter(syntaxVariant, *AsmInfo));
   
   if (!InstPrinter)
     return;
@@ -314,11 +311,10 @@ bool EDDisassembler::registerIsProgramCounter(unsigned registerID) {
   return (programCounters.find(registerID) != programCounters.end());
 }
 
-int EDDisassembler::printInst(std::string& str,
-                              MCInst& inst) {
+int EDDisassembler::printInst(std::string &str, MCInst &inst) {
   PrinterMutex.acquire();
   
-  InstPrinter->printInst(&inst);
+  InstPrinter->printInst(&inst, *InstStream);
   InstStream->flush();
   str = *InstString;
   InstString->clear();
index 0caf539ac959e0c82c814bdfeb0fe7080cd988fa..9fe07909284c2e984cf0dcf4ea4951371db9b30a 100644 (file)
@@ -48,8 +48,8 @@ public:
 }
 
 static bool PrintInsts(const MCDisassembler &DisAsm,
-                      MCInstPrinter &Printer, const ByteArrayTy &Bytes,
-                      SourceMgr &SM) {
+                       MCInstPrinter &Printer, const ByteArrayTy &Bytes,
+                       SourceMgr &SM) {
   // Wrap the vector in a MemoryObject.
   VectorMemoryObject memoryObject(Bytes);
   
@@ -62,7 +62,7 @@ static bool PrintInsts(const MCDisassembler &DisAsm,
     
     if (DisAsm.getInstruction(Inst, Size, memoryObject, Index, 
                                /*REMOVE*/ nulls())) {
-      Printer.printInst(&Inst);
+      Printer.printInst(&Inst, outs());
       outs() << "\n";
     }
     else {
@@ -92,7 +92,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
     return -1;
   }
   
-  OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(0, *AsmInfo, outs()));
+  OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(0, *AsmInfo));
   if (!IP) {
     errs() << "error: no instruction printer for target " << Triple << '\n';
     return -1;
index 6f1448b191acf33f3134631d0d71337c9ee9badc..be7e55d510db678db4117b6582697fd0dd2df1bd 100644 (file)
@@ -290,7 +290,7 @@ static int AssembleInput(const char *ProgName) {
 
   if (FileType == OFT_AssemblyFile) {
     MCInstPrinter *IP =
-      TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *Out);
+      TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI);
     if (ShowEncoding)
       CE.reset(TheTarget->createCodeEmitter(*TM, Ctx));
     Str.reset(createAsmStreamer(Ctx, *Out,TM->getTargetData()->isLittleEndian(),