We need to pass the TargetMachine object to the InstPrinter if we are printing
authorBill Wendling <isanbard@gmail.com>
Mon, 21 Mar 2011 04:13:46 +0000 (04:13 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 21 Mar 2011 04:13:46 +0000 (04:13 +0000)
the alias of an InstAlias instead of the thing being aliased. Because we need to
know the features that are valid for an InstAlias.

This is part of a work-in-progress.

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

18 files changed:
include/llvm/Target/TargetRegistry.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/MC/MCDisassembler/EDDisassembler.cpp
lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/InstPrinter/ARMInstPrinter.h
lib/Target/MBlaze/InstPrinter/MBlazeInstPrinter.h
lib/Target/MBlaze/MBlazeAsmPrinter.cpp
lib/Target/MSP430/InstPrinter/MSP430InstPrinter.h
lib/Target/MSP430/MSP430AsmPrinter.cpp
lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/X86/InstPrinter/X86ATTInstPrinter.h
lib/Target/X86/InstPrinter/X86IntelInstPrinter.h
lib/Target/X86/X86AsmPrinter.cpp
tools/llvm-mc/Disassembler.cpp
tools/llvm-mc/Disassembler.h
tools/llvm-mc/llvm-mc.cpp
tools/llvm-objdump/llvm-objdump.cpp

index f851ad0a9bfb1307ba3babd98f6bbde6ab3e8e0e..3739a0f83a4ec81f63c8553b73b76a8c6eea02b5 100644 (file)
@@ -78,6 +78,7 @@ namespace llvm {
                                                 TargetMachine &TM);
     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
+                                                  TargetMachine &TM,
                                                   unsigned SyntaxVariant,
                                                   const MCAsmInfo &MAI);
     typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
@@ -286,11 +287,12 @@ namespace llvm {
       return MCDisassemblerCtorFn(*this);
     }
 
-    MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
+    MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
+                                       unsigned SyntaxVariant,
                                        const MCAsmInfo &MAI) const {
       if (!MCInstPrinterCtorFn)
         return 0;
-      return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
+      return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
     }
 
 
index a9e8045918fd4e5e0b3e313bb66f56e16e911b87..89013a63cab6a47420de60a332c53b9fb0017403 100644 (file)
@@ -133,7 +133,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
   default: return true;
   case CGFT_AssemblyFile: {
     MCInstPrinter *InstPrinter =
-      getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI);
+      getTarget().createMCInstPrinter(*this, MAI.getAssemblerDialect(), MAI);
 
     // Create a code emitter if asked to show the encoding.
     MCCodeEmitter *MCE = 0;
index 2fd14db2a45d61301299da6652547b7b058b8864..f679647dd852fe682f726a4d4500e272f526cc3f 100644 (file)
@@ -193,7 +193,8 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
   
   InstString.reset(new std::string);
   InstStream.reset(new raw_string_ostream(*InstString));
-  InstPrinter.reset(Tgt->createMCInstPrinter(LLVMSyntaxVariant, *AsmInfo));
+  InstPrinter.reset(Tgt->createMCInstPrinter(*TargetMachine, LLVMSyntaxVariant,
+                                             *AsmInfo));
   
   if (!InstPrinter)
     return;
index 784a661928bca3b36f149325dcb2566226b7331c..8eb1993a15a24b4101ead25af05ed89e04d32935 100644 (file)
@@ -1791,10 +1791,11 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
 //===----------------------------------------------------------------------===//
 
 static MCInstPrinter *createARMMCInstPrinter(const Target &T,
+                                             TargetMachine &TM,
                                              unsigned SyntaxVariant,
                                              const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new ARMInstPrinter(MAI);
+    return new ARMInstPrinter(TM, MAI);
   return 0;
 }
 
index a44f208d15402fb9ae73e3a3f5c1a98c427f2dad..29948eee66b9b338060abc7f7a3f0a87f347f09e 100644 (file)
 #include "llvm/MC/MCInstPrinter.h"
 
 namespace llvm {
-  class MCOperand;
+
+class MCOperand;
+class TargetMachine;
 
 class ARMInstPrinter : public MCInstPrinter {
 public:
-  ARMInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {}
+  ARMInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
+    : MCInstPrinter(MAI) {}
 
   virtual void printInst(const MCInst *MI, raw_ostream &O);
   virtual StringRef getOpcodeName(unsigned Opcode) const;
index bebc6c83d5448ede1cb4367f7537bf6975ea7795..13c4b49f981cfc5e6a37cf4fd89caba55c030aac 100644 (file)
 
 namespace llvm {
   class MCOperand;
+  class TargetMachine;
 
   class MBlazeInstPrinter : public MCInstPrinter {
   public:
-    MBlazeInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {
-    }
+    MBlazeInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
+      : MCInstPrinter(MAI) {}
 
     virtual void printInst(const MCInst *MI, raw_ostream &O);
 
index 0016df569b93e935a8cd90635495c7020bb19c87..0f0f60e69f082f6f34b6e2fa6d10067cf16747fd 100644 (file)
@@ -319,10 +319,11 @@ isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
 }
 
 static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T,
+                                                TargetMachine &TM,
                                                 unsigned SyntaxVariant,
                                                 const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new MBlazeInstPrinter(MAI);
+    return new MBlazeInstPrinter(TM, MAI);
   return 0;
 }
 
index f0e1ce22841b5ce20697413a0b210775f68d4460..63860dcc7e3ade0ce2a8f1637080db17ef69df80 100644 (file)
 
 namespace llvm {
   class MCOperand;
+  class TargetMachine;
 
   class MSP430InstPrinter : public MCInstPrinter {
   public:
-    MSP430InstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {
-    }
+    MSP430InstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
+      : MCInstPrinter(MAI) {}
 
     virtual void printInst(const MCInst *MI, raw_ostream &O);
 
index a1a7f44c19c484cab303e35dd08b2890cb75952a..5264d680d8b391183e7119ea0731cdcb7be7953f 100644 (file)
@@ -164,10 +164,11 @@ void MSP430AsmPrinter::EmitInstruction(const MachineInstr *MI) {
 }
 
 static MCInstPrinter *createMSP430MCInstPrinter(const Target &T,
+                                                TargetMachine &TM,
                                                 unsigned SyntaxVariant,
                                                 const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new MSP430InstPrinter(MAI);
+    return new MSP430InstPrinter(TM, MAI);
   return 0;
 }
 
index ebc10daa5f16d67df4f4039471e534170a4567ef..9cf9db9c26b78567541d4f94342d011c15025ffe 100644 (file)
 #include "llvm/MC/MCInstPrinter.h"
 
 namespace llvm {
-  class MCOperand;
+
+class MCOperand;
+class TargetMachine;
 
 class PPCInstPrinter : public MCInstPrinter {
   // 0 -> AIX, 1 -> Darwin.
   unsigned SyntaxVariant;
 public:
-  PPCInstPrinter(const MCAsmInfo &MAI, unsigned syntaxVariant)
+  PPCInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI,
+                 unsigned syntaxVariant)
     : MCInstPrinter(MAI), SyntaxVariant(syntaxVariant) {}
   
   bool isDarwinSyntax() const {
index 8ed5d7f0ee7101d5ca5f39525539e4cd4a80ee21..09a9be998247cad6949064d3c9427ec20ad6f93d 100644 (file)
@@ -680,9 +680,10 @@ static AsmPrinter *createPPCAsmPrinterPass(TargetMachine &tm,
 }
 
 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
+                                             TargetMachine &TM,
                                              unsigned SyntaxVariant,
                                              const MCAsmInfo &MAI) {
-  return new PPCInstPrinter(MAI, SyntaxVariant);
+  return new PPCInstPrinter(TM, MAI, SyntaxVariant);
 }
 
 
index eb986643014c782f30d0fde91c34d72ee2686485..0a10c6c1a6b39495782ec7ab8516cffb92604de0 100644 (file)
 #include "llvm/MC/MCInstPrinter.h"
 
 namespace llvm {
-  class MCOperand;
+
+class MCOperand;
+class TargetMachine;
   
 class X86ATTInstPrinter : public MCInstPrinter {
 public:
-  X86ATTInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {}
-
+  X86ATTInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
+    : MCInstPrinter(MAI) {}
   
   virtual void printInst(const MCInst *MI, raw_ostream &OS);
   virtual StringRef getOpcodeName(unsigned Opcode) const;
index 6f120322742b274455931a64d3f68ac7a876d66b..b1dc3f46941415c5515a58cdf8fd29fe06737e7b 100644 (file)
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
-  class MCOperand;
+
+class MCOperand;
+class TargetMachine;
   
 class X86IntelInstPrinter : public MCInstPrinter {
 public:
-  X86IntelInstPrinter(const MCAsmInfo &MAI)
+  X86IntelInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
     : MCInstPrinter(MAI) {}
   
   virtual void printInst(const MCInst *MI, raw_ostream &OS);
index 99b4479a9fc9ba9a67ca89d3b17c0a9bf744cf76..c2d53c4dd26cf1b9bb5883d00bf39e50c76beb39 100644 (file)
@@ -709,12 +709,13 @@ void X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
 //===----------------------------------------------------------------------===//
 
 static MCInstPrinter *createX86MCInstPrinter(const Target &T,
+                                             TargetMachine &TM,
                                              unsigned SyntaxVariant,
                                              const MCAsmInfo &MAI) {
   if (SyntaxVariant == 0)
-    return new X86ATTInstPrinter(MAI);
+    return new X86ATTInstPrinter(TM, MAI);
   if (SyntaxVariant == 1)
-    return new X86IntelInstPrinter(MAI);
+    return new X86IntelInstPrinter(TM, MAI);
   return 0;
 }
 
index d98b57ebc6591e5193c5672b8b2fd05d3f214513..41b92a1b302156189397d32ca932f122434322ec 100644 (file)
@@ -127,7 +127,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
   return false;
 }
 
-int Disassembler::disassemble(const Target &T, const std::string &Triple,
+int Disassembler::disassemble(const Target &T,  TargetMachine &TM,
+                              const std::string &Triple,
                               MemoryBuffer &Buffer,
                               raw_ostream &Out) {
   // Set up disassembler.
@@ -145,7 +146,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
   }
   
   int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
-  OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant,
+  OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(TM, AsmPrinterVariant,
                                                     *AsmInfo));
   if (!IP) {
     errs() << "error: no instruction printer for target " << Triple << '\n';
index b56f2e95455582a6265decfbfc1493f7ab08122b..aaf77b5a0ff713c0a4a2bd64c57c15d63a6aec9e 100644 (file)
 
 namespace llvm {
 
-class Target;
 class MemoryBuffer;
+class Target;
+class TargetMachine;
 class raw_ostream;
 
 class Disassembler {
 public:
-  static int disassemble(const Target &target, 
+  static int disassemble(const Target &target,
+                         TargetMachine &TM,
                          const std::string &tripleString,
                          MemoryBuffer &buffer,
                          raw_ostream &Out);
index 2c22bedf1c2d6ad787b14c5fbc7dddcd8b46d36a..b7818665abf0ff5b3d80bdef9890a31aeeb6509d 100644 (file)
@@ -342,7 +342,7 @@ static int AssembleInput(const char *ProgName) {
   // FIXME: There is a bit of code duplication with addPassesToEmitFile.
   if (FileType == OFT_AssemblyFile) {
     MCInstPrinter *IP =
-      TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI);
+      TheTarget->createMCInstPrinter(*TM, OutputAsmVariant, *MAI);
     MCCodeEmitter *CE = 0;
     TargetAsmBackend *TAB = 0;
     if (ShowEncoding) {
@@ -403,12 +403,34 @@ static int DisassembleInput(const char *ProgName, bool Enhanced) {
     return 1;
 
   int Res;
-  if (Enhanced)
+  if (Enhanced) {
     Res =
       Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os());
-  else
-    Res = Disassembler::disassemble(*TheTarget, TripleName,
+  } else {
+    // Package up features to be passed to target/subtarget
+    std::string FeaturesStr;
+    if (MCPU.size()) {
+      SubtargetFeatures Features;
+      Features.setCPU(MCPU);
+      FeaturesStr = Features.getString();
+    }
+
+    // FIXME: We shouldn't need to do this (and link in codegen).
+    //        When we split this out, we should do it in a way that makes
+    //        it straightforward to switch subtargets on the fly (.e.g,
+    //        the .cpu and .code16 directives).
+    OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
+                                                               FeaturesStr));
+
+    if (!TM) {
+      errs() << ProgName << ": error: could not create target for triple '"
+             << TripleName << "'.\n";
+      return 1;
+    }
+
+    Res = Disassembler::disassemble(*TheTarget, *TM, TripleName,
                                     *Buffer.take(), Out->os());
+  }
 
   // Keep output if no errors.
   if (Res == 0) Out->keep();
index 1fef8b6e2496f4fa454d060d4d01e1aa510f31a0..de0165690aecfbc7463390d4ecd76e3d8190786a 100644 (file)
@@ -38,6 +38,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/system_error.h"
+#include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetRegistry.h"
 #include "llvm/Target/TargetSelect.h"
 #include <algorithm>
@@ -182,9 +183,21 @@ static void DisassembleInput(const StringRef &Filename) {
       return;
     }
 
+    // FIXME: We shouldn't need to do this (and link in codegen).
+    //        When we split this out, we should do it in a way that makes
+    //        it straightforward to switch subtargets on the fly (.e.g,
+    //        the .cpu and .code16 directives).
+    std::string FeaturesStr;
+    OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
+                                                               FeaturesStr));
+    if (!TM) {
+      errs() << "error: could not create target for triple " << TripleName << "\n";
+      return;
+    }
+
     int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
     OwningPtr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
-                                  AsmPrinterVariant, *AsmInfo));
+                                  *TM, AsmPrinterVariant, *AsmInfo));
     if (!IP) {
       errs() << "error: no instruction printer for target " << TripleName << '\n';
       return;