Joos1W Compiler Framework
All Classes Functions Typedefs Pages
Context.cc
1 #include "tir/Context.h"
2 
3 #include <iostream>
4 
5 #include "tir/Constant.h"
6 #include "tir/Type.h"
7 #include "tir/Value.h"
8 
9 namespace tir {
10 
11 std::ostream& operator<<(std::ostream& os, const Value& value) {
12  return value.print(os);
13 }
14 
15 Context::Context(BumpAllocator& alloc) : alloc_{alloc}, pimpl_{nullptr} {
16  void* buf1 = alloc.allocate_bytes(sizeof(OpaquePointerType),
17  alignof(OpaquePointerType));
18  auto* pointerType = new(buf1) OpaquePointerType{this};
19  void* buf2 = alloc.allocate_bytes(sizeof(Type), alignof(Type));
20  auto* voidType = new(buf2) Type{this};
21  void* buf3 = alloc.allocate_bytes(sizeof(Type), alignof(Type));
22  auto* labelType = new(buf3) Type{this};
23  void* buf4 = alloc.allocate_bytes(sizeof(ConstantNullPointer),
24  alignof(ConstantNullPointer));
25  auto* nullPointer = new(buf4) ConstantNullPointer{*this, pointerType};
26  // Replace pimpl_ with the new ContextPImpl
27  void* buff = alloc.allocate_bytes(sizeof(ContextPImpl), alignof(ContextPImpl));
28  pimpl_ = new(buff)
29  ContextPImpl{alloc, pointerType, voidType, labelType, nullPointer};
30 }
31 
32 } // namespace tir