Mercurial > projects > ldc
comparison gen/rttibuilder.cpp @ 1382:a0a4d4dac1a4
Renamed !TypeInfoBuilder to !RTTIBuilder.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 17 May 2009 15:20:58 +0200 |
parents | a5d0e04298a8 |
children | f15a2d131ceb |
comparison
equal
deleted
inserted
replaced
1381:44c8eef6e6ee | 1382:a0a4d4dac1a4 |
---|---|
10 #include "gen/rttibuilder.h" | 10 #include "gen/rttibuilder.h" |
11 #include "gen/tollvm.h" | 11 #include "gen/tollvm.h" |
12 | 12 |
13 #include "ir/irstruct.h" | 13 #include "ir/irstruct.h" |
14 | 14 |
15 TypeInfoBuilder::TypeInfoBuilder(ClassDeclaration* base_class) | 15 RTTIBuilder::RTTIBuilder(ClassDeclaration* base_class) |
16 { | 16 { |
17 // make sure the base typeinfo class has been processed | 17 // make sure the base typeinfo class has been processed |
18 base_class->codegen(Type::sir); | 18 base_class->codegen(Type::sir); |
19 | 19 |
20 base = base_class; | 20 base = base_class; |
27 inits.push_back(baseir->getVtblSymbol()); | 27 inits.push_back(baseir->getVtblSymbol()); |
28 // and monitor | 28 // and monitor |
29 push_null_vp(); | 29 push_null_vp(); |
30 } | 30 } |
31 | 31 |
32 void TypeInfoBuilder::push(llvm::Constant* C) | 32 void RTTIBuilder::push(llvm::Constant* C) |
33 { | 33 { |
34 inits.push_back(C); | 34 inits.push_back(C); |
35 } | 35 } |
36 | 36 |
37 void TypeInfoBuilder::push_null_vp() | 37 void RTTIBuilder::push_null_vp() |
38 { | 38 { |
39 inits.push_back(getNullValue(getVoidPtrType())); | 39 inits.push_back(getNullValue(getVoidPtrType())); |
40 } | 40 } |
41 | 41 |
42 void TypeInfoBuilder::push_typeinfo(Type* t) | 42 void RTTIBuilder::push_typeinfo(Type* t) |
43 { | 43 { |
44 inits.push_back(DtoTypeInfoOf(t, true)); | 44 inits.push_back(DtoTypeInfoOf(t, true)); |
45 } | 45 } |
46 | 46 |
47 void TypeInfoBuilder::push_classinfo(ClassDeclaration* cd) | 47 void RTTIBuilder::push_classinfo(ClassDeclaration* cd) |
48 { | 48 { |
49 inits.push_back(cd->ir.irStruct->getClassInfoSymbol()); | 49 inits.push_back(cd->ir.irStruct->getClassInfoSymbol()); |
50 } | 50 } |
51 | 51 |
52 void TypeInfoBuilder::push_string(const char* str) | 52 void RTTIBuilder::push_string(const char* str) |
53 { | 53 { |
54 inits.push_back(DtoConstString(str)); | 54 inits.push_back(DtoConstString(str)); |
55 } | 55 } |
56 | 56 |
57 void TypeInfoBuilder::push_null_void_array() | 57 void RTTIBuilder::push_null_void_array() |
58 { | 58 { |
59 const llvm::Type* T = DtoType(Type::tvoid->arrayOf()); | 59 const llvm::Type* T = DtoType(Type::tvoid->arrayOf()); |
60 inits.push_back(getNullValue(T)); | 60 inits.push_back(getNullValue(T)); |
61 } | 61 } |
62 | 62 |
63 void TypeInfoBuilder::push_void_array(uint64_t dim, llvm::Constant* ptr) | 63 void RTTIBuilder::push_void_array(uint64_t dim, llvm::Constant* ptr) |
64 { | 64 { |
65 inits.push_back(DtoConstSlice( | 65 inits.push_back(DtoConstSlice( |
66 DtoConstSize_t(dim), | 66 DtoConstSize_t(dim), |
67 DtoBitCast(ptr, getVoidPtrType()) | 67 DtoBitCast(ptr, getVoidPtrType()) |
68 )); | 68 )); |
69 } | 69 } |
70 | 70 |
71 void TypeInfoBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym) | 71 void RTTIBuilder::push_void_array(llvm::Constant* CI, Type* valtype, Dsymbol* mangle_sym) |
72 { | 72 { |
73 std::string initname(mangle_sym->mangle()); | 73 std::string initname(mangle_sym->mangle()); |
74 initname.append(".rtti.void[].data"); | 74 initname.append(".rtti.void[].data"); |
75 | 75 |
76 LLGlobalVariable* G = new llvm::GlobalVariable( | 76 LLGlobalVariable* G = new llvm::GlobalVariable( |
81 LLConstant* ptr = DtoBitCast(CI, DtoType(valtype->pointerTo())); | 81 LLConstant* ptr = DtoBitCast(CI, DtoType(valtype->pointerTo())); |
82 | 82 |
83 push_void_array(dim, G); | 83 push_void_array(dim, G); |
84 } | 84 } |
85 | 85 |
86 void TypeInfoBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym) | 86 void RTTIBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym) |
87 { | 87 { |
88 std::string initname(mangle_sym?mangle_sym->mangle():".ldc"); | 88 std::string initname(mangle_sym?mangle_sym->mangle():".ldc"); |
89 initname.append(".rtti."); | 89 initname.append(".rtti."); |
90 initname.append(valtype->arrayOf()->toChars()); | 90 initname.append(valtype->arrayOf()->toChars()); |
91 initname.append(".data"); | 91 initname.append(".data"); |
98 DtoConstSize_t(dim), | 98 DtoConstSize_t(dim), |
99 DtoBitCast(CI, DtoType(valtype->pointerTo())) | 99 DtoBitCast(CI, DtoType(valtype->pointerTo())) |
100 )); | 100 )); |
101 } | 101 } |
102 | 102 |
103 void TypeInfoBuilder::push_uint(unsigned u) | 103 void RTTIBuilder::push_uint(unsigned u) |
104 { | 104 { |
105 inits.push_back(DtoConstUint(u)); | 105 inits.push_back(DtoConstUint(u)); |
106 } | 106 } |
107 | 107 |
108 void TypeInfoBuilder::push_size(uint64_t s) | 108 void RTTIBuilder::push_size(uint64_t s) |
109 { | 109 { |
110 inits.push_back(DtoConstSize_t(s)); | 110 inits.push_back(DtoConstSize_t(s)); |
111 } | 111 } |
112 | 112 |
113 void TypeInfoBuilder::push_funcptr(FuncDeclaration* fd) | 113 void RTTIBuilder::push_funcptr(FuncDeclaration* fd) |
114 { | 114 { |
115 if (fd) | 115 if (fd) |
116 { | 116 { |
117 fd->codegen(Type::sir); | 117 fd->codegen(Type::sir); |
118 LLConstant* F = fd->ir.irFunc->func; | 118 LLConstant* F = fd->ir.irFunc->func; |
122 { | 122 { |
123 push_null_vp(); | 123 push_null_vp(); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 void TypeInfoBuilder::finalize(IrGlobal* tid) | 127 void RTTIBuilder::finalize(IrGlobal* tid) |
128 { | 128 { |
129 // create the inititalizer | 129 // create the inititalizer |
130 LLConstant* tiInit = llvm::ConstantStruct::get(&inits[0], inits.size(), false); | 130 LLConstant* tiInit = llvm::ConstantStruct::get(&inits[0], inits.size(), false); |
131 | 131 |
132 // refine global type | 132 // refine global type |