annotate dmd/codegen/Util.d @ 177:1475fd394c9e

bug fixes
author korDen
date Sun, 10 Oct 2010 10:38:55 +0400
parents af724d3510d7
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 113
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Loc;
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
5 import dmd.Id;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Array;
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
9 import dmd.Declaration;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.RET;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.LINK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Expression;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
17 import dmd.Parameter;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.STC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.Global;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
20 import dmd.Module;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.InterfaceDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.AggregateDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.AttribDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.TupleDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.StructDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.VarDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.ClassDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.TemplateMixin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.TypedefDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.ExpInitializer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeFunction;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.TypeStruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.TypeSArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.LabelStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 import dmd.DsymbolExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.TYPE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.Classsym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.SFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.STR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.TF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.mTYman;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.TYFL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 import dmd.backend.LIST;
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
58 import dmd.backend.iasm : binary;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 import std.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 import core.stdc.string;
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
62 import core.stdc.stdlib;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
64 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
65
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
66
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
67 /* If variable var of type typ is a reference
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
68 */
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
69 version(SARRAYVALUE)
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
70 {
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
71 bool ISREF(Declaration var, Type tb) {return var.isOut() || var.isRef();}
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
72 }
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
73 else
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
74 bool ISREF(Declaration var, Type tb) {return (var.isParameter() && tb.ty == TY.Tsarray) || var.isOut() || var.isRef();}
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
75
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
76
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
77
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 /************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 * Call a function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 */
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
81 elem* callfunc(Loc loc,
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 IRState* irs,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 int directcall, // 1: don't do virtual call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Type tret, // return type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 elem *ec, // evaluates to function address
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 Type ectype, // original type of ec
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 FuncDeclaration fd, // if !=null, this is the function being called
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 Type t, // TypeDelegate or TypeFunction for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 elem* ehidden, // if !=null, this is the 'hidden' argument
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 77
diff changeset
90 Expressions arguments)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 elem* ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 elem* ethis = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 elem* eside = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 tym_t ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 tym_t tyret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 RET retmethod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 int reverse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 TypeFunction tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 OPER op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 printf("callfunc(directcall = %d, tret = '%s', ec = %p, fd = %p)\n",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 directcall, tret.toChars(), ec, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 printf("ec: "); elem_print(ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 printf("fd = '%s'\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 if (t.ty == TY.Tdelegate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 // A delegate consists of:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 // { Object *this; Function *funcptr; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 assert(!fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 assert(t.nextOf().ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 tf = cast(TypeFunction)t.nextOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 ethis = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 ec = el_same(&ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 ethis = el_una(OPER.OP64_32, TYM.TYnptr, ethis); // get this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 ec = array_toPtr(t, ec); // get funcptr
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 ec = el_una(OPER.OPind, tf.totym(), ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
127 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 assert(t.ty == TY.Tfunction);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 tf = cast(TypeFunction)t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 retmethod = tf.retStyle();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 ty = ec.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 if (fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 ty = fd.toSymbol().Stype.Tty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 reverse = tyrevfunc(ty);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 ep = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 if (arguments)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 // j=1 if _arguments[] is first argument
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 int j = (tf.linkage == LINK.LINKd && tf.varargs == 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
143 foreach (size_t i, Expression arg; arguments)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
144 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 elem* ea;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
147 //writef("\targ[%d]: %s\n", i, arg.toChars());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
149 size_t nparams = Parameter.dim(tf.parameters);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (i - j < nparams && i >= j)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
152 auto p = Parameter.getNth(tf.parameters, i - j);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 if (p.storageClass & (STC.STCout | STC.STCref))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 // Convert argument to a pointer,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 // use AddrExp.toElem()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 Expression ae = arg.addressOf(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 ea = ae.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 ea = arg.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 L1:
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
165 if (tybasic(ea.Ety) == TYM.TYstruct || tybasic(ea.Ety) == TYarray)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 ea = el_una(OPER.OPstrpar, TYM.TYstruct, ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 ea.Enumbytes = ea.E1.Enumbytes;
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
169 //assert(ea.Enumbytes);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (reverse)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 ep = el_param(ep,ea);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 ep = el_param(ea,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 if (retmethod == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 if (!ehidden)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
181 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 // Don't have one, so create one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 type* tt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
185 Type tret2 = tf.next; // in dmd tret is shadowed here, so -> tret2
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
186 if (tret2.toBasetype().ty == Tstruct ||
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
187 tret2.toBasetype().ty == Tsarray)
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
188 tt = tret2.toCtype();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 else
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
190 tt = type_fake(tret2.totym());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 Symbol* stmp = symbol_genauto(tt);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 ehidden = el_ptr(stmp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 if ((global.params.isLinux || global.params.isOSX || global.params.isFreeBSD || global.params.isSolaris) && tf.linkage != LINK.LINKd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 ; // ehidden goes last on Linux/OSX C++
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if (ep)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 static if (false) { // BUG: implement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 if (reverse && type_mangle(tfunc) == mTYman.mTYman_cpp) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 ep = el_param(ehidden,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 ep = el_param(ep,ehidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 ep = el_param(ep,ehidden);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 ep = ehidden;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 ehidden = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 if (fd && fd.isMember2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 InterfaceDeclaration intd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 Symbol* sfunc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 AggregateDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 ad = fd.isThis();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 ethis = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 if (ad.isStructDeclaration() && tybasic(ec.Ety) != TYM.TYnptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 ethis = addressElem(ec, ectype);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 // Evaluate ec for side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 eside = ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 sfunc = fd.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 if (!fd.isVirtual() ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 directcall || // BUG: fix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 fd.isFinal())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 // make static call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 ec = el_var(sfunc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 // make virtual call
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 elem* ev;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 uint vindex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 assert(ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 ev = el_same(&ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 ev = el_una(OPER.OPind, TYM.TYnptr, ev);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 vindex = fd.vtblIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 // Build *(ev + vindex * 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 ec = el_bin(OPER.OPadd, TYM.TYnptr, ev, el_long(TYM.TYint, vindex * 4));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 ec = el_una(OPER.OPind, TYM.TYnptr, ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 ec = el_una(OPER.OPind, tybasic(sfunc.Stype.Tty), ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 else if (fd && fd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 assert(!ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 ethis = getEthis(Loc(0), irs, fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 ep = el_param(ep, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 if (ehidden)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 ep = el_param(ep, ehidden); // if ehidden goes last
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 tyret = tret.totym();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 // Look for intrinsic functions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 if (ec.Eoper == OPER.OPvar && (op = intrinsic_oper(ec.EV.sp.Vsym.Sident.ptr)) != OPER.OPMAX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 el_free(ec);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 if (OTbinary(op))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 ep.Eoper = op;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 ep.Ety = tyret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 e = ep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 if (op == OPER.OPscale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 elem *et = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 e.E1() = el_una(OPER.OPd_ld, TYM.TYldouble, e.E1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 e.E1() = el_una(OPER.OPs32_d, TYM.TYdouble, e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 e.E2() = et;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 else if (op == OPER.OPyl2x || op == OPER.OPyl2xp1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 elem *et = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 e.E1() = e.E2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 e.E2() = et;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 e = el_una(op,tyret,ep);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 else if (ep)
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
301 /* Do not do "no side effect" calls if a hidden parameter is passed,
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
302 * as the return value is stored through the hidden parameter, which
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
303 * is a side effect.
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
304 */
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
305 e = el_bin((tf.ispure && tf.isnothrow && (retmethod != RET.RETstack)) ?
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
306 OPcallns : OPcall, tyret, ec, ep);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 else
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
308 e = el_una((tf.ispure && tf.isnothrow && (retmethod != RET.RETstack)) ?
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
309 OPucallns : OPucall, tyret, ec);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 if (retmethod == RET.RETstack)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 e = el_una(OPER.OPind, tyret, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 if (tf.isref)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 e = el_una(OPER.OPind, tyret, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 if (tybasic(tyret) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 e.Enumbytes = cast(uint)tret.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 e = el_combine(eside, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 * Fake a struct symbol.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 Classsym* fake_classsym(Identifier id)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
339 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 TYPE* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 Classsym* scc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 scc = cast(Classsym*)symbol_calloc(toStringz(id.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 scc.Sclass = SC.SCstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 scc.Sstruct = struct_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 scc.Sstruct.Sstructalign = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 //scc.Sstruct.ptrtype = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 scc.Sstruct.Sflags = STR.STRglobal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 t = type_alloc(TYM.TYstruct);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 t.Tflags |= TF.TFsizeunknown | TF.TFforward;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 t.Ttag = scc; // structure tag name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 assert(t.Tmangle == 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 t.Tmangle = mTYman.mTYman_d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 scc.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 slist_add(scc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 return scc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 /******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 * Return elem that evaluates to the static frame pointer for function fd.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 * If fd is a member function, the returned expression will compute the value
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 * of fd's 'this' variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 * This routine is critical for implementing nested functions.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 elem* getEthis(Loc loc, IRState* irs, Dsymbol fd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 elem* ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 FuncDeclaration thisfd = irs.getFunc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 Dsymbol fdparent = fd.toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 //printf("getEthis(thisfd = '%s', fd = '%s', fdparent = '%s')\n", thisfd.toChars(), fd.toChars(), fdparent.toChars());
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
375 if (fdparent == thisfd ||
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
376 /* These two are compiler generated functions for the in and out contracts,
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
377 * and are called from an overriding function, not just the one they're
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
378 * nested inside, so this hack is so they'll pass
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
379 */
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
380 fd.ident == Id.require || fd.ident == Id.ensure)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
381 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 /* Going down one nesting level, i.e. we're calling
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 * a nested function from its enclosing function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 if (irs.sclosure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 ethis = el_var(irs.sclosure);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 if (irs.sthis)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
391 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 // We have a 'this' pointer for the current function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 /* If no variables in the current function's frame are
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 * referenced by nested functions, then we can 'skip'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 * adding this frame into the linked list of stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 * frames.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 bool cond = (thisfd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 bool cond = thisfd.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 if (cond)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
406 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 /* Local variables are referenced, can't skip.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 * Address of 'this' gives the 'this' for the nested
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 * function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 ethis = el_una(OPER.OPaddr, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
415 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 /* No 'this' pointer for current function,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 * use null if no references to the current function's frame
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 ethis = el_long(TYM.TYnptr, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 bool cond = (thisfd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 bool cond = thisfd.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 if (cond)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
426 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 /* OPframeptr is an operator that gets the frame pointer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 * for the current function, i.e. for the x86 it gets
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 * the value of EBP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 ethis.Eoper = OPER.OPframeptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
434
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 67
diff changeset
435 //if (fdparent != thisfd) ethis = el_bin(OPadd, TYnptr, ethis, el_long(TYint, 0x18));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 if (!irs.sthis) // if no frame pointer for this function
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 fd.error(loc, "is a nested function and cannot be accessed from %s", irs.getFunc().toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 ethis = el_long(TYM.TYnptr, 0); // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 Dsymbol s = thisfd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 while (fd != s)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
449 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 /* Go up a nesting level, i.e. we need to find the 'this'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 * of an enclosing function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 * Our 'enclosing function' may also be an inner class.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 //printf("\ts = '%s'\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 thisfd = s.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 if (thisfd)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
458 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 /* Enclosing function is a function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 if (fdparent == s.toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 if (thisfd.isNested())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 FuncDeclaration p = s.toParent2().isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 bool cond = !p || p.closureVars.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 bool cond = !p || p.nestedFrameRef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 if (cond) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 else if (thisfd.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 // Error should have been caught by front end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
487 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 /* Enclosed by an aggregate. That means the current
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 * function must be a member function of that aggregate.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 StructDeclaration sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 AggregateDeclaration ad = s.isAggregateDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 if (!ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 goto Lnoframe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 cd = s.isClassDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 if (cd && fd.isClassDeclaration() && fd.isClassDeclaration().isBaseOf(cd, null))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 sd = s.isStructDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 if (fd == sd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 if (!ad.isNested() || !ad.vthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Lnoframe:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 irs.getFunc().error(loc, "cannot get frame pointer to %s", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 return el_long(TYM.TYnptr, 0); // error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 ethis = el_bin(OPER.OPadd, TYM.TYnptr, ethis, el_long(TYM.TYint, ad.vthis.offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 if (fdparent == s.toParent2())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 if (auto fdd = s.toParent2().isFuncDeclaration())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 /* Remember that frames for functions that have no
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 * nested references are skipped in the linked list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 * of frames.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 bool cond = (fdd.closureVars.dim != 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 } else {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
530 bool cond = fdd.nestedFrameRef;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 if (cond) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 s = s.toParent2();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 assert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 printf("ethis:\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 elem_print(ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 return ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 * Convert array to a pointer to the data.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 elem* array_toPtr(Type t, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 //printf("array_toPtr()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 case TY.Tpointer:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 case TY.Tdelegate:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 if (e.Eoper == OPER.OPcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 e.E2() = array_toPtr(t, e.E2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 else if (e.Eoper == OPER.OPpair)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 e.Eoper = OPER.OPcomma;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 e.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 static if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 e = el_una(OPER.OPmsw, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 e = el_bin(OPER.OPadd, TYM.TYnptr, e, el_long(TYM.TYint, 4));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 e = el_una(OPER.OPind, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 case TY.Tsarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 ///t.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 * Take address of an elem.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 elem* addressElem(elem* e, Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 elem** pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 //printf("addressElem()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 for (pe = &e; (*pe).Eoper == OPER.OPcomma; pe = &(*pe).E2()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 if ((*pe).Eoper != OPER.OPvar && (*pe).Eoper != OPER.OPind)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 Symbol* stmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 elem* eeq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 elem* ee = *pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 type* tx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 // Convert to ((tmp=ee),tmp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 TY ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 if (t && ((ty = t.toBasetype().ty) == TY.Tstruct || ty == TY.Tsarray))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 tx = t.toCtype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 tx = type_fake(ee.Ety);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 stmp = symbol_genauto(tx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 eeq = el_bin(OPER.OPeq,ee.Ety,el_var(stmp),ee);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 if (tybasic(ee.Ety) == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 eeq.Eoper = OPER.OPstreq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 eeq.Enumbytes = ee.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 else if (tybasic(ee.Ety) == TYM.TYarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 eeq.Eoper = OPER.OPstreq;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 eeq.Ety = TYM.TYstruct;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 eeq.Ejty = cast(ubyte)eeq.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 eeq.Enumbytes = cast(uint)t.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 *pe = el_bin(OPER.OPcomma, ee.Ety, eeq, el_var(stmp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 * Convert intrinsic function to operator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 * Returns that operator, -1 if not an intrinsic function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
656 //extern (C++) extern int intrinsic_op(char* name);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
657
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 OPER intrinsic_oper(const(char)* name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 {
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
660 version(DMDV1)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
661 enum const(char) *namearray[] =
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
662 [
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
663 "4math3cosFeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
664 "4math3sinFeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
665 "4math4fabsFeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
666 "4math4rintFeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
667 "4math4sqrtFdZd",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
668 "4math4sqrtFeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
669 "4math4sqrtFfZf",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
670 "4math4yl2xFeeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
671 "4math5ldexpFeiZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
672 "4math6rndtolFeZl",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
673 "4math6yl2xp1FeeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
674
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
675 "9intrinsic2btFPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
676 "9intrinsic3bsfFkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
677 "9intrinsic3bsrFkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
678 "9intrinsic3btcFPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
679 "9intrinsic3btrFPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
680 "9intrinsic3btsFPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
681 "9intrinsic3inpFkZh",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
682 "9intrinsic4inplFkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
683 "9intrinsic4inpwFkZt",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
684 "9intrinsic4outpFkhZh",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
685 "9intrinsic5bswapFkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
686 "9intrinsic5outplFkkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
687 "9intrinsic5outpwFktZt",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
688 ];
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
689 else
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
690 enum const(char) *namearray[] =
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
691 [
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
692 /* The names are mangled differently because of the pure and
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
693 * nothrow attributes.
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
694 */
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
695 "4math3cosFNaNbNfeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
696 "4math3sinFNaNbNfeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
697 "4math4fabsFNaNbNfeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
698 "4math4rintFNaNbNfeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
699 "4math4sqrtFNaNbNfdZd",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
700 "4math4sqrtFNaNbNfeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
701 "4math4sqrtFNaNbNffZf",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
702 "4math4yl2xFNaNbNfeeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
703 "4math5ldexpFNaNbNfeiZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
704 "4math6rndtolFNaNbNfeZl",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
705 "4math6yl2xp1FNaNbNfeeZe",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
706
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
707 "9intrinsic2btFNaNbxPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
708 "9intrinsic3bsfFNaNbkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
709 "9intrinsic3bsrFNaNbkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
710 "9intrinsic3btcFNbPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
711 "9intrinsic3btrFNbPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
712 "9intrinsic3btsFNbPkkZi",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
713 "9intrinsic3inpFNbkZh",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
714 "9intrinsic4inplFNbkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
715 "9intrinsic4inpwFNbkZt",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
716 "9intrinsic4outpFNbkhZh",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
717 "9intrinsic5bswapFNaNbkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
718 "9intrinsic5outplFNbkkZk",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
719 "9intrinsic5outpwFNbktZt",
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
720 ];
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
721
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
722 enum OPER ioptab[] =
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
723 [
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
724 OPcos,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
725 OPsin,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
726 OPabs,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
727 OPrint,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
728 OPsqrt,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
729 OPsqrt,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
730 OPsqrt,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
731 OPyl2x,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
732 OPscale,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
733 OPrndtol,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
734 OPyl2xp1,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
735
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
736 OPbt,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
737 OPbsf,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
738 OPbsr,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
739 OPbtc,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
740 OPbtr,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
741 OPbts,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
742 OPinp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
743 OPinp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
744 OPinp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
745 OPoutp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
746 OPbswap,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
747 OPoutp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
748 OPoutp,
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
749 ];
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
750
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
751 debug
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
752 {
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
753 assert(namearray.length == ioptab.length);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
754 // assume sorted namearray
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
755 for (int i = 0; i < namearray.length - 1; i++)
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
756 {
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
757 if (strcmp(namearray[i], namearray[i + 1]) >= 0)
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
758 {
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
759 printf("namearray[%d] = '%s'\n", i, namearray[i]);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
760 assert(0);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
761 }
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
762 }
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
763 }
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
764
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
765 size_t length = strlen(name);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
766 if (length < 11 || !(name[7] == 'm' || name[7] == 'i') || name[0..6] != "_D3std")
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
767 return OPMAX;
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
768
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
769 int p = binary(name + 6, namearray.ptr, namearray.length);
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
770 if(p == -1)
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
771 return OPMAX;
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
772 return ioptab[p];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 elem* Dsymbol_toElem(Dsymbol s, IRState *irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 elem *e = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 Symbol* sp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 AttribDeclaration ad;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 VarDeclaration vd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 ClassDeclaration cd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 StructDeclaration sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 TemplateMixin tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 TupleDeclaration td;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 TypedefDeclaration tyd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 //printf("Dsymbol_toElem() %s\n", s.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 ad = s.isAttribDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 if (ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
795 auto decl = ad.include(null, null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 if (decl && decl.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 {
74
7e0d548de9e6 Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 73
diff changeset
798 foreach(s; decl)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 e = el_combine(e, Dsymbol_toElem(s, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 else if ((vd = s.isVarDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 s = s.toAlias();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 if (s != vd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 return Dsymbol_toElem(s, irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 if (vd.isStatic() || vd.storage_class & (STC.STCextern | STC.STCtls | STC.STCgshared))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 vd.toObjFile(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 sp = s.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 symbol_add(sp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 //printf("\tadding symbol '%s'\n", sp.Sident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 if (vd.init)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 ExpInitializer ie = vd.init.isExpInitializer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 if (ie) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 e = ie.exp.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 else if ((cd = s.isClassDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 irs.deferToObj.push(cast(void*)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 else if ((sd = s.isStructDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 irs.deferToObj.push(cast(void*)sd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 else if ((fd = s.isFuncDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 //printf("function %s\n", fd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 irs.deferToObj.push(cast(void*)fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 else if ((tm = s.isTemplateMixin()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 //printf("%s\n", tm.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 if (tm.members)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 74
diff changeset
841 foreach(Dsymbol sm; tm.members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 e = el_combine(e, Dsymbol_toElem(sm, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 else if ((td = s.isTupleDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 for (size_t i = 0; i < td.objects.dim; i++)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
848 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 108
diff changeset
849 auto o = td.objects[i];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 ///if (o.dyncast() == DYNCAST_EXPRESSION)
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 108
diff changeset
851 if (auto eo = cast(Expression)o)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
852 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 if (eo.op == TOK.TOKdsymbol)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
854 {
113
3482c73a991b More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 108
diff changeset
855 auto se = cast(DsymbolExp)eo;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 e = el_combine(e, Dsymbol_toElem(se.s, irs));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 else if ((tyd = s.isTypedefDeclaration()) !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 irs.deferToObj.push(cast(void*)tyd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 * Given an expression e that is an array,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 * determine and set the 'length' variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 * lengthVar Symbol of 'length' variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 * &e expression that is the array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 * t1 Type of the array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 * e is rewritten to avoid side effects
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 * expression that initializes 'length'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 elem* resolveLengthVar(VarDeclaration lengthVar, elem** pe, Type t1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 //printf("resolveLengthVar()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 elem* einit = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 if (lengthVar && !(lengthVar.storage_class & STC.STCconst))
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
888 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 elem* elength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 Symbol* slength;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 if (t1.ty == TY.Tsarray)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
893 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 TypeSArray tsa = cast(TypeSArray)t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 long length = tsa.dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 elength = el_long(TYM.TYuint, length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 goto L3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 else if (t1.ty == TY.Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 elength = *pe;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 *pe = el_same(&elength);
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
904 elength = el_una(OP64_32, TYM.TYuint, elength);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 L3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 slength = lengthVar.toSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 //symbol_add(slength);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909
140
31c086f76669 dmd.lib now only contains the backend
Trass3r
parents: 135
diff changeset
910 einit = el_bin(OPeq, TYM.TYuint, el_var(slength), elength);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 return einit;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 * Set an array pointed to by eptr to evalue:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 * eptr[0..edim] = evalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 * eptr where to write the data to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 * evalue value to write
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 * edim number of times to write evalue to eptr[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 * tb type of evalue
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 elem* setArray(elem* eptr, elem* edim, Type tb, elem* evalue, IRState* irs, int op)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
926 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 int r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 elem* e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 int sz = cast(int)tb.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 if (tb.ty == TY.Tfloat80 || tb.ty == TY.Timaginary80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 r = RTLSYM.RTLSYM_MEMSET80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 else if (tb.ty == TY.Tcomplex80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 r = RTLSYM.RTLSYM_MEMSET160;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 else if (tb.ty == TY.Tcomplex64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 r = RTLSYM.RTLSYM_MEMSET128;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 switch (sz)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 case 1: r = RTLSYM.RTLSYM_MEMSET8; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 case 2: r = RTLSYM.RTLSYM_MEMSET16; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 case 4: r = RTLSYM.RTLSYM_MEMSET32; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 case 8: r = RTLSYM.RTLSYM_MEMSET64; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 default: r = RTLSYM.RTLSYM_MEMSETN; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 /* Determine if we need to do postblit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 if (op != TOK.TOKblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 StructDeclaration sd = needsPostblit(tb);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 if (sd)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
954 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 /* Need to do postblit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 * void *_d_arraysetassign(void *p, void *value, int dim, TypeInfo ti);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 r = (op == TOK.TOKconstruct) ? RTLSYM.RTLSYM_ARRAYSETCTOR : RTLSYM.RTLSYM_ARRAYSETASSIGN;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 evalue = el_una(OPER.OPaddr, TYM.TYnptr, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 Expression ti = tb.getTypeInfo(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 elem* eti = ti.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 e = el_params(eti, edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 if (r == RTLSYM.RTLSYM_MEMSETN)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 // void *_memsetn(void *p, void *value, int dim, int sizelem)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 evalue = el_una(OPER.OPaddr, TYM.TYnptr, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 elem *esz = el_long(TYM.TYint, sz);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 e = el_params(esz, edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 if (sz > 1 && sz <= 8 && evalue.Eoper == OPER.OPconst && el_allbits(evalue, 0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 r = RTLSYM.RTLSYM_MEMSET8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 edim = el_bin(OPER.OPmul, TYM.TYuint, edim, el_long(TYM.TYuint, sz));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
984 if (tybasic(evalue.Ety) == TYM.TYstruct || tybasic(evalue.Ety) == TYarray)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 evalue = el_una(OPER.OPstrpar, TYM.TYstruct, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 evalue.Enumbytes = evalue.E1.Enumbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 assert(evalue.Enumbytes);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 // Be careful about parameter side effect ordering
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 if (r == RTLSYM.RTLSYM_MEMSET8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 e = el_param(edim, evalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 e = el_bin(OPER.OPmemset, TYM.TYnptr, eptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 e = el_params(edim, evalue, eptr, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[r]), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 /*************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 * Initialize the hidden aggregate member, vthis, with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 * the context pointer.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 * *(ey + ad.vthis.offset) = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 elem* setEthis(Loc loc, IRState* irs, elem* ey, AggregateDeclaration ad)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 elem* ethis;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 FuncDeclaration thisfd = irs.getFunc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 int offset = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 Dsymbol cdp = ad.toParent2(); // class/func we're nested in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 //printf("setEthis(ad = %s, cdp = %s, thisfd = %s)\n", ad.toChars(), cdp.toChars(), thisfd.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 if (cdp is thisfd)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1022 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 /* Class we're new'ing is a local class in this function:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 * void thisfd() { class ad { } }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 if (irs.sclosure)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 ethis = el_var(irs.sclosure);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 else if (irs.sthis)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 if (thisfd.closureVars.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 /// } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 /// if (thisfd.nestedFrameRef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 ethis = el_ptr(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 ethis = el_long(TYM.TYnptr, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 /// version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 if (thisfd.closureVars.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 /// } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 /// if (thisfd.nestedFrameRef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 ethis.Eoper = OPER.OPframeptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 else if (thisfd.vthis && (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 cdp == thisfd.toParent2() || (
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 cdp.isClassDeclaration() && cdp.isClassDeclaration().isBaseOf(thisfd.toParent2().isClassDeclaration(), &offset)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 )
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1060 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 /* Class we're new'ing is at the same level as thisfd
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 assert(offset == 0); // BUG: should handle this case
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 ethis = el_var(irs.sthis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 ethis = getEthis(loc, irs, ad.toParent2());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 ethis = el_una(OPER.OPaddr, TYM.TYnptr, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 ey = el_bin(OPER.OPadd, TYM.TYnptr, ey, el_long(TYM.TYint, ad.vthis.offset));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 ey = el_una(OPER.OPind, TYM.TYnptr, ey);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 ey = el_bin(OPER.OPeq, TYM.TYnptr, ey, ethis);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 return ey;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 /********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 * Determine if t is an array of structs that need a postblit.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 StructDeclaration needsPostblit(Type t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 while (t.ty == TY.Tsarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 t = t.nextOf().toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 if (t.ty == TY.Tstruct)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1091 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 StructDeclaration sd = (cast(TypeStruct)t).sym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 if (sd.postblit)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 return sd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 /*****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 * Convert array to a dynamic array.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 elem* array_toDarray(Type t, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 uint dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 elem* ef = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 elem* ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 //printf("array_toDarray(t = %s)\n", t.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 t = t.toBasetype();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 switch (t.ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 case TY.Tarray:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 case TY.Tsarray:
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
1119 e = addressElem(e, t);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 dim = cast(uint)(cast(TypeSArray)t).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 e = el_pair(TYM.TYullong, el_long(TYM.TYint, dim), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 switch (e.Eoper)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 case OPER.OPconst:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 size_t len = tysize[tybasic(e.Ety)];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 elem* es = el_calloc();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 es.Eoper = OPER.OPstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 // Match MEM_PH_FREE for OPstring in ztc\el.c
177
1475fd394c9e bug fixes
korDen
parents: 174
diff changeset
1135 es.EV.ss.Vstring = cast(char*)malloc(len); /// !
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 memcpy(es.EV.ss.Vstring, &e.EV, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 es.EV.ss.Vstrlen = len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 es.Ety = TYM.TYnptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 e = es;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 case OPER.OPvar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 e = el_una(OPER.OPaddr, TYM.TYnptr, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 case OPER.OPcomma:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 ef = el_combine(ef, e.E1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 ex = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 e = e.E2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 ex.E1() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 ex.E2() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 el_free(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 case OPER.OPind:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 ex = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 e = e.E1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 ex.E1() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 ex.E2() = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 el_free(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 // Copy expression to a variable and take the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 // address of that variable.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 Symbol* stmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 tym_t ty = tybasic(e.Ety);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 if (ty == TYM.TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 if (e.Enumbytes == 4)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 ty = TYM.TYint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 else if (e.Enumbytes == 8)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 ty = TYM.TYllong;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 e.Ety = ty;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 stmp = symbol_genauto(type_fake(ty));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 e = el_bin(OPER.OPeq, e.Ety, el_var(stmp), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 e = el_bin(OPER.OPcomma, TYM.TYnptr, e, el_una(OPER.OPaddr, TYM.TYnptr, el_var(stmp)));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 dim = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 e = el_pair(TYM.TYullong, el_long(TYM.TYint, dim), e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 return el_combine(ef, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
1194 /************************************
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
1195 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 elem* sarray_toDarray(Loc loc, Type tfrom, Type tto, elem* e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 //printf("sarray_toDarray()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 //elem_print(e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 uint dim = cast(uint)(cast(TypeSArray)tfrom).dim.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 if (tto)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 uint fsize = cast(uint)tfrom.nextOf().size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 uint tsize = cast(uint)tto.nextOf().size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 if ((dim * fsize) % tsize != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 Lerr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 error(loc, "cannot cast %s to %s since sizes don't line up", tfrom.toChars(), tto.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 dim = (dim * fsize) / tsize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 L1:
108
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
1217 elem* elen = el_long(TYM.TYint, dim);
6da99741178e e2ir.c changes, mainly accounts for static arrays being value types now
Trass3r
parents: 84
diff changeset
1218 e = addressElem(e, tfrom);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 e = el_pair(TYM.TYullong, elen, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 elem* eval_Darray(IRState* irs, Expression e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 elem* ex = e.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 return array_toDarray(e.type, ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 /***********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 * Generate code to set index into scope table.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 void setScopeIndex(Blockx* blx, block* b, int scope_index)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 version (SEH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 block_appendexp(b, nteh_setScopeTableIndex(blx, scope_index));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 * Create a static symbol we can hang DT initializers onto.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 Symbol* static_sym()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 Symbol* s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 type* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 t = type_alloc(TYint);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 t.Tcount++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 s = symbol_calloc("internal");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 s.Sclass = SCstatic;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 s.Sfl = FLextern;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 s.Sflags |= SFLnodebug;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 s.Stype = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 version (ELFOBJ_OR_MACHOBJ) {
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1257 s.Sseg = Segment.DATA;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 slist_add(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 * Convert label to block.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 block* labelToBlock(Loc loc, Blockx *blx, LabelDsymbol label)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 LabelStatement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 if (!label.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 error(loc, "undefined label %s", label.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 s = label.statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 if (!s.lblock)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1279 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 s.lblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 if (s.isReturnLabel)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 s.lblock.Btry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 return s.lblock;
22
fd4acc376c45 Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents: 5
diff changeset
1285 }
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1286
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1287 /*******************************************
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1288 * Generate elem to zero fill contents of Symbol stmp
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1289 * from *poffset..offset2.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1290 * May store anywhere from 0..maxoff, as this function
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1291 * tries to use aligned int stores whereever possible.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1292 * Update *poffset to end of initialized hole; *poffset will be >= offset2.
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1293 */
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1294
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1295 elem* fillHole(Symbol* stmp, size_t* poffset, size_t offset2, size_t maxoff)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1296 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1297 elem* e = null;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1298 int basealign = 1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1299
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1300 while (*poffset < offset2)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1301 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1302 tym_t ty;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1303 elem* e1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1304
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1305 if (tybasic(stmp.Stype.Tty) == TYnptr)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1306 e1 = el_var(stmp);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1307 else
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1308 e1 = el_ptr(stmp);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1309
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1310 if (basealign)
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1311 *poffset &= ~3;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1312
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1313 basealign = 1;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1314 size_t sz = maxoff - *poffset;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1315 switch (sz)
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1316 {
67
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1317 case 1: ty = TYchar; break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1318 case 2: ty = TYshort; break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1319 case 3:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1320 ty = TYshort;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1321 basealign = 0;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1322 break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1323 default:
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1324 ty = TYlong;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1325 break;
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1326 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1327 e1 = el_bin(OPadd, TYnptr, e1, el_long(TYsize_t, *poffset));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1328 e1 = el_una(OPind, ty, e1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1329 e1 = el_bin(OPeq, ty, e1, el_long(ty, 0));
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1330 e = el_combine(e, e1);
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1331 *poffset += tysize[ty];
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1332 }
f708f0452e81 some of the backend/codegen stuff implemented
korDen
parents: 22
diff changeset
1333 return e;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 140
diff changeset
1334 }