I prepared this patch and I noticed we're using composition through MCTargetStreamer to achieve a type of polymorphism as in:
MCTargetStreamer *TS = getTargetStreamer(); if (TS) TS->emitLabel(Symbol); MCTargetStreamer *TS = getTargetStreamer(); if (TS) TS->emitAssignment(Symbol, Value);
I did this in-kind with MCAsmStreamer::getInstPrinter though let me know if we want to do this a different way, perhaps through subclassing MCAsmStreamer. Previously I had hooked createMCAsmStreamer in the TargetRegistry though this has been recently removed.
static MCStreamer *
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
bool isVerboseAsm, bool useDwarfDirectory, MCInstPrinter *IP, MCCodeEmitter *CE, MCAsmBackend *MAB, bool ShowInst) { HexagonAsmInstPrinter *HIP = new HexagonAsmInstPrinter(IP); MCStreamer *S = llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory, HIP, CE, MAB, ShowInst); new HexagonTargetAsmStreamer(*S, Ctx, OS, isVerboseAsm, HIP); return S;
}
I needed to create a pretty-printing MCInstPrinter that llvm-mc can use when asm streaming and this seemed like the most direct way to incorporate this functionality.
The crux of the issue is many users of MCInstPrinter, llvm-mc, llvm-objdump, lldb, assume the output of MCInstPrinter is short and on one line and can be decorated in the front and back with disassembly context, function names, addresses, annotations etc. When the instruction gets longer than a line the output looks weird and should be pretty-printed by the user.
Let me know if anyone has ideas if/how this could be better implemented.