Mercurial > projects > ldc
comparison gen/tollvm.c @ 73:b706170e24a9 trunk
[svn r77] Fixed foreach on slice.
Fixed some nested function problems when accessing outer function parameters.
Major changes to handling of structs.
Initial support for unions.
Probably more...
author | lindquist |
---|---|
date | Wed, 31 Oct 2007 03:11:32 +0100 |
parents | d7e764e62462 |
children | 714057ff2dbb |
comparison
equal
deleted
inserted
replaced
72:d7e764e62462 | 73:b706170e24a9 |
---|---|
15 #include "gen/elem.h" | 15 #include "gen/elem.h" |
16 #include "gen/arrays.h" | 16 #include "gen/arrays.h" |
17 | 17 |
18 bool LLVM_DtoIsPassedByRef(Type* type) | 18 bool LLVM_DtoIsPassedByRef(Type* type) |
19 { | 19 { |
20 TY t = type->ty; | 20 TY t = LLVM_DtoDType(type)->ty; |
21 if (t == Tstruct || t == Tarray || t == Tdelegate) | 21 return (t == Tstruct || t == Tarray || t == Tdelegate); |
22 return true; | |
23 else if (t == Ttypedef) { | |
24 Type* bt = type->toBasetype(); | |
25 assert(bt); | |
26 return LLVM_DtoIsPassedByRef(bt); | |
27 } | |
28 return false; | |
29 } | 22 } |
30 | 23 |
31 Type* LLVM_DtoDType(Type* t) | 24 Type* LLVM_DtoDType(Type* t) |
32 { | 25 { |
33 if (t->ty == Ttypedef) { | 26 if (t->ty == Ttypedef) { |
528 VarDeclaration* vd = (VarDeclaration*)si->vars.data[i]; | 521 VarDeclaration* vd = (VarDeclaration*)si->vars.data[i]; |
529 Type* vdtype = LLVM_DtoDType(vd->type); | 522 Type* vdtype = LLVM_DtoDType(vd->type); |
530 assert(vd); | 523 assert(vd); |
531 Logger::println("vars[%d] = %s", i, vd->toChars()); | 524 Logger::println("vars[%d] = %s", i, vd->toChars()); |
532 | 525 |
533 std::vector<unsigned> idxs; | |
534 si->ad->offsetToIndex(vdtype, vd->offset, idxs); | |
535 assert(idxs.size() == 1); | |
536 unsigned idx = idxs[0]; | |
537 | |
538 llvm::Constant* v = 0; | 526 llvm::Constant* v = 0; |
527 | |
528 assert(vd->llvmFieldIndex >= 0); | |
529 unsigned idx = vd->llvmFieldIndex; | |
539 | 530 |
540 if (ExpInitializer* ex = ini->isExpInitializer()) | 531 if (ExpInitializer* ex = ini->isExpInitializer()) |
541 { | 532 { |
542 v = ex->exp->toConstElem(gIR); | 533 v = ex->exp->toConstElem(gIR); |
543 } | 534 } |
555 } | 546 } |
556 else | 547 else |
557 assert(v); | 548 assert(v); |
558 | 549 |
559 inits[idx] = v; | 550 inits[idx] = v; |
551 Logger::cout() << "init[" << idx << "] = " << *v << '\n'; | |
560 } | 552 } |
561 | 553 |
562 // fill out nulls | 554 // fill out nulls |
563 assert(si->ad->llvmInitZ); | 555 assert(si->ad->llvmInitZ); |
564 if (si->ad->llvmInitZ->isNullValue()) | 556 if (si->ad->llvmInitZ->isNullValue()) |
1269 FuncDeclaration* f = fcur->decl; | 1261 FuncDeclaration* f = fcur->decl; |
1270 | 1262 |
1271 // on this stack | 1263 // on this stack |
1272 if (fd == f) { | 1264 if (fd == f) { |
1273 llvm::Value* v = LLVM_DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp"); | 1265 llvm::Value* v = LLVM_DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp"); |
1274 if (vd->isParameter() && (vd->isRef() || vd->isOut())) | 1266 if (vd->isParameter() && (vd->isRef() || vd->isOut() || LLVM_DtoIsPassedByRef(vd->type))) { |
1267 Logger::cout() << "1267 loading: " << *v << '\n'; | |
1275 v = gIR->ir->CreateLoad(v,"tmp"); | 1268 v = gIR->ir->CreateLoad(v,"tmp"); |
1269 } | |
1276 return v; | 1270 return v; |
1277 } | 1271 } |
1278 | 1272 |
1279 // on a caller stack | 1273 // on a caller stack |
1280 llvm::Value* ptr = f->llvmThisVar; | 1274 llvm::Value* ptr = f->llvmThisVar; |
1291 Logger::cout() << "nested var reference:" << '\n' << *ptr << *nesttype << '\n'; | 1285 Logger::cout() << "nested var reference:" << '\n' << *ptr << *nesttype << '\n'; |
1292 | 1286 |
1293 while (f) { | 1287 while (f) { |
1294 if (fd == f) { | 1288 if (fd == f) { |
1295 llvm::Value* v = LLVM_DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp"); | 1289 llvm::Value* v = LLVM_DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp"); |
1296 if (vd->isParameter() && (vd->isRef() || vd->isOut())) | 1290 if (vd->isParameter() && (vd->isRef() || vd->isOut() || LLVM_DtoIsPassedByRef(vd->type))) { |
1291 Logger::cout() << "1291 loading: " << *v << '\n'; | |
1297 v = gIR->ir->CreateLoad(v,"tmp"); | 1292 v = gIR->ir->CreateLoad(v,"tmp"); |
1293 } | |
1298 return v; | 1294 return v; |
1299 } | 1295 } |
1300 else { | 1296 else { |
1301 ptr = LLVM_DtoGEPi(ptr,0,0,"tmp"); | 1297 ptr = LLVM_DtoGEPi(ptr,0,0,"tmp"); |
1302 ptr = gIR->ir->CreateLoad(ptr,"tmp"); | 1298 ptr = gIR->ir->CreateLoad(ptr,"tmp"); |