From dda20ea73d958584e6b162b34dd421582c52ddbb Mon Sep 17 00:00:00 2001 From: David Truby Date: Wed, 30 Oct 2024 15:05:18 +0000 Subject: [PATCH] [flang] Add fir-lsp-server (#114059) This patch adds a fir-lsp-server tool for editor support for editing fir files, using the existing MLIR lsp server support. See https://mlir.llvm.org/docs/Tools/MLIRLSP/ for more information. --- flang/tools/CMakeLists.txt | 1 + flang/tools/fir-lsp-server/CMakeLists.txt | 17 +++++++++++++++++ flang/tools/fir-lsp-server/fir-lsp-server.cpp | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 flang/tools/fir-lsp-server/CMakeLists.txt create mode 100644 flang/tools/fir-lsp-server/fir-lsp-server.cpp diff --git a/flang/tools/CMakeLists.txt b/flang/tools/CMakeLists.txt index 337545ae0d4d7a..1d2d2c608faf95 100644 --- a/flang/tools/CMakeLists.txt +++ b/flang/tools/CMakeLists.txt @@ -12,3 +12,4 @@ add_subdirectory(flang-driver) add_subdirectory(tco) add_subdirectory(f18-parse-demo) add_subdirectory(fir-opt) +add_subdirectory(fir-lsp-server) diff --git a/flang/tools/fir-lsp-server/CMakeLists.txt b/flang/tools/fir-lsp-server/CMakeLists.txt new file mode 100644 index 00000000000000..ff0ced6693b97f --- /dev/null +++ b/flang/tools/fir-lsp-server/CMakeLists.txt @@ -0,0 +1,17 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + AsmParser + ) + +add_flang_tool(fir-lsp-server fir-lsp-server.cpp) + +get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) +get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS) +target_link_libraries(fir-lsp-server PRIVATE + CUFDialect + FIRDialect + HLFIRDialect + MLIRLspServerLib + ${dialect_libs} + ${extension_libs}) diff --git a/flang/tools/fir-lsp-server/fir-lsp-server.cpp b/flang/tools/fir-lsp-server/fir-lsp-server.cpp new file mode 100644 index 00000000000000..8b724e292b5abb --- /dev/null +++ b/flang/tools/fir-lsp-server/fir-lsp-server.cpp @@ -0,0 +1,9 @@ +#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" +#include "flang/Optimizer/Support/InitFIR.h" + +int main(int argc, char **argv) { + mlir::DialectRegistry registry; + fir::support::registerNonCodegenDialects(registry); + fir::support::addFIRExtensions(registry); + return mlir::failed(mlir::MlirLspServerMain(argc, argv, registry)); +}