comparison gen/toir.c @ 15:37a4fdab33fc trunk

[svn r19] * Added support for reassigning 'this' inside class constructors. * Added preliminary support for UnrolledLoopStatement. That is foreach on a tuple.
author lindquist
date Wed, 03 Oct 2007 04:56:32 +0200
parents 0e86428ee567
children c05ef76f1c20
comparison
equal deleted inserted replaced
14:0e86428ee567 15:37a4fdab33fc
382 assert(0); 382 assert(0);
383 } 383 }
384 else if (e1ty == Tclass) { 384 else if (e1ty == Tclass) {
385 if (e2ty == Tclass) { 385 if (e2ty == Tclass) {
386 llvm::Value* tmp = r->getValue(); 386 llvm::Value* tmp = r->getValue();
387 Logger::cout() << "tmp: " << *tmp << ", " << *l->mem << '\n'; 387 Logger::cout() << "tmp: " << *tmp << " ||| " << *l->mem << '\n';
388 new llvm::StoreInst(tmp, l->mem, p->scopebb()); 388 // assignment to this in constructor special case
389 if (l->isthis) {
390 FuncDeclaration* fdecl = p->funcdecls.back();
391 // respecify the this param
392 if (!llvm::isa<llvm::AllocaInst>(fdecl->llvmThisVar))
393 fdecl->llvmThisVar = new llvm::AllocaInst(tmp->getType(), "newthis", p->topallocapoint());
394 new llvm::StoreInst(tmp, fdecl->llvmThisVar, p->scopebb());
395 }
396 // regular class ref -> class ref assignment
397 else {
398 new llvm::StoreInst(tmp, l->mem, p->scopebb());
399 }
389 } 400 }
390 else 401 else
391 assert(0); 402 assert(0);
392 } 403 }
393 else if (e1ty == Tdelegate) { 404 else if (e1ty == Tdelegate) {
1216 if (e1->type->ty == Tpointer) { 1227 if (e1->type->ty == Tpointer) {
1217 assert(e1->type->next->ty == Tstruct); 1228 assert(e1->type->next->ty == Tstruct);
1218 TypeStruct* ts = (TypeStruct*)e1->type->next; 1229 TypeStruct* ts = (TypeStruct*)e1->type->next;
1219 ts->sym->offsetToIndex(vd->offset, vdoffsets); 1230 ts->sym->offsetToIndex(vd->offset, vdoffsets);
1220 Logger::println("Struct member offset:%d", vd->offset); 1231 Logger::println("Struct member offset:%d", vd->offset);
1221 src = l->val; 1232 src = l->val ? l->val : l->mem;
1222 } 1233 }
1223 else if (e1->type->ty == Tclass) { 1234 else if (e1->type->ty == Tclass) {
1224 TypeClass* tc = (TypeClass*)e1->type; 1235 TypeClass* tc = (TypeClass*)e1->type;
1225 Logger::println("Class member offset: %d", vd->offset); 1236 Logger::println("Class member offset: %d", vd->offset);
1226 tc->sym->offsetToIndex(vd->offset, vdoffsets); 1237 tc->sym->offsetToIndex(vd->offset, vdoffsets);
1277 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars()); 1288 Logger::print("ThisExp::toElem: %s | %s\n", toChars(), type->toChars());
1278 LOG_SCOPE; 1289 LOG_SCOPE;
1279 elem* e = new elem; 1290 elem* e = new elem;
1280 1291
1281 if (VarDeclaration* vd = var->isVarDeclaration()) { 1292 if (VarDeclaration* vd = var->isVarDeclaration()) {
1282 assert(vd->llvmValue == 0); 1293 /*assert(vd->llvmValue == 0);
1283 1294
1284 llvm::Function* fn = p->topfunc(); 1295 llvm::Function* fn = p->topfunc();
1285 assert(fn); 1296 assert(fn);
1286 1297
1287 TypeFunction* tf = p->topfunctype(); 1298 TypeFunction* tf = p->topfunctype();
1290 llvm::Value* v = 0; 1301 llvm::Value* v = 0;
1291 if (tf->llvmRetInPtr) 1302 if (tf->llvmRetInPtr)
1292 v = ++fn->arg_begin(); 1303 v = ++fn->arg_begin();
1293 else 1304 else
1294 v = fn->arg_begin(); 1305 v = fn->arg_begin();
1295 assert(v); 1306 assert(v);*/
1296 1307
1297 e->val = v; 1308 llvm::Value* v = p->funcdecls.back()->llvmThisVar;
1309 if (llvm::isa<llvm::AllocaInst>(v))
1310 v = new llvm::LoadInst(v, "tmp", p->scopebb());
1311 e->mem = v;
1298 e->type = elem::VAL; 1312 e->type = elem::VAL;
1313 e->isthis = true;
1299 } 1314 }
1300 else { 1315 else {
1301 assert(0); 1316 assert(0);
1302 } 1317 }
1303 1318
1792 } 1807 }
1793 } 1808 }
1794 1809
1795 e->inplace = true; 1810 e->inplace = true;
1796 e->type = elem::VAR; 1811 e->type = elem::VAR;
1797 1812
1798 return e; 1813 return e;
1799 } 1814 }
1800 1815
1801 ////////////////////////////////////////////////////////////////////////////////////////// 1816 //////////////////////////////////////////////////////////////////////////////////////////
1802 1817