1 //===--- Block.cpp - Allocated blocks for the interpreter -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Defines the classes describing allocated blocks.
11 //===----------------------------------------------------------------------===//
13 #include "InterpBlock.h"
16 using namespace clang
;
17 using namespace clang::interp
;
19 void Block::addPointer(Pointer
*P
) {
27 assert(!hasPointer(P
));
36 void Block::removePointer(Pointer
*P
) {
44 assert(hasPointer(P
));
51 P
->Prev
->Next
= P
->Next
;
53 P
->Next
->Prev
= P
->Prev
;
56 void Block::cleanup() {
57 if (Pointers
== nullptr && IsDead
)
58 (reinterpret_cast<DeadBlock
*>(this + 1) - 1)->free();
61 void Block::replacePointer(Pointer
*Old
, Pointer
*New
) {
70 assert(hasPointer(Old
));
76 Old
->Pointee
= nullptr;
79 assert(!hasPointer(Old
));
80 assert(hasPointer(New
));
85 bool Block::hasPointer(const Pointer
*P
) const {
86 for (const Pointer
*C
= Pointers
; C
; C
= C
->Next
) {
94 DeadBlock::DeadBlock(DeadBlock
*&Root
, Block
*Blk
)
95 : Root(Root
), B(Blk
->Desc
, Blk
->IsStatic
, Blk
->IsExtern
, /*isDead=*/true) {
96 // Add the block to the chain of dead blocks.
104 // Transfer pointers.
105 B
.Pointers
= Blk
->Pointers
;
106 for (Pointer
*P
= Blk
->Pointers
; P
; P
= P
->Next
)
110 void DeadBlock::free() {