13 #ifndef MLIR_PARSER_PARSER_H
14 #define MLIR_PARSER_PARSER_H
37 template <
typename ContainerOpT>
42 if (llvm::hasSingleElement(*parsedBlock)) {
43 if (ContainerOpT op = dyn_cast<ContainerOpT>(&parsedBlock->
front())) {
51 if constexpr (std::is_same_v<ContainerOpT, Operation *>) {
54 <<
"source must contain a single top-level operation, found: "
59 ContainerOpT::template hasTrait<OpTrait::OneRegion>() &&
60 (ContainerOpT::template hasTrait<OpTrait::NoTerminator>() ||
61 OpTrait::template hasSingleBlockImplicitTerminator<
62 ContainerOpT>::value),
63 "Expected `ContainerOpT` to have a single region with a single "
64 "block that has an implicit terminator or does not require one");
67 ContainerOpT op = ContainerOpT::create(builder, sourceFileLoc);
69 assert(op->getNumRegions() == 1 && op->getRegion(0).hasOneBlock() &&
70 "expected generated operation to have a single region with a single "
78 if (
failed(op.verifyInvariants()))
92 LogicalResult
parseSourceFile(
const llvm::SourceMgr &sourceMgr, Block *block,
93 const ParserConfig &
config,
94 LocationAttr *sourceFileLoc =
nullptr);
100 LogicalResult
parseSourceFile(
const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
101 Block *block,
const ParserConfig &
config,
102 LocationAttr *sourceFileLoc =
nullptr);
112 const ParserConfig &
config,
113 LocationAttr *sourceFileLoc =
nullptr);
123 llvm::SourceMgr &sourceMgr, Block *block,
124 const ParserConfig &
config,
125 LocationAttr *sourceFileLoc =
nullptr);
132 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
133 Block *block,
const ParserConfig &
config,
134 LocationAttr *sourceFileLoc =
nullptr);
146 const ParserConfig &
config,
147 StringRef sourceName =
"",
148 LocationAttr *sourceFileLoc =
nullptr);
153 template <
typename ContainerOpT,
typename... ParserArgs>
155 ParserArgs &&...args) {
161 return detail::constructContainerOpForParserIfNecessary<ContainerOpT>(
162 &block,
config.getContext(), sourceFileLoc);
174 template <
typename ContainerOpT = Operation *>
175 inline OwningOpRef<ContainerOpT>
177 return detail::parseSourceFile<ContainerOpT>(
config, sourceMgr);
184 template <
typename ContainerOpT = Operation *>
185 inline OwningOpRef<ContainerOpT>
188 return detail::parseSourceFile<ContainerOpT>(
config, sourceMgr);
199 template <
typename ContainerOpT = Operation *>
202 return detail::parseSourceFile<ContainerOpT>(
config, filename);
213 template <
typename ContainerOpT = Operation *>
215 llvm::SourceMgr &sourceMgr,
217 return detail::parseSourceFile<ContainerOpT>(
config, filename, sourceMgr);
224 template <
typename ContainerOpT = Operation *>
225 inline OwningOpRef<ContainerOpT>
227 const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
229 return detail::parseSourceFile<ContainerOpT>(
config, filename, sourceMgr);
243 template <
typename ContainerOpT = Operation *>
246 StringRef sourceName =
"") {
252 return detail::constructContainerOpForParserIfNecessary<ContainerOpT>(
253 &block,
config.getContext(), sourceFileLoc);
Block represents an ordered list of Operations.
OpListType & getOperations()
Location objects represent source locations information in MLIR.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class helps build Operations.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
This class represents a configuration for the MLIR assembly parser.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
OwningOpRef< ContainerOpT > constructContainerOpForParserIfNecessary(Block *parsedBlock, MLIRContext *context, Location sourceFileLoc)
Given a block containing operations that have just been parsed, if the block contains a single operat...
OwningOpRef< ContainerOpT > parseSourceFile(const ParserConfig &config, ParserArgs &&...args)
The internal implementation of the templated parseSourceFile methods below, that simply forwards to t...
Include the generated interface declarations.
const FrozenRewritePatternSet GreedyRewriteConfig config
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 ...