MLIR  20.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 diagnostic is emitted to the context and a null value is
48 /// returned.
49 /// If `numRead` is provided, it is set to the number of consumed characters on
50 /// succesful parse. Otherwise, parsing fails if the entire string is not
51 /// consumed.
52 /// Some internal copying can be skipped if the source string is known to be
53 /// null terminated.
54 Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context,
55  Type type = {}, size_t *numRead = nullptr,
56  bool isKnownNullTerminated = false);
57 
58 /// This parses a single MLIR type to an MLIR context if it was valid. If not,
59 /// an error diagnostic is emitted to the context.
60 /// If `numRead` is provided, it is set to the number of consumed characters on
61 /// succesful parse. Otherwise, parsing fails if the entire string is not
62 /// consumed.
63 /// Some internal copying can be skipped if the source string is known to be
64 /// null terminated.
65 Type parseType(llvm::StringRef typeStr, MLIRContext *context,
66  size_t *numRead = nullptr, bool isKnownNullTerminated = false);
67 
68 /// This parses a single IntegerSet/AffineMap to an MLIR context if it was
69 /// valid. If not, an error message is emitted through a new
70 /// SourceMgrDiagnosticHandler constructed from a new SourceMgr with a single
71 /// MemoryBuffer wrapping `str`. If the passed `str` has additional tokens that
72 /// were not part of the IntegerSet/AffineMap, a failure is returned.
73 AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context);
74 IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context);
75 
76 } // namespace mlir
77 
78 #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:46
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:60
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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:2816
AffineMap parseAffineMap(llvm::StringRef str, MLIRContext *context)
This parses a single IntegerSet/AffineMap to an MLIR context if it was valid.
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context, Type type={}, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR attribute to an MLIR context if it was valid.
Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR type to an MLIR context if it was valid.
IntegerSet parseIntegerSet(llvm::StringRef str, MLIRContext *context)