clang  10.0.0svn
Block.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 "Block.h"
14 #include "Pointer.h"
15 
16 using namespace clang;
17 using 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 
79 void 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 }
Descriptor for a dead block.
Definition: Block.h:112
StringRef P
Descriptor * Desc
Pointer to the stack slot descriptor.
Definition: Block.h:105
A pointer to a memory block, live or dead.
Definition: Pointer.h:39
A memory block, either on the stack or in the heap.
Definition: Block.h:37
void movePointer(Pointer *From, Pointer *To)
Definition: Block.cpp:47
bool IsDead
Flag indicating if the pointer is dead.
Definition: Block.h:103
Pointer * Pointers
Start of the chain of pointers.
Definition: Block.h:95
void removePointer(Pointer *P)
Definition: Block.cpp:31
bool IsStatic
Flag indicating if the block has static storage duration.
Definition: Block.h:99
bool IsExtern
Flag indicating if the block is an extern.
Definition: Block.h:101
DeadBlock(DeadBlock *&Root, Block *Blk)
Copies the block.
Definition: Block.cpp:63
Dataflow Directional Tag Classes.
void addPointer(Pointer *P)
Definition: Block.cpp:21
#define true
Definition: stdbool.h:16