1 | //===- offload-tblgen/offload-tblgen.cpp ----------------------------------===// |
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 | // This is a Tablegen tool that produces source files for the Offload project. |
10 | // See offload/API/README.md for more information. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "llvm/Support/CommandLine.h" |
15 | #include "llvm/Support/InitLLVM.h" |
16 | #include "llvm/TableGen/Main.h" |
17 | #include "llvm/TableGen/Record.h" |
18 | |
19 | #include "Generators.hpp" |
20 | |
21 | namespace llvm { |
22 | namespace offload { |
23 | namespace tblgen { |
24 | |
25 | enum ActionType { |
26 | PrintRecords, |
27 | DumpJSON, |
28 | GenAPI, |
29 | GenFuncNames, |
30 | GenImplFuncDecls, |
31 | GenEntryPoints, |
32 | , |
33 | GenExports, |
34 | GenErrcodes, |
35 | }; |
36 | |
37 | namespace { |
38 | cl::opt<ActionType> Action( |
39 | cl::desc("Action to perform:" ), |
40 | cl::values( |
41 | clEnumValN(PrintRecords, "print-records" , |
42 | "Print all records to stdout (default)" ), |
43 | clEnumValN(DumpJSON, "dump-json" , |
44 | "Dump all records as machine-readable JSON" ), |
45 | clEnumValN(GenAPI, "gen-api" , "Generate Offload API header contents" ), |
46 | clEnumValN(GenFuncNames, "gen-func-names" , |
47 | "Generate a list of all Offload API function names" ), |
48 | clEnumValN( |
49 | GenImplFuncDecls, "gen-impl-func-decls" , |
50 | "Generate declarations for Offload API implementation functions" ), |
51 | clEnumValN(GenEntryPoints, "gen-entry-points" , |
52 | "Generate Offload API wrapper function definitions" ), |
53 | clEnumValN(GenPrintHeader, "gen-print-header" , |
54 | "Generate Offload API print header" ), |
55 | clEnumValN(GenExports, "gen-exports" , |
56 | "Generate export file for the Offload library" ), |
57 | clEnumValN(GenErrcodes, "gen-errcodes" , |
58 | "Generate Offload Error Code enum" ))); |
59 | } |
60 | |
61 | static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) { |
62 | switch (Action) { |
63 | case PrintRecords: |
64 | OS << Records; |
65 | break; |
66 | case DumpJSON: |
67 | EmitJSON(RK: Records, OS); |
68 | break; |
69 | case GenAPI: |
70 | EmitOffloadAPI(Records, OS); |
71 | break; |
72 | case GenFuncNames: |
73 | EmitOffloadFuncNames(Records, OS); |
74 | break; |
75 | case GenImplFuncDecls: |
76 | EmitOffloadImplFuncDecls(Records, OS); |
77 | break; |
78 | case GenEntryPoints: |
79 | EmitOffloadEntryPoints(Records, OS); |
80 | break; |
81 | case GenPrintHeader: |
82 | EmitOffloadPrintHeader(Records, OS); |
83 | break; |
84 | case GenExports: |
85 | EmitOffloadExports(Records, OS); |
86 | break; |
87 | case GenErrcodes: |
88 | EmitOffloadErrcodes(Records, OS); |
89 | break; |
90 | } |
91 | |
92 | return false; |
93 | } |
94 | |
95 | int OffloadTblgenMain(int argc, char **argv) { |
96 | InitLLVM y(argc, argv); |
97 | cl::ParseCommandLineOptions(argc, argv); |
98 | return TableGenMain(argv0: argv[0], MainFn: &OffloadTableGenMain); |
99 | } |
100 | } // namespace tblgen |
101 | } // namespace offload |
102 | } // namespace llvm |
103 | |
104 | using namespace llvm; |
105 | using namespace offload::tblgen; |
106 | |
107 | int main(int argc, char **argv) { return OffloadTblgenMain(argc, argv); } |
108 | |