MLIR  16.0.0git
Classes | Functions
MLIRServer.cpp File Reference
#include "MLIRServer.h"
#include "../lsp-server-support/Logging.h"
#include "../lsp-server-support/SourceMgrUtils.h"
#include "Protocol.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/AsmParser/AsmParserState.h"
#include "mlir/AsmParser/CodeComplete.h"
#include "mlir/Bytecode/BytecodeWriter.h"
#include "mlir/IR/FunctionInterfaces.h"
#include "mlir/IR/Operation.h"
#include "mlir/Parser/Parser.h"
#include "llvm/Support/Base64.h"
#include "llvm/Support/SourceMgr.h"
+ Include dependency graph for MLIRServer.cpp:

Go to the source code of this file.

Classes

struct  mlir::lsp::MLIRServer::Impl
 

Functions

static Optional< lsp::LocationgetLocationFromLoc (StringRef uriScheme, FileLineColLoc loc)
 Returns a language server location from the given MLIR file location. More...
 
static Optional< lsp::LocationgetLocationFromLoc (llvm::SourceMgr &sourceMgr, Location loc, StringRef uriScheme, const lsp::URIForFile *uri=nullptr)
 Returns a language server location from the given MLIR location, or None if one couldn't be created. More...
 
static void collectLocationsFromLoc (Location loc, std::vector< lsp::Location > &locations, const lsp::URIForFile &uri)
 Collect all of the locations from the given MLIR location that are not contained within the given URI. More...
 
static bool contains (SMRange range, SMLoc loc)
 Returns true if the given range contains the given source location. More...
 
static bool isDefOrUse (const AsmParserState::SMDefinition &def, SMLoc loc, SMRange *overlappedRange=nullptr)
 Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition. More...
 
static Optional< unsigned > getResultNumberFromLoc (SMLoc loc)
 Given a location pointing to a result, return the result number it refers to or None if it refers to all of the results. More...
 
static Optional< StringRef > getTextFromRange (SMRange range)
 Given a source location range, return the text covered by the given range. More...
 
static unsigned getBlockNumber (Block *block)
 Given a block, return its position in its parent region. More...
 
static void printDefBlockName (raw_ostream &os, Block *block, SMRange loc={})
 Given a block and source location, print the source name of the block to the given output stream. More...
 
static void printDefBlockName (raw_ostream &os, const AsmParserState::BlockDefinition &def)
 
static lsp::Diagnostic getLspDiagnoticFromDiag (llvm::SourceMgr &sourceMgr, Diagnostic &diag, const lsp::URIForFile &uri)
 Convert the given MLIR diagnostic to the LSP form. More...
 

Function Documentation

◆ collectLocationsFromLoc()

static void collectLocationsFromLoc ( Location  loc,
std::vector< lsp::Location > &  locations,
const lsp::URIForFile uri 
)
static

Collect all of the locations from the given MLIR location that are not contained within the given URI.

Definition at line 80 of file MLIRServer.cpp.

References mlir::WalkResult::advance(), mlir::Location::dyn_cast(), getLocationFromLoc(), mlir::lsp::URIForFile::scheme(), and mlir::LocationAttr::walk().

◆ contains()

static bool contains ( SMRange  range,
SMLoc  loc 
)
static

Returns true if the given range contains the given source location.

Note that this has slightly different behavior than SMRange because it is inclusive of the end location.

Definition at line 100 of file MLIRServer.cpp.

Referenced by isDefOrUse(), and lexLocStringTok().

◆ getBlockNumber()

static unsigned getBlockNumber ( Block block)
static

Given a block, return its position in its parent region.

Definition at line 165 of file MLIRServer.cpp.

References mlir::Region::begin(), and mlir::Block::getParent().

◆ getLocationFromLoc() [1/2]

static Optional<lsp::Location> getLocationFromLoc ( llvm::SourceMgr &  sourceMgr,
Location  loc,
StringRef  uriScheme,
const lsp::URIForFile uri = nullptr 
)
static

Returns a language server location from the given MLIR location, or None if one couldn't be created.

uriScheme is the scheme to use when building new uris. uri is an optional additional filter that, when present, is used to filter sub locations that do not share the same uri.

Definition at line 49 of file MLIRServer.cpp.

References mlir::WalkResult::advance(), mlir::lsp::convertTokenLocToRange(), mlir::Location::dyn_cast(), getLocationFromLoc(), mlir::WalkResult::interrupt(), max(), and mlir::LocationAttr::walk().

◆ getLocationFromLoc() [2/2]

static Optional<lsp::Location> getLocationFromLoc ( StringRef  uriScheme,
FileLineColLoc  loc 
)
static

Returns a language server location from the given MLIR file location.

uriScheme is the scheme to use when building new uris.

Definition at line 27 of file MLIRServer.cpp.

References mlir::lsp::Position::character, mlir::lsp::Logger::error(), mlir::lsp::URIForFile::fromFile(), mlir::lsp::Position::line, and toString().

Referenced by collectLocationsFromLoc(), getLocationFromLoc(), and getLspDiagnoticFromDiag().

◆ getLspDiagnoticFromDiag()

static lsp::Diagnostic getLspDiagnoticFromDiag ( llvm::SourceMgr &  sourceMgr,
Diagnostic diag,
const lsp::URIForFile uri 
)
static

◆ getResultNumberFromLoc()

static Optional<unsigned> getResultNumberFromLoc ( SMLoc  loc)
static

Given a location pointing to a result, return the result number it refers to or None if it refers to all of the results.

Definition at line 130 of file MLIRServer.cpp.

◆ getTextFromRange()

static Optional<StringRef> getTextFromRange ( SMRange  range)
static

Given a source location range, return the text covered by the given range.

If the range is invalid, returns None.

Definition at line 157 of file MLIRServer.cpp.

References None.

◆ isDefOrUse()

static bool isDefOrUse ( const AsmParserState::SMDefinition def,
SMLoc  loc,
SMRange *  overlappedRange = nullptr 
)
static

Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition.

If provided, overlappedRange is set to the range within def that the provided loc overlapped with.

Definition at line 108 of file MLIRServer.cpp.

References contains(), mlir::AsmParserState::SMDefinition::loc, and mlir::AsmParserState::SMDefinition::uses.

◆ printDefBlockName() [1/2]

static void printDefBlockName ( raw_ostream &  os,
Block block,
SMRange  loc = {} 
)
static

Given a block and source location, print the source name of the block to the given output stream.

Definition at line 171 of file MLIRServer.cpp.

Referenced by printDefBlockName().

◆ printDefBlockName() [2/2]

static void printDefBlockName ( raw_ostream &  os,
const AsmParserState::BlockDefinition def 
)
static