xref: /freebsd-src/contrib/llvm-project/llvm/utils/TableGen/TableGenBackends.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===- TableGenBackends.h - Declarations for LLVM TableGen Backends -------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the declarations for all of the LLVM TableGen
100b57cec5SDimitry Andric // backends. A "TableGen backend" is just a function. See below for a
110b57cec5SDimitry Andric // precise description.
120b57cec5SDimitry Andric //
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifndef LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H
160b57cec5SDimitry Andric #define LLVM_UTILS_TABLEGEN_TABLEGENBACKENDS_H
170b57cec5SDimitry Andric 
18*06c3fb27SDimitry Andric #include <string>
19*06c3fb27SDimitry Andric 
200b57cec5SDimitry Andric // A TableGen backend is a function that looks like
210b57cec5SDimitry Andric //
220b57cec5SDimitry Andric //    EmitFoo(RecordKeeper &RK, raw_ostream &OS /*, anything else you need */ )
230b57cec5SDimitry Andric //
240b57cec5SDimitry Andric // What you do inside of that function is up to you, but it will usually
250b57cec5SDimitry Andric // involve generating C++ code to the provided raw_ostream.
260b57cec5SDimitry Andric //
270b57cec5SDimitry Andric // The RecordKeeper is just a top-level container for an in-memory
280b57cec5SDimitry Andric // representation of the data encoded in the TableGen file. What a TableGen
290b57cec5SDimitry Andric // backend does is walk around that in-memory representation and generate
300b57cec5SDimitry Andric // stuff based on the information it contains.
310b57cec5SDimitry Andric //
320b57cec5SDimitry Andric // The in-memory representation is a node-graph (think of it like JSON but
330b57cec5SDimitry Andric // with a richer ontology of types), where the nodes are subclasses of
340b57cec5SDimitry Andric // Record. The methods `getClass`, `getDef` are the basic interface to
350b57cec5SDimitry Andric // access the node-graph.  RecordKeeper also provides a handy method
360b57cec5SDimitry Andric // `getAllDerivedDefinitions`. Consult "include/llvm/TableGen/Record.h" for
370b57cec5SDimitry Andric // the exact interfaces provided by Record's and RecordKeeper.
380b57cec5SDimitry Andric //
390b57cec5SDimitry Andric // A common pattern for TableGen backends is for the EmitFoo function to
400b57cec5SDimitry Andric // instantiate a class which holds some context for the generation process,
410b57cec5SDimitry Andric // and then have most of the work happen in that class's methods. This
420b57cec5SDimitry Andric // pattern partly has historical roots in the previous TableGen backend API
430b57cec5SDimitry Andric // that involved a class and an invocation like `FooEmitter(RK).run(OS)`.
440b57cec5SDimitry Andric //
450b57cec5SDimitry Andric // Remember to wrap private things in an anonymous namespace. For most
460b57cec5SDimitry Andric // backends, this means that the EmitFoo function is the only thing not in
470b57cec5SDimitry Andric // the anonymous namespace.
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric // FIXME: Reorganize TableGen so that build dependencies can be more
500b57cec5SDimitry Andric // accurately expressed. Currently, touching any of the emitters (or
510b57cec5SDimitry Andric // anything that they transitively depend on) causes everything dependent
520b57cec5SDimitry Andric // on TableGen to be rebuilt (this includes all the targets!). Perhaps have
530b57cec5SDimitry Andric // a standalone TableGen binary and have the backends be loadable modules
540b57cec5SDimitry Andric // of some sort; then the dependency could be expressed as being on the
550b57cec5SDimitry Andric // module, and all the modules would have a common dependency on the
560b57cec5SDimitry Andric // TableGen binary with as few dependencies as possible on the rest of
570b57cec5SDimitry Andric // LLVM.
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric namespace llvm {
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric class raw_ostream;
620b57cec5SDimitry Andric class RecordKeeper;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric void EmitMapTable(RecordKeeper &RK, raw_ostream &OS);
650b57cec5SDimitry Andric 
66*06c3fb27SDimitry Andric // Defined in DecoderEmitter.cpp
67*06c3fb27SDimitry Andric void EmitDecoder(RecordKeeper &RK, raw_ostream &OS,
68*06c3fb27SDimitry Andric                  const std::string &PredicateNamespace);
69*06c3fb27SDimitry Andric 
70*06c3fb27SDimitry Andric } // namespace llvm
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric #endif
73