Changeset 747:46d0755451a4
- Timestamp:
- 11/01/08 13:25:10
(2 months ago)
- Author:
- Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
- branch:
- default
- Message:
Added DtoRawVarDeclaration? routine to handle special variables in some statements.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r719 |
r747 |
|
| 1321 | 1321 | } |
|---|
| 1322 | 1322 | |
|---|
| | 1323 | // does pretty much the same as DtoDeclarationExp, except it doesn't initialize, and only handles var declarations |
|---|
| | 1324 | LLValue* DtoRawVarDeclaration(VarDeclaration* var) |
|---|
| | 1325 | { |
|---|
| | 1326 | // we don't handle globals with this one |
|---|
| | 1327 | assert(!var->isDataseg()); |
|---|
| | 1328 | |
|---|
| | 1329 | // we don't handle aliases either |
|---|
| | 1330 | assert(!var->aliassym); |
|---|
| | 1331 | |
|---|
| | 1332 | // referenced by nested function? |
|---|
| | 1333 | if (var->nestedref) |
|---|
| | 1334 | { |
|---|
| | 1335 | assert(var->ir.irLocal); |
|---|
| | 1336 | assert(!var->ir.irLocal->value); |
|---|
| | 1337 | |
|---|
| | 1338 | // alloca |
|---|
| | 1339 | var->ir.irLocal->value = DtoAlloca(DtoType(var->type), var->toChars()); |
|---|
| | 1340 | |
|---|
| | 1341 | // store the address into the nested vars array |
|---|
| | 1342 | assert(var->ir.irLocal->nestedIndex >= 0); |
|---|
| | 1343 | LLValue* gep = DtoGEPi(gIR->func()->decl->ir.irFunc->nestedVar, 0, var->ir.irLocal->nestedIndex); |
|---|
| | 1344 | assert(isaPointer(var->ir.irLocal->value)); |
|---|
| | 1345 | LLValue* val = DtoBitCast(var->ir.irLocal->value, getVoidPtrType()); |
|---|
| | 1346 | DtoStore(val, gep); |
|---|
| | 1347 | } |
|---|
| | 1348 | // normal local variable |
|---|
| | 1349 | else |
|---|
| | 1350 | { |
|---|
| | 1351 | assert(!var->ir.isSet()); |
|---|
| | 1352 | var->ir.irLocal = new IrLocal(var); |
|---|
| | 1353 | var->ir.irLocal->value = DtoAlloca(DtoType(var->type), var->toChars()); |
|---|
| | 1354 | } |
|---|
| | 1355 | |
|---|
| | 1356 | // add debug info |
|---|
| | 1357 | if (global.params.symdebug) |
|---|
| | 1358 | DtoDwarfLocalVariable(var->ir.irLocal->value, var); |
|---|
| | 1359 | |
|---|
| | 1360 | // return the alloca |
|---|
| | 1361 | return var->ir.irLocal->value; |
|---|
| | 1362 | } |
|---|
| 1323 | 1363 | |
|---|
| 1324 | 1364 | /****************************************************************************************/ |
|---|
| r715 |
r747 |
|
| 84 | 84 | // declaration inside a declarationexp |
|---|
| 85 | 85 | DValue* DtoDeclarationExp(Dsymbol* declaration); |
|---|
| | 86 | LLValue* DtoRawVarDeclaration(VarDeclaration* var); |
|---|
| 86 | 87 | |
|---|
| 87 | 88 | // initializer helpers |
|---|
| r745 |
r747 |
|
| 155 | 155 | |
|---|
| 156 | 156 | if (match) |
|---|
| 157 | | DtoDeclarationExp(match); |
|---|
| | 157 | DtoRawVarDeclaration(match); |
|---|
| 158 | 158 | |
|---|
| 159 | 159 | DValue* cond_e = condition->toElem(p); |
|---|
| … | … | |
| 927 | 927 | LLValue* keyvar; |
|---|
| 928 | 928 | if (key) |
|---|
| 929 | | { |
|---|
| 930 | | DtoDeclarationExp(key); |
|---|
| 931 | | keyvar = key->ir.irLocal->value; |
|---|
| 932 | | } |
|---|
| | 929 | keyvar = DtoRawVarDeclaration(key); |
|---|
| 933 | 930 | else |
|---|
| 934 | 931 | keyvar = DtoAlloca(keytype, "foreachkey"); |
|---|
| … | … | |
| 937 | 934 | // value |
|---|
| 938 | 935 | Logger::println("value = %s", value->toPrettyChars()); |
|---|
| 939 | | DtoDeclarationExp(value); |
|---|
| | 936 | DtoRawVarDeclaration(value); |
|---|
| 940 | 937 | const LLType* valtype = DtoType(value->type); |
|---|
| 941 | 938 | LLValue* valvar = NULL; |
|---|
| … | … | |
| 1150 | 1147 | |
|---|
| 1151 | 1148 | DValue* e = exp->toElem(p); |
|---|
| 1152 | | |
|---|
| 1153 | | // DtoDeclarationExp(wthis); or preferably equivalent without initialization... |
|---|
| 1154 | | if (wthis->ir.isSet()) |
|---|
| 1155 | | { |
|---|
| 1156 | | assert(wthis->nestedref); |
|---|
| 1157 | | assert(wthis->ir.irLocal); |
|---|
| 1158 | | assert(!wthis->ir.irLocal->value); |
|---|
| 1159 | | wthis->ir.irLocal->value = DtoAlloca(DtoType(wthis->type), wthis->toChars()); |
|---|
| 1160 | | |
|---|
| 1161 | | // store the address into the nested vars array |
|---|
| 1162 | | assert(wthis->ir.irLocal->nestedIndex >= 0); |
|---|
| 1163 | | LLValue* gep = DtoGEPi(gIR->func()->decl->ir.irFunc->nestedVar, 0, wthis->ir.irLocal->nestedIndex); |
|---|
| 1164 | | assert(isaPointer(wthis->ir.irLocal->value)); |
|---|
| 1165 | | LLValue* val = DtoBitCast(wthis->ir.irLocal->value, getVoidPtrType()); |
|---|
| 1166 | | DtoStore(val, gep); |
|---|
| 1167 | | } |
|---|
| 1168 | | else |
|---|
| 1169 | | { |
|---|
| 1170 | | assert(!wthis->nestedref); |
|---|
| 1171 | | wthis->ir.irLocal = new IrLocal(wthis); |
|---|
| 1172 | | wthis->ir.irLocal->value = DtoAlloca(DtoType(wthis->type), wthis->toChars()); |
|---|
| 1173 | | } |
|---|
| 1174 | | |
|---|
| 1175 | | DtoStore(e->getRVal(), wthis->ir.irLocal->value); |
|---|
| | 1149 | LLValue* mem = DtoRawVarDeclaration(wthis); |
|---|
| | 1150 | DtoStore(e->getRVal(), mem); |
|---|
| 1176 | 1151 | |
|---|
| 1177 | 1152 | body->toIR(p); |
|---|