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 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:
- To allow multiple language output of this backend, all the generated strings are managed by class inherited from PrinterInterface (see details below).
- Splits the single DecoderEmitter.cpp file into multiple files for readability purposes and unites them under their own namespace.
- Adds a sequence diagram about the generation process (to give a rough overview).
- Adds documentation how the decoder works (state machine) and describes how the decoding state machine is build.
- For readability some very long methods were shortened by extracting code into separated methods.
- 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.
double quotes are not necessary here, please remove them for better readability