Mercurial > projects > ldc
comparison gen/rttibuilder.cpp @ 1383:f15a2d131ceb
Update !ClassInfo generation to use !RTTIBuilder, slight update of !RTTIBuilder .
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 17 May 2009 16:27:01 +0200 |
parents | a0a4d4dac1a4 |
children | b6aa03164436 |
comparison
equal
deleted
inserted
replaced
1382:a0a4d4dac1a4 | 1383:f15a2d131ceb |
---|---|
30 } | 30 } |
31 | 31 |
32 void RTTIBuilder::push(llvm::Constant* C) | 32 void RTTIBuilder::push(llvm::Constant* C) |
33 { | 33 { |
34 inits.push_back(C); | 34 inits.push_back(C); |
35 } | |
36 | |
37 void RTTIBuilder::push_null(Type* T) | |
38 { | |
39 inits.push_back(getNullValue(DtoType(T))); | |
35 } | 40 } |
36 | 41 |
37 void RTTIBuilder::push_null_vp() | 42 void RTTIBuilder::push_null_vp() |
38 { | 43 { |
39 inits.push_back(getNullValue(getVoidPtrType())); | 44 inits.push_back(getNullValue(getVoidPtrType())); |
75 | 80 |
76 LLGlobalVariable* G = new llvm::GlobalVariable( | 81 LLGlobalVariable* G = new llvm::GlobalVariable( |
77 CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); | 82 CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); |
78 G->setAlignment(valtype->alignsize()); | 83 G->setAlignment(valtype->alignsize()); |
79 | 84 |
80 size_t dim = getTypePaddedSize(CI->getType()); | 85 push_void_array(getTypePaddedSize(CI->getType()), G); |
81 LLConstant* ptr = DtoBitCast(CI, DtoType(valtype->pointerTo())); | |
82 | |
83 push_void_array(dim, G); | |
84 } | 86 } |
85 | 87 |
86 void RTTIBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym) | 88 void RTTIBuilder::push_array(llvm::Constant * CI, uint64_t dim, Type* valtype, Dsymbol * mangle_sym) |
87 { | 89 { |
88 std::string initname(mangle_sym?mangle_sym->mangle():".ldc"); | 90 std::string initname(mangle_sym?mangle_sym->mangle():".ldc"); |
92 | 94 |
93 LLGlobalVariable* G = new llvm::GlobalVariable( | 95 LLGlobalVariable* G = new llvm::GlobalVariable( |
94 CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); | 96 CI->getType(), true, TYPEINFO_LINKAGE_TYPE, CI, initname, gIR->module); |
95 G->setAlignment(valtype->alignsize()); | 97 G->setAlignment(valtype->alignsize()); |
96 | 98 |
97 inits.push_back(DtoConstSlice( | 99 push_array(dim, DtoBitCast(G, DtoType(valtype->pointerTo()))); |
98 DtoConstSize_t(dim), | 100 } |
99 DtoBitCast(CI, DtoType(valtype->pointerTo())) | 101 |
100 )); | 102 void RTTIBuilder::push_array(uint64_t dim, llvm::Constant * ptr) |
103 { | |
104 inits.push_back(DtoConstSlice(DtoConstSize_t(dim), ptr)); | |
101 } | 105 } |
102 | 106 |
103 void RTTIBuilder::push_uint(unsigned u) | 107 void RTTIBuilder::push_uint(unsigned u) |
104 { | 108 { |
105 inits.push_back(DtoConstUint(u)); | 109 inits.push_back(DtoConstUint(u)); |
108 void RTTIBuilder::push_size(uint64_t s) | 112 void RTTIBuilder::push_size(uint64_t s) |
109 { | 113 { |
110 inits.push_back(DtoConstSize_t(s)); | 114 inits.push_back(DtoConstSize_t(s)); |
111 } | 115 } |
112 | 116 |
113 void RTTIBuilder::push_funcptr(FuncDeclaration* fd) | 117 void RTTIBuilder::push_funcptr(FuncDeclaration* fd, Type* castto) |
114 { | 118 { |
115 if (fd) | 119 if (fd) |
116 { | 120 { |
117 fd->codegen(Type::sir); | 121 fd->codegen(Type::sir); |
118 LLConstant* F = fd->ir.irFunc->func; | 122 LLConstant* F = fd->ir.irFunc->func; |
123 if (castto) | |
124 F = DtoBitCast(F, DtoType(castto)); | |
119 inits.push_back(F); | 125 inits.push_back(F); |
126 } | |
127 else if (castto) | |
128 { | |
129 push_null(castto); | |
120 } | 130 } |
121 else | 131 else |
122 { | 132 { |
123 push_null_vp(); | 133 push_null_vp(); |
124 } | 134 } |
133 llvm::cast<llvm::OpaqueType>(tid->type.get())->refineAbstractTypeTo(tiInit->getType()); | 143 llvm::cast<llvm::OpaqueType>(tid->type.get())->refineAbstractTypeTo(tiInit->getType()); |
134 | 144 |
135 // set the initializer | 145 // set the initializer |
136 isaGlobalVar(tid->value)->setInitializer(tiInit); | 146 isaGlobalVar(tid->value)->setInitializer(tiInit); |
137 } | 147 } |
148 | |
149 LLConstant* RTTIBuilder::get_constant() | |
150 { | |
151 // just return the inititalizer | |
152 return llvm::ConstantStruct::get(&inits[0], inits.size(), false); | |
153 } |