MLIR  17.0.0git
AsmParser.h
Go to the documentation of this file.
1 //===- AsmParser.h - MLIR AsmParser Library Interface -----------*- 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 is contains the interface to the MLIR assembly parser library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_ASMPARSER_ASMPARSER_H
14 #define MLIR_ASMPARSER_ASMPARSER_H
15 
16 #include "mlir/IR/AsmState.h"
17 #include <cstddef>
18 
19 namespace llvm {
20 class SourceMgr;
21 class StringRef;
22 } // namespace llvm
23 
24 namespace mlir {
25 class AsmParserState;
26 class AsmParserCodeCompleteContext;
27 
28 /// This parses the file specified by the indicated SourceMgr and appends parsed
29 /// operations to the given block. If the block is non-empty, the operations are
30 /// placed before the current terminator. If parsing is successful, success is
31 /// returned. Otherwise, an error message is emitted through the error handler
32 /// registered in the context, and failure is returned. If `sourceFileLoc` is
33 /// non-null, it is populated with a file location representing the start of the
34 /// source file that is being parsed. If `asmState` is non-null, it is populated
35 /// with detailed information about the parsed IR (including exact locations for
36 /// SSA uses and definitions). `asmState` should only be provided if this
37 /// detailed information is desired. If `codeCompleteContext` is non-null, it is
38 /// used to signal tracking of a code completion event (generally only ever
39 /// useful for LSP or other high level language tooling).
40 LogicalResult
41 parseAsmSourceFile(const llvm::SourceMgr &sourceMgr, Block *block,
42  const ParserConfig &config,
43  AsmParserState *asmState = nullptr,
44  AsmParserCodeCompleteContext *codeCompleteContext = nullptr);
45 
46 /// This parses a single MLIR attribute to an MLIR context if it was valid. If
47 /// not, an error message is emitted through a new SourceMgrDiagnosticHandler
48 /// constructed from a new SourceMgr with a single a MemoryBuffer wrapping
49 /// `attrStr`. If the passed `attrStr` has additional tokens that were not part
50 /// of the type, an error is emitted.
51 // TODO: Improve diagnostic reporting.
52 Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context);
53 Attribute parseAttribute(llvm::StringRef attrStr, Type type);
54 
55 /// This parses a single MLIR attribute to an MLIR context if it was valid. If
56 /// not, an error message is emitted through a new SourceMgrDiagnosticHandler
57 /// constructed from a new SourceMgr with a single a MemoryBuffer wrapping
58 /// `attrStr`. The number of characters of `attrStr` parsed in the process is
59 /// returned in `numRead`.
60 Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context,
61  size_t &numRead);
62 Attribute parseAttribute(llvm::StringRef attrStr, Type type, size_t &numRead);
63 
64 /// This parses a single MLIR type to an MLIR context if it was valid. If not,
65 /// an error message is emitted through a new SourceMgrDiagnosticHandler
66 /// constructed from a new SourceMgr with a single a MemoryBuffer wrapping
67 /// `typeStr`. If the passed `typeStr` has additional tokens that were not part
68 /// of the type, an error is emitted.
69 // TODO: Improve diagnostic reporting.
70 Type parseType(llvm::StringRef typeStr, MLIRContext *context);
71 
72 /// This parses a single MLIR type to an MLIR context if it was valid. If not,
73 /// an error message is emitted through a new SourceMgrDiagnosticHandler
74 /// constructed from a new SourceMgr with a single a MemoryBuffer wrapping
75 /// `typeStr`. The number of characters of `typeStr` parsed in the process is
76 /// returned in `numRead`.
77 Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t &numRead);
78 
79 /// This parses a single IntegerSet/AffineMap to an MLIR context if it was
80 /// valid. If not, an error message is emitted through a new
81 /// SourceMgrDiagnosticHandler constructed from a new SourceMgr with a single
82 /// MemoryBuffer wrapping `str`. If the passed `str` has additional tokens that
83 /// were not part of the IntegerSet/AffineMap, a failure is returned.
84 AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context);
85 IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context);
86 
87 } // namespace mlir
88 
89 #endif // MLIR_ASMPARSER_ASMPARSER_H
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition: AffineMap.h:43
Attributes are known-constant values of operations.
Definition: Attributes.h:25
An integer set representing a conjunction of one or more affine equalities and inequalities.
Definition: IntegerSet.h:44
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
Include the generated interface declarations.
Definition: CallGraph.h:229
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 ...
Definition: Parser.cpp:2654
AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context)
This parses a single IntegerSet/AffineMap to an MLIR context if it was valid.
Type parseType(llvm::StringRef typeStr, MLIRContext *context)
This parses a single MLIR type to an MLIR context if it was valid.
IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context)
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context)
This parses a single MLIR attribute to an MLIR context if it was valid.