13 #ifndef MLIR_PARSER_PARSER_H 14 #define MLIR_PARSER_PARSER_H 37 template <
typename ContainerOpT>
41 ContainerOpT::template hasTrait<OpTrait::OneRegion>() &&
42 (ContainerOpT::template hasTrait<OpTrait::NoTerminator>() ||
43 OpTrait::template hasSingleBlockImplicitTerminator<
44 ContainerOpT>::
value),
45 "Expected `ContainerOpT` to have a single region with a single " 46 "block that has an implicit terminator or does not require one");
49 if (llvm::hasSingleElement(*parsedBlock)) {
50 if (ContainerOpT op = dyn_cast<ContainerOpT>(parsedBlock->
front())) {
58 ContainerOpT op = builder.
create<ContainerOpT>(sourceFileLoc);
60 assert(op->getNumRegions() == 1 && llvm::hasSingleElement(op->getRegion(0)) &&
61 "expected generated operation to have a single region with a single " 69 if (
failed(op.verifyInvariants()))
105 llvm::SourceMgr &sourceMgr,
Block *block,
123 template <
typename ContainerOpT,
typename... ParserArgs>
125 ParserArgs &&...args) {
131 return detail::constructContainerOpForParserIfNecessary<ContainerOpT>(
144 template <
typename ContainerOpT>
147 return detail::parseSourceFile<ContainerOpT>(config, sourceMgr);
158 template <
typename ContainerOpT>
161 return detail::parseSourceFile<ContainerOpT>(config, filename);
172 template <
typename ContainerOpT>
174 llvm::SourceMgr &sourceMgr,
176 return detail::parseSourceFile<ContainerOpT>(config, filename, sourceMgr);
187 template <
typename ContainerOpT>
194 return detail::constructContainerOpForParserIfNecessary<ContainerOpT>(
200 #endif // MLIR_PARSER_PARSER_H Include the generated interface declarations.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
OwningOpRef< ContainerOpT > parseSourceString(llvm::StringRef sourceStr, const ParserConfig &config)
This parses the provided string containing MLIR.
Block represents an ordered list of Operations.
MLIRContext * getContext() const
Return the MLIRContext to be used when parsing.
OpListType & getOperations()
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
Location objects represent source locations information in MLIR.
static constexpr const bool value
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents an efficient way to signal success or failure.
OwningOpRef< ContainerOpT > parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr, const ParserConfig &config)
This parses the file specified by the indicated filename using the provided SourceMgr.
This class represents a configuration for the MLIR assembly parser.
MLIRContext is the top-level object for a collection of MLIR operations.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
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...
This class helps build Operations.