[PATCH] D136808: Refactor Tblgen DecoderEmitter to allow multiple language output
Rot127 via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 26 18:11:17 PDT 2022
Rot127 created this revision.
Rot127 added reviewers: resistor, 0x59616e, grosbach.
Herald added a project: All.
Rot127 requested review of this revision.
Herald added a project: LLVM.
This refactor of the TableGen `DecoderEmitter` allows to output the generated code in different languages (C is added here).
Please note that this review request is for feedback purpose only and not meant to be merged.
The changes were made on branch `llvm-15.0.3`.
**Justification**
The necessity for this refactor came from our wish at Capstone <https://github.com/capstone-engine/capstone> to generate the decoder tables and decoder methods/functions in C and not C++.
Simply patching our fork would have ended in regular maintenance work which we would like to avoid (especially since we had to do it for at least four backends).
Since translating the generated C++ to C with scripts is a mess we wanted a more fundamental solution.
**Summary**
The refactor does the following:
1. To allow multiple language output of this backend, all the generated strings are managed by class inherited from `PrinterInterface` (see details below).
2. Splits the single `DecoderEmitter.cpp` file into multiple files for readability purposes and unites them under their own namespace.
3. Adds a sequence diagram about the generation process (to give a rough overview).
4. Adds documentation how the decoder works (state machine) and describes how the decoding state machine is build.
5. For readability some very long methods were shortened by extracting code into separated methods.
6. The generation logic was not touched in any way (Except two variable renamings so they match the documentation (`FilteredInstructions` -> `FilteredInstrSubsets`, `VariableInstructions` -> `VariableInstrSubsets`)).
The newly introduced "Printer" classes (`PrinterInterface` and children) handle all strings which are emitted into the output stream.
For each language there exists an implementation of the abstract `PrinterInterface` (here C++ and C for Capstone).
The `DecoderEmitter` and `FilterChooser` have an instance of a `PrinterInterface` and request strings from it or trigger the writing of the code to the output stream.
Depending on the language which should be written a different implementation of the `PrinterInterface` is set in `DecoderEmitter` and `FilterChooser`.
**Feedback request**
Other backends which emit code would need a "PrinterInterface" as well (e.g. `AsmWriter`, `RegisterInfo`, `InstrInfo`, `SubtargetInfo`).
The changes made here are a lot. Hence I don't expect and wouldn't want them to be merged.
But I kindly ask you for your feedback.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136808
Files:
llvm/utils/TableGen/CMakeLists.txt
llvm/utils/TableGen/DecoderEmitter.cpp
llvm/utils/TableGen/DecoderEmitter/CMakeLists.txt
llvm/utils/TableGen/DecoderEmitter/DecoderEmitter.cpp
llvm/utils/TableGen/DecoderEmitter/DecoderEmitter.h
llvm/utils/TableGen/DecoderEmitter/DecoderEmitterTypes.h
llvm/utils/TableGen/DecoderEmitter/Filter.cpp
llvm/utils/TableGen/DecoderEmitter/FilterChooser.cpp
llvm/utils/TableGen/DecoderEmitter/HelperFunctions.cpp
llvm/utils/TableGen/DecoderEmitter/InstructionDecoding.md
llvm/utils/TableGen/DecoderEmitter/Printer.h
llvm/utils/TableGen/DecoderEmitter/PrinterCapstone.cpp
llvm/utils/TableGen/DecoderEmitter/PrinterLLVM.cpp
llvm/utils/TableGen/DecoderEmitter/README.md
llvm/utils/TableGen/DisassemblerEmitter.cpp
llvm/utils/TableGen/TableGen.cpp
llvm/utils/TableGen/TableGenBackends.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136808.470969.patch
Type: text/x-patch
Size: 264272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221027/017be428/attachment-0001.bin>
More information about the llvm-commits
mailing list