Joos1W Compiler Framework
All Classes Functions Typedefs Pages
Context.h
1 #pragma once
2 
3 #include "utils/BumpAllocator.h"
4 
5 namespace tir {
6 
7 class Type;
8 class ConstantNullPointer;
9 class FunctionType;
10 class ArrayType;
11 class IntegerType;
12 class StructType;
13 
14 struct ContextPImpl {
15 public:
16  ContextPImpl(BumpAllocator& alloc, Type* const pointerType,
17  Type* const voidType, Type* const labelType,
18  ConstantNullPointer* const nullPointer)
19  : functionTypes(alloc),
20  arrayTypes(alloc),
21  integerTypes(alloc),
22  structTypes(alloc),
23  pointerType(pointerType),
24  voidType(voidType),
25  labelType(labelType),
26  nullPointer(nullPointer) {}
27 
28 public:
29  std::pmr::vector<FunctionType*> functionTypes;
30  std::pmr::vector<ArrayType*> arrayTypes;
31  std::pmr::vector<IntegerType*> integerTypes;
32  std::pmr::vector<StructType*> structTypes;
33  Type* const pointerType;
34  Type* const voidType;
35  Type* const labelType;
36  ConstantNullPointer* const nullPointer;
37 };
38 
39 class Context {
40 public:
41  Context(BumpAllocator& alloc);
42  Context(const Context&) = delete;
43  Context(Context&&) = delete;
44  Context& operator=(const Context&) = delete;
45  Context& operator=(Context&&) = delete;
46 
47  BumpAllocator& alloc() { return alloc_; }
48  ContextPImpl& pimpl() { return *pimpl_; }
49  ContextPImpl const& pimpl() const { return *pimpl_; }
50  unsigned getNextValueID() { return value_counter++; }
51 
52 private:
53  BumpAllocator& alloc_;
54  ContextPImpl* pimpl_;
55  unsigned value_counter = 0;
56 };
57 
58 } // namespace tir