1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

We need to pass the TargetMachine object to the InstPrinter if we are printing

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.

llvm-svn: 127986
This commit is contained in:
Bill Wendling 2011-03-21 04:13:46 +00:00
parent 59d24b6777
commit a2eec46242
18 changed files with 90 additions and 32 deletions

View File

@ -78,6 +78,7 @@ namespace llvm {
TargetMachine &TM); TargetMachine &TM);
typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T); typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T, typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI); const MCAsmInfo &MAI);
typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T, typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
@ -286,11 +287,12 @@ namespace llvm {
return MCDisassemblerCtorFn(*this); return MCDisassemblerCtorFn(*this);
} }
MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant, MCInstPrinter *createMCInstPrinter(TargetMachine &TM,
unsigned SyntaxVariant,
const MCAsmInfo &MAI) const { const MCAsmInfo &MAI) const {
if (!MCInstPrinterCtorFn) if (!MCInstPrinterCtorFn)
return 0; return 0;
return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI); return MCInstPrinterCtorFn(*this, TM, SyntaxVariant, MAI);
} }

View File

@ -133,7 +133,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
default: return true; default: return true;
case CGFT_AssemblyFile: { case CGFT_AssemblyFile: {
MCInstPrinter *InstPrinter = MCInstPrinter *InstPrinter =
getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI); getTarget().createMCInstPrinter(*this, MAI.getAssemblerDialect(), MAI);
// Create a code emitter if asked to show the encoding. // Create a code emitter if asked to show the encoding.
MCCodeEmitter *MCE = 0; MCCodeEmitter *MCE = 0;

View File

@ -193,7 +193,8 @@ EDDisassembler::EDDisassembler(CPUKey &key) :
InstString.reset(new std::string); InstString.reset(new std::string);
InstStream.reset(new raw_string_ostream(*InstString)); InstStream.reset(new raw_string_ostream(*InstString));
InstPrinter.reset(Tgt->createMCInstPrinter(LLVMSyntaxVariant, *AsmInfo)); InstPrinter.reset(Tgt->createMCInstPrinter(*TargetMachine, LLVMSyntaxVariant,
*AsmInfo));
if (!InstPrinter) if (!InstPrinter)
return; return;

View File

@ -1791,10 +1791,11 @@ void ARMAsmPrinter::EmitInstruction(const MachineInstr *MI) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static MCInstPrinter *createARMMCInstPrinter(const Target &T, static MCInstPrinter *createARMMCInstPrinter(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI) { const MCAsmInfo &MAI) {
if (SyntaxVariant == 0) if (SyntaxVariant == 0)
return new ARMInstPrinter(MAI); return new ARMInstPrinter(TM, MAI);
return 0; return 0;
} }

View File

@ -17,11 +17,14 @@
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
namespace llvm { namespace llvm {
class MCOperand;
class MCOperand;
class TargetMachine;
class ARMInstPrinter : public MCInstPrinter { class ARMInstPrinter : public MCInstPrinter {
public: 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 void printInst(const MCInst *MI, raw_ostream &O);
virtual StringRef getOpcodeName(unsigned Opcode) const; virtual StringRef getOpcodeName(unsigned Opcode) const;

View File

@ -18,11 +18,12 @@
namespace llvm { namespace llvm {
class MCOperand; class MCOperand;
class TargetMachine;
class MBlazeInstPrinter : public MCInstPrinter { class MBlazeInstPrinter : public MCInstPrinter {
public: public:
MBlazeInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) { MBlazeInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
} : MCInstPrinter(MAI) {}
virtual void printInst(const MCInst *MI, raw_ostream &O); virtual void printInst(const MCInst *MI, raw_ostream &O);

View File

@ -319,10 +319,11 @@ isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const {
} }
static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T, static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI) { const MCAsmInfo &MAI) {
if (SyntaxVariant == 0) if (SyntaxVariant == 0)
return new MBlazeInstPrinter(MAI); return new MBlazeInstPrinter(TM, MAI);
return 0; return 0;
} }

View File

@ -18,11 +18,12 @@
namespace llvm { namespace llvm {
class MCOperand; class MCOperand;
class TargetMachine;
class MSP430InstPrinter : public MCInstPrinter { class MSP430InstPrinter : public MCInstPrinter {
public: public:
MSP430InstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) { MSP430InstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
} : MCInstPrinter(MAI) {}
virtual void printInst(const MCInst *MI, raw_ostream &O); virtual void printInst(const MCInst *MI, raw_ostream &O);

View File

@ -164,10 +164,11 @@ void MSP430AsmPrinter::EmitInstruction(const MachineInstr *MI) {
} }
static MCInstPrinter *createMSP430MCInstPrinter(const Target &T, static MCInstPrinter *createMSP430MCInstPrinter(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI) { const MCAsmInfo &MAI) {
if (SyntaxVariant == 0) if (SyntaxVariant == 0)
return new MSP430InstPrinter(MAI); return new MSP430InstPrinter(TM, MAI);
return 0; return 0;
} }

View File

@ -17,13 +17,16 @@
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
namespace llvm { namespace llvm {
class MCOperand;
class MCOperand;
class TargetMachine;
class PPCInstPrinter : public MCInstPrinter { class PPCInstPrinter : public MCInstPrinter {
// 0 -> AIX, 1 -> Darwin. // 0 -> AIX, 1 -> Darwin.
unsigned SyntaxVariant; unsigned SyntaxVariant;
public: public:
PPCInstPrinter(const MCAsmInfo &MAI, unsigned syntaxVariant) PPCInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI,
unsigned syntaxVariant)
: MCInstPrinter(MAI), SyntaxVariant(syntaxVariant) {} : MCInstPrinter(MAI), SyntaxVariant(syntaxVariant) {}
bool isDarwinSyntax() const { bool isDarwinSyntax() const {

View File

@ -680,9 +680,10 @@ static AsmPrinter *createPPCAsmPrinterPass(TargetMachine &tm,
} }
static MCInstPrinter *createPPCMCInstPrinter(const Target &T, static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI) { const MCAsmInfo &MAI) {
return new PPCInstPrinter(MAI, SyntaxVariant); return new PPCInstPrinter(TM, MAI, SyntaxVariant);
} }

View File

@ -17,12 +17,14 @@
#include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstPrinter.h"
namespace llvm { namespace llvm {
class MCOperand;
class MCOperand;
class TargetMachine;
class X86ATTInstPrinter : public MCInstPrinter { class X86ATTInstPrinter : public MCInstPrinter {
public: 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 void printInst(const MCInst *MI, raw_ostream &OS);
virtual StringRef getOpcodeName(unsigned Opcode) const; virtual StringRef getOpcodeName(unsigned Opcode) const;

View File

@ -18,11 +18,13 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
namespace llvm { namespace llvm {
class MCOperand;
class MCOperand;
class TargetMachine;
class X86IntelInstPrinter : public MCInstPrinter { class X86IntelInstPrinter : public MCInstPrinter {
public: public:
X86IntelInstPrinter(const MCAsmInfo &MAI) X86IntelInstPrinter(TargetMachine &TM, const MCAsmInfo &MAI)
: MCInstPrinter(MAI) {} : MCInstPrinter(MAI) {}
virtual void printInst(const MCInst *MI, raw_ostream &OS); virtual void printInst(const MCInst *MI, raw_ostream &OS);

View File

@ -709,12 +709,13 @@ void X86AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static MCInstPrinter *createX86MCInstPrinter(const Target &T, static MCInstPrinter *createX86MCInstPrinter(const Target &T,
TargetMachine &TM,
unsigned SyntaxVariant, unsigned SyntaxVariant,
const MCAsmInfo &MAI) { const MCAsmInfo &MAI) {
if (SyntaxVariant == 0) if (SyntaxVariant == 0)
return new X86ATTInstPrinter(MAI); return new X86ATTInstPrinter(TM, MAI);
if (SyntaxVariant == 1) if (SyntaxVariant == 1)
return new X86IntelInstPrinter(MAI); return new X86IntelInstPrinter(TM, MAI);
return 0; return 0;
} }

View File

@ -127,7 +127,8 @@ static bool ByteArrayFromString(ByteArrayTy &ByteArray,
return false; 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, MemoryBuffer &Buffer,
raw_ostream &Out) { raw_ostream &Out) {
// Set up disassembler. // Set up disassembler.
@ -145,7 +146,7 @@ int Disassembler::disassemble(const Target &T, const std::string &Triple,
} }
int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(AsmPrinterVariant, OwningPtr<MCInstPrinter> IP(T.createMCInstPrinter(TM, AsmPrinterVariant,
*AsmInfo)); *AsmInfo));
if (!IP) { if (!IP) {
errs() << "error: no instruction printer for target " << Triple << '\n'; errs() << "error: no instruction printer for target " << Triple << '\n';

View File

@ -19,13 +19,15 @@
namespace llvm { namespace llvm {
class Target;
class MemoryBuffer; class MemoryBuffer;
class Target;
class TargetMachine;
class raw_ostream; class raw_ostream;
class Disassembler { class Disassembler {
public: public:
static int disassemble(const Target &target, static int disassemble(const Target &target,
TargetMachine &TM,
const std::string &tripleString, const std::string &tripleString,
MemoryBuffer &buffer, MemoryBuffer &buffer,
raw_ostream &Out); raw_ostream &Out);

View File

@ -342,7 +342,7 @@ static int AssembleInput(const char *ProgName) {
// FIXME: There is a bit of code duplication with addPassesToEmitFile. // FIXME: There is a bit of code duplication with addPassesToEmitFile.
if (FileType == OFT_AssemblyFile) { if (FileType == OFT_AssemblyFile) {
MCInstPrinter *IP = MCInstPrinter *IP =
TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI); TheTarget->createMCInstPrinter(*TM, OutputAsmVariant, *MAI);
MCCodeEmitter *CE = 0; MCCodeEmitter *CE = 0;
TargetAsmBackend *TAB = 0; TargetAsmBackend *TAB = 0;
if (ShowEncoding) { if (ShowEncoding) {
@ -403,12 +403,34 @@ static int DisassembleInput(const char *ProgName, bool Enhanced) {
return 1; return 1;
int Res; int Res;
if (Enhanced) if (Enhanced) {
Res = Res =
Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os()); Disassembler::disassembleEnhanced(TripleName, *Buffer.take(), Out->os());
else } else {
Res = Disassembler::disassemble(*TheTarget, TripleName, // 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()); *Buffer.take(), Out->os());
}
// Keep output if no errors. // Keep output if no errors.
if (Res == 0) Out->keep(); if (Res == 0) Out->keep();

View File

@ -38,6 +38,7 @@
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/system_error.h" #include "llvm/Support/system_error.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetSelect.h" #include "llvm/Target/TargetSelect.h"
#include <algorithm> #include <algorithm>
@ -182,9 +183,21 @@ static void DisassembleInput(const StringRef &Filename) {
return; 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(); int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
OwningPtr<MCInstPrinter> IP(TheTarget->createMCInstPrinter( OwningPtr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
AsmPrinterVariant, *AsmInfo)); *TM, AsmPrinterVariant, *AsmInfo));
if (!IP) { if (!IP) {
errs() << "error: no instruction printer for target " << TripleName << '\n'; errs() << "error: no instruction printer for target " << TripleName << '\n';
return; return;