Mercurial > projects > ldc
comparison gen/toir.c @ 24:25bb577878e8 trunk
[svn r28] * Fixed accessing aggregate fields. it was still not quite right. hopefully is now :)
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 10:13:21 +0200 |
parents | 77e3d1ddae3f |
children | 12fd8ce55d9c |
comparison
equal
deleted
inserted
replaced
23:77e3d1ddae3f | 24:25bb577878e8 |
---|---|
460 assert(r->type == elem::CONST); | 460 assert(r->type == elem::CONST); |
461 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); | 461 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); |
462 | 462 |
463 TypeStruct* ts = (TypeStruct*)e1->type->next; | 463 TypeStruct* ts = (TypeStruct*)e1->type->next; |
464 std::vector<unsigned> offsets(1,0); | 464 std::vector<unsigned> offsets(1,0); |
465 ts->sym->offsetToIndex(cofs->getZExtValue(), offsets); | 465 ts->sym->offsetToIndex(type->next, cofs->getZExtValue(), offsets); |
466 e->mem = LLVM_DtoGEP(l->getValue(), offsets, "tmp", p->scopebb()); | 466 e->mem = LLVM_DtoGEP(l->getValue(), offsets, "tmp", p->scopebb()); |
467 e->type = elem::VAR; | 467 e->type = elem::VAR; |
468 e->field = true; | 468 e->field = true; |
469 } | 469 } |
470 else if (e1->type->ty == Tpointer) { | 470 else if (e1->type->ty == Tpointer) { |
1152 assert(vd->llvmValue); | 1152 assert(vd->llvmValue); |
1153 if (vd->type->ty == Tstruct && !(type->ty == Tpointer && type->next == vd->type)) { | 1153 if (vd->type->ty == Tstruct && !(type->ty == Tpointer && type->next == vd->type)) { |
1154 TypeStruct* vdt = (TypeStruct*)vd->type; | 1154 TypeStruct* vdt = (TypeStruct*)vd->type; |
1155 e = new elem; | 1155 e = new elem; |
1156 std::vector<unsigned> dst(1,0); | 1156 std::vector<unsigned> dst(1,0); |
1157 vdt->sym->offsetToIndex(offset, dst); | 1157 vdt->sym->offsetToIndex(type->next, offset, dst); |
1158 llvm::Value* ptr = vd->llvmValue; | 1158 llvm::Value* ptr = vd->llvmValue; |
1159 assert(ptr); | 1159 assert(ptr); |
1160 e->mem = LLVM_DtoGEP(ptr,dst,"tmp",p->scopebb()); | 1160 e->mem = LLVM_DtoGEP(ptr,dst,"tmp",p->scopebb()); |
1161 e->type = elem::VAL; | 1161 e->type = elem::VAL; |
1162 e->field = true; | 1162 e->field = true; |
1240 std::vector<unsigned> vdoffsets(1,0); | 1240 std::vector<unsigned> vdoffsets(1,0); |
1241 llvm::Value* src = 0; | 1241 llvm::Value* src = 0; |
1242 if (e1->type->ty == Tpointer) { | 1242 if (e1->type->ty == Tpointer) { |
1243 assert(e1->type->next->ty == Tstruct); | 1243 assert(e1->type->next->ty == Tstruct); |
1244 TypeStruct* ts = (TypeStruct*)e1->type->next; | 1244 TypeStruct* ts = (TypeStruct*)e1->type->next; |
1245 ts->sym->offsetToIndex(vd->offset, vdoffsets); | 1245 ts->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); |
1246 Logger::println("Struct member offset:%d", vd->offset); | 1246 Logger::println("Struct member offset:%d", vd->offset); |
1247 src = l->val ? l->val : l->mem; | 1247 src = l->val ? l->val : l->mem; |
1248 } | 1248 } |
1249 else if (e1->type->ty == Tclass) { | 1249 else if (e1->type->ty == Tclass) { |
1250 TypeClass* tc = (TypeClass*)e1->type; | 1250 TypeClass* tc = (TypeClass*)e1->type; |
1251 Logger::println("Class member offset: %d", vd->offset); | 1251 Logger::println("Class member offset: %d", vd->offset); |
1252 tc->sym->offsetToIndex(vd->offset, vdoffsets); | 1252 tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); |
1253 src = l->getValue(); | 1253 src = l->getValue(); |
1254 } | 1254 } |
1255 assert(vdoffsets.size() != 1); | 1255 assert(vdoffsets.size() != 1); |
1256 assert(src != 0); | 1256 assert(src != 0); |
1257 llvm::Value* arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb()); | 1257 llvm::Value* arrptr = LLVM_DtoGEP(src,vdoffsets,"tmp",p->scopebb()); |
1374 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); | 1374 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); |
1375 | 1375 |
1376 Expression* vx = (Expression*)elements->data[i]; | 1376 Expression* vx = (Expression*)elements->data[i]; |
1377 if (vx != 0) { | 1377 if (vx != 0) { |
1378 elem* ve = vx->toElem(p); | 1378 elem* ve = vx->toElem(p); |
1379 //Logger::cout() << *ve->val << " | " << *arrptr << '\n'; | 1379 llvm::Value* val = ve->getValue(); |
1380 new llvm::StoreInst(ve->getValue(), arrptr, p->scopebb()); | 1380 Logger::cout() << *val << " | " << *arrptr << '\n'; |
1381 new llvm::StoreInst(val, arrptr, p->scopebb()); | |
1381 delete ve; | 1382 delete ve; |
1382 } | 1383 } |
1383 else { | 1384 else { |
1384 assert(0); | 1385 assert(0); |
1385 } | 1386 } |