comparison gen/typinf.cpp @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents 9c79b61fb638
children 44a95ac7368a
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
249 void DtoResolveTypeInfo(TypeInfoDeclaration* tid) 249 void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
250 { 250 {
251 if (tid->llvmResolved) return; 251 if (tid->llvmResolved) return;
252 tid->llvmResolved = true; 252 tid->llvmResolved = true;
253 253
254 Logger::println("* DtoResolveTypeInfo(%s)", tid->toChars()); 254 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
255 LOG_SCOPE; 255 LOG_SCOPE;
256 256
257 tid->llvmIRGlobal = new IRGlobal(tid); 257 tid->llvmIRGlobal = new IRGlobal(tid);
258 258
259 gIR->declareList.push_back(tid); 259 gIR->declareList.push_back(tid);
262 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) 262 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
263 { 263 {
264 if (tid->llvmDeclared) return; 264 if (tid->llvmDeclared) return;
265 tid->llvmDeclared = true; 265 tid->llvmDeclared = true;
266 266
267 Logger::println("* DtoDeclareTypeInfo(%s)", tid->toChars()); 267 Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars());
268 LOG_SCOPE; 268 LOG_SCOPE;
269 269
270 std::string mangled(tid->mangle()); 270 std::string mangled(tid->mangle());
271 271
272 Logger::println("type = '%s'", tid->tinfo->toChars()); 272 Logger::println("type = '%s'", tid->tinfo->toChars());
273 Logger::println("typeinfo mangle: %s", mangled.c_str()); 273 Logger::println("typeinfo mangle: %s", mangled.c_str());
274 274
275 // this is a declaration of a builtin __initZ var 275 // this is a declaration of a builtin __initZ var
276 if (tid->tinfo->builtinTypeInfo()) { 276 if (tid->tinfo->builtinTypeInfo()) {
277 tid->llvmValue = LLVM_D_GetRuntimeGlobal(gIR->module, mangled.c_str()); 277 llvm::Value* found = gIR->module->getNamedGlobal(mangled);
278 assert(tid->llvmValue); 278 if (!found)
279 mangled.append("__TYPE"); 279 {
280 gIR->module->addTypeName(mangled, tid->llvmValue->getType()->getContainedType(0)); 280 const llvm::Type* t = llvm::OpaqueType::get();
281 Logger::println("Got typeinfo var: %s", tid->llvmValue->getName().c_str()); 281 llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module);
282 tid->llvmInitialized = true; 282 assert(g);
283 tid->llvmDefined = true; 283 tid->llvmValue = g;
284 mangled.append("__TYPE");
285 gIR->module->addTypeName(mangled, tid->llvmValue->getType()->getContainedType(0));
286 Logger::println("Got typeinfo var: %s", tid->llvmValue->getName().c_str());
287 tid->llvmInitialized = true;
288 tid->llvmDefined = true;
289 }
290 else if (!tid->llvmValue) {
291 tid->llvmValue = found;
292 tid->llvmInitialized = true;
293 tid->llvmDefined = true;
294 }
284 } 295 }
285 // custom typedef 296 // custom typedef
286 else { 297 else {
287 tid->llvmDeclare(); 298 tid->llvmDeclare();
288 gIR->constInitList.push_back(tid); 299 gIR->constInitList.push_back(tid);
292 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) 303 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
293 { 304 {
294 if (tid->llvmInitialized) return; 305 if (tid->llvmInitialized) return;
295 tid->llvmInitialized = true; 306 tid->llvmInitialized = true;
296 307
297 Logger::println("* DtoConstInitTypeInfo(%s)", tid->toChars()); 308 Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars());
298 LOG_SCOPE; 309 LOG_SCOPE;
299 310
300 gIR->defineList.push_back(tid); 311 gIR->defineList.push_back(tid);
301 } 312 }
302 313
303 void DtoDefineTypeInfo(TypeInfoDeclaration* tid) 314 void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
304 { 315 {
305 if (tid->llvmDefined) return; 316 if (tid->llvmDefined) return;
306 tid->llvmDefined = true; 317 tid->llvmDefined = true;
307 318
308 Logger::println("* DtoDefineTypeInfo(%s)", tid->toChars()); 319 Logger::println("DtoDefineTypeInfo(%s)", tid->toChars());
309 LOG_SCOPE; 320 LOG_SCOPE;
310 321
311 tid->llvmDefine(); 322 tid->llvmDefine();
312 } 323 }
313 324
910 fdx = s ? s->isFuncDeclaration() : NULL; 921 fdx = s ? s->isFuncDeclaration() : NULL;
911 if (fdx) 922 if (fdx)
912 { 923 {
913 fd = fdx->overloadExactMatch(tftohash); 924 fd = fdx->overloadExactMatch(tftohash);
914 if (fd) { 925 if (fd) {
926 DtoForceDeclareDsymbol(fd);
915 assert(fd->llvmValue != 0); 927 assert(fd->llvmValue != 0);
916 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); 928 llvm::Constant* c = isaConstant(fd->llvmValue);
917 assert(c); 929 assert(c);
918 c = llvm::ConstantExpr::getBitCast(c, ptty); 930 c = llvm::ConstantExpr::getBitCast(c, ptty);
919 sinits.push_back(c); 931 sinits.push_back(c);
920 } 932 }
921 else { 933 else {
935 ptty = isaPointer(stype->getElementType(5+i)); 947 ptty = isaPointer(stype->getElementType(5+i));
936 if (fdx) 948 if (fdx)
937 { 949 {
938 fd = fdx->overloadExactMatch(tfeqptr); 950 fd = fdx->overloadExactMatch(tfeqptr);
939 if (fd) { 951 if (fd) {
952 DtoForceDeclareDsymbol(fd);
940 assert(fd->llvmValue != 0); 953 assert(fd->llvmValue != 0);
941 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); 954 llvm::Constant* c = isaConstant(fd->llvmValue);
942 assert(c); 955 assert(c);
943 c = llvm::ConstantExpr::getBitCast(c, ptty); 956 c = llvm::ConstantExpr::getBitCast(c, ptty);
944 sinits.push_back(c); 957 sinits.push_back(c);
945 } 958 }
946 else { 959 else {
962 fdx = s ? s->isFuncDeclaration() : NULL; 975 fdx = s ? s->isFuncDeclaration() : NULL;
963 if (fdx) 976 if (fdx)
964 { 977 {
965 fd = fdx->overloadExactMatch(tftostring); 978 fd = fdx->overloadExactMatch(tftostring);
966 if (fd) { 979 if (fd) {
980 DtoForceDeclareDsymbol(fd);
967 assert(fd->llvmValue != 0); 981 assert(fd->llvmValue != 0);
968 llvm::Constant* c = llvm::cast_or_null<llvm::Constant>(fd->llvmValue); 982 llvm::Constant* c = isaConstant(fd->llvmValue);
969 assert(c); 983 assert(c);
970 c = llvm::ConstantExpr::getBitCast(c, ptty); 984 c = llvm::ConstantExpr::getBitCast(c, ptty);
971 sinits.push_back(c); 985 sinits.push_back(c);
972 } 986 }
973 else { 987 else {