1b60736ecSDimitry Andric //===- SkeletonEmitter.cpp - Skeleton TableGen backend -*- C++ -*-===// 2b60736ecSDimitry Andric // 3b60736ecSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b60736ecSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5b60736ecSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b60736ecSDimitry Andric // 7b60736ecSDimitry Andric //===----------------------------------------------------------------------===// 8b60736ecSDimitry Andric // 9b60736ecSDimitry Andric // This Tablegen backend emits ... 10b60736ecSDimitry Andric // 11b60736ecSDimitry Andric //===----------------------------------------------------------------------===// 12b60736ecSDimitry Andric 13ecbca9f5SDimitry Andric #include "llvm/ADT/StringRef.h" 14b60736ecSDimitry Andric #include "llvm/TableGen/TableGenBackend.h" 15b60736ecSDimitry Andric 16b60736ecSDimitry Andric #define DEBUG_TYPE "skeleton-emitter" 17b60736ecSDimitry Andric 18ecbca9f5SDimitry Andric namespace llvm { 19ecbca9f5SDimitry Andric class RecordKeeper; 20ecbca9f5SDimitry Andric class raw_ostream; 21ecbca9f5SDimitry Andric } // namespace llvm 22ecbca9f5SDimitry Andric 23b60736ecSDimitry Andric using namespace llvm; 24b60736ecSDimitry Andric 25b60736ecSDimitry Andric namespace { 26b60736ecSDimitry Andric 27b60736ecSDimitry Andric // Any helper data structures can be defined here. Some backends use 28b60736ecSDimitry Andric // structs to collect information from the records. 29b60736ecSDimitry Andric 30b60736ecSDimitry Andric class SkeletonEmitter { 31b60736ecSDimitry Andric private: 32b60736ecSDimitry Andric RecordKeeper &Records; 33b60736ecSDimitry Andric 34b60736ecSDimitry Andric public: SkeletonEmitter(RecordKeeper & RK)35b60736ecSDimitry Andric SkeletonEmitter(RecordKeeper &RK) : Records(RK) {} 36b60736ecSDimitry Andric 37b60736ecSDimitry Andric void run(raw_ostream &OS); 38b60736ecSDimitry Andric }; // emitter class 39b60736ecSDimitry Andric 40b60736ecSDimitry Andric } // anonymous namespace 41b60736ecSDimitry Andric run(raw_ostream & OS)42b60736ecSDimitry Andricvoid SkeletonEmitter::run(raw_ostream &OS) { 43b60736ecSDimitry Andric emitSourceFileHeader("Skeleton data structures", OS); 44b60736ecSDimitry Andric 45b60736ecSDimitry Andric (void)Records; // To suppress unused variable warning; remove on use. 46b60736ecSDimitry Andric } 47b60736ecSDimitry Andric 487fa27ce4SDimitry Andric // Choose either option A or B. 49b60736ecSDimitry Andric 507fa27ce4SDimitry Andric //===----------------------------------------------------------------------===// 517fa27ce4SDimitry Andric // Option A: Register the backed as class <SkeletonEmitter> 527fa27ce4SDimitry Andric static TableGen::Emitter::OptClass<SkeletonEmitter> 537fa27ce4SDimitry Andric X("gen-skeleton-class", "Generate example skeleton class"); 54b60736ecSDimitry Andric 557fa27ce4SDimitry Andric //===----------------------------------------------------------------------===// 567fa27ce4SDimitry Andric // Option B: Register "EmitSkeleton" directly 577fa27ce4SDimitry Andric // The emitter entry may be private scope. EmitSkeleton(RecordKeeper & RK,raw_ostream & OS)587fa27ce4SDimitry Andricstatic void EmitSkeleton(RecordKeeper &RK, raw_ostream &OS) { 59b60736ecSDimitry Andric // Instantiate the emitter class and invoke run(). 60b60736ecSDimitry Andric SkeletonEmitter(RK).run(OS); 61b60736ecSDimitry Andric } 62b60736ecSDimitry Andric 637fa27ce4SDimitry Andric static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, 647fa27ce4SDimitry Andric "Generate example skeleton entry"); 65