This is an archive of the discontinued LLVM Phabricator instance.

Specializing AsmStreamer InstPrinter
AbandonedPublic

Authored by colinl on May 29 2015, 4:00 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

colinl updated this revision to Diff 26830.May 29 2015, 4:00 PM
colinl retitled this revision from to Specializing AsmStreamer InstPrinter.
colinl updated this object.
colinl edited the test plan for this revision. (Show Details)
colinl added reviewers: rafael, Bigcheese.
colinl set the repository for this revision to rL LLVM.
colinl added a subscriber: Unknown Object (MLST).
colinl abandoned this revision.Jun 18 2015, 2:27 PM