fix an ugly wart in the MCInstPrinter api where the

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
This commit is contained in:
Chris Lattner 2010-04-04 05:04:31 +00:00
parent 35c33bd772
commit d374087be5
18 changed files with 42 additions and 58 deletions

View 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.

View 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);
}

View 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,

View 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();

View 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;
}

View 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);

View 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);

View 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;
}

View 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);
}

View File

@ -16,18 +16,15 @@
#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);

View 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);

View 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.

View 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;
}

View 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);

View 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.

View 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();

View 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;

View 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(),