| 1 | //===- MlirPdllLspServerMain.cpp - MLIR PDLL Language Server main ---------===// |
| 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 | #include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h" |
| 10 | #include "LSPServer.h" |
| 11 | #include "PDLLServer.h" |
| 12 | #include "mlir/Tools/lsp-server-support/Logging.h" |
| 13 | #include "mlir/Tools/lsp-server-support/Transport.h" |
| 14 | #include "llvm/Support/CommandLine.h" |
| 15 | #include "llvm/Support/Program.h" |
| 16 | |
| 17 | using namespace mlir; |
| 18 | using namespace mlir::lsp; |
| 19 | |
| 20 | LogicalResult mlir::MlirPdllLspServerMain(int argc, char **argv) { |
| 21 | llvm::cl::opt<JSONStreamStyle> inputStyle{ |
| 22 | "input-style" , |
| 23 | llvm::cl::desc("Input JSON stream encoding" ), |
| 24 | llvm::cl::values(clEnumValN(JSONStreamStyle::Standard, "standard" , |
| 25 | "usual LSP protocol" ), |
| 26 | clEnumValN(JSONStreamStyle::Delimited, "delimited" , |
| 27 | "messages delimited by `// -----` lines, " |
| 28 | "with // comment support" )), |
| 29 | llvm::cl::init(Val: JSONStreamStyle::Standard), |
| 30 | llvm::cl::Hidden, |
| 31 | }; |
| 32 | llvm::cl::opt<bool> litTest{ |
| 33 | "lit-test" , |
| 34 | llvm::cl::desc( |
| 35 | "Abbreviation for -input-style=delimited -pretty -log=verbose. " |
| 36 | "Intended to simplify lit tests" ), |
| 37 | llvm::cl::init(Val: false), |
| 38 | }; |
| 39 | llvm::cl::opt<Logger::Level> logLevel{ |
| 40 | "log" , |
| 41 | llvm::cl::desc("Verbosity of log messages written to stderr" ), |
| 42 | llvm::cl::values( |
| 43 | clEnumValN(Logger::Level::Error, "error" , "Error messages only" ), |
| 44 | clEnumValN(Logger::Level::Info, "info" , |
| 45 | "High level execution tracing" ), |
| 46 | clEnumValN(Logger::Level::Debug, "verbose" , "Low level details" )), |
| 47 | llvm::cl::init(Val: Logger::Level::Info), |
| 48 | }; |
| 49 | llvm::cl::opt<bool> prettyPrint{ |
| 50 | "pretty" , |
| 51 | llvm::cl::desc("Pretty-print JSON output" ), |
| 52 | llvm::cl::init(Val: false), |
| 53 | }; |
| 54 | llvm::cl::list<std::string> ( |
| 55 | "pdll-extra-dir" , llvm::cl::desc("Extra directory of include files" ), |
| 56 | llvm::cl::value_desc("directory" ), llvm::cl::Prefix); |
| 57 | llvm::cl::list<std::string> compilationDatabases( |
| 58 | "pdll-compilation-database" , |
| 59 | llvm::cl::desc("Compilation YAML databases containing additional " |
| 60 | "compilation information for .pdll files" )); |
| 61 | |
| 62 | llvm::cl::ParseCommandLineOptions(argc, argv, Overview: "PDLL LSP Language Server" ); |
| 63 | |
| 64 | if (litTest) { |
| 65 | inputStyle = JSONStreamStyle::Delimited; |
| 66 | logLevel = Logger::Level::Debug; |
| 67 | prettyPrint = true; |
| 68 | } |
| 69 | |
| 70 | // Configure the logger. |
| 71 | Logger::setLogLevel(logLevel); |
| 72 | |
| 73 | // Configure the transport used for communication. |
| 74 | llvm::sys::ChangeStdinToBinary(); |
| 75 | JSONTransport transport(stdin, llvm::outs(), inputStyle, prettyPrint); |
| 76 | |
| 77 | // Configure the servers and start the main language server. |
| 78 | PDLLServer::Options options(compilationDatabases, extraIncludeDirs); |
| 79 | PDLLServer server(options); |
| 80 | return runPdllLSPServer(server, transport); |
| 81 | } |
| 82 | |