Mercurial > projects > ldc
comparison gen/toir.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 |
---|---|
486 DtoResizeDynArray(l->getLVal(), r->getRVal()); | 486 DtoResizeDynArray(l->getLVal(), r->getRVal()); |
487 else | 487 else |
488 DtoAssign(l, r); | 488 DtoAssign(l, r); |
489 } | 489 } |
490 | 490 |
491 return l; | 491 if (l->isSlice() || l->isComplex()) |
492 return l; | |
493 return new DImValue(type, l->getRVal()); | |
492 } | 494 } |
493 | 495 |
494 ////////////////////////////////////////////////////////////////////////////////////////// | 496 ////////////////////////////////////////////////////////////////////////////////////////// |
495 | 497 |
496 DValue* AddExp::toElem(IRState* p) | 498 DValue* AddExp::toElem(IRState* p) |
505 Type* e1type = DtoDType(e1->type); | 507 Type* e1type = DtoDType(e1->type); |
506 Type* e1next = e1type->next ? DtoDType(e1type->next) : NULL; | 508 Type* e1next = e1type->next ? DtoDType(e1type->next) : NULL; |
507 Type* e2type = DtoDType(e2->type); | 509 Type* e2type = DtoDType(e2->type); |
508 | 510 |
509 if (e1type != e2type) { | 511 if (e1type != e2type) { |
510 if (e1type->ty == Tpointer && e1next && e1next->ty == Tstruct) { | 512 if (llvmFieldIndex) { |
513 assert(e1type->ty == Tpointer && e1next && e1next->ty == Tstruct); | |
511 Logger::println("add to AddrExp of struct"); | 514 Logger::println("add to AddrExp of struct"); |
512 assert(r->isConst()); | 515 assert(r->isConst()); |
513 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); | 516 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->isConst()->c); |
514 | 517 |
515 TypeStruct* ts = (TypeStruct*)e1next; | 518 TypeStruct* ts = (TypeStruct*)e1next; |
999 for (int i=0; i<arguments->dim; i++,j++) { | 1002 for (int i=0; i<arguments->dim; i++,j++) { |
1000 Argument* fnarg = Argument::getNth(tf->parameters, i); | 1003 Argument* fnarg = Argument::getNth(tf->parameters, i); |
1001 llargs[j] = DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]); | 1004 llargs[j] = DtoArgument(llfnty->getParamType(j), fnarg, (Expression*)arguments->data[i]); |
1002 // this hack is necessary :/ | 1005 // this hack is necessary :/ |
1003 if (dfn && dfn->func && dfn->func->llvmRunTimeHack) { | 1006 if (dfn && dfn->func && dfn->func->llvmRunTimeHack) { |
1004 Logger::println("llvmRunTimeHack==true"); | 1007 Logger::println("llvmRunTimeHack==true - force casting argument"); |
1005 if (llargs[j]->getType() != llfnty->getParamType(j)) { | 1008 if (llargs[j]->getType() != llfnty->getParamType(j)) { |
1009 Logger::cout() << "from: " << *llargs[j]->getType() << " to: " << *llfnty->getParamType(j); | |
1006 llargs[j] = DtoBitCast(llargs[j], llfnty->getParamType(j)); | 1010 llargs[j] = DtoBitCast(llargs[j], llfnty->getParamType(j)); |
1007 } | 1011 } |
1008 } | 1012 } |
1009 } | 1013 } |
1010 Logger::println("%d params passed", n); | 1014 Logger::println("%d params passed", n); |
1153 | 1157 |
1154 ////////////////////////////////////////////////////////////////////////////////////////// | 1158 ////////////////////////////////////////////////////////////////////////////////////////// |
1155 | 1159 |
1156 DValue* AddrExp::toElem(IRState* p) | 1160 DValue* AddrExp::toElem(IRState* p) |
1157 { | 1161 { |
1158 Logger::print("AddrExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1162 Logger::println("AddrExp::toElem: %s | %s", toChars(), type->toChars()); |
1159 LOG_SCOPE; | 1163 LOG_SCOPE; |
1160 DValue* v = e1->toElem(p); | 1164 DValue* v = e1->toElem(p); |
1161 if (v->isField()) | 1165 if (v->isField()) { |
1166 Logger::println("is field"); | |
1162 return v; | 1167 return v; |
1168 } | |
1163 else if (DFuncValue* fv = v->isFunc()) { | 1169 else if (DFuncValue* fv = v->isFunc()) { |
1170 Logger::println("is func"); | |
1164 //Logger::println("FuncDeclaration"); | 1171 //Logger::println("FuncDeclaration"); |
1165 FuncDeclaration* fd = fv->func; | 1172 FuncDeclaration* fd = fv->func; |
1166 assert(fd); | 1173 assert(fd); |
1167 if (fd->llvmValue == 0) | 1174 if (fd->llvmValue == 0) |
1168 DtoForceDeclareDsymbol(fd); | 1175 DtoForceDeclareDsymbol(fd); |
1169 return new DFuncValue(fd, fd->llvmValue); | 1176 return new DFuncValue(fd, fd->llvmValue); |
1170 } | 1177 } |
1171 else if (DImValue* im = v->isIm()) { | 1178 else if (DImValue* im = v->isIm()) { |
1179 Logger::println("is immediate"); | |
1172 return v; | 1180 return v; |
1173 } | 1181 } |
1182 Logger::println("is nothing special"); | |
1174 return new DFieldValue(type, v->getLVal(), false); | 1183 return new DFieldValue(type, v->getLVal(), false); |
1175 } | 1184 } |
1176 | 1185 |
1177 ////////////////////////////////////////////////////////////////////////////////////////// | 1186 ////////////////////////////////////////////////////////////////////////////////////////// |
1178 | 1187 |
1179 DValue* PtrExp::toElem(IRState* p) | 1188 DValue* PtrExp::toElem(IRState* p) |
1180 { | 1189 { |
1181 Logger::print("PtrExp::toElem: %s | %s\n", toChars(), type->toChars()); | 1190 Logger::println("PtrExp::toElem: %s | %s", toChars(), type->toChars()); |
1182 LOG_SCOPE; | 1191 LOG_SCOPE; |
1183 | 1192 |
1184 DValue* a = e1->toElem(p); | 1193 DValue* a = e1->toElem(p); |
1185 | 1194 |
1186 if (p->topexp() && p->topexp()->e1 == this) { | 1195 if (p->topexp() && p->topexp()->e1 == this) { |
1550 DValue* l = e1->toElem(p); | 1559 DValue* l = e1->toElem(p); |
1551 DValue* r = e2->toElem(p); | 1560 DValue* r = e2->toElem(p); |
1552 | 1561 |
1553 Type* t = DtoDType(e1->type); | 1562 Type* t = DtoDType(e1->type); |
1554 Type* e2t = DtoDType(e2->type); | 1563 Type* e2t = DtoDType(e2->type); |
1555 assert(t == e2t); | 1564 //assert(t == e2t); |
1556 | 1565 |
1557 llvm::Value* eval = 0; | 1566 llvm::Value* eval = 0; |
1558 | 1567 |
1559 if (t->isintegral() || t->ty == Tpointer) | 1568 if (t->isintegral() || t->ty == Tpointer) |
1560 { | 1569 { |
1569 cmpop = llvm::ICmpInst::ICMP_NE; | 1578 cmpop = llvm::ICmpInst::ICMP_NE; |
1570 break; | 1579 break; |
1571 default: | 1580 default: |
1572 assert(0); | 1581 assert(0); |
1573 } | 1582 } |
1574 eval = new llvm::ICmpInst(cmpop, l->getRVal(), r->getRVal(), "tmp", p->scopebb()); | 1583 llvm::Value* lv = l->getRVal(); |
1584 llvm::Value* rv = r->getRVal(); | |
1585 if (rv->getType() != lv->getType()) { | |
1586 rv = DtoBitCast(rv, lv->getType()); | |
1587 } | |
1588 eval = new llvm::ICmpInst(cmpop, lv, rv, "tmp", p->scopebb()); | |
1575 } | 1589 } |
1576 else if (t->iscomplex()) | 1590 else if (t->iscomplex()) |
1577 { | 1591 { |
1578 Logger::println("complex"); | 1592 Logger::println("complex"); |
1579 eval = DtoComplexEquals(op, l, r); | 1593 eval = DtoComplexEquals(op, l, r); |
2210 assert(fd); | 2224 assert(fd); |
2211 | 2225 |
2212 if (fd->isNested()) Logger::println("nested"); | 2226 if (fd->isNested()) Logger::println("nested"); |
2213 Logger::println("kind = %s\n", fd->kind()); | 2227 Logger::println("kind = %s\n", fd->kind()); |
2214 | 2228 |
2215 DtoForceDeclareDsymbol(fd); | 2229 DtoForceDefineDsymbol(fd); |
2216 | 2230 |
2217 bool temp = false; | 2231 bool temp = false; |
2218 llvm::Value* lval = NULL; | 2232 llvm::Value* lval = NULL; |
2219 if (p->topexp() && p->topexp()->e2 == this) { | 2233 if (p->topexp() && p->topexp()->e2 == this) { |
2220 assert(p->topexp()->v); | 2234 assert(p->topexp()->v); |