119 lines · cpp
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-exception6//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 21namespace llvm {22namespace offload {23namespace tblgen {24 25enum ActionType {26 PrintRecords,27 DumpJSON,28 GenAPI,29 GenDoc,30 GenFuncNames,31 GenImplFuncDecls,32 GenEntryPoints,33 GenPrintHeader,34 GenExports,35 GenErrcodes,36 GenInfo,37};38 39namespace {40cl::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 66static bool OffloadTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {67 switch (Action) {68 case PrintRecords:69 OS << Records;70 break;71 case DumpJSON:72 EmitJSON(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 106int OffloadTblgenMain(int argc, char **argv) {107 InitLLVM y(argc, argv);108 cl::ParseCommandLineOptions(argc, argv);109 return TableGenMain(argv[0], &OffloadTableGenMain);110}111} // namespace tblgen112} // namespace offload113} // namespace llvm114 115using namespace llvm;116using namespace offload::tblgen;117 118int main(int argc, char **argv) { return OffloadTblgenMain(argc, argv); }119