xref: /freebsd-src/contrib/llvm-project/llvm/lib/TableGen/TableGenBackendSkeleton.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1e8d8bef9SDimitry Andric //===- SkeletonEmitter.cpp - Skeleton TableGen backend          -*- C++ -*-===//
2e8d8bef9SDimitry Andric //
3e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e8d8bef9SDimitry Andric //
7e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8e8d8bef9SDimitry Andric //
9e8d8bef9SDimitry Andric // This Tablegen backend emits ...
10e8d8bef9SDimitry Andric //
11e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
12e8d8bef9SDimitry Andric 
131fd87a68SDimitry Andric #include "llvm/ADT/StringRef.h"
14e8d8bef9SDimitry Andric #include "llvm/TableGen/TableGenBackend.h"
15e8d8bef9SDimitry Andric 
16e8d8bef9SDimitry Andric #define DEBUG_TYPE "skeleton-emitter"
17e8d8bef9SDimitry Andric 
181fd87a68SDimitry Andric namespace llvm {
191fd87a68SDimitry Andric class RecordKeeper;
201fd87a68SDimitry Andric class raw_ostream;
211fd87a68SDimitry Andric } // namespace llvm
221fd87a68SDimitry Andric 
23e8d8bef9SDimitry Andric using namespace llvm;
24e8d8bef9SDimitry Andric 
25e8d8bef9SDimitry Andric namespace {
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric // Any helper data structures can be defined here. Some backends use
28e8d8bef9SDimitry Andric // structs to collect information from the records.
29e8d8bef9SDimitry Andric 
30e8d8bef9SDimitry Andric class SkeletonEmitter {
31e8d8bef9SDimitry Andric private:
32e8d8bef9SDimitry Andric   RecordKeeper &Records;
33e8d8bef9SDimitry Andric 
34e8d8bef9SDimitry Andric public:
SkeletonEmitter(RecordKeeper & RK)35e8d8bef9SDimitry Andric   SkeletonEmitter(RecordKeeper &RK) : Records(RK) {}
36e8d8bef9SDimitry Andric 
37e8d8bef9SDimitry Andric   void run(raw_ostream &OS);
38e8d8bef9SDimitry Andric }; // emitter class
39e8d8bef9SDimitry Andric 
40e8d8bef9SDimitry Andric } // anonymous namespace
41e8d8bef9SDimitry Andric 
run(raw_ostream & OS)42e8d8bef9SDimitry Andric void SkeletonEmitter::run(raw_ostream &OS) {
43e8d8bef9SDimitry Andric   emitSourceFileHeader("Skeleton data structures", OS);
44e8d8bef9SDimitry Andric 
45e8d8bef9SDimitry Andric   (void)Records; // To suppress unused variable warning; remove on use.
46e8d8bef9SDimitry Andric }
47e8d8bef9SDimitry Andric 
48*06c3fb27SDimitry Andric // Choose either option A or B.
49e8d8bef9SDimitry Andric 
50*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
51*06c3fb27SDimitry Andric // Option A: Register the backed as class <SkeletonEmitter>
52*06c3fb27SDimitry Andric static TableGen::Emitter::OptClass<SkeletonEmitter>
53*06c3fb27SDimitry Andric     X("gen-skeleton-class", "Generate example skeleton class");
54e8d8bef9SDimitry Andric 
55*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
56*06c3fb27SDimitry Andric // Option B: Register "EmitSkeleton" directly
57*06c3fb27SDimitry Andric // The emitter entry may be private scope.
EmitSkeleton(RecordKeeper & RK,raw_ostream & OS)58*06c3fb27SDimitry Andric static void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) {
59e8d8bef9SDimitry Andric   // Instantiate the emitter class and invoke run().
60e8d8bef9SDimitry Andric   SkeletonEmitter(RK).run(OS);
61e8d8bef9SDimitry Andric }
62e8d8bef9SDimitry Andric 
63*06c3fb27SDimitry Andric static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton,
64*06c3fb27SDimitry Andric                                 "Generate example skeleton entry");
65