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
19namespace llvm {
20
21class raw_ostream;
22class RecordKeeper;
23
24} // namespace llvm
25
26namespace llvm_libc {
27
28typedef llvm::SmallVector<llvm::StringRef, 4> ArgVector;
29
30class Command {
31public:
32 class ErrorReporter {
33 llvm::SMLoc Loc;
34 const llvm::SourceMgr &SrcMgr;
35
36 public:
37 ErrorReporter(llvm::SMLoc L, llvm::SourceMgr &SM) : Loc(L), SrcMgr(SM) {}
38
39 [[noreturn]] void printFatalError(llvm::Twine Msg) const {
40 SrcMgr.PrintMessage(Loc, llvm::SourceMgr::DK_Error, Msg);
41 std::exit(status: 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

source code of libc/utils/HdrGen/Command.h