Mercurial > projects > ldc
comparison gen/toir.cpp @ 468:45a67b6f1310
Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
in this regard. Code for accessing nested variables and contexts rewritten. Probably more. Fairly well tested.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 04 Aug 2008 02:59:34 +0200 |
parents | 261b05cf4d1c |
children | d0dad1fe0f45 |
comparison
equal
deleted
inserted
replaced
467:261b05cf4d1c | 468:45a67b6f1310 |
---|---|
104 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo, true); | 104 return new DVarValue(type, vd, cid->cd->ir.irStruct->classInfo, true); |
105 } | 105 } |
106 // nested variable | 106 // nested variable |
107 else if (vd->nestedref) { | 107 else if (vd->nestedref) { |
108 Logger::println("nested variable"); | 108 Logger::println("nested variable"); |
109 return new DVarValue(type, vd, DtoNestedVariable(vd), true); | 109 return DtoNestedVariable(type, vd); |
110 } | 110 } |
111 // function parameter | 111 // function parameter |
112 else if (vd->isParameter()) { | 112 else if (vd->isParameter()) { |
113 Logger::println("function param"); | 113 Logger::println("function param"); |
114 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration(); | 114 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration(); |
115 if (fd && fd != p->func()->decl) { | 115 if (fd && fd != p->func()->decl) { |
116 Logger::println("nested parameter"); | 116 Logger::println("nested parameter"); |
117 return new DVarValue(type, vd, DtoNestedVariable(vd), true); | 117 return DtoNestedVariable(type, vd); |
118 } | 118 } |
119 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { | 119 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { |
120 return new DVarValue(type, vd, vd->ir.getIrValue(), true); | 120 return new DVarValue(type, vd, vd->ir.getIrValue(), true); |
121 } | 121 } |
122 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { | 122 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { |
470 DtoAssign(loc, l, r); | 470 DtoAssign(loc, l, r); |
471 | 471 |
472 if (l->isSlice() || l->isComplex()) | 472 if (l->isSlice() || l->isComplex()) |
473 return l; | 473 return l; |
474 | 474 |
475 if (type->toBasetype()->ty == Tstruct && e2->type->isintegral()) | 475 return r; |
476 { | |
477 // handle struct = 0; | |
478 return l; | |
479 } | |
480 else | |
481 { | |
482 assert(type->equals(e2->type)); | |
483 return r; | |
484 } | |
485 } | 476 } |
486 | 477 |
487 ////////////////////////////////////////////////////////////////////////////////////////// | 478 ////////////////////////////////////////////////////////////////////////////////////////// |
488 | 479 |
489 DValue* AddExp::toElem(IRState* p) | 480 DValue* AddExp::toElem(IRState* p) |
984 // FIXME: check for TOKthis in AssertExp instead | 975 // FIXME: check for TOKthis in AssertExp instead |
985 if (!var) | 976 if (!var) |
986 { | 977 { |
987 LLValue* v = p->func()->thisVar; | 978 LLValue* v = p->func()->thisVar; |
988 assert(v); | 979 assert(v); |
989 return new DImValue(type, v); | 980 return new DVarValue(type, v, true); |
990 } | 981 } |
991 // regular this expr | 982 // regular this expr |
992 else if (VarDeclaration* vd = var->isVarDeclaration()) { | 983 else if (VarDeclaration* vd = var->isVarDeclaration()) { |
993 LLValue* v; | 984 LLValue* v; |
994 if (vd->toParent2() != p->func()->decl) { | 985 if (vd->toParent2() != p->func()->decl) { |
995 Logger::println("nested this exp"); | 986 Logger::println("nested this exp"); |
996 v = DtoLoad(DtoNestedVariable(vd)); | 987 return DtoNestedVariable(type, vd); |
997 } | 988 } |
998 else { | 989 else { |
999 Logger::println("normal this exp"); | 990 Logger::println("normal this exp"); |
1000 v = p->func()->decl->ir.irFunc->thisVar; | 991 v = p->func()->decl->ir.irFunc->thisVar; |
1001 if (llvm::isa<llvm::AllocaInst>(v)) | 992 } |
1002 v = DtoLoad(v); | 993 return new DVarValue(type, vd, v, true); |
1003 } | |
1004 const LLType* t = DtoType(type); | |
1005 if (v->getType() != t) | |
1006 v = DtoBitCast(v, t); | |
1007 return new DThisValue(type, vd, v); | |
1008 } | 994 } |
1009 | 995 |
1010 // anything we're not yet handling ? | 996 // anything we're not yet handling ? |
1011 assert(0); | 997 assert(0); |
1012 return 0; | 998 return 0; |
1495 } | 1481 } |
1496 if (!onstack) { | 1482 if (!onstack) { |
1497 LLValue* rval = dval->getRVal(); | 1483 LLValue* rval = dval->getRVal(); |
1498 DtoDeleteClass(rval); | 1484 DtoDeleteClass(rval); |
1499 } | 1485 } |
1500 if (!dval->isThis() && dval->isVar() && dval->isVar()->lval) { | 1486 if (dval->isVar() && dval->isVar()->lval) { |
1501 LLValue* lval = dval->getLVal(); | 1487 LLValue* lval = dval->getLVal(); |
1502 DtoStore(llvm::Constant::getNullValue(lval->getType()->getContainedType(0)), lval); | 1488 DtoStore(llvm::Constant::getNullValue(lval->getType()->getContainedType(0)), lval); |
1503 } | 1489 } |
1504 } | 1490 } |
1505 // dyn array | 1491 // dyn array |