Index: include/llvm/MC/MCStreamer.h =================================================================== --- include/llvm/MC/MCStreamer.h +++ include/llvm/MC/MCStreamer.h @@ -72,11 +72,13 @@ class MCTargetStreamer { protected: MCStreamer &Streamer; + MCInstPrinter *InstPrinter; public: MCTargetStreamer(MCStreamer &S); virtual ~MCTargetStreamer(); + MCInstPrinter *getInstPrinter() { return InstPrinter; } const MCStreamer &getStreamer() { return Streamer; } // Allow a target to add behavior to the EmitLabel of MCStreamer. Index: lib/MC/MCAsmStreamer.cpp =================================================================== --- lib/MC/MCAsmStreamer.cpp +++ lib/MC/MCAsmStreamer.cpp @@ -70,6 +70,16 @@ InstPrinter->setCommentStream(CommentStream); } + MCInstPrinter *getInstPrinter() { + auto Streamer = getTargetStreamer(); + if(Streamer != nullptr) { + auto Printer = Streamer->getInstPrinter(); + if(Printer != nullptr) + return Printer; + } + return InstPrinter.get(); + } + inline void EmitEOL() { // If we don't have any comments, just emit a \n. if (!IsVerboseAsm) { @@ -949,7 +959,7 @@ if (!MAI->useDwarfRegNumForCFI()) { const MCRegisterInfo *MRI = getContext().getRegisterInfo(); unsigned LLVMRegister = MRI->getLLVMRegNum(Register, true); - InstPrinter->printRegName(OS, LLVMRegister); + getInstPrinter()->printRegName(OS, LLVMRegister); } else { OS << Register; } @@ -1256,11 +1266,11 @@ // Show the MCInst if enabled. if (ShowInst) { - Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n "); + Inst.dump_pretty(GetCommentOS(), getInstPrinter(), "\n "); GetCommentOS() << "\n"; } - InstPrinter->printInst(&Inst, OS, "", STI); + getInstPrinter()->printInst(&Inst, OS, "", STI); EmitEOL(); } Index: lib/MC/MCStreamer.cpp =================================================================== --- lib/MC/MCStreamer.cpp +++ lib/MC/MCStreamer.cpp @@ -29,7 +29,8 @@ // Pin the vtables to this file. MCTargetStreamer::~MCTargetStreamer() {} -MCTargetStreamer::MCTargetStreamer(MCStreamer &S) : Streamer(S) { +MCTargetStreamer::MCTargetStreamer(MCStreamer &S) + : Streamer(S), InstPrinter(nullptr) { S.setTargetStreamer(this); } Index: lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h =================================================================== --- lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h +++ lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h @@ -24,7 +24,7 @@ void printInst(MCInst const *MI, raw_ostream &O, StringRef Annot, MCSubtargetInfo const &STI) override; void printRegName(raw_ostream &O, unsigned RegNo) const override; - std::unique_ptr RawPrinter; + MCInstPrinter *RawPrinter; }; /// Prints bundles as a newline separated list of individual instructions /// Duplexes are separated by a vertical tab \v character Index: lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp =================================================================== --- lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp +++ lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp @@ -35,6 +35,21 @@ #define GET_REGINFO_MC_DESC #include "HexagonGenRegisterInfo.inc" +namespace { +class HexagonTargetAsmStreamer : public MCTargetStreamer { + formatted_raw_ostream &OS; + bool isVerboseAsm; + HexagonAsmInstPrinter IP; +public: + HexagonTargetAsmStreamer(MCStreamer &S, + formatted_raw_ostream &OS, MCInstPrinter *IPrinter, bool isVerboseAsm + ) + : MCTargetStreamer(S), OS(OS), isVerboseAsm(isVerboseAsm), IP (IPrinter) { + InstPrinter = &IP; + } +}; +} + MCInstrInfo *llvm::createHexagonMCInstrInfo() { MCInstrInfo *X = new MCInstrInfo(); InitHexagonMCInstrInfo(X); @@ -87,6 +102,12 @@ return nullptr; } +static MCTargetStreamer * +createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, + bool IsVerboseAsm) { + return new HexagonTargetAsmStreamer(S, OS, InstPrint, IsVerboseAsm); +} + // Force static initialization. extern "C" void LLVMInitializeHexagonTargetMC() { // Register the MC asm info. @@ -112,6 +133,10 @@ TargetRegistry::RegisterMCCodeEmitter(TheHexagonTarget, createHexagonMCCodeEmitter); + // Register the asm streamer + TargetRegistry::RegisterAsmTargetStreamer(TheHexagonTarget, + createMCAsmTargetStreamer); + // Register the MC Inst Printer TargetRegistry::RegisterMCInstPrinter(TheHexagonTarget, createHexagonMCInstPrinter);