Mercurial > projects > ldc
comparison gen/tollvm.c @ 51:61bc1b4ad3c4 trunk
[svn r55] Foreach was always generating code as if the value variable was 'ref'
Other not-so-major improvements
author | lindquist |
---|---|
date | Mon, 22 Oct 2007 17:25:44 +0200 |
parents | 6fcc08a4d406 |
children | 0c77619e803b |
comparison
equal
deleted
inserted
replaced
50:6fcc08a4d406 | 51:61bc1b4ad3c4 |
---|---|
433 return _func; | 433 return _func; |
434 } | 434 } |
435 | 435 |
436 ////////////////////////////////////////////////////////////////////////////////////////// | 436 ////////////////////////////////////////////////////////////////////////////////////////// |
437 | 437 |
438 llvm::Value* LLVM_DtoStructZeroInit(TypeStruct* t, llvm::Value* v) | 438 llvm::Value* LLVM_DtoStructZeroInit(llvm::Value* v) |
439 { | 439 { |
440 assert(gIR); | 440 assert(gIR); |
441 uint64_t n = gTargetData->getTypeSize(t->llvmType); | 441 uint64_t n = gTargetData->getTypeSize(v->getType()->getContainedType(0)); |
442 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); | 442 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); |
443 llvm::Type* sarrty = llvm::PointerType::get(llvm::Type::Int8Ty); | 443 llvm::Type* sarrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
444 | 444 |
445 llvm::Value* sarr = new llvm::BitCastInst(v,sarrty,"tmp",gIR->scopebb()); | 445 llvm::Value* sarr = new llvm::BitCastInst(v,sarrty,"tmp",gIR->scopebb()); |
446 | 446 |
457 return ret; | 457 return ret; |
458 } | 458 } |
459 | 459 |
460 ////////////////////////////////////////////////////////////////////////////////////////// | 460 ////////////////////////////////////////////////////////////////////////////////////////// |
461 | 461 |
462 llvm::Value* LLVM_DtoStructCopy(TypeStruct* t, llvm::Value* dst, llvm::Value* src) | 462 llvm::Value* LLVM_DtoStructCopy(llvm::Value* dst, llvm::Value* src) |
463 { | 463 { |
464 assert(dst->getType() == src->getType()); | 464 assert(dst->getType() == src->getType()); |
465 assert(gIR); | 465 assert(gIR); |
466 | 466 |
467 uint64_t n = gTargetData->getTypeSize(t->llvmType); | 467 uint64_t n = gTargetData->getTypeSize(dst->getType()->getContainedType(0)); |
468 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); | 468 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); |
469 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); | 469 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
470 | 470 |
471 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); | 471 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); |
472 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); | 472 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); |
1108 } | 1108 } |
1109 else { | 1109 else { |
1110 llvm::Value* allocaInst = 0; | 1110 llvm::Value* allocaInst = 0; |
1111 llvm::BasicBlock* entryblock = &gIR->topfunc()->front(); | 1111 llvm::BasicBlock* entryblock = &gIR->topfunc()->front(); |
1112 //const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType()); | 1112 //const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType()); |
1113 const llvm::PointerType* pty = llvm::PointerType::get(LLVM_DtoType(argexp->type)); | 1113 const llvm::Type* realtypell = LLVM_DtoType(realtype); |
1114 const llvm::PointerType* pty = llvm::PointerType::get(realtypell); | |
1114 if (argty == Tstruct) { | 1115 if (argty == Tstruct) { |
1115 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); | 1116 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); |
1116 TypeStruct* ts = (TypeStruct*)LLVM_DtoDType(argexp->type); | 1117 LLVM_DtoStructCopy(allocaInst,arg->mem); |
1117 LLVM_DtoStructCopy(ts,allocaInst,arg->mem); | |
1118 } | 1118 } |
1119 else if (argty == Tdelegate) { | 1119 else if (argty == Tdelegate) { |
1120 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); | 1120 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); |
1121 LLVM_DtoDelegateCopy(allocaInst,arg->mem); | 1121 LLVM_DtoDelegateCopy(allocaInst,arg->mem); |
1122 } | 1122 } |
1123 else if (argty == Tarray) { | 1123 else if (argty == Tarray) { |
1124 if (arg->type == elem::SLICE) { | 1124 if (arg->type == elem::SLICE) { |
1125 allocaInst = new llvm::AllocaInst(LLVM_DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); | 1125 allocaInst = new llvm::AllocaInst(realtypell, "tmpparam", gIR->topallocapoint()); |
1126 LLVM_DtoSetArray(allocaInst, arg->arg, arg->mem); | 1126 LLVM_DtoSetArray(allocaInst, arg->arg, arg->mem); |
1127 } | 1127 } |
1128 else { | 1128 else { |
1129 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); | 1129 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint()); |
1130 LLVM_DtoArrayAssign(allocaInst,arg->mem); | 1130 LLVM_DtoArrayAssign(allocaInst,arg->mem); |
1207 } | 1207 } |
1208 | 1208 |
1209 assert(0 && "nested var not found"); | 1209 assert(0 && "nested var not found"); |
1210 return NULL; | 1210 return NULL; |
1211 } | 1211 } |
1212 | |
1213 ////////////////////////////////////////////////////////////////////////////////////////// | |
1214 | |
1215 void LLVM_DtoAssign(Type* t, llvm::Value* lhs, llvm::Value* rhs) | |
1216 { | |
1217 Logger::cout() << "assignment:" << '\n' << *lhs << *rhs << '\n'; | |
1218 | |
1219 if (t->ty == Tstruct) { | |
1220 assert(lhs->getType() == rhs->getType()); | |
1221 LLVM_DtoStructCopy(lhs,rhs); | |
1222 } | |
1223 else if (t->ty == Tarray) { | |
1224 assert(lhs->getType() == rhs->getType()); | |
1225 LLVM_DtoArrayAssign(lhs,rhs); | |
1226 } | |
1227 else if (t->ty == Tsarray) { | |
1228 assert(lhs->getType() == rhs->getType()); | |
1229 LLVM_DtoStaticArrayCopy(lhs,rhs); | |
1230 } | |
1231 else if (t->ty == Tdelegate) { | |
1232 assert(lhs->getType() == rhs->getType()); | |
1233 LLVM_DtoDelegateCopy(lhs,rhs); | |
1234 } | |
1235 else { | |
1236 assert(lhs->getType()->getContainedType(0) == rhs->getType()); | |
1237 gIR->ir->CreateStore(rhs, lhs); | |
1238 } | |
1239 } |