llvm-objdump: syntax highlighting based on rich disassembly

Hi all,

I'm going to implement syntax highlighting in llvm-objdump based on
Rich Disassembly[1] and I'd like to hear your comments on how should I
implement it. Now I have two ideas to implement the feature:

(a) Make MCInstPrinter return a well-typed value and traverse it in
llvm-objdump to highlight the disassembly.
(b) Parse the rich disassembly output string in the llvm-objdump and
highlight the disassembly.

Making MCInstPrinter return the "well-typed" marked-up value just like
abstract syntax tree instead of writing an annotated string into a
raw_ostream sounds more preferable way to me. However, it would
involve large changes to the existing MCInstPrinter implementations.

In contrast, parsing the rich disassembly output in llvm-objdump
sounds a bit awkward, but we don't need to change the MCInstPrinter at
all. That said, parsing the text surely degrades the disassemble
performance so we should disable the parsing and highlighting by
default. I wrote and uploaded a prototype of this [2].

Do you have any thoughts?

Thanks,
Seiya

[1] https://llvm.org/docs/MarkedUpDisassembly.html
[2] ⚙ D64311 [llvm-objdump] Implement syntax highlighting

Hi all,

I’m going to implement syntax highlighting in llvm-objdump based on
Rich Disassembly[1] and I’d like to hear your comments on how should I
implement it. Now I have two ideas to implement the feature:

(a) Make MCInstPrinter return a well-typed value and traverse it in
llvm-objdump to highlight the disassembly.
(b) Parse the rich disassembly output string in the llvm-objdump and
highlight the disassembly.

Making MCInstPrinter return the “well-typed” marked-up value just like
abstract syntax tree instead of writing an annotated string into a
raw_ostream sounds more preferable way to me. However, it would
involve large changes to the existing MCInstPrinter implementations.

In contrast, parsing the rich disassembly output in llvm-objdump
sounds a bit awkward, but we don’t need to change the MCInstPrinter at
all. That said, parsing the text surely degrades the disassemble
performance so we should disable the parsing and highlighting by
default. I wrote and uploaded a prototype of this [2].

Do you have any thoughts?

Thanks,
Seiya

[1] https://llvm.org/docs/MarkedUpDisassembly.html
[2] https://reviews.llvm.org/D64311

I really dislike the idea of having llvm-objdump do any assembly parsing.

Another solution would be to have MCInstPrinter also be able to store (range, semantic) pairs that can then be used to insert highlighting.

  • Michael Spencer

Hi all,

I've uploaded the series of patches for this feature (you can see some
screenshots on the Phabricator):

https://reviews.llvm.org/D65191