| 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 | GenDoc, |
| 30 | GenFuncNames, |
| 31 | GenImplFuncDecls, |
| 32 | GenEntryPoints, |
| 33 | , |
| 34 | GenExports, |
| 35 | GenErrcodes, |
| 36 | GenInfo, |
| 37 | }; |
| 38 | |
| 39 | namespace { |
| 40 | cl::opt<ActionType> Action( |
| 41 | cl::desc("Action to perform:" ), |
| 42 | cl::values( |
| 43 | clEnumValN(PrintRecords, "print-records" , |
| 44 | "Print all records to stdout (default)" ), |
| 45 | clEnumValN(DumpJSON, "dump-json" , |
| 46 | "Dump all records as machine-readable JSON" ), |
| 47 | clEnumValN(GenAPI, "gen-api" , "Generate Offload API header contents" ), |
| 48 | clEnumValN(GenDoc, "gen-doc" , |
| 49 | "Generate Offload API documentation contents" ), |
| 50 | clEnumValN(GenFuncNames, "gen-func-names" , |
| 51 | "Generate a list of all Offload API function names" ), |
| 52 | clEnumValN( |
| 53 | GenImplFuncDecls, "gen-impl-func-decls" , |
| 54 | "Generate declarations for Offload API implementation functions" ), |
| 55 | clEnumValN(GenEntryPoints, "gen-entry-points" , |
| 56 | "Generate Offload API wrapper function definitions" ), |
| 57 | clEnumValN(GenPrintHeader, "gen-print-header" , |
| 58 | "Generate Offload API print header" ), |
| 59 | clEnumValN(GenExports, "gen-exports" , |
| 60 | "Generate export file for the Offload library" ), |
| 61 | clEnumValN(GenErrcodes, "gen-errcodes" , |
| 62 | "Generate Offload Error Code enum" ), |
| 63 | clEnumValN(GenInfo, "gen-info" , "Generate Offload Info enum" ))); |
| 64 | } |
| 65 | |
| 66 | static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) { |
| 67 | switch (Action) { |
| 68 | case PrintRecords: |
| 69 | OS << Records; |
| 70 | break; |
| 71 | case DumpJSON: |
| 72 | EmitJSON(RK: Records, OS); |
| 73 | break; |
| 74 | case GenAPI: |
| 75 | EmitOffloadAPI(Records, OS); |
| 76 | break; |
| 77 | case GenDoc: |
| 78 | EmitOffloadDoc(Records, OS); |
| 79 | break; |
| 80 | case GenFuncNames: |
| 81 | EmitOffloadFuncNames(Records, OS); |
| 82 | break; |
| 83 | case GenImplFuncDecls: |
| 84 | EmitOffloadImplFuncDecls(Records, OS); |
| 85 | break; |
| 86 | case GenEntryPoints: |
| 87 | EmitOffloadEntryPoints(Records, OS); |
| 88 | break; |
| 89 | case GenPrintHeader: |
| 90 | EmitOffloadPrintHeader(Records, OS); |
| 91 | break; |
| 92 | case GenExports: |
| 93 | EmitOffloadExports(Records, OS); |
| 94 | break; |
| 95 | case GenErrcodes: |
| 96 | EmitOffloadErrcodes(Records, OS); |
| 97 | break; |
| 98 | case GenInfo: |
| 99 | EmitOffloadInfo(Records, OS); |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | int OffloadTblgenMain(int argc, char **argv) { |
| 107 | InitLLVM y(argc, argv); |
| 108 | cl::ParseCommandLineOptions(argc, argv); |
| 109 | return TableGenMain(argv0: argv[0], MainFn: &OffloadTableGenMain); |
| 110 | } |
| 111 | } // namespace tblgen |
| 112 | } // namespace offload |
| 113 | } // namespace llvm |
| 114 | |
| 115 | using namespace llvm; |
| 116 | using namespace offload::tblgen; |
| 117 | |
| 118 | int main(int argc, char **argv) { return OffloadTblgenMain(argc, argv); } |
| 119 | |