1 //===-- The main header generation class ------------------------*- 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_GENERATOR_H
10 #define LLVM_LIBC_UTILS_HDRGEN_GENERATOR_H
11 
12 #include "Command.h"
13 
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringRef.h"
16 
17 #include <memory>
18 #include <string>
19 #include <unordered_map>
20 
21 namespace llvm {
22 
23 class raw_ostream;
24 class RecordKeeper;
25 
26 } // namespace llvm
27 
28 namespace llvm_libc {
29 
30 class Command;
31 
32 class Generator {
33   llvm::StringRef HeaderDefFile;
34   llvm::StringRef StdHeader;
35   std::unordered_map<std::string, std::string> &ArgMap;
36 
37   std::unique_ptr<Command> IncludeFileCmd;
38   std::unique_ptr<Command> PublicAPICmd;
39 
40   Command *getCommandHandler(llvm::StringRef CommandName);
41 
42   void parseCommandArgs(llvm::StringRef ArgStr, ArgVector &Args);
43 
44   void printError(llvm::StringRef Msg);
45 
46 public:
Generator(const std::string & DefFile,const std::string & Header,std::unordered_map<std::string,std::string> & Map)47   Generator(const std::string &DefFile, const std::string &Header,
48             std::unordered_map<std::string, std::string> &Map)
49       : HeaderDefFile(DefFile), StdHeader(Header), ArgMap(Map) {}
50 
51   void generate(llvm::raw_ostream &OS, llvm::RecordKeeper &Records);
52 };
53 
54 } // namespace llvm_libc
55 
56 #endif // LLVM_LIBC_UTILS_HDRGEN_GENERATOR_H
57