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/DenseMapInfo.h" 141fd87a68SDimitry Andric #include "llvm/ADT/StringRef.h" 15e8d8bef9SDimitry Andric #include "llvm/TableGen/TableGenBackend.h" 16e8d8bef9SDimitry Andric 17e8d8bef9SDimitry Andric #define DEBUG_TYPE "skeleton-emitter" 18e8d8bef9SDimitry Andric 191fd87a68SDimitry Andric namespace llvm { 201fd87a68SDimitry Andric class RecordKeeper; 211fd87a68SDimitry Andric class raw_ostream; 221fd87a68SDimitry Andric } // namespace llvm 231fd87a68SDimitry Andric 24e8d8bef9SDimitry Andric using namespace llvm; 25e8d8bef9SDimitry Andric 26e8d8bef9SDimitry Andric namespace { 27e8d8bef9SDimitry Andric 28e8d8bef9SDimitry Andric // Any helper data structures can be defined here. Some backends use 29e8d8bef9SDimitry Andric // structs to collect information from the records. 30e8d8bef9SDimitry Andric 31e8d8bef9SDimitry Andric class SkeletonEmitter { 32e8d8bef9SDimitry Andric private: 33e8d8bef9SDimitry Andric RecordKeeper &Records; 34e8d8bef9SDimitry Andric 35e8d8bef9SDimitry Andric public: 36e8d8bef9SDimitry Andric SkeletonEmitter(RecordKeeper &RK) : Records(RK) {} 37e8d8bef9SDimitry Andric 38e8d8bef9SDimitry Andric void run(raw_ostream &OS); 39e8d8bef9SDimitry Andric }; // emitter class 40e8d8bef9SDimitry Andric 41e8d8bef9SDimitry Andric } // anonymous namespace 42e8d8bef9SDimitry Andric 43e8d8bef9SDimitry Andric void SkeletonEmitter::run(raw_ostream &OS) { 44e8d8bef9SDimitry Andric emitSourceFileHeader("Skeleton data structures", OS); 45e8d8bef9SDimitry Andric 46e8d8bef9SDimitry Andric (void)Records; // To suppress unused variable warning; remove on use. 47e8d8bef9SDimitry Andric } 48e8d8bef9SDimitry Andric 49*06c3fb27SDimitry Andric // Choose either option A or B. 50e8d8bef9SDimitry Andric 51*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 52*06c3fb27SDimitry Andric // Option A: Register the backed as class <SkeletonEmitter> 53*06c3fb27SDimitry Andric static TableGen::Emitter::OptClass<SkeletonEmitter> 54*06c3fb27SDimitry Andric X("gen-skeleton-class", "Generate example skeleton class"); 55e8d8bef9SDimitry Andric 56*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 57*06c3fb27SDimitry Andric // Option B: Register "EmitSkeleton" directly 58*06c3fb27SDimitry Andric // The emitter entry may be private scope. 59*06c3fb27SDimitry Andric static void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) { 60e8d8bef9SDimitry Andric // Instantiate the emitter class and invoke run(). 61e8d8bef9SDimitry Andric SkeletonEmitter(RK).run(OS); 62e8d8bef9SDimitry Andric } 63e8d8bef9SDimitry Andric 64*06c3fb27SDimitry Andric static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, 65*06c3fb27SDimitry Andric "Generate example skeleton entry"); 66