From 3b9efca8e8b5f853b782645ec45cb8ed843d7297 Mon Sep 17 00:00:00 2001 From: Alexei Starovoitov Date: Tue, 13 Dec 2016 19:07:08 +0000 Subject: [PATCH] [bpf] change llvm-objdump to print dec instead of hex since bpf instruction stream is multiple of 8 change llvm-objdump to print decimal instruction number instead of hex address, so that users don't have to do this math manually to match kernel verifier output Signed-off-by: Alexei Starovoitov llvm-svn: 289569 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 319d8afcc0b0..8373f0ce3f1e 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -594,6 +594,26 @@ public: }; AMDGCNPrettyPrinter AMDGCNPrettyPrinterInst; +class BPFPrettyPrinter : public PrettyPrinter { +public: + void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef Bytes, + uint64_t Address, raw_ostream &OS, StringRef Annot, + MCSubtargetInfo const &STI, SourcePrinter *SP) override { + if (SP && (PrintSource || PrintLines)) + SP->printSourceLine(OS, Address); + OS << format("%8" PRId64 ":", Address / 8); + if (!NoShowRawInsn) { + OS << "\t"; + dumpBytes(Bytes, OS); + } + if (MI) + IP.printInst(MI, OS, "", STI); + else + OS << " "; + } +}; +BPFPrettyPrinter BPFPrettyPrinterInst; + PrettyPrinter &selectPrettyPrinter(Triple const &Triple) { switch(Triple.getArch()) { default: @@ -602,6 +622,9 @@ PrettyPrinter &selectPrettyPrinter(Triple const &Triple) { return HexagonPrettyPrinterInst; case Triple::amdgcn: return AMDGCNPrettyPrinterInst; + case Triple::bpfel: + case Triple::bpfeb: + return BPFPrettyPrinterInst; } } }