[PATCH] Specializing AsmStreamer InstPrinter

Colin LeMahieu colinl at codeaurora.org
Fri May 29 16:00:40 PDT 2015


Hi rafael, Bigcheese,

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.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D10142

Files:
  include/llvm/MC/MCStreamer.h
  lib/MC/MCAsmStreamer.cpp
  lib/MC/MCStreamer.cpp
  lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.h
  lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10142.26830.patch
Type: text/x-patch
Size: 4768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150529/7146e6d8/attachment.bin>


More information about the llvm-commits mailing list