Mercurial > projects > ldc
comparison gen/toobj.cpp @ 89:ccca1c13e13a trunk
[svn r93] a few fixes, some phobos additions.
some very rough groundwork for moduleinfo and classinfo support
author | lindquist |
---|---|
date | Wed, 07 Nov 2007 02:45:47 +0100 |
parents | 058d3925950e |
children | 61615fa85940 |
comparison
equal
deleted
inserted
replaced
88:058d3925950e | 89:ccca1c13e13a |
---|---|
89 Dsymbol* dsym = (Dsymbol*)(members->data[k]); | 89 Dsymbol* dsym = (Dsymbol*)(members->data[k]); |
90 assert(dsym); | 90 assert(dsym); |
91 dsym->toObjFile(); | 91 dsym->toObjFile(); |
92 } | 92 } |
93 | 93 |
94 // generate ModuleInfo | |
95 genmoduleinfo(); | |
96 | |
94 gTargetData = 0; | 97 gTargetData = 0; |
95 | 98 |
96 // emit the llvm main function if necessary | 99 // emit the llvm main function if necessary |
97 if (ir.emitMain) { | 100 if (ir.emitMain) { |
98 DtoMain(); | 101 DtoMain(); |
137 | 140 |
138 // Put out instance of ModuleInfo for this Module | 141 // Put out instance of ModuleInfo for this Module |
139 | 142 |
140 void Module::genmoduleinfo() | 143 void Module::genmoduleinfo() |
141 { | 144 { |
145 // The layout is: | |
146 // { | |
147 // void **vptr; | |
148 // monitor_t monitor; | |
149 // char[] name; // class name | |
150 // ModuleInfo importedModules[]; | |
151 // ClassInfo localClasses[]; | |
152 // uint flags; // initialization state | |
153 // void *ctor; | |
154 // void *dtor; | |
155 // void *unitTest; | |
156 // } | |
157 | |
158 if (moduleinfo) { | |
159 Logger::println("moduleinfo"); | |
160 } | |
161 if (vmoduleinfo) { | |
162 Logger::println("vmoduleinfo"); | |
163 } | |
164 if (needModuleInfo()) { | |
165 Logger::println("**** ATTENTION: module info is needed but skipped"); | |
166 } | |
167 | |
168 | |
169 /* | |
170 Symbol *msym = toSymbol(); | |
171 unsigned offset; | |
172 unsigned sizeof_ModuleInfo = 12 * PTRSIZE; | |
173 | |
174 ////////////////////////////////////////////// | |
175 | |
176 csym->Sclass = SCglobal; | |
177 csym->Sfl = FLdata; | |
178 | |
179 // The layout is: | |
180 // { | |
181 // void **vptr; | |
182 // monitor_t monitor; | |
183 // char[] name; // class name | |
184 // ModuleInfo importedModules[]; | |
185 // ClassInfo localClasses[]; | |
186 // uint flags; // initialization state | |
187 // void *ctor; | |
188 // void *dtor; | |
189 // void *unitTest; | |
190 // } | |
191 dt_t *dt = NULL; | |
192 | |
193 if (moduleinfo) | |
194 dtxoff(&dt, moduleinfo->toVtblSymbol(), 0, TYnptr); // vtbl for ModuleInfo | |
195 else | |
196 dtdword(&dt, 0); // BUG: should be an assert() | |
197 dtdword(&dt, 0); // monitor | |
198 | |
199 // name[] | |
200 char *name = toPrettyChars(); | |
201 size_t namelen = strlen(name); | |
202 dtdword(&dt, namelen); | |
203 dtabytes(&dt, TYnptr, 0, namelen + 1, name); | |
204 | |
205 ClassDeclarations aclasses; | |
206 int i; | |
207 | |
208 //printf("members->dim = %d\n", members->dim); | |
209 for (i = 0; i < members->dim; i++) | |
210 { | |
211 Dsymbol *member; | |
212 | |
213 member = (Dsymbol *)members->data[i]; | |
214 //printf("\tmember '%s'\n", member->toChars()); | |
215 member->addLocalClass(&aclasses); | |
216 } | |
217 | |
218 // importedModules[] | |
219 int aimports_dim = aimports.dim; | |
220 for (i = 0; i < aimports.dim; i++) | |
221 { Module *m = (Module *)aimports.data[i]; | |
222 if (!m->needModuleInfo()) | |
223 aimports_dim--; | |
224 } | |
225 dtdword(&dt, aimports_dim); | |
226 if (aimports.dim) | |
227 dtxoff(&dt, csym, sizeof_ModuleInfo, TYnptr); | |
228 else | |
229 dtdword(&dt, 0); | |
230 | |
231 // localClasses[] | |
232 dtdword(&dt, aclasses.dim); | |
233 if (aclasses.dim) | |
234 dtxoff(&dt, csym, sizeof_ModuleInfo + aimports_dim * PTRSIZE, TYnptr); | |
235 else | |
236 dtdword(&dt, 0); | |
237 | |
238 if (needmoduleinfo) | |
239 dtdword(&dt, 0); // flags (4 means MIstandalone) | |
240 else | |
241 dtdword(&dt, 4); // flags (4 means MIstandalone) | |
242 | |
243 if (sctor) | |
244 dtxoff(&dt, sctor, 0, TYnptr); | |
245 else | |
246 dtdword(&dt, 0); | |
247 | |
248 if (sdtor) | |
249 dtxoff(&dt, sdtor, 0, TYnptr); | |
250 else | |
251 dtdword(&dt, 0); | |
252 | |
253 if (stest) | |
254 dtxoff(&dt, stest, 0, TYnptr); | |
255 else | |
256 dtdword(&dt, 0); | |
257 | |
258 ////////////////////////////////////////////// | |
259 | |
260 for (i = 0; i < aimports.dim; i++) | |
261 { | |
262 Module *m; | |
263 | |
264 m = (Module *)aimports.data[i]; | |
265 if (m->needModuleInfo()) | |
266 { Symbol *s = m->toSymbol(); | |
267 s->Sflags |= SFLweak; | |
268 dtxoff(&dt, s, 0, TYnptr); | |
269 } | |
270 } | |
271 | |
272 for (i = 0; i < aclasses.dim; i++) | |
273 { | |
274 ClassDeclaration *cd; | |
275 | |
276 cd = (ClassDeclaration *)aclasses.data[i]; | |
277 dtxoff(&dt, cd->toSymbol(), 0, TYnptr); | |
278 } | |
279 | |
280 csym->Sdt = dt; | |
281 #if ELFOBJ | |
282 // Cannot be CONST because the startup code sets flag bits in it | |
283 csym->Sseg = DATA; | |
284 #endif | |
285 outdata(csym); | |
286 | |
287 ////////////////////////////////////////////// | |
288 | |
289 obj_moduleinfo(msym); | |
290 */ | |
142 } | 291 } |
143 | 292 |
144 /* ================================================================== */ | 293 /* ================================================================== */ |
145 | 294 |
146 void Dsymbol::toObjFile() | 295 void Dsymbol::toObjFile() |
551 | 700 |
552 gIR->classes.pop_back(); | 701 gIR->classes.pop_back(); |
553 gIR->structs.pop_back(); | 702 gIR->structs.pop_back(); |
554 | 703 |
555 llvmInProgress = false; | 704 llvmInProgress = false; |
705 | |
706 // if (ClassDeclaration::classinfo != this) | |
707 // DtoClassInfo(this); | |
556 } | 708 } |
557 | 709 |
558 /****************************************** | 710 /****************************************** |
559 * Get offset of base class's vtbl[] initializer from start of csym. | 711 * Get offset of base class's vtbl[] initializer from start of csym. |
560 * Returns ~0 if not this csym. | 712 * Returns ~0 if not this csym. |