1 //===-- Base class for header generation commands ---------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIBC_UTILS_HDRGEN_COMMAND_H 10 #define LLVM_LIBC_UTILS_HDRGEN_COMMAND_H 11 12 #include "llvm/ADT/SmallVector.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/ADT/Twine.h" 15 #include "llvm/Support/SourceMgr.h" 16 17 #include <cstdlib> 18 19 namespace llvm { 20 21 class raw_ostream; 22 class RecordKeeper; 23 24 } // namespace llvm 25 26 namespace llvm_libc { 27 28 typedef llvm::SmallVector<llvm::StringRef, 4> ArgVector; 29 30 class Command { 31 public: 32 class ErrorReporter { 33 llvm::SMLoc Loc; 34 const llvm::SourceMgr &SrcMgr; 35 36 public: ErrorReporter(llvm::SMLoc L,llvm::SourceMgr & SM)37 ErrorReporter(llvm::SMLoc L, llvm::SourceMgr &SM) : Loc(L), SrcMgr(SM) {} 38 printFatalError(llvm::Twine Msg)39 [[noreturn]] void printFatalError(llvm::Twine Msg) const { 40 SrcMgr.PrintMessage(Loc, llvm::SourceMgr::DK_Error, Msg); 41 std::exit(1); 42 } 43 }; 44 45 virtual ~Command(); 46 47 virtual void run(llvm::raw_ostream &OS, const ArgVector &Args, 48 llvm::StringRef StdHeader, llvm::RecordKeeper &Records, 49 const ErrorReporter &Reporter) const = 0; 50 }; 51 52 } // namespace llvm_libc 53 54 #endif // LLVM_LIBC_UTILS_HDRGEN_COMMAND_H 55