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]"));
35 llvm::cl::opt
<bool> ExportDecls(
37 llvm::cl::desc("Output a new header containing only the entrypoints."));
39 void ParseArgValuePairs(std::unordered_map
<std::string
, std::string
> &Map
) {
40 for (std::string
&R
: ReplacementValues
) {
41 auto Pair
= llvm::StringRef(R
).split('=');
42 Map
[std::string(Pair
.first
)] = std::string(Pair
.second
);
46 } // anonymous namespace
50 bool HeaderGeneratorMain(llvm::raw_ostream
&OS
, llvm::RecordKeeper
&Records
) {
51 std::unordered_map
<std::string
, std::string
> ArgMap
;
52 ParseArgValuePairs(ArgMap
);
53 Generator
G(HeaderDefFile
, EntrypointNamesOption
, StandardHeader
, ArgMap
);
55 G
.generateDecls(OS
, Records
);
57 G
.generate(OS
, Records
);
62 } // namespace llvm_libc
64 int main(int argc
, char *argv
[]) {
65 llvm::cl::ParseCommandLineOptions(argc
, argv
);
66 return TableGenMain(argv
[0], &llvm_libc::HeaderGeneratorMain
);