annotate gen/nested.cpp @ 1222:b6370749ec8d

Use 'undef' instead of null for unneeded contexts.
author Frits van Bommel <fvbommel wxs.nl>
date Fri, 17 Apr 2009 03:47:56 +0200
parents 7977096f0e49
children 5f340a6dc749
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
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
9 #include "llvm/Support/CommandLine.h"
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
10 namespace cl = llvm::cl;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
11
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
12 /// What the context pointer for a nested function looks like
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
13 enum NestedCtxType {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
14 /// Context is void*[] of pointers to variables.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
15 /// Variables from higher levels are at the front.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
16 NCArray,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
17
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
18 /// Context is a struct containing variables belonging to the parent function.
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
19 /// If the parent function itself has a parent function, one of the members is
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
20 /// a pointer to its context. (linked-list style)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
21 // FIXME: implement
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
22 // TODO: Functions without any variables accessed by nested functions, but
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
23 // with a parent whose variables are accessed, can use the parent's
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
24 // context.
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
25 // NOTE: This is what DMD seems to do.
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
26 NCStruct,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
27
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
28 /// Context is a list of pointers to structs of variables, followed by the
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
29 /// variables of the inner-most function with variables accessed by nested
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
30 /// functions. The initial pointers point to similar structs for enclosing
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
31 /// functions.
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
32 /// Only functions whose variables are accessed by nested functions create
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
33 /// new frames, others just pass on what got passed in.
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
34 NCHybrid
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
35 };
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
36
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
37 static cl::opt<NestedCtxType> nestedCtx("nested-ctx",
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
38 cl::desc("How to construct a nested function's context:"),
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
39 cl::ZeroOrMore,
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
40 cl::values(
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
41 clEnumValN(NCArray, "array", "Array of pointers to variables (including multi-level)"),
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
42 //clEnumValN(NCStruct, "struct", "Struct of variables (with multi-level via linked list)"),
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
43 clEnumValN(NCHybrid, "hybrid", "List of pointers to structs of variables, one per level."),
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
44 clEnumValEnd),
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
45 cl::init(NCHybrid));
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
46
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
47
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
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 /*////////////////////////////////////////////////////////////////////////////////////////
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 // 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
51 ////////////////////////////////////////////////////////////////////////////////////////*/
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
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
53 static FuncDeclaration* getParentFunc(Dsymbol* sym, bool stopOnStatic) {
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
54 if (!sym)
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
55 return NULL;
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
56 Dsymbol* parent = sym->parent;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
57 assert(parent);
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
58 while (parent && !parent->isFuncDeclaration()) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
59 if (stopOnStatic) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
60 Declaration* decl = sym->isDeclaration();
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
61 if (decl && decl->isStatic())
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
62 return NULL;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
63 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
64 parent = parent->parent;
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
65 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
66
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
67 return (parent ? parent->isFuncDeclaration() : NULL);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
68 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
69
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
70 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
71 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
72 Logger::println("DtoNestedVariable for %s @ %s", vd->toChars(), loc.toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
73 LOG_SCOPE;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
74
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
75 ////////////////////////////////////
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
76 // Locate context value
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
77
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
78 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
79 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
80
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 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
82
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 // 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
84 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
85 {
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 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
87 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
88 }
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
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
90 // get the nested context
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
91 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
92 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
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 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
95 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
96 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
97 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
98 else if (irfunc->nestedVar)
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
99 ctx = irfunc->nestedVar;
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
100 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
101 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
102 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
103
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 assert(vd->ir.irLocal);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
105
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
106 ////////////////////////////////////
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
107 // Extract variable from nested context
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
108
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
109 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
110 LLValue* val = DtoBitCast(ctx, getPtrToType(getVoidPtrType()));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
111 val = DtoGEPi1(val, vd->ir.irLocal->nestedIndex);
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
112 val = DtoAlignedLoad(val);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
113 assert(vd->ir.irLocal->value);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
114 val = DtoBitCast(val, vd->ir.irLocal->value->getType(), vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
115 return new DVarValue(astype, vd, val);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
116 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
117 else if (nestedCtx == NCHybrid) {
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
118 LLValue* val = DtoBitCast(ctx, LLPointerType::getUnqual(irfunc->frameType));
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
119 Logger::cout() << "Context: " << *val << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
120 Logger::cout() << "of type: " << *val->getType() << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
121
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
122 unsigned vardepth = vd->ir.irLocal->nestedDepth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
123 unsigned funcdepth = irfunc->depth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
124
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
125 Logger::cout() << "Variable: " << vd->toChars() << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
126 Logger::cout() << "Variable depth: " << vardepth << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
127 Logger::cout() << "Function: " << irfunc->decl->toChars() << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
128 Logger::cout() << "Function depth: " << funcdepth << '\n';
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
129
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
130 if (vardepth == funcdepth) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
131 // This is not always handled above because functions without
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
132 // variables accessed by nested functions don't create new frames.
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
133 Logger::println("Same depth");
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
134 } else {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
135 // Load frame pointer and index that...
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
136 Logger::println("Lower depth");
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
137 val = DtoGEPi(val, 0, vd->ir.irLocal->nestedDepth);
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
138 Logger::cout() << "Frame index: " << *val << '\n';
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
139 val = DtoAlignedLoad(val, (std::string(".frame.") + vdparent->toChars()).c_str());
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
140 Logger::cout() << "Frame: " << *val << '\n';
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
141 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
142 val = DtoGEPi(val, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
143 Logger::cout() << "Addr: " << *val << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
144 Logger::cout() << "of type: " << *val->getType() << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
145 if (vd->ir.irLocal->byref) {
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
146 val = DtoAlignedLoad(val);
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
147 Logger::cout() << "Was byref, now: " << *val << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
148 Logger::cout() << "of type: " << *val->getType() << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
149 }
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
150
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
151 return new DVarValue(astype, vd, val);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
152 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
153 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
154 assert(0 && "Not implemented yet");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
155 }
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
156 }
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
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 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
159 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
160 Logger::println("DtoNestedInit for %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
161 LOG_SCOPE
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
162
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
163 IrFunction* irfunc = gIR->func()->decl->ir.irFunc;
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
164 LLValue* nestedVar = irfunc->nestedVar;
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
165
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
166 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
167 // alloca as usual if no value already
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
168 if (!vd->ir.irLocal->value)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
169 vd->ir.irLocal->value = DtoAlloca(DtoType(vd->type), vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
170
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
171 // store the address into the nested vars array
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
172 assert(vd->ir.irLocal->nestedIndex >= 0);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
173 LLValue* gep = DtoGEPi(nestedVar, 0, vd->ir.irLocal->nestedIndex);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
174
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
175 assert(isaPointer(vd->ir.irLocal->value));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
176 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
177
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
178 DtoAlignedStore(val, gep);
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
179 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
180 else if (nestedCtx == NCHybrid) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
181 assert(vd->ir.irLocal->value && "Nested variable without storage?");
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
182
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
183 if (!vd->isParameter() && (vd->isRef() || vd->isOut())) {
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
184 unsigned vardepth = vd->ir.irLocal->nestedDepth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
185
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
186 LLValue* val = NULL;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
187 // Retrieve frame pointer
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
188 if (vardepth == irfunc->depth) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
189 val = nestedVar;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
190 } else {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
191 FuncDeclaration *parentfunc = getParentFunc(vd, true);
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
192 assert(parentfunc && "No parent function for nested variable?");
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
193
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
194 val = DtoGEPi(val, 0, vardepth);
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
195 val = DtoAlignedLoad(val, (std::string(".frame.") + parentfunc->toChars()).c_str());
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
196 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
197 val = DtoGEPi(val, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
198 DtoAlignedStore(vd->ir.irLocal->value, val);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
199 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
200 // Already initialized in DtoCreateNestedContext
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
201 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
202 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
203 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
204 assert(0 && "Not implemented yet");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
205 }
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
206 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
208 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
209 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
210 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
211 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
212
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
213 IrFunction* irfunc = gIR->func();
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
214 bool fromParent = true;
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
215
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
216 LLValue* val;
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
217 // 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
218 // use its own context
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
219 if (irfunc->nestedVar) {
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
220 val = irfunc->nestedVar;
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
221 fromParent = false;
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
222 }
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
223 // 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
224 else if (irfunc->nestArg)
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
225 val = irfunc->nestArg;
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
226 // 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
227 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
228 {
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
229 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
230 if (!cd || !cd->vthis)
1222
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
231 return llvm::UndefValue::get(getVoidPtrType());
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
232 val = DtoLoad(irfunc->thisArg);
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
233 val = DtoLoad(DtoGEPi(val, 0,cd->vthis->ir.irField->index, ".vthis"));
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
234 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
235 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
236 {
1222
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
237 return llvm::UndefValue::get(getVoidPtrType());
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
238 }
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
239 if (nestedCtx == NCHybrid) {
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
240 // If sym is a nested function, and it's parent context is different than the
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
241 // one we got, adjust it.
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
242
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
243 if (FuncDeclaration* fd = getParentFunc(sym->isFuncDeclaration(), true)) {
1222
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
244 // if this is for a function that doesn't access variables from
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
245 // enclosing scopes, it doesn't matter what we pass.
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
246 // Tell LLVM about it by passing an 'undef'.
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
247 if (fd->ir.irFunc->depth == 0)
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
248 return llvm::UndefValue::get(getVoidPtrType());
b6370749ec8d Use 'undef' instead of null for unneeded contexts.
Frits van Bommel <fvbommel wxs.nl>
parents: 1218
diff changeset
249
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
250 Logger::println("For nested function, parent is %s", fd->toChars());
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
251 FuncDeclaration* ctxfd = irfunc->decl;
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
252 Logger::println("Current function is %s", ctxfd->toChars());
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
253 if (fromParent) {
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
254 ctxfd = getParentFunc(ctxfd, true);
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
255 assert(ctxfd && "Context from outer function, but no outer function?");
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
256 }
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
257 Logger::println("Context is from %s", ctxfd->toChars());
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
258
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
259 unsigned neededDepth = fd->ir.irFunc->depth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
260 unsigned ctxDepth = ctxfd->ir.irFunc->depth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
261
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
262 Logger::cout() << "Needed depth: " << neededDepth << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
263 Logger::cout() << "Context depth: " << ctxDepth << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
264
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
265 if (neededDepth >= ctxDepth) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
266 assert(neededDepth <= ctxDepth + 1 && "How are we going more than one nesting level up?");
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
267 // fd needs the same context as we do, so all is well
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
268 Logger::println("Calling sibling function or directly nested function");
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
269 } else {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
270 val = DtoBitCast(val, LLPointerType::getUnqual(ctxfd->ir.irFunc->frameType));
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
271 val = DtoGEPi(val, 0, neededDepth);
1213
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
272 val = DtoAlignedLoad(val, (std::string(".frame.") + fd->toChars()).c_str());
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
273 }
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
274 }
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
275 }
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
276 Logger::cout() << "result = " << *val << '\n';
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
277 Logger::cout() << "of type " << *val->getType() << '\n';
9430d4959ab4 Fix a bug in nested context code that occured when calling a function nested in
Frits van Bommel <fvbommel wxs.nl>
parents: 1212
diff changeset
278 return val;
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
279 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
280
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
281 void DtoCreateNestedContext(FuncDeclaration* fd) {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
282 Logger::println("DtoCreateNestedContext for %s", fd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
283 LOG_SCOPE
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
284
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
285 if (nestedCtx == NCArray) {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
286 // construct nested variables array
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
287 if (!fd->nestedVars.empty())
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
288 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
289 Logger::println("has nested frame");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
290 // start with adding all enclosing parent frames until a static parent is reached
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
291 int nparelems = 0;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
292 if (!fd->isStatic())
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
293 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
294 Dsymbol* par = fd->toParent2();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
295 while (par)
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
296 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
297 if (FuncDeclaration* parfd = par->isFuncDeclaration())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
298 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
299 nparelems += parfd->nestedVars.size();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
300 // stop at first static
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
301 if (parfd->isStatic())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
302 break;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
303 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
304 else if (ClassDeclaration* parcd = par->isClassDeclaration())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
305 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
306 // nothing needed
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
307 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
308 else
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
309 {
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
310 break;
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
311 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
312
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
313 par = par->toParent2();
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
314 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
315 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
316 int nelems = fd->nestedVars.size() + nparelems;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
317
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
318 // make array type for nested vars
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
319 const LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
320
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
321 // alloca it
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
322 LLValue* nestedVars = DtoAlloca(nestedVarsTy, ".nested_vars");
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
323
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
324 IrFunction* irfunction = fd->ir.irFunc;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
325
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
326 // copy parent frame into beginning
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
327 if (nparelems)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
328 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
329 LLValue* src = irfunction->nestArg;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
330 if (!src)
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
331 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
332 assert(irfunction->thisArg);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
333 assert(fd->isMember2());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
334 LLValue* thisval = DtoLoad(irfunction->thisArg);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
335 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
336 assert(cd);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
337 assert(cd->vthis);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
338 src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis"));
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
339 }
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
340 DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE),
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
341 getABITypeAlign(getVoidPtrType()));
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
342 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
343
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
344 // store in IrFunction
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
345 irfunction->nestedVar = nestedVars;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
346
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
347 // go through all nested vars and assign indices
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
348 int idx = nparelems;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
349 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
350 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
351 VarDeclaration* vd = *i;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
352 if (!vd->ir.irLocal)
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
353 vd->ir.irLocal = new IrLocal(vd);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
354
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
355 if (vd->isParameter())
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
356 {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
357 Logger::println("nested param: %s", vd->toChars());
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
358 LLValue* gep = DtoGEPi(nestedVars, 0, idx);
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
359 LLValue* val = DtoBitCast(vd->ir.irLocal->value, getVoidPtrType());
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
360 DtoAlignedStore(val, gep);
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
361 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
362 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
363 {
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
364 Logger::println("nested var: %s", vd->toChars());
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
365 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
366
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
367 vd->ir.irLocal->nestedIndex = idx++;
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
368 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
369 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
370 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
371 else if (nestedCtx == NCHybrid) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
372 // construct nested variables array
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
373 if (!fd->nestedVars.empty())
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
374 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
375 Logger::println("has nested frame");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
376 // start with adding all enclosing parent frames until a static parent is reached
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
377
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
378 const LLStructType* innerFrameType = NULL;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
379 unsigned depth = 0;
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
380 if (!fd->isStatic()) {
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
381 if (FuncDeclaration* parfd = getParentFunc(fd, true)) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
382 innerFrameType = parfd->ir.irFunc->frameType;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
383 if (innerFrameType)
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
384 depth = parfd->ir.irFunc->depth + 1;
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
385 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
386 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
387 fd->ir.irFunc->depth = depth;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
388
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
389 Logger::cout() << "Function " << fd->toChars() << " has depth " << depth << '\n';
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
390
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
391 typedef std::vector<const LLType*> TypeVec;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
392 TypeVec types;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
393 if (depth != 0) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
394 assert(innerFrameType);
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
395 // Add frame pointer types for all but last frame
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
396 if (depth > 1) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
397 for (unsigned i = 0; i < (depth - 1); ++i) {
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
398 types.push_back(innerFrameType->getElementType(i));
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
399 }
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
400 }
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
401 // Add frame pointer type for last frame
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
402 types.push_back(LLPointerType::getUnqual(innerFrameType));
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
403 }
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
404
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
405 if (Logger::enabled()) {
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
406 Logger::println("Frame types: ");
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
407 LOG_SCOPE;
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
408 for (TypeVec::iterator i = types.begin(); i != types.end(); ++i)
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
409 Logger::cout() << **i << '\n';
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
410 }
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
411
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
412 // Add the direct nested variables of this function, and update their indices to match.
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
413 // TODO: optimize ordering for minimal space usage?
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
414 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
415 {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
416 VarDeclaration* vd = *i;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
417 if (!vd->ir.irLocal)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
418 vd->ir.irLocal = new IrLocal(vd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
419
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
420 vd->ir.irLocal->nestedIndex = types.size();
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
421 vd->ir.irLocal->nestedDepth = depth;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
422 if (vd->isParameter()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
423 // Parameters already have storage associated with them (to handle byref etc.),
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
424 // so handle specially for now by storing a pointer instead of a value.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
425 assert(vd->ir.irLocal->value);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
426 // FIXME: don't do this for normal parameters?
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
427 types.push_back(vd->ir.irLocal->value->getType());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
428 } else if (vd->isRef() || vd->isOut()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
429 // Foreach variables can also be by reference, for instance.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
430 types.push_back(DtoType(vd->type->pointerTo()));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
431 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
432 types.push_back(DtoType(vd->type));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
433 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
434 if (Logger::enabled()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
435 Logger::println("Nested var: %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
436 Logger::cout() << "of type: " << *types.back() << '\n';
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
437 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
438 }
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
439
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
440 const LLStructType* frameType = LLStructType::get(types);
1218
7977096f0e49 Name some types.
Frits van Bommel <fvbommel wxs.nl>
parents: 1216
diff changeset
441 gIR->module->addTypeName(std::string("nest.") + fd->toChars(), frameType);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
442
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
443 Logger::cout() << "frameType = " << *frameType << '\n';
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
444
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
445 // Store type in IrFunction
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
446 IrFunction* irfunction = fd->ir.irFunc;
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
447 irfunction->frameType = frameType;
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
448
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
449 // Create frame for current function and append to frames list
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
450 // FIXME: For D2, this should be a gc_malloc (or similar) call, not alloca
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
451 LLValue* frame = DtoAlloca(frameType, ".frame");
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
452
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
453 // copy parent frames into beginning
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
454 if (depth != 0) {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
455 LLValue* src = irfunction->nestArg;
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
456 if (!src) {
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
457 assert(irfunction->thisArg);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
458 assert(fd->isMember2());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
459 LLValue* thisval = DtoLoad(irfunction->thisArg);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
460 ClassDeclaration* cd = fd->isMember2()->isClassDeclaration();
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
461 assert(cd);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
462 assert(cd->vthis);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
463 Logger::println("Indexing to 'this'");
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
464 src = DtoLoad(DtoGEPi(thisval, 0, cd->vthis->ir.irField->index, ".vthis"));
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
465 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
466 if (depth > 1) {
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
467 src = DtoBitCast(src, getVoidPtrType());
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
468 LLValue* dst = DtoBitCast(frame, getVoidPtrType());
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
469 DtoMemCpy(dst, src, DtoConstSize_t((depth-1) * PTRSIZE),
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
470 getABITypeAlign(getVoidPtrType()));
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
471 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
472 // Copy nestArg into framelist; the outer frame is not in the list of pointers
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
473 src = DtoBitCast(src, types[depth-1]);
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
474 LLValue* gep = DtoGEPi(frame, 0, depth-1);
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
475 DtoAlignedStore(src, gep);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
476 }
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
477
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
478 // store context in IrFunction
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
479 irfunction->nestedVar = frame;
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
480
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
481 // go through all nested vars and assign addresses where possible.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
482 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
483 {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
484 VarDeclaration* vd = *i;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
485
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
486 LLValue* gep = DtoGEPi(frame, 0, vd->ir.irLocal->nestedIndex, vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
487 if (vd->isParameter()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
488 Logger::println("nested param: %s", vd->toChars());
1210
3d4581761b4c Add some alignment info where LLVM might otherwise be more pessimistic.
Frits van Bommel <fvbommel wxs.nl>
parents: 1209
diff changeset
489 DtoAlignedStore(vd->ir.irLocal->value, gep);
1209
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
490 vd->ir.irLocal->byref = true;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
491 } else if (vd->isRef() || vd->isOut()) {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
492 // This slot is initialized in DtoNestedInit, to handle things like byref foreach variables
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
493 // which move around in memory.
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
494 vd->ir.irLocal->byref = true;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
495 } else {
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
496 Logger::println("nested var: %s", vd->toChars());
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
497 if (vd->ir.irLocal->value)
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
498 Logger::cout() << "Pre-existing value: " << *vd->ir.irLocal->value << '\n';
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
499 assert(!vd->ir.irLocal->value);
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
500 vd->ir.irLocal->value = gep;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
501 vd->ir.irLocal->byref = false;
8699c450a1a0 Implement -nested-ctx=hybrid
Frits van Bommel <fvbommel wxs.nl>
parents: 1208
diff changeset
502 }
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
503 }
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
504 } else if (FuncDeclaration* parFunc = getParentFunc(fd, true)) {
1212
df2227fdc860 For the outermost function needing a context frame, use the address of that
Frits van Bommel <fvbommel wxs.nl>
parents: 1210
diff changeset
505 // Propagate context arg properties if the context arg is passed on unmodified.
1216
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
506 fd->ir.irFunc->frameType = parFunc->ir.irFunc->frameType;
033f18ec1371 Unify %.frames_list and %.frame into a single data structure, generalizing r1212
Frits van Bommel <fvbommel wxs.nl>
parents: 1213
diff changeset
507 fd->ir.irFunc->depth = parFunc->ir.irFunc->depth;
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
508 }
1208
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
509 }
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
510 else {
2a37f4745ddd Add an option to change the way nested variables are handled.
Frits van Bommel <fvbommel wxs.nl>
parents: 1207
diff changeset
511 assert(0 && "Not implemented yet");
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
512 }
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
diff changeset
513 }