xref: /llvm-project/mlir/include/mlir/Tools/PDLL/AST/Context.h (revision 81f2f4dfb2922e4f7af8bbfd8b653eda7c1f1339)
1 //===- Context.h - PDLL AST Context -----------------------------*- 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 #ifndef MLIR_TOOLS_PDLL_AST_CONTEXT_H_
10 #define MLIR_TOOLS_PDLL_AST_CONTEXT_H_
11 
12 #include "mlir/Support/StorageUniquer.h"
13 #include "mlir/Tools/PDLL/AST/Diagnostic.h"
14 
15 namespace mlir {
16 namespace pdll {
17 namespace ods {
18 class Context;
19 } // namespace ods
20 
21 namespace ast {
22 /// This class represents the main context of the PDLL AST. It handles
23 /// allocating all of the AST constructs, and manages all state necessary for
24 /// the AST.
25 class Context {
26 public:
27   explicit Context(ods::Context &odsContext);
28   Context(const Context &) = delete;
29   Context &operator=(const Context &) = delete;
30 
31   /// Return the allocator owned by this context.
getAllocator()32   llvm::BumpPtrAllocator &getAllocator() { return allocator; }
33 
34   /// Return the storage uniquer used for AST types.
getTypeUniquer()35   StorageUniquer &getTypeUniquer() { return typeUniquer; }
36 
37   /// Return the ODS context used by the AST.
getODSContext()38   ods::Context &getODSContext() { return odsContext; }
getODSContext()39   const ods::Context &getODSContext() const { return odsContext; }
40 
41   /// Return the diagnostic engine of this context.
getDiagEngine()42   DiagnosticEngine &getDiagEngine() { return diagEngine; }
43 
44 private:
45   /// The diagnostic engine of this AST context.
46   DiagnosticEngine diagEngine;
47 
48   /// The ODS context used by the AST.
49   ods::Context &odsContext;
50 
51   /// The allocator used for AST nodes, and other entities allocated within the
52   /// context.
53   llvm::BumpPtrAllocator allocator;
54 
55   /// The uniquer used for creating AST types.
56   StorageUniquer typeUniquer;
57 };
58 
59 } // namespace ast
60 } // namespace pdll
61 } // namespace mlir
62 
63 #endif // MLIR_TOOLS_PDLL_AST_CONTEXT_H_
64