clang 17.0.0git
InterpBlock.cpp
Go to the documentation of this file.
1//===--- Block.cpp - Allocated blocks for the interpreter -------*- 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// Defines the classes describing allocated blocks.
10//
11//===----------------------------------------------------------------------===//
12
13#include "InterpBlock.h"
14#include "Pointer.h"
15
16using namespace clang;
17using namespace clang::interp;
18
19
20
22 if (IsStatic)
23 return;
24 if (Pointers)
25 Pointers->Prev = P;
26 P->Next = Pointers;
27 P->Prev = nullptr;
28 Pointers = P;
29}
30
32 if (IsStatic)
33 return;
34 if (Pointers == P)
35 Pointers = P->Next;
36 if (P->Prev)
37 P->Prev->Next = P->Next;
38 if (P->Next)
39 P->Next->Prev = P->Prev;
40}
41
43 if (Pointers == nullptr && IsDead)
44 (reinterpret_cast<DeadBlock *>(this + 1) - 1)->free();
45}
46
48 if (IsStatic)
49 return;
50 To->Prev = From->Prev;
51 if (To->Prev)
52 To->Prev->Next = To;
53 To->Next = From->Next;
54 if (To->Next)
55 To->Next->Prev = To;
56 if (Pointers == From)
57 Pointers = To;
58
59 From->Prev = nullptr;
60 From->Next = nullptr;
61}
62
64 : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
65 // Add the block to the chain of dead blocks.
66 if (Root)
67 Root->Prev = this;
68
69 Next = Root;
70 Prev = nullptr;
71 Root = this;
72
73 // Transfer pointers.
74 B.Pointers = Blk->Pointers;
75 for (Pointer *P = Blk->Pointers; P; P = P->Next)
76 P->Pointee = &B;
77}
78
79void DeadBlock::free() {
80 if (Prev)
81 Prev->Next = Next;
82 if (Next)
83 Next->Prev = Prev;
84 if (Root == this)
85 Root = Next;
86 ::free(this);
87}
StringRef P
bool IsStatic
Definition: Format.cpp:2784
A memory block, either on the stack or in the heap.
Definition: InterpBlock.h:49
void movePointer(Pointer *From, Pointer *To)
Definition: InterpBlock.cpp:47
void addPointer(Pointer *P)
Definition: InterpBlock.cpp:21
void removePointer(Pointer *P)
Definition: InterpBlock.cpp:31
bool IsStatic
Flag indicating if the block has static storage duration.
Definition: InterpBlock.h:134
Pointer * Pointers
Start of the chain of pointers.
Definition: InterpBlock.h:130
bool IsDead
Flag indicating if the pointer is dead.
Definition: InterpBlock.h:138
Descriptor for a dead block.
Definition: InterpBlock.h:147
DeadBlock(DeadBlock *&Root, Block *Blk)
Copies the block.
Definition: InterpBlock.cpp:63
A pointer to a memory block, live or dead.
Definition: Pointer.h:61
#define true
Definition: stdbool.h:21