[PATCH] D111658: Add JSON output skeleton to llvm-readelf

Jayson Yan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 21:55:54 PDT 2021


Jaysonyan added a comment.

> 4. Change `JSONScopedPrinter` to derive from `ReadobjScopedPrinter` and implement the additional functions (and move it into the llvm-readobj code).

One thing that makes this implementation plan difficult is that `JSONScopedPrinter` needs to output valid json. There are some methods offered by
`ScopedPrinter` that would make it difficult to ensure a `JSONScopedPrinter` prints valid json while still offering these methods. The most notable
is `startLine()` which provides direct access to the underlying `raw_ostream`.  If the `JSONScopedPrinter` inherits from `ScopedPrinter` I don't believe
there is a way around not offering this method.

All implementations of `ObjDumper` utilize methods such as `startLine()` or perform other operations that may be undesirable/invalid to in json such as
not enclosing each method in its own child object or having duplicate object keys (ex `COFFDumper::printCOFFExports`). So it may be preferable to keep
the current structure and have `ObjDumper` implementations rely on a specific printer-type. Since passing a `JSONScopedPrinter` to any dumper that isn't
the `JSONELFDumper` would likely produce invalid json.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111658/new/

https://reviews.llvm.org/D111658



More information about the llvm-commits mailing list