MLIR  20.0.0git
ParseUtilities.h
Go to the documentation of this file.
1 //===- ParseUtilities.h - MLIR Tool Parse Utilities -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file containts common utilities for implementing the file-parsing
10 // behaviour for MLIR tools.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TOOLS_PARSEUTILITIES_H
15 #define MLIR_TOOLS_PARSEUTILITIES_H
16 
17 #include "mlir/IR/BuiltinOps.h"
18 #include "mlir/Parser/Parser.h"
19 
20 namespace mlir {
21 /// This parses the file specified by the indicated SourceMgr. If parsing was
22 /// not successful, null is returned and an error message is emitted through the
23 /// error handler registered in the context.
24 /// If 'insertImplicitModule' is true a top-level 'builtin.module' op will be
25 /// inserted that contains the parsed IR, unless one exists already.
26 inline OwningOpRef<Operation *>
27 parseSourceFileForTool(const std::shared_ptr<llvm::SourceMgr> &sourceMgr,
28  const ParserConfig &config, bool insertImplicitModule) {
29  if (insertImplicitModule) {
30  // TODO: Move implicit module logic out of 'parseSourceFile' and into here.
31  return parseSourceFile<ModuleOp>(sourceMgr, config);
32  }
33  return parseSourceFile(sourceMgr, config);
34 }
35 } // namespace mlir
36 
37 #endif // MLIR_TOOLS_PARSEUTILITIES_H
This class represents a configuration for the MLIR assembly parser.
Definition: AsmState.h:467
Include the generated interface declarations.
OwningOpRef< Operation * > parseSourceFileForTool(const std::shared_ptr< llvm::SourceMgr > &sourceMgr, const ParserConfig &config, bool insertImplicitModule)
This parses the file specified by the indicated SourceMgr.
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 ...
Definition: Parser.cpp:20