Mercurial > projects > ldc
comparison gen/toir.cpp @ 705:5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Rewrote DtoIndexStruct/Class , the old implementation were way too complex for what we really need now - since the DotVar changes.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Tue, 14 Oct 2008 15:35:49 +0200 |
parents | 43165a082535 |
children | 30b42a283c8e |
comparison
equal
deleted
inserted
replaced
704:43165a082535 | 705:5a2983f97498 |
---|---|
498 Type* e1type = e1->type->toBasetype(); | 498 Type* e1type = e1->type->toBasetype(); |
499 Type* e1next = e1type->next ? e1type->next->toBasetype() : NULL; | 499 Type* e1next = e1type->next ? e1type->next->toBasetype() : NULL; |
500 Type* e2type = e2->type->toBasetype(); | 500 Type* e2type = e2->type->toBasetype(); |
501 | 501 |
502 if (e1type != e2type) { | 502 if (e1type != e2type) { |
503 /*if (llvmFieldIndex) { | 503 if (e1type->ty == Tpointer) { |
504 assert(e1type->ty == Tpointer && e1next && e1next->ty == Tstruct); | |
505 Logger::println("add to AddrExp of struct"); | |
506 assert(r->isConst()); | |
507 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); | |
508 | |
509 TypeStruct* ts = (TypeStruct*)e1next; | |
510 DStructIndexVector offsets; | |
511 LLValue* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); | |
512 return new DFieldValue(type, v); | |
513 } | |
514 else*/ if (e1type->ty == Tpointer) { | |
515 Logger::println("add to pointer"); | 504 Logger::println("add to pointer"); |
516 if (r->isConst()) { | 505 if (r->isConst()) { |
517 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); | 506 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); |
518 if (cofs->isZero()) { | 507 if (cofs->isZero()) { |
519 Logger::println("is zero"); | 508 Logger::println("is zero"); |
941 //Logger::println("e1type=%s", e1type->toChars()); | 930 //Logger::println("e1type=%s", e1type->toChars()); |
942 //Logger::cout() << *DtoType(e1type) << '\n'; | 931 //Logger::cout() << *DtoType(e1type) << '\n'; |
943 | 932 |
944 if (VarDeclaration* vd = var->isVarDeclaration()) { | 933 if (VarDeclaration* vd = var->isVarDeclaration()) { |
945 LLValue* arrptr; | 934 LLValue* arrptr; |
935 // indexing struct pointer | |
946 if (e1type->ty == Tpointer) { | 936 if (e1type->ty == Tpointer) { |
947 assert(e1type->next->ty == Tstruct); | 937 assert(e1type->next->ty == Tstruct); |
948 TypeStruct* ts = (TypeStruct*)e1type->next; | 938 TypeStruct* ts = (TypeStruct*)e1type->next; |
949 Logger::println("Struct member offset:%d", vd->offset); | 939 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); |
950 | 940 } |
951 LLValue* src = l->getRVal(); | 941 // indexing normal struct |
952 | |
953 DStructIndexVector vdoffsets; | |
954 arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); | |
955 } | |
956 // happens for tuples | |
957 else if (e1type->ty == Tstruct) { | 942 else if (e1type->ty == Tstruct) { |
958 TypeStruct* ts = (TypeStruct*)e1type; | 943 TypeStruct* ts = (TypeStruct*)e1type; |
959 Logger::println("Struct member offset:%d", vd->offset); | 944 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); |
960 | 945 } |
961 LLValue* src = l->getRVal(); | 946 // indexing class |
962 | |
963 DStructIndexVector vdoffsets; | |
964 arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); | |
965 } | |
966 else if (e1type->ty == Tclass) { | 947 else if (e1type->ty == Tclass) { |
967 TypeClass* tc = (TypeClass*)e1type; | 948 TypeClass* tc = (TypeClass*)e1type; |
968 Logger::println("Class member offset: %d", vd->offset); | 949 arrptr = DtoIndexClass(l->getRVal(), tc->sym, vd); |
969 | |
970 LLValue* src = l->getRVal(); | |
971 | |
972 DStructIndexVector vdoffsets; | |
973 arrptr = DtoIndexClass(src, tc->sym, vd->type, vd->offset, vdoffsets); | |
974 } | 950 } |
975 else | 951 else |
976 assert(0); | 952 assert(0); |
977 | 953 |
978 //Logger::cout() << "mem: " << *arrptr << '\n'; | 954 //Logger::cout() << "mem: " << *arrptr << '\n'; |
1341 LLValue* lv = l->getRVal(); | 1317 LLValue* lv = l->getRVal(); |
1342 LLValue* rv = r->getRVal(); | 1318 LLValue* rv = r->getRVal(); |
1343 if (rv->getType() != lv->getType()) { | 1319 if (rv->getType() != lv->getType()) { |
1344 rv = DtoBitCast(rv, lv->getType()); | 1320 rv = DtoBitCast(rv, lv->getType()); |
1345 } | 1321 } |
1322 if (Logger::enabled()) | |
1323 { | |
1324 Logger::cout() << "lv: " << *lv << '\n'; | |
1325 Logger::cout() << "rv: " << *rv << '\n'; | |
1326 } | |
1346 eval = p->ir->CreateICmp(cmpop, lv, rv, "tmp"); | 1327 eval = p->ir->CreateICmp(cmpop, lv, rv, "tmp"); |
1347 } | 1328 } |
1348 else if (t->iscomplex()) | 1329 else if (t->iscomplex()) |
1349 { | 1330 { |
1350 Logger::println("complex"); | 1331 Logger::println("complex"); |