Mercurial > projects > ldc
comparison gen/statements.cpp @ 1185:8baf611f0009
Fix nested references to 'ref' foreach variables.
These "walk around" the array being iterated over, so they're a bit trickier
than other variables to get right.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 01 Apr 2009 00:01:44 +0200 |
parents | 7d28dcbff23e |
children | 0686701178d3 |
comparison
equal
deleted
inserted
replaced
1183:df386fd4030e | 1185:8baf611f0009 |
---|---|
1028 keyvar = DtoAlloca(keytype, "foreachkey"); | 1028 keyvar = DtoAlloca(keytype, "foreachkey"); |
1029 LLValue* zerokey = llvm::ConstantInt::get(keytype,0,false); | 1029 LLValue* zerokey = llvm::ConstantInt::get(keytype,0,false); |
1030 | 1030 |
1031 // value | 1031 // value |
1032 Logger::println("value = %s", value->toPrettyChars()); | 1032 Logger::println("value = %s", value->toPrettyChars()); |
1033 DtoRawVarDeclaration(value); | |
1034 const LLType* valtype = DtoType(value->type); | |
1035 LLValue* valvar = NULL; | 1033 LLValue* valvar = NULL; |
1036 if (!value->isRef() && !value->isOut()) | 1034 if (!value->isRef() && !value->isOut()) { |
1035 // Create a local variable to serve as the value. | |
1036 DtoRawVarDeclaration(value); | |
1037 valvar = value->ir.irLocal->value; | 1037 valvar = value->ir.irLocal->value; |
1038 } | |
1038 | 1039 |
1039 // what to iterate | 1040 // what to iterate |
1040 DValue* aggrval = aggr->toElem(p); | 1041 DValue* aggrval = aggr->toElem(p); |
1041 Type* aggrtype = aggr->type->toBasetype(); | 1042 Type* aggrtype = aggr->type->toBasetype(); |
1042 | 1043 |
1091 p->scope() = IRScope(bodybb,nextbb); | 1092 p->scope() = IRScope(bodybb,nextbb); |
1092 | 1093 |
1093 // get value for this iteration | 1094 // get value for this iteration |
1094 LLConstant* zero = llvm::ConstantInt::get(keytype,0,false); | 1095 LLConstant* zero = llvm::ConstantInt::get(keytype,0,false); |
1095 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); | 1096 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); |
1096 value->ir.irLocal->value = DtoGEP1(val,loadedKey); | 1097 LLValue* gep = DtoGEP1(val,loadedKey); |
1097 | 1098 |
1098 if (!value->isRef() && !value->isOut()) { | 1099 if (!value->isRef() && !value->isOut()) { |
1100 // Copy value to local variable, and use it as the value variable. | |
1099 DVarValue dst(value->type, valvar); | 1101 DVarValue dst(value->type, valvar); |
1100 DVarValue src(value->type, value->ir.irLocal->value); | 1102 DVarValue src(value->type, gep); |
1101 DtoAssign(loc, &dst, &src); | 1103 DtoAssign(loc, &dst, &src); |
1102 value->ir.irLocal->value = valvar; | 1104 value->ir.irLocal->value = valvar; |
1105 } else { | |
1106 // Use the GEP as the address of the value variable. | |
1107 DtoRawVarDeclaration(value, gep); | |
1103 } | 1108 } |
1104 | 1109 |
1105 // emit body | 1110 // emit body |
1106 p->func()->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); | 1111 p->func()->targetScopes.push_back(IRTargetScope(this,NULL,nextbb,endbb)); |
1107 if(body) | 1112 if(body) |