comparison gen/statements.cpp @ 156:ccd07d9f2ce9 trunk

[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author ChristianK
date Thu, 01 May 2008 13:05:53 +0200
parents 7f92f477ff53
children a8cd9bc1021a
comparison
equal deleted inserted replaced
155:7f92f477ff53 156:ccd07d9f2ce9
75 if (exp) 75 if (exp)
76 { 76 {
77 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { 77 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) {
78 IrFunction* f = p->func(); 78 IrFunction* f = p->func();
79 assert(f->type->llvmRetInPtr); 79 assert(f->type->llvmRetInPtr);
80 assert(gIR->irFunc[f->decl]->retArg); 80 assert(gIR->irDsymbol[f->decl].irFunc->retArg);
81 81
82 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); 82 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum);
83 83
84 DValue* rvar = new DVarValue(f->type->next, gIR->irFunc[f->decl]->retArg, true); 84 DValue* rvar = new DVarValue(f->type->next, gIR->irDsymbol[f->decl].irFunc->retArg, true);
85 85
86 p->exps.push_back(IRExp(NULL,exp,rvar)); 86 p->exps.push_back(IRExp(NULL,exp,rvar));
87 DValue* e = exp->toElem(p); 87 DValue* e = exp->toElem(p);
88 p->exps.pop_back(); 88 p->exps.pop_back();
89 89
799 const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t(); 799 const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t();
800 llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); 800 llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint());
801 if (key) 801 if (key)
802 { 802 {
803 //key->llvmValue = keyvar; 803 //key->llvmValue = keyvar;
804 assert(!key->irLocal); 804 assert(!gIR->irDsymbol[key].irLocal);
805 key->irLocal = new IrLocal(key); 805 gIR->irDsymbol[key].irLocal = new IrLocal(key);
806 key->irLocal->value = keyvar; 806 gIR->irDsymbol[key].irLocal->value = keyvar;
807 } 807 }
808 llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false); 808 llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false);
809 809
810 // value 810 // value
811 const llvm::Type* valtype = DtoType(value->type); 811 const llvm::Type* valtype = DtoType(value->type);
812 llvm::Value* valvar = NULL; 812 llvm::Value* valvar = NULL;
813 if (!value->isRef() && !value->isOut()) 813 if (!value->isRef() && !value->isOut())
814 valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint()); 814 valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint());
815 assert(!value->irLocal); 815 assert(!gIR->irDsymbol[value].irLocal);
816 value->irLocal = new IrLocal(value); 816 gIR->irDsymbol[value].irLocal = new IrLocal(value);
817 817
818 // what to iterate 818 // what to iterate
819 DValue* aggrval = aggr->toElem(p); 819 DValue* aggrval = aggr->toElem(p);
820 Type* aggrtype = DtoDType(aggr->type); 820 Type* aggrtype = DtoDType(aggr->type);
821 821
907 907
908 // get value for this iteration 908 // get value for this iteration
909 llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false); 909 llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false);
910 llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); 910 llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp");
911 if (aggrtype->ty == Tsarray) 911 if (aggrtype->ty == Tsarray)
912 value->irLocal->value = DtoGEP(val,zero,loadedKey,"tmp"); 912 gIR->irDsymbol[value].irLocal->value = DtoGEP(val,zero,loadedKey,"tmp");
913 else if (aggrtype->ty == Tarray) 913 else if (aggrtype->ty == Tarray)
914 value->irLocal->value = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb()); 914 gIR->irDsymbol[value].irLocal->value = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb());
915 915
916 if (!value->isRef() && !value->isOut()) { 916 if (!value->isRef() && !value->isOut()) {
917 DValue* dst = new DVarValue(value->type, valvar, true); 917 DValue* dst = new DVarValue(value->type, valvar, true);
918 DValue* src = new DVarValue(value->type, value->irLocal->value, true); 918 DValue* src = new DVarValue(value->type, gIR->irDsymbol[value].irLocal->value, true);
919 DtoAssign(dst, src); 919 DtoAssign(dst, src);
920 value->irLocal->value = valvar; 920 gIR->irDsymbol[value].irLocal->value = valvar;
921 } 921 }
922 922
923 // emit body 923 // emit body
924 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,nextbb,endbb)); 924 p->loopbbs.push_back(IRLoopScope(this,enclosingtryfinally,nextbb,endbb));
925 body->toIR(p); 925 body->toIR(p);
1044 1044
1045 assert(exp); 1045 assert(exp);
1046 assert(body); 1046 assert(body);
1047 1047
1048 DValue* e = exp->toElem(p); 1048 DValue* e = exp->toElem(p);
1049 wthis->irLocal->value = e->getRVal(); 1049 gIR->irDsymbol[wthis].irLocal->value = e->getRVal();
1050 delete e; 1050 delete e;
1051 1051
1052 body->toIR(p); 1052 body->toIR(p);
1053 } 1053 }
1054 1054