comparison gen/toir.cpp @ 98:6789050b5ad1 trunk

[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references. Now uses the DMD _adEq(void[], void[], TypeInfo) runtime function for array equality comparison.
author lindquist
date Wed, 14 Nov 2007 23:39:10 +0100
parents c4e161556a21
children a676a7743642
comparison
equal deleted inserted replaced
97:c4e161556a21 98:6789050b5ad1
62 const llvm::Type* lltype = DtoType(vd->type); 62 const llvm::Type* lltype = DtoType(vd->type);
63 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); 63 llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint());
64 //allocainst->setAlignment(vd->type->alignsize()); // TODO 64 //allocainst->setAlignment(vd->type->alignsize()); // TODO
65 vd->llvmValue = allocainst; 65 vd->llvmValue = allocainst;
66 } 66 }
67 Logger::cout() << "llvm value for decl: " << *vd->llvmValue << '\n';
67 DValue* ie = DtoInitializer(vd->init); 68 DValue* ie = DtoInitializer(vd->init);
68 } 69 }
69 70
70 return new DVarValue(vd, vd->llvmValue, true); 71 return new DVarValue(vd, vd->llvmValue, true);
71 } 72 }
1362 DValue* SymOffExp::toElem(IRState* p) 1363 DValue* SymOffExp::toElem(IRState* p)
1363 { 1364 {
1364 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars()); 1365 Logger::print("SymOffExp::toElem: %s | %s\n", toChars(), type->toChars());
1365 LOG_SCOPE; 1366 LOG_SCOPE;
1366 1367
1368 assert(0 && "SymOffExp::toElem should no longer be called :/");
1369
1367 if (VarDeclaration* vd = var->isVarDeclaration()) 1370 if (VarDeclaration* vd = var->isVarDeclaration())
1368 { 1371 {
1369 Logger::println("VarDeclaration"); 1372 Logger::println("VarDeclaration");
1370 if (!vd->llvmTouched && vd->isDataseg()) 1373 if (!vd->llvmTouched && vd->isDataseg())
1371 vd->toObjFile(); 1374 vd->toObjFile();
1372
1373 // TODO
1374 /*
1375 if (vd->isTypedefDeclaration()) {
1376 e->istypeinfo = true;
1377 }
1378 */
1379 1375
1380 assert(vd->llvmValue); 1376 assert(vd->llvmValue);
1381 Type* t = DtoDType(type); 1377 Type* t = DtoDType(type);
1382 Type* tnext = DtoDType(t->next); 1378 Type* tnext = DtoDType(t->next);
1383 Type* vdtype = DtoDType(vd->type); 1379 Type* vdtype = DtoDType(vd->type);
1538 assert(fdecl->vtblIndex > 0); 1534 assert(fdecl->vtblIndex > 0);
1539 assert(e1type->ty == Tclass); 1535 assert(e1type->ty == Tclass);
1540 1536
1541 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 1537 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
1542 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); 1538 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false);
1539 Logger::cout() << "vthis: " << *vthis << '\n';
1543 funcval = DtoGEP(vthis, zero, zero, "tmp", p->scopebb()); 1540 funcval = DtoGEP(vthis, zero, zero, "tmp", p->scopebb());
1544 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); 1541 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
1545 funcval = DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb()); 1542 funcval = DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb());
1546 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); 1543 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
1547 assert(funcval->getType() == fdecl->llvmValue->getType()); 1544 assert(funcval->getType() == fdecl->llvmValue->getType());
1869 default: 1866 default:
1870 assert(0); 1867 assert(0);
1871 } 1868 }
1872 eval = new llvm::FCmpInst(cmpop, l->getRVal(), r->getRVal(), "tmp", p->scopebb()); 1869 eval = new llvm::FCmpInst(cmpop, l->getRVal(), r->getRVal(), "tmp", p->scopebb());
1873 } 1870 }
1874 else if (t->ty == Tsarray) 1871 else if (t->ty == Tsarray || t->ty == Tarray)
1875 { 1872 {
1876 Logger::println("static array"); 1873 Logger::println("static or dynamic array");
1877 eval = DtoStaticArrayCompare(op,l->getRVal(),r->getRVal()); 1874 eval = DtoArrayEquals(op,l,r);
1878 }
1879 else if (t->ty == Tarray)
1880 {
1881 Logger::println("dynamic array");
1882 eval = DtoDynArrayCompare(op,l->getRVal(),r->getRVal());
1883 } 1875 }
1884 else if (t->ty == Tdelegate) 1876 else if (t->ty == Tdelegate)
1885 { 1877 {
1886 Logger::println("delegate"); 1878 Logger::println("delegate");
1887 eval = DtoCompareDelegate(op,l->getRVal(),r->getRVal()); 1879 eval = DtoCompareDelegate(op,l->getRVal(),r->getRVal());
2566 } 2558 }
2567 } 2559 }
2568 else 2560 else
2569 assert(0); 2561 assert(0);
2570 2562
2563 Logger::cout() << "array literal mem: " << *mem << '\n';
2564
2571 for (unsigned i=0; i<elements->dim; ++i) 2565 for (unsigned i=0; i<elements->dim; ++i)
2572 { 2566 {
2573 Expression* expr = (Expression*)elements->data[i]; 2567 Expression* expr = (Expression*)elements->data[i];
2574 llvm::Value* elemAddr = DtoGEPi(mem,0,i,"tmp",p->scopebb()); 2568 llvm::Value* elemAddr = DtoGEPi(mem,0,i,"tmp",p->scopebb());
2569 DVarValue* vv = new DVarValue(expr->type, elemAddr, true);
2570 p->exps.push_back(IRExp(NULL, expr, vv));
2575 DValue* e = expr->toElem(p); 2571 DValue* e = expr->toElem(p);
2576 new llvm::StoreInst(e->getRVal(), elemAddr, p->scopebb()); 2572 p->exps.pop_back();
2573
2574 DImValue* im = e->isIm();
2575 if (!im || !im->inPlace()) {
2576 DtoAssign(vv, e);
2577 }
2577 } 2578 }
2578 2579
2579 if (ty->ty == Tsarray) 2580 if (ty->ty == Tsarray)
2580 return new DImValue(type, mem, true); 2581 return new DImValue(type, mem, true);
2581 else if (ty->ty == Tarray) 2582 else if (ty->ty == Tarray)