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