comparison gen/toir.cpp @ 123:7f9a0a58394b trunk

[svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile. Removed some potentially very long logging lines. Added support for inner classes.
author lindquist
date Wed, 28 Nov 2007 03:01:51 +0100
parents 36ab367572df
children a939ec89fc72
comparison
equal deleted inserted replaced
122:36ab367572df 123:7f9a0a58394b
1262 DValue* l = e1->toElem(p); 1262 DValue* l = e1->toElem(p);
1263 1263
1264 Type* t = DtoDType(type); 1264 Type* t = DtoDType(type);
1265 Type* e1type = DtoDType(e1->type); 1265 Type* e1type = DtoDType(e1->type);
1266 1266
1267 Logger::print("e1type=%s\n", e1type->toChars()); 1267 //Logger::print("e1type=%s\n", e1type->toChars());
1268 1268
1269 if (VarDeclaration* vd = var->isVarDeclaration()) { 1269 if (VarDeclaration* vd = var->isVarDeclaration()) {
1270 llvm::Value* arrptr; 1270 llvm::Value* arrptr;
1271 if (e1type->ty == Tpointer) { 1271 if (e1type->ty == Tpointer) {
1272 assert(e1type->next->ty == Tstruct); 1272 assert(e1type->next->ty == Tstruct);
1280 TypeClass* tc = (TypeClass*)e1type; 1280 TypeClass* tc = (TypeClass*)e1type;
1281 Logger::println("Class member offset: %d", vd->offset); 1281 Logger::println("Class member offset: %d", vd->offset);
1282 std::vector<unsigned> vdoffsets(1,0); 1282 std::vector<unsigned> vdoffsets(1,0);
1283 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); 1283 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets);
1284 llvm::Value* src = l->getRVal(); 1284 llvm::Value* src = l->getRVal();
1285 Logger::cout() << "src: " << *src << '\n'; 1285 //Logger::cout() << "src: " << *src << '\n';
1286 arrptr = DtoGEP(src,vdoffsets,"tmp",p->scopebb()); 1286 arrptr = DtoGEP(src,vdoffsets,"tmp",p->scopebb());
1287 } 1287 }
1288 else 1288 else
1289 assert(0); 1289 assert(0);
1290 1290
1291 Logger::cout() << "mem: " << *arrptr << '\n'; 1291 //Logger::cout() << "mem: " << *arrptr << '\n';
1292 return new DVarValue(vd, arrptr, true); 1292 return new DVarValue(vd, arrptr, true);
1293 } 1293 }
1294 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) 1294 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
1295 { 1295 {
1296 DtoResolveDsymbol(fdecl); 1296 DtoResolveDsymbol(fdecl);
1312 assert(fdecl->vtblIndex > 0); 1312 assert(fdecl->vtblIndex > 0);
1313 assert(e1type->ty == Tclass); 1313 assert(e1type->ty == Tclass);
1314 1314
1315 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 1315 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
1316 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); 1316 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false);
1317 Logger::cout() << "vthis: " << *vthis << '\n'; 1317 //Logger::cout() << "vthis: " << *vthis << '\n';
1318 funcval = DtoGEP(vthis, zero, zero, "tmp", p->scopebb()); 1318 funcval = DtoGEP(vthis, zero, zero, "tmp", p->scopebb());
1319 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); 1319 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
1320 funcval = DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb()); 1320 funcval = DtoGEP(funcval, zero, vtblidx, toChars(), p->scopebb());
1321 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); 1321 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb());
1322 //assert(funcval->getType() == DtoType(fdecl->type)); 1322 //assert(funcval->getType() == DtoType(fdecl->type));
1330 //assert(funcval->getType() == DtoType(fdecl->type)); 1330 //assert(funcval->getType() == DtoType(fdecl->type));
1331 } 1331 }
1332 return new DFuncValue(fdecl, funcval, vthis2); 1332 return new DFuncValue(fdecl, funcval, vthis2);
1333 } 1333 }
1334 else { 1334 else {
1335 printf("unknown: %s\n", var->toChars()); 1335 printf("unsupported dotvarexp: %s\n", var->toChars());
1336 } 1336 }
1337 1337
1338 assert(0); 1338 assert(0);
1339 return 0; 1339 return 0;
1340 } 1340 }
1754 DValue* NewExp::toElem(IRState* p) 1754 DValue* NewExp::toElem(IRState* p)
1755 { 1755 {
1756 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars()); 1756 Logger::print("NewExp::toElem: %s | %s\n", toChars(), type->toChars());
1757 LOG_SCOPE; 1757 LOG_SCOPE;
1758 1758
1759 assert(!thisexp); 1759 assert(!newargs && "arguments to new not yet supported");
1760 assert(!newargs);
1761 assert(newtype); 1760 assert(newtype);
1762 assert(!allocator); 1761 assert(!allocator && "custom allocators not yet supported");
1763 1762
1764 Type* ntype = DtoDType(newtype); 1763 Type* ntype = DtoDType(newtype);
1765 1764
1766 const llvm::Type* t = DtoType(ntype); 1765 const llvm::Type* t = DtoType(ntype);
1767 1766
1807 emem = new llvm::MallocInst(t,"tmp",p->scopebb()); 1806 emem = new llvm::MallocInst(t,"tmp",p->scopebb());
1808 } 1807 }
1809 1808
1810 if (ntype->ty == Tclass) { 1809 if (ntype->ty == Tclass) {
1811 // first apply the static initializer 1810 // first apply the static initializer
1812 DtoInitClass((TypeClass*)ntype, emem); 1811 TypeClass* tc = (TypeClass*)ntype;
1812 DtoInitClass(tc, emem);
1813
1814 // set the this var for nested classes
1815 if (thisexp) {
1816 DValue* thisval = thisexp->toElem(p);
1817 size_t idx = 2;
1818 idx += tc->sym->llvmIRStruct->interfaces.size();
1819 DtoStore(thisval->getRVal(), DtoGEPi(emem,0,idx,"tmp"));
1820 }
1813 1821
1814 // then call constructor 1822 // then call constructor
1815 if (arguments) { 1823 if (arguments) {
1816 assert(member); 1824 assert(member);
1817 assert(member->llvmValue); 1825 assert(member->llvmValue);