comparison gen/toir.c @ 30:881158a93592 trunk

[svn r34] * Fixed passing a struct literal as function argument
author lindquist
date Thu, 04 Oct 2007 14:15:54 +0200
parents 253a5fc4033a
children a86fe7496b58
comparison
equal deleted inserted replaced
29:253a5fc4033a 30:881158a93592
931 // regular parameters 931 // regular parameters
932 for (int i=0; i<arguments->dim; i++,j++) 932 for (int i=0; i<arguments->dim; i++,j++)
933 { 933 {
934 Expression* argexp = (Expression*)arguments->data[i]; 934 Expression* argexp = (Expression*)arguments->data[i];
935 elem* arg = argexp->toElem(p); 935 elem* arg = argexp->toElem(p);
936 if (arg->inplace) {
937 assert(arg->mem);
938 llargs[j] = arg->mem;
939 continue;
940 }
936 941
937 Argument* fnarg = Argument::getNth(tf->parameters, i); 942 Argument* fnarg = Argument::getNth(tf->parameters, i);
938 943
939 TY argty = argexp->type->ty; 944 TY argty = argexp->type->ty;
940 if (argty == Tstruct || argty == Tdelegate || argty == Tarray) { 945 if (argty == Tstruct || argty == Tdelegate || argty == Tarray) {
1383 { 1388 {
1384 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); 1389 Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars());
1385 LOG_SCOPE; 1390 LOG_SCOPE;
1386 elem* e = new elem; 1391 elem* e = new elem;
1387 1392
1388 // if there is no lval, this must be a static initializer for a global. correct? 1393 llvm::Value* sptr = 0;
1394
1395 // if there is no lval, this is probably a temporary struct literal. correct?
1389 if (p->lvals.empty()) 1396 if (p->lvals.empty())
1390 { 1397 {
1391 // TODO 1398 sptr = new llvm::AllocaInst(LLVM_DtoType(type),"tmpstructliteral",p->topallocapoint());
1392 assert(0); 1399 e->mem = sptr;
1393 } 1400 e->type = elem::VAR;
1394 // otherwise write directly in the lvalue 1401 }
1402 // already has memory
1395 else 1403 else
1396 { 1404 {
1397 llvm::Value* sptr = p->toplval(); 1405 sptr = p->toplval();
1398 assert(sptr); 1406 }
1399 1407
1400 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); 1408 assert(sptr);
1401 1409
1402 unsigned n = elements->dim; 1410 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
1403 for (unsigned i=0; i<n; ++i) 1411
1404 { 1412 unsigned n = elements->dim;
1405 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false); 1413 for (unsigned i=0; i<n; ++i)
1406 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); 1414 {
1407 1415 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
1408 Expression* vx = (Expression*)elements->data[i]; 1416 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb());
1409 if (vx != 0) { 1417
1410 elem* ve = vx->toElem(p); 1418 Expression* vx = (Expression*)elements->data[i];
1411 llvm::Value* val = ve->getValue(); 1419 if (vx != 0) {
1412 Logger::cout() << *val << " | " << *arrptr << '\n'; 1420 elem* ve = vx->toElem(p);
1413 if (vx->type->ty == Tstruct) { 1421 llvm::Value* val = ve->getValue();
1414 TypeStruct* ts = (TypeStruct*)vx->type; 1422 Logger::cout() << *val << " | " << *arrptr << '\n';
1415 LLVM_DtoStructCopy(ts,arrptr,val); 1423 if (vx->type->ty == Tstruct) {
1416 } 1424 TypeStruct* ts = (TypeStruct*)vx->type;
1417 else 1425 LLVM_DtoStructCopy(ts,arrptr,val);
1418 new llvm::StoreInst(val, arrptr, p->scopebb()); 1426 }
1419 delete ve; 1427 else
1420 } 1428 new llvm::StoreInst(val, arrptr, p->scopebb());
1421 else { 1429 delete ve;
1422 assert(0); 1430 }
1423 } 1431 else {
1432 assert(0);
1424 } 1433 }
1425 } 1434 }
1426 1435
1427 e->inplace = true; 1436 e->inplace = true;
1428 1437