16 #include "llvm/Support/SourceMgr.h"
23 const auto *sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID());
26 sourceBuf->getBufferIdentifier(),
37 const auto *sourceBuf =
38 sourceMgr->getMemoryBuffer(sourceMgr->getMainFileID());
41 sourceBuf->getBufferIdentifier(),
52 auto sourceMgr = std::make_shared<llvm::SourceMgr>();
53 return parseSourceFile(filename, sourceMgr, block, config, sourceFileLoc);
57 llvm::SourceMgr &sourceMgr,
59 if (sourceMgr.getNumBuffers() != 0) {
62 "only main buffer parsed at the moment");
64 auto fileOrErr = llvm::MemoryBuffer::getFileOrSTDIN(filename);
65 if (fileOrErr.getError())
67 "could not open input file " + filename);
70 sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
75 llvm::SourceMgr &sourceMgr,
Block *block,
83 llvm::StringRef filename,
const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
95 llvm::MemoryBuffer::getMemBuffer(sourceStr, sourceName,
100 llvm::SourceMgr sourceMgr;
101 sourceMgr.AddNewSourceBuffer(std::move(memBuffer), SMLoc());
Block represents an ordered list of Operations.
Location objects represent source locations information in MLIR.
MLIRContext is the top-level object for a collection of MLIR operations.
This class represents a configuration for the MLIR assembly parser.
MLIRContext * getContext() const
Return the MLIRContext to be used when parsing.
Include the generated interface declarations.
LogicalResult parseAsmSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, AsmParserState *asmState=nullptr, AsmParserCodeCompleteContext *codeCompleteContext=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...
bool isBytecode(llvm::MemoryBufferRef buffer)
Returns true if the given buffer starts with the magic bytes that signal MLIR bytecode.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, const ParserConfig &config, StringRef sourceName="", LocationAttr *sourceFileLoc=nullptr)
This parses the IR string and appends parsed operations to the given block.
LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult readBytecodeFile(llvm::MemoryBufferRef buffer, Block *block, const ParserConfig &config)
Read the operations defined within the given memory buffer, containing MLIR bytecode,...