[PATCH] D138323: {TableGen] RegisterInfo backend - Add abstraction layer between code generation logic and syntax output

Rot127 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 18 12:37:25 PST 2022


Rot127 created this revision.
Rot127 added reviewers: myhsu, 0x59616e.
Rot127 added a project: LLVM.
Herald added a project: All.
Rot127 requested review of this revision.
Herald added a subscriber: llvm-commits.

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`.

The code generation stays in the TableGen backend. The generated syntax string however is written by an implementation of `PrinterInterface` 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 to the output stream.

Before this patch the TableGen backend wrote the generated code and its 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 output (`PrinterInterface`) it is easier to output syntax of other languages.
It is only necessary to implement the methods of the `PrinterInterface` class and emit the 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.
If this gets upstreamed I will refactor other backends over this and the next month.

For more background info 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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138323

Files:
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/Printer.cpp
  llvm/utils/TableGen/Printer.h
  llvm/utils/TableGen/PrinterLLVM.cpp
  llvm/utils/TableGen/PrinterTypes.h
  llvm/utils/TableGen/RegisterInfoEmitter.cpp
  llvm/utils/TableGen/RegisterInfoEmitterTypes.h
  llvm/utils/TableGen/SequenceToOffsetTable.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138323.476551.patch
Type: text/x-patch
Size: 155296 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221118/32d5393d/attachment-0001.bin>


More information about the llvm-commits mailing list