Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:36

0001 //===- llvm/TableGen/TableGenBackend.h - Backend utilities ------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Useful utilities for TableGen backends.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_TABLEGEN_TABLEGENBACKEND_H
0014 #define LLVM_TABLEGEN_TABLEGENBACKEND_H
0015 
0016 #include "llvm/ADT/STLFunctionalExtras.h"
0017 #include "llvm/ADT/StringRef.h"
0018 #include "llvm/TableGen/Record.h"
0019 
0020 namespace llvm {
0021 
0022 class RecordKeeper;
0023 class raw_ostream;
0024 
0025 namespace TableGen::Emitter {
0026 using FnT = function_ref<void(const RecordKeeper &Records, raw_ostream &OS)>;
0027 
0028 /// Creating an `Opt` object registers the command line option \p Name with
0029 /// TableGen backend and associates the callback \p CB with that option. If
0030 /// \p ByDefault is true, then that callback is applied by default if no
0031 /// command line option was specified.
0032 struct Opt {
0033   Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault = false);
0034 };
0035 
0036 /// Convienence wrapper around `Opt` that registers `EmitterClass::run` as the
0037 /// callback.
0038 template <class EmitterC> class OptClass : Opt {
0039   static void run(const RecordKeeper &RK, raw_ostream &OS) {
0040     EmitterC(RK).run(OS);
0041   }
0042 
0043 public:
0044   OptClass(StringRef Name, StringRef Desc) : Opt(Name, run, Desc) {}
0045 };
0046 
0047 /// Apply callback for any command line option registered above. Returns false
0048 /// is no callback was applied.
0049 bool ApplyCallback(const RecordKeeper &Records, raw_ostream &OS);
0050 
0051 } // namespace TableGen::Emitter
0052 
0053 /// emitSourceFileHeader - Output an LLVM style file header to the specified
0054 /// raw_ostream.
0055 void emitSourceFileHeader(StringRef Desc, raw_ostream &OS,
0056                           const RecordKeeper &Record = RecordKeeper());
0057 
0058 } // namespace llvm
0059 
0060 #endif // LLVM_TABLEGEN_TABLEGENBACKEND_H