-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwnt_RefCounting.h
67 lines (44 loc) · 1.76 KB
/
wnt_RefCounting.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*=====================================================================
RefCounting.h
-------------------
Copyright Nicholas Chapman
Generated at 2011-04-25 19:15:39 +0100
=====================================================================*/
#pragma once
#include "wnt_ASTNode.h"
namespace llvm { class Type; }
namespace Winter
{
/*=====================================================================
RefCounting
-------------------
procedure destructor:
---------------------
for each field/element:
calls decrementor
procedure decrementor:
----------------------
entry:
if ref count == 1:
then:
call destructor
if heap allocated:
heap_allocated_then_BB:
call free
else:
else
decrement ref count
merge:
ret void
=====================================================================*/
namespace RefCounting
{
// Emit LLVM code for incrStringRefCount(), incrVArrayRefCount() etc.. to the current LLVM module, store pointers to them in common_functions.
void emitRefCountingFunctions(llvm::Module* module, const llvm::DataLayout* target_data, CommonFunctions& common_functions);
void emitDecrementorForType(llvm::Module* module, const llvm::DataLayout* target_data, const CommonFunctions& common_functions, const ConstTypeVRef& refcounted_type);
void emitDestructorForType(llvm::Module* module, const llvm::DataLayout* target_data, const CommonFunctions& common_functions, const ConstTypeVRef& type);
llvm::Function* getOrInsertDecrementorForType(llvm::Module* module, const ConstTypeVRef& type);
llvm::Function* getOrInsertDestructorForType(llvm::Module* module, const ConstTypeVRef& type);
llvm::Type* refCountLLVMType(llvm::Module* module);
} // end namespace RefCounting
} // end namespace Winter