[SampleProfileLoader] Fix integer overflow in generateMDProfMetadata (#90217)
[llvm-project.git] / mlir / lib / AsmParser / ParserState.h
blob159058a18fa4e1ef45ad44b700b2fc046631a91a
1 //===- ParserState.h - MLIR ParserState -------------------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef MLIR_LIB_ASMPARSER_PARSERSTATE_H
10 #define MLIR_LIB_ASMPARSER_PARSERSTATE_H
12 #include "Lexer.h"
13 #include "mlir/IR/Attributes.h"
14 #include "mlir/IR/OpImplementation.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringMap.h"
18 namespace mlir {
19 class OpAsmDialectInterface;
21 namespace detail {
23 //===----------------------------------------------------------------------===//
24 // SymbolState
25 //===----------------------------------------------------------------------===//
27 /// This class contains record of any parsed top-level symbols.
28 struct SymbolState {
29 /// A map from attribute alias identifier to Attribute.
30 llvm::StringMap<Attribute> attributeAliasDefinitions;
32 /// A map from type alias identifier to Type.
33 llvm::StringMap<Type> typeAliasDefinitions;
35 /// A map of dialect resource keys to the resolved resource name and handle
36 /// to use during parsing.
37 DenseMap<const OpAsmDialectInterface *,
38 llvm::StringMap<std::pair<std::string, AsmDialectResourceHandle>>>
39 dialectResources;
41 /// A map from unique integer identifier to DistinctAttr.
42 DenseMap<uint64_t, DistinctAttr> distinctAttributes;
45 //===----------------------------------------------------------------------===//
46 // ParserState
47 //===----------------------------------------------------------------------===//
49 /// This class refers to all of the state maintained globally by the parser,
50 /// such as the current lexer position etc.
51 struct ParserState {
52 ParserState(const llvm::SourceMgr &sourceMgr, const ParserConfig &config,
53 SymbolState &symbols, AsmParserState *asmState,
54 AsmParserCodeCompleteContext *codeCompleteContext)
55 : config(config),
56 lex(sourceMgr, config.getContext(), codeCompleteContext),
57 curToken(lex.lexToken()), lastToken(Token::error, ""), symbols(symbols),
58 asmState(asmState), codeCompleteContext(codeCompleteContext) {}
59 ParserState(const ParserState &) = delete;
60 void operator=(const ParserState &) = delete;
62 /// The configuration used to setup the parser.
63 const ParserConfig &config;
65 /// The lexer for the source file we're parsing.
66 Lexer lex;
68 /// This is the next token that hasn't been consumed yet.
69 Token curToken;
71 /// This is the last token that has been consumed.
72 Token lastToken;
74 /// The current state for symbol parsing.
75 SymbolState &symbols;
77 /// Stack of potentially cyclic mutable attributes or type currently being
78 /// parsed.
79 SetVector<const void *> cyclicParsingStack;
81 /// An optional pointer to a struct containing high level parser state to be
82 /// populated during parsing.
83 AsmParserState *asmState;
85 /// An optional code completion context.
86 AsmParserCodeCompleteContext *codeCompleteContext;
88 // Contains the stack of default dialect to use when parsing regions.
89 // A new dialect get pushed to the stack before parsing regions nested
90 // under an operation implementing `OpAsmOpInterface`, and
91 // popped when done. At the top-level we start with "builtin" as the
92 // default, so that the top-level `module` operation parses as-is.
93 SmallVector<StringRef> defaultDialectStack{"builtin"};
96 } // namespace detail
97 } // namespace mlir
99 #endif // MLIR_LIB_ASMPARSER_PARSERSTATE_H