comparison gen/tollvm.cpp @ 108:288fe1029e1f trunk

[svn r112] Fixed 'case 1,2,3:' style case statements. Fixed a bunch of bugs with return/break/continue in loops. Fixed support for the DMDFE hidden implicit return value variable. This can be needed for some foreach statements where the loop body is converted to a nested delegate, but also possibly returns from the function. Added std.math to phobos. Added AA runtime support code, done ground work for implementing AAs. Several other bugfixes.
author lindquist
date Tue, 20 Nov 2007 05:29:20 +0100
parents 3efbcc81ba45
children 5ab8e92611f9
comparison
equal deleted inserted replaced
107:3efbcc81ba45 108:288fe1029e1f
170 case Tenum: 170 case Tenum:
171 { 171 {
172 Type* bt = t->toBasetype(); 172 Type* bt = t->toBasetype();
173 assert(bt); 173 assert(bt);
174 return DtoType(bt); 174 return DtoType(bt);
175 }
176
177 // associative arrays
178 case Taarray:
179 {
180 // TODO this is a kludge
181 return llvm::PointerType::get(llvm::Type::Int8Ty);
175 } 182 }
176 183
177 default: 184 default:
178 printf("trying to convert unknown type with value %d\n", t->ty); 185 printf("trying to convert unknown type with value %d\n", t->ty);
179 assert(0); 186 assert(0);
794 IRFunction* fcur = gIR->func(); 801 IRFunction* fcur = gIR->func();
795 FuncDeclaration* f = fcur->decl; 802 FuncDeclaration* f = fcur->decl;
796 803
797 // on this stack 804 // on this stack
798 if (fd == f) { 805 if (fd == f) {
799 llvm::Value* v = DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp"); 806 llvm::Value* vdv = vd->llvmValue;
807 if (!vdv)
808 {
809 Logger::println(":o null vd->llvmValue for: %s", vd->toChars());
810 vdv = fd->llvmNested;
811 assert(vdv);
812 }
813 assert(vd->llvmNestedIndex != ~0);
814 llvm::Value* v = DtoGEPi(vdv,0,unsigned(vd->llvmNestedIndex),"tmp");
800 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) { 815 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
801 Logger::cout() << "1267 loading: " << *v << '\n'; 816 Logger::cout() << "1267 loading: " << *v << '\n';
802 v = gIR->ir->CreateLoad(v,"tmp"); 817 v = gIR->ir->CreateLoad(v,"tmp");
803 } 818 }
804 return v; 819 return v;
857 } 872 }
858 else if (t->ty == Tarray) { 873 else if (t->ty == Tarray) {
859 // lhs is slice 874 // lhs is slice
860 if (DSliceValue* s = lhs->isSlice()) { 875 if (DSliceValue* s = lhs->isSlice()) {
861 if (DSliceValue* s2 = rhs->isSlice()) { 876 if (DSliceValue* s2 = rhs->isSlice()) {
862 DtoArrayCopy(s, s2); 877 DtoArrayCopySlices(s, s2);
863 } 878 }
864 else if (t->next == t2) { 879 else if (t->next == t2) {
865 if (s->len) 880 if (s->len)
866 DtoArrayInit(s->ptr, s->len, rhs->getRVal()); 881 DtoArrayInit(s->ptr, s->len, rhs->getRVal());
867 else 882 else
868 DtoArrayInit(s->ptr, rhs->getRVal()); 883 DtoArrayInit(s->ptr, rhs->getRVal());
869 } 884 }
870 else 885 else {
871 assert(rhs->inPlace()); 886 DtoArrayCopyToSlice(s, rhs);
887 }
872 } 888 }
873 // rhs is slice 889 // rhs is slice
874 else if (DSliceValue* s = rhs->isSlice()) { 890 else if (DSliceValue* s = rhs->isSlice()) {
875 DtoSetArray(lhs->getLVal(),s->len,s->ptr); 891 DtoSetArray(lhs->getLVal(),s->len,s->ptr);
876 } 892 }
924 DtoComplexSet(dst, cx->re, cx->im); 940 DtoComplexSet(dst, cx->re, cx->im);
925 else 941 else
926 DtoComplexAssign(dst, rhs->getRVal()); 942 DtoComplexAssign(dst, rhs->getRVal());
927 } 943 }
928 else { 944 else {
945 llvm::Value* l;
946 if (DLRValue* lr = lhs->isLRValue()) {
947 l = lr->getLVal();
948 rhs = DtoCast(rhs, lr->getLType());
949 }
950 else {
951 l = lhs->getLVal();
952 }
929 llvm::Value* r = rhs->getRVal(); 953 llvm::Value* r = rhs->getRVal();
930 llvm::Value* l = lhs->getLVal();
931 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; 954 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
932 const llvm::Type* lit = l->getType()->getContainedType(0); 955 const llvm::Type* lit = l->getType()->getContainedType(0);
933 if (r->getType() != lit) { // :( 956 if (r->getType() != lit) { // :(
934 r = DtoBitCast(r, lit); 957 r = DtoBitCast(r, lit);
935 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n'; 958 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
1122 } 1145 }
1123 1146
1124 DValue* DtoCast(DValue* val, Type* to) 1147 DValue* DtoCast(DValue* val, Type* to)
1125 { 1148 {
1126 Type* fromtype = DtoDType(val->getType()); 1149 Type* fromtype = DtoDType(val->getType());
1150 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
1127 if (fromtype->isintegral()) { 1151 if (fromtype->isintegral()) {
1128 return DtoCastInt(val, to); 1152 return DtoCastInt(val, to);
1129 } 1153 }
1130 else if (fromtype->iscomplex()) { 1154 else if (fromtype->iscomplex()) {
1131 return DtoCastComplex(val, to); 1155 return DtoCastComplex(val, to);