//===- TableGenBackend.cpp - Utilities for TableGen Backends ----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file provides useful services for TableGen backends... // //===----------------------------------------------------------------------===// #include "llvm/TableGen/TableGenBackend.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cassert> #include <cstddef> usingnamespacellvm; usingnamespaceTableGen::Emitter; const size_t MAX_LINE_LEN = …; // CommandLine options of class type are not directly supported with some // specific exceptions like std::string which are safe to copy. In our case, // the `FnT` function_ref object is also safe to copy. So provide a // specialization of `OptionValue` for `FnT` type that stores it as a copy. // This is essentially similar to OptionValue<std::string> specialization for // strings. template <> struct cl::OptionValue<FnT> final : cl::OptionValueCopy<FnT> { … }; namespace { struct OptCreatorT { … }; } // namespace static ManagedStatic<cl::opt<FnT>, OptCreatorT> CallbackFunction; Opt::Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault) { … } /// Apply callback specified on the command line. Returns true if no callback /// was applied. bool llvm::TableGen::Emitter::ApplyCallback(const RecordKeeper &Records, raw_ostream &OS) { … } static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill, StringRef Suffix) { … } void llvm::emitSourceFileHeader(StringRef Desc, raw_ostream &OS, const RecordKeeper &Record) { … }