annotate gen/nested.cpp @ 1207:83d3b25c2213

Isolate all knowledge of what a function's nested context looks like in a single place. No functional change.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 12 Apr 2009 13:08:24 +0200
parents
children 2a37f4745ddd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
1 #include "gen/nested.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
2
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
3 #include "gen/dvalue.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
4 #include "gen/irstate.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
5 #include "gen/llvmhelpers.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
6 #include "gen/logger.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
7 #include "gen/tollvm.h"
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
8
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
9 /****************************************************************************************/
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
10 /*////////////////////////////////////////////////////////////////////////////////////////
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
11 // NESTED VARIABLE HELPERS
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
12 ////////////////////////////////////////////////////////////////////////////////////////*/
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
13
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
14 DValue* DtoNestedVariable(Loc loc, Type* astype, VarDeclaration* vd)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
15 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
16 Dsymbol* vdparent = vd->toParent2();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
17 assert(vdparent);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
18
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
19 IrFunction* irfunc = gIR->func();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
20
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
21 // is the nested variable in this scope?
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
22 if (vdparent == irfunc->decl)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
23 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
24 LLValue* val = vd->ir.getIrValue();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
25 return new DVarValue(astype, vd, val);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
26 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
27
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
28 // get it from the nested context
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
29 LLValue* ctx = 0;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
30 if (irfunc->decl->isMember2())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
31 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
32 ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
33 LLValue* val = DtoLoad(irfunc->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
34 ctx = DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
35 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
36 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
37 ctx = irfunc->nestArg;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
38 assert(ctx);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
39
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
40 assert(vd->ir.irLocal);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
41 LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType()));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
42 val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
43 val = DtoLoad(val);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
44 assert(vd->ir.irLocal->value);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
45 val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
46 return new DVarValue(astype, vd, val);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
47 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
48
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
49 void DtoNestedInit(VarDeclaration* vd)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
50 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
51 // alloca as usual if no value already
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
52 if (!vd->ir.irLocal->value)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
53 vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
54
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
55 // store the address into the nested vars array
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
56 assert(vd->ir.irLocal->nestedIndex >= 0);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
57 LLValue* gep = DtoGEPi(gIR->func()->decl->ir.irFunc->nestedVar, 0, vd->ir.irLocal->nestedIndex);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
58
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
59 assert(isaPointer(vd->ir.irLocal->value));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
60 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
61
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
62 DtoStore(val, gep);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
63 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
64
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
65 LLValue* DtoNestedContext(Loc loc, Dsymbol* sym)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
66 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
67 Logger::println("DtoNestedContext for %s", sym->toPrettyChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
68 LOG_SCOPE;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
69
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
70 IrFunction* irfunc = gIR->func();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
71
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
72 // if this func has its own vars that are accessed by nested funcs
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
73 // use its own context
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
74 if (irfunc->nestedVar)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
75 return irfunc->nestedVar;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
76 // otherwise, it may have gotten a context from the caller
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
77 else if (irfunc->nestArg)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
78 return irfunc->nestArg;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
79 // or just have a this argument
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
80 else if (irfunc->thisArg)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
81 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
82 ClassDeclaration* cd = irfunc->decl->isMember2()->isClassDeclaration();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
83 if (!cd || !cd->vthis)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
84 return getNullPtr(getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
85 LLValue* val = DtoLoad(irfunc->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
86 return DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
87 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
88 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
89 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
90 return getNullPtr(getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
91 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
92 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
93
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
94 void DtoCreateNestedContext(FuncDeclaration* fd) {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
95 // construct nested variables array
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
96 if (!fd->nestedVars.empty())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
97 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
98 Logger::println("has nested frame");
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
99 // start with adding all enclosing parent frames until a static parent is reached
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
100 int nparelems = 0;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
101 if (!fd->isStatic())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
102 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
103 Dsymbol* par = fd->toParent2();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
104 while (par)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
105 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
106 if (FuncDeclaration* parfd = par->isFuncDeclaration())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
107 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
108 nparelems += parfd->nestedVars.size();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
109 // stop at first static
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
110 if (parfd->isStatic())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
111 break;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
112 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
113 else if (ClassDeclaration* parcd = par->isClassDeclaration())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
114 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
115 // nothing needed
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
116 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
117 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
118 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
119 break;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
120 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
121
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
122 par = par->toParent2();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
123 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
124 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
125 int nelems = fd->nestedVars.size() + nparelems;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
126
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
127 // make array type for nested vars
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
128 const LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
129
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
130 // alloca it
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
131 LLValue* nestedVars = DtoAlloca(nestedVarsTy, ".nested_vars");
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
132
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
133 IrFunction* irfunction = fd->ir.irFunc;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
134
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
135 // copy parent frame into beginning
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
136 if (nparelems)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
137 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
138 LLValue* src = irfunction->nestArg;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
139 if (!src)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
140 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
141 assert(irfunction->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
142 assert(fd->isMember2());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
143 LLValue* thisval = DtoLoad(irfunction->thisArg);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
144 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
145 assert(cd);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
146 assert(cd->vthis);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
147 src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis"));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
148 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
149 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE));
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
150 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
151
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
152 // store in IrFunction
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
153 irfunction->nestedVar = nestedVars;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
154
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
155 // go through all nested vars and assign indices
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
156 int idx = nparelems;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
157 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
158 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
159 VarDeclaration* vd = *i;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
160 if (!vd->ir.irLocal)
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
161 vd->ir.irLocal = new IrLocal(vd);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
162
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
163 if (vd->isParameter())
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
164 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
165 Logger::println("nested param: %s", vd->toChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
166 LLValue* gep = DtoGEPi(nestedVars, 0, idx);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
167 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
168 DtoStore(val, gep);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
169 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
170 else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
171 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
172 Logger::println("nested var: %s", vd->toChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
173 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
174
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
175 vd->ir.irLocal->nestedIndex = idx++;
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
176 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
177
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
178 // fixup nested result variable
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
179 #if DMDV2
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
180 if (fd->vresult && fd->vresult->nestedrefs.dim) {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
181 #else
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
182 if (fd->vresult && fd->vresult->nestedref) {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
183 #endif
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
184 Logger::println("nested vresult value: %s", fd->vresult->toChars());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
185 LLValue* gep = DtoGEPi(nestedVars, 0, fd->vresult->ir.irLocal->nestedIndex);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
186 LLValue* val = DtoBitCast(fd->vresult->ir.irLocal->value, getVoidPtrType());
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
187 DtoStore(val, gep);
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
188 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
189 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
190 }