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