Mercurial > projects > ldc
comparison gen/typinf.cpp @ 133:44a95ac7368a trunk
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
In particular, assertions has been fixed to include file/line info, and much more!
author | lindquist |
---|---|
date | Mon, 14 Jan 2008 05:11:54 +0100 |
parents | 1700239cab2e |
children | 0e28624814e8 |
comparison
equal
deleted
inserted
replaced
132:1700239cab2e | 133:44a95ac7368a |
---|---|
369 // vtbl | 369 // vtbl |
370 std::vector<llvm::Constant*> sinits; | 370 std::vector<llvm::Constant*> sinits; |
371 sinits.push_back(base->llvmVtbl); | 371 sinits.push_back(base->llvmVtbl); |
372 | 372 |
373 // monitor | 373 // monitor |
374 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 374 sinits.push_back(getNullPtr(getPtrToType(llvm::Type::Int8Ty))); |
375 | 375 |
376 assert(tinfo->ty == Ttypedef); | 376 assert(tinfo->ty == Ttypedef); |
377 TypeTypedef *tc = (TypeTypedef *)tinfo; | 377 TypeTypedef *tc = (TypeTypedef *)tinfo; |
378 TypedefDeclaration *sd = tc->sym; | 378 TypedefDeclaration *sd = tc->sym; |
379 | 379 |
398 char *name = sd->toPrettyChars(); | 398 char *name = sd->toPrettyChars(); |
399 sinits.push_back(DtoConstString(name)); | 399 sinits.push_back(DtoConstString(name)); |
400 assert(sinits.back()->getType() == stype->getElementType(3)); | 400 assert(sinits.back()->getType() == stype->getElementType(3)); |
401 | 401 |
402 // void[] init | 402 // void[] init |
403 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | 403 const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty); |
404 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type | 404 if (tinfo->isZeroInit() || !sd->init) // 0 initializer, or the same as the base type |
405 { | 405 { |
406 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); | 406 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), getNullPtr(initpt))); |
407 } | 407 } |
408 else | 408 else |
409 { | 409 { |
410 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); | 410 llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); |
411 std::string ciname(sd->mangle()); | 411 std::string ciname(sd->mangle()); |
412 ciname.append("__init"); | 412 ciname.append("__init"); |
413 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); | 413 llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
414 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); | 414 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
415 size_t cisize = gTargetData->getTypeSize(DtoType(sd->basetype)); | 415 size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); |
416 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 416 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
417 } | 417 } |
418 | 418 |
419 // create the symbol | 419 // create the symbol |
420 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 420 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
455 // vtbl | 455 // vtbl |
456 std::vector<llvm::Constant*> sinits; | 456 std::vector<llvm::Constant*> sinits; |
457 sinits.push_back(base->llvmVtbl); | 457 sinits.push_back(base->llvmVtbl); |
458 | 458 |
459 // monitor | 459 // monitor |
460 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 460 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
461 | 461 |
462 assert(tinfo->ty == Tenum); | 462 assert(tinfo->ty == Tenum); |
463 TypeEnum *tc = (TypeEnum *)tinfo; | 463 TypeEnum *tc = (TypeEnum *)tinfo; |
464 EnumDeclaration *sd = tc->sym; | 464 EnumDeclaration *sd = tc->sym; |
465 | 465 |
483 char *name = sd->toPrettyChars(); | 483 char *name = sd->toPrettyChars(); |
484 sinits.push_back(DtoConstString(name)); | 484 sinits.push_back(DtoConstString(name)); |
485 assert(sinits.back()->getType() == stype->getElementType(3)); | 485 assert(sinits.back()->getType() == stype->getElementType(3)); |
486 | 486 |
487 // void[] init | 487 // void[] init |
488 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | 488 const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty); |
489 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type | 489 if (tinfo->isZeroInit() || !sd->defaultval) // 0 initializer, or the same as the base type |
490 { | 490 { |
491 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); | 491 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
492 } | 492 } |
493 else | 493 else |
496 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); | 496 llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); |
497 std::string ciname(sd->mangle()); | 497 std::string ciname(sd->mangle()); |
498 ciname.append("__init"); | 498 ciname.append("__init"); |
499 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); | 499 llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); |
500 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); | 500 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); |
501 size_t cisize = gTargetData->getTypeSize(memty); | 501 size_t cisize = getTypeStoreSize(memty); |
502 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 502 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
503 } | 503 } |
504 | 504 |
505 // create the symbol | 505 // create the symbol |
506 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); | 506 llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); |
535 // vtbl | 535 // vtbl |
536 std::vector<llvm::Constant*> sinits; | 536 std::vector<llvm::Constant*> sinits; |
537 sinits.push_back(base->llvmVtbl); | 537 sinits.push_back(base->llvmVtbl); |
538 | 538 |
539 // monitor | 539 // monitor |
540 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 540 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
541 | 541 |
542 // TypeInfo base | 542 // TypeInfo base |
543 Logger::println("generating base typeinfo"); | 543 Logger::println("generating base typeinfo"); |
544 basetype->getTypeInfo(NULL); | 544 basetype->getTypeInfo(NULL); |
545 assert(basetype->vtinfo); | 545 assert(basetype->vtinfo); |
647 std::vector<llvm::Constant*> sinits; | 647 std::vector<llvm::Constant*> sinits; |
648 // first is always the vtable | 648 // first is always the vtable |
649 sinits.push_back(base->llvmVtbl); | 649 sinits.push_back(base->llvmVtbl); |
650 | 650 |
651 // monitor | 651 // monitor |
652 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 652 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
653 | 653 |
654 // value typeinfo | 654 // value typeinfo |
655 assert(tinfo->ty == Tsarray); | 655 assert(tinfo->ty == Tsarray); |
656 TypeSArray *tc = (TypeSArray *)tinfo; | 656 TypeSArray *tc = (TypeSArray *)tinfo; |
657 tc->next->getTypeInfo(NULL); | 657 tc->next->getTypeInfo(NULL); |
710 std::vector<llvm::Constant*> sinits; | 710 std::vector<llvm::Constant*> sinits; |
711 // first is always the vtable | 711 // first is always the vtable |
712 sinits.push_back(base->llvmVtbl); | 712 sinits.push_back(base->llvmVtbl); |
713 | 713 |
714 // monitor | 714 // monitor |
715 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 715 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
716 | 716 |
717 // get type | 717 // get type |
718 assert(tinfo->ty == Taarray); | 718 assert(tinfo->ty == Taarray); |
719 TypeAArray *tc = (TypeAArray *)tinfo; | 719 TypeAArray *tc = (TypeAArray *)tinfo; |
720 | 720 |
845 // vtbl | 845 // vtbl |
846 std::vector<llvm::Constant*> sinits; | 846 std::vector<llvm::Constant*> sinits; |
847 sinits.push_back(base->llvmVtbl); | 847 sinits.push_back(base->llvmVtbl); |
848 | 848 |
849 // monitor | 849 // monitor |
850 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 850 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
851 | 851 |
852 // char[] name | 852 // char[] name |
853 char *name = sd->toPrettyChars(); | 853 char *name = sd->toPrettyChars(); |
854 sinits.push_back(DtoConstString(name)); | 854 sinits.push_back(DtoConstString(name)); |
855 //Logger::println("************** A"); | 855 //Logger::println("************** A"); |
856 assert(sinits.back()->getType() == stype->getElementType(2)); | 856 assert(sinits.back()->getType() == stype->getElementType(2)); |
857 | 857 |
858 // void[] init | 858 // void[] init |
859 const llvm::PointerType* initpt = llvm::PointerType::get(llvm::Type::Int8Ty); | 859 const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty); |
860 if (sd->zeroInit) // 0 initializer, or the same as the base type | 860 if (sd->zeroInit) // 0 initializer, or the same as the base type |
861 { | 861 { |
862 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); | 862 sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); |
863 } | 863 } |
864 else | 864 else |
865 { | 865 { |
866 size_t cisize = gTargetData->getTypeSize(tc->llvmType->get()); | 866 size_t cisize = getTypeStoreSize(tc->llvmType->get()); |
867 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->llvmInit, initpt); | 867 llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->llvmInit, initpt); |
868 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); | 868 sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); |
869 } | 869 } |
870 | 870 |
871 // toX functions ground work | 871 // toX functions ground work |
1044 std::vector<llvm::Constant*> sinits; | 1044 std::vector<llvm::Constant*> sinits; |
1045 // first is always the vtable | 1045 // first is always the vtable |
1046 sinits.push_back(base->llvmVtbl); | 1046 sinits.push_back(base->llvmVtbl); |
1047 | 1047 |
1048 // monitor | 1048 // monitor |
1049 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 1049 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
1050 | 1050 |
1051 // get classinfo | 1051 // get classinfo |
1052 assert(tinfo->ty == Tclass); | 1052 assert(tinfo->ty == Tclass); |
1053 TypeClass *tc = (TypeClass *)tinfo; | 1053 TypeClass *tc = (TypeClass *)tinfo; |
1054 assert(tc->sym->llvmClass); | 1054 assert(tc->sym->llvmClass); |
1100 std::vector<llvm::Constant*> sinits; | 1100 std::vector<llvm::Constant*> sinits; |
1101 // first is always the vtable | 1101 // first is always the vtable |
1102 sinits.push_back(base->llvmVtbl); | 1102 sinits.push_back(base->llvmVtbl); |
1103 | 1103 |
1104 // monitor | 1104 // monitor |
1105 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 1105 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
1106 | 1106 |
1107 // get classinfo | 1107 // get classinfo |
1108 assert(tinfo->ty == Tclass); | 1108 assert(tinfo->ty == Tclass); |
1109 TypeClass *tc = (TypeClass *)tinfo; | 1109 TypeClass *tc = (TypeClass *)tinfo; |
1110 assert(tc->sym->llvmClass); | 1110 assert(tc->sym->llvmClass); |
1156 std::vector<llvm::Constant*> sinits; | 1156 std::vector<llvm::Constant*> sinits; |
1157 // first is always the vtable | 1157 // first is always the vtable |
1158 sinits.push_back(base->llvmVtbl); | 1158 sinits.push_back(base->llvmVtbl); |
1159 | 1159 |
1160 // monitor | 1160 // monitor |
1161 sinits.push_back(llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty))); | 1161 sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); |
1162 | 1162 |
1163 // create elements array | 1163 // create elements array |
1164 assert(tinfo->ty == Ttuple); | 1164 assert(tinfo->ty == Ttuple); |
1165 TypeTuple *tu = (TypeTuple *)tinfo; | 1165 TypeTuple *tu = (TypeTuple *)tinfo; |
1166 | 1166 |
1167 size_t dim = tu->arguments->dim; | 1167 size_t dim = tu->arguments->dim; |
1168 std::vector<llvm::Constant*> arrInits; | 1168 std::vector<llvm::Constant*> arrInits; |
1169 | 1169 |
1170 const llvm::Type* tiTy = Type::typeinfo->type->llvmType->get(); | 1170 const llvm::Type* tiTy = Type::typeinfo->type->llvmType->get(); |
1171 tiTy = llvm::PointerType::get(tiTy); | 1171 tiTy = getPtrToType(tiTy); |
1172 | 1172 |
1173 for (size_t i = 0; i < dim; i++) | 1173 for (size_t i = 0; i < dim; i++) |
1174 { | 1174 { |
1175 Argument *arg = (Argument *)tu->arguments->data[i]; | 1175 Argument *arg = (Argument *)tu->arguments->data[i]; |
1176 arg->type->getTypeInfo(NULL); | 1176 arg->type->getTypeInfo(NULL); |