1 //===-- "main" function of libc-hdrgen ------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/CommandLine.h"
13 #include "llvm/TableGen/Main.h"
16 #include <unordered_map>
20 llvm::cl::opt
<std::string
>
21 HeaderDefFile("def", llvm::cl::desc("Path to the .h.def file."),
22 llvm::cl::value_desc("<filename>"), llvm::cl::Required
);
23 llvm::cl::opt
<std::string
> StandardHeader(
25 llvm::cl::desc("The standard header file which is to be generated."),
26 llvm::cl::value_desc("<header file>"));
27 llvm::cl::list
<std::string
> EntrypointNamesOption(
28 "e", llvm::cl::value_desc("<list of entrypoints>"),
30 "Each --e is one entrypoint (generated from entrypoints.txt)"),
32 llvm::cl::list
<std::string
> ReplacementValues(
33 "args", llvm::cl::desc("Command separated <argument name>=<value> pairs."),
34 llvm::cl::value_desc("<name=value>[,name=value]"));
36 void ParseArgValuePairs(std::unordered_map
<std::string
, std::string
> &Map
) {
37 for (std::string
&R
: ReplacementValues
) {
38 auto Pair
= llvm::StringRef(R
).split('=');
39 Map
[std::string(Pair
.first
)] = std::string(Pair
.second
);
43 } // anonymous namespace
47 bool HeaderGeneratorMain(llvm::raw_ostream
&OS
, llvm::RecordKeeper
&Records
) {
48 std::unordered_map
<std::string
, std::string
> ArgMap
;
49 ParseArgValuePairs(ArgMap
);
50 Generator
G(HeaderDefFile
, EntrypointNamesOption
, StandardHeader
, ArgMap
);
51 G
.generate(OS
, Records
);
56 } // namespace llvm_libc
58 int main(int argc
, char *argv
[]) {
59 llvm::cl::ParseCommandLineOptions(argc
, argv
);
60 return TableGenMain(argv
[0], &llvm_libc::HeaderGeneratorMain
);