Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / utils / HdrGen / Command.h
blob895f472c3ad32dec4b15d13894b255f44fd8b2e7
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_UTILS_HDRGEN_COMMAND_H
10 #define LLVM_LIBC_UTILS_HDRGEN_COMMAND_H
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/SourceMgr.h"
17 #include <cstdlib>
19 namespace llvm {
21 class raw_ostream;
22 class RecordKeeper;
24 } // namespace llvm
26 namespace llvm_libc {
28 typedef llvm::SmallVector<llvm::StringRef, 4> ArgVector;
30 class Command {
31 public:
32 class ErrorReporter {
33 llvm::SMLoc Loc;
34 const llvm::SourceMgr &SrcMgr;
36 public:
37 ErrorReporter(llvm::SMLoc L, llvm::SourceMgr &SM) : Loc(L), SrcMgr(SM) {}
39 [[noreturn]] void printFatalError(llvm::Twine Msg) const {
40 SrcMgr.PrintMessage(Loc, llvm::SourceMgr::DK_Error, Msg);
41 std::exit(1);
45 virtual ~Command();
47 virtual void run(llvm::raw_ostream &OS, const ArgVector &Args,
48 llvm::StringRef StdHeader, llvm::RecordKeeper &Records,
49 const ErrorReporter &Reporter) const = 0;
52 } // namespace llvm_libc
54 #endif // LLVM_LIBC_UTILS_HDRGEN_COMMAND_H