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;
21 void Block::addPointer(Pointer *P) {
31 void Block::removePointer(Pointer *P) {
37 P->Prev->Next = P->Next;
39 P->Next->Prev = P->Prev;
42 void Block::cleanup() {
43 if (Pointers == nullptr && IsDead)
44 (reinterpret_cast<DeadBlock *>(this + 1) - 1)->free();
47 void Block::movePointer(Pointer *From, Pointer *To) {
50 To->Prev = From->Prev;
53 To->Next = From->Next;
63 DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
64 : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
65 // Add the block to the chain of dead blocks.
74 B.Pointers = Blk->Pointers;
75 for (Pointer *P = Blk->Pointers; P; P = P->Next)
79 void DeadBlock::free() {