Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 1151:3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
- Eliminated the DLRValue DValue.
- Implemented proactive handling of l-value CastExpS.
- Minor tweak in runtime memory.d .
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Sat, 28 Mar 2009 05:00:43 +0100 |
parents | 3d1b16dabd25 |
children | 7d28dcbff23e |
comparison
equal
deleted
inserted
replaced
1150:2a687353c84d | 1151:3cf0066e6faf |
---|---|
470 } | 470 } |
471 r = DtoBitCast(r, l->getType()->getContainedType(0)); | 471 r = DtoBitCast(r, l->getType()->getContainedType(0)); |
472 DtoStore(r, l); | 472 DtoStore(r, l); |
473 } | 473 } |
474 else if (t->iscomplex()) { | 474 else if (t->iscomplex()) { |
475 LLValue* dst; | 475 LLValue* dst = lhs->getLVal(); |
476 if (DLRValue* lr = lhs->isLRValue()) { | 476 LLValue* src = DtoCast(loc, rhs, lhs->getType())->getRVal(); |
477 dst = lr->getLVal(); | 477 DtoStore(src, dst); |
478 rhs = DtoCastComplex(loc, rhs, lr->getLType()); | |
479 } | |
480 else { | |
481 dst = lhs->getLVal(); | |
482 } | |
483 DtoStore(rhs->getRVal(), dst); | |
484 } | 478 } |
485 else { | 479 else { |
486 LLValue* l = lhs->getLVal(); | 480 LLValue* l = lhs->getLVal(); |
487 LLValue* r = rhs->getRVal(); | 481 LLValue* r = rhs->getRVal(); |
488 if (Logger::enabled()) | 482 if (Logger::enabled()) |
489 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; | 483 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; |
490 const LLType* lit = l->getType()->getContainedType(0); | 484 const LLType* lit = l->getType()->getContainedType(0); |
491 if (r->getType() != lit) { | 485 if (r->getType() != lit) { |
492 // handle lvalue cast assignments | 486 r = DtoCast(loc, rhs, lhs->getType())->getRVal(); |
493 if (DLRValue* lr = lhs->isLRValue()) { | |
494 Logger::println("lvalue cast!"); | |
495 r = DtoCast(loc, rhs, lr->getLType())->getRVal(); | |
496 } | |
497 else { | |
498 r = DtoCast(loc, rhs, lhs->getType())->getRVal(); | |
499 } | |
500 if (Logger::enabled()) | 487 if (Logger::enabled()) |
501 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; | 488 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; |
502 assert(r->getType() == l->getType()->getContainedType(0)); | 489 assert(r->getType() == l->getType()->getContainedType(0)); |
503 } | 490 } |
504 gIR->ir->CreateStore(r, l); | 491 gIR->ir->CreateStore(r, l); |
721 } | 708 } |
722 | 709 |
723 DValue* DtoCast(Loc& loc, DValue* val, Type* to) | 710 DValue* DtoCast(Loc& loc, DValue* val, Type* to) |
724 { | 711 { |
725 Type* fromtype = val->getType()->toBasetype(); | 712 Type* fromtype = val->getType()->toBasetype(); |
713 Type* totype = to->toBasetype(); | |
714 if (fromtype->equals(totype)) | |
715 return val; | |
716 | |
726 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); | 717 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); |
718 LOG_SCOPE; | |
719 | |
727 if (fromtype->isintegral()) { | 720 if (fromtype->isintegral()) { |
728 return DtoCastInt(loc, val, to); | 721 return DtoCastInt(loc, val, to); |
729 } | 722 } |
730 else if (fromtype->iscomplex()) { | 723 else if (fromtype->iscomplex()) { |
731 return DtoCastComplex(loc, val, to); | 724 return DtoCastComplex(loc, val, to); |
857 DtoResolveTypeInfo(fd); | 850 DtoResolveTypeInfo(fd); |
858 } | 851 } |
859 else { | 852 else { |
860 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); | 853 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); |
861 assert(0 && "unsupported dsymbol for DtoResolveDsymbol"); | 854 assert(0 && "unsupported dsymbol for DtoResolveDsymbol"); |
862 } | |
863 } | |
864 | |
865 ////////////////////////////////////////////////////////////////////////////////////////// | |
866 | |
867 void DtoDeclareDsymbol(Dsymbol* dsym) | |
868 { | |
869 DtoResolveDsymbol(dsym); | |
870 | |
871 if (StructDeclaration* sd = dsym->isStructDeclaration()) { | |
872 DtoDeclareStruct(sd); | |
873 } | |
874 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
875 DtoDeclareClass(cd); | |
876 } | |
877 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
878 DtoDeclareFunction(fd); | |
879 } | |
880 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { | |
881 DtoDeclareTypeInfo(fd); | |
882 } | |
883 else { | |
884 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); | |
885 assert(0 && "unsupported dsymbol for DtoDeclareDsymbol"); | |
886 } | |
887 } | |
888 | |
889 ////////////////////////////////////////////////////////////////////////////////////////// | |
890 | |
891 void DtoConstInitDsymbol(Dsymbol* dsym) | |
892 { | |
893 DtoDeclareDsymbol(dsym); | |
894 | |
895 if (StructDeclaration* sd = dsym->isStructDeclaration()) { | |
896 DtoConstInitStruct(sd); | |
897 } | |
898 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
899 DtoConstInitClass(cd); | |
900 } | |
901 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { | |
902 DtoConstInitTypeInfo(fd); | |
903 } | |
904 else if (VarDeclaration* vd = dsym->isVarDeclaration()) { | |
905 DtoConstInitGlobal(vd); | |
906 } | |
907 else { | |
908 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); | |
909 assert(0 && "unsupported dsymbol for DtoConstInitDsymbol"); | |
910 } | |
911 } | |
912 | |
913 ////////////////////////////////////////////////////////////////////////////////////////// | |
914 | |
915 void DtoDefineDsymbol(Dsymbol* dsym) | |
916 { | |
917 DtoConstInitDsymbol(dsym); | |
918 | |
919 if (StructDeclaration* sd = dsym->isStructDeclaration()) { | |
920 DtoDefineStruct(sd); | |
921 } | |
922 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) { | |
923 DtoDefineClass(cd); | |
924 } | |
925 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { | |
926 Type::sir->addFunctionBody(fd->ir.irFunc); | |
927 } | |
928 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) { | |
929 DtoDefineTypeInfo(fd); | |
930 } | |
931 else { | |
932 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); | |
933 assert(0 && "unsupported dsymbol for DtoDefineDsymbol"); | |
934 } | 855 } |
935 } | 856 } |
936 | 857 |
937 ////////////////////////////////////////////////////////////////////////////////////////// | 858 ////////////////////////////////////////////////////////////////////////////////////////// |
938 | 859 |