This patch introduces an abstraction layer for TableGen backends. It separates the code generation logic and the syntax string output into separated modules.
One module is the backend (`RegisterInfo` in this patch), the other an implementation of the abstract class `PrinterInterface`LLVM`.
The code generation stays in the TableGen backend. The generated syntax stringsyntax generation however is written by an implementation of `PrinterInterface`moved to `PrinterLLVM`, which writes the result to the output stream.
Whenever the backend has generated a piece of code it requests the `PrinterInterface` to write the syntax to the output stream.
The `PrinterInterface` only gets the necessary objects from the backend (e.g. Records to write, Register names etc.) and writes the syntax string`PrinterLLVM` to write the syntax to the output stream.
Before this patch the TableGen backend wrote the generated code and itsthe syntax on its own to the output stream.
This had the disadvantage that no other languages, then the default C++ syntax, could be output easily.
With the separation of the code generation (backend) and syntax outputgeneration (`PrinterInterface`LLVM`) it is easier to output syntax of other languages.
It is only necessary toalso possible write a printer which emits only specific parts of the generated code.
A new printer only implements the methods of the `PrinterInterface` clasLLVM` it needs and emit thes its language syntax which is needed.
In this patch the `RegisterInfo` backend was refactored to use the `PrinterInterface` (`PrinterInterface` implementation in `PrinterLLVM.cpp`) as output module.`PrinterLLVM` as output module.
If this gets upstreamed I can provide the refactor for the following modules in the next days:
- DecoderEmitter
- SubtargetInfo
- InstructionInfo
If this gets upstreamed I will refactor other backends over this and the next month.- AsmMatcher
For more background info and where this idea is coming from you can take a look at:
_Feedback implementation_
https://reviews.llvm.org/D136808
_Discussion in discourse.llvm.org_
https://discourse.llvm.org/t/comments-needed-for-refactoring-decoderemitter-tablegen-backend/65738