Mercurial > projects > ldc
comparison gen/functions.cpp @ 1148:3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Fri, 27 Mar 2009 21:50:32 +0100 |
parents | 4c20fcc4252b |
children | 5ebe8224988b |
comparison
equal
deleted
inserted
replaced
1147:dbe4af57b240 | 1148:3d1b16dabd25 |
---|---|
24 | 24 |
25 using namespace llvm::Attribute; | 25 using namespace llvm::Attribute; |
26 | 26 |
27 const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain) | 27 const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain) |
28 { | 28 { |
29 // already built ? | |
30 if (type->ir.type != NULL) { | |
31 //assert(f->fty != NULL); | |
32 return llvm::cast<llvm::FunctionType>(type->ir.type->get()); | |
33 } | |
34 | |
29 if (Logger::enabled()) | 35 if (Logger::enabled()) |
30 Logger::println("DtoFunctionType(%s)", type->toChars()); | 36 Logger::println("DtoFunctionType(%s)", type->toChars()); |
31 LOG_SCOPE | 37 LOG_SCOPE |
32 // sanity check | 38 // sanity check |
33 assert(type->ty == Tfunction); | 39 assert(type->ty == Tfunction); |
34 TypeFunction* f = (TypeFunction*)type; | 40 TypeFunction* f = (TypeFunction*)type; |
35 | 41 |
36 // already built ? | |
37 if (type->ir.type != NULL) { | |
38 //assert(f->fty != NULL); | |
39 return llvm::cast<llvm::FunctionType>(type->ir.type->get()); | |
40 } | |
41 | |
42 if (f->linkage != LINKintrinsic) { | 42 if (f->linkage != LINKintrinsic) { |
43 // Tell the ABI we're resolving a new function type | 43 // Tell the ABI we're resolving a new function type |
44 gABI->newFunctionType(f); | 44 gABI->newFunctionType(f); |
45 } | 45 } |
46 | 46 |
239 | 239 |
240 ////////////////////////////////////////////////////////////////////////////////////////// | 240 ////////////////////////////////////////////////////////////////////////////////////////// |
241 | 241 |
242 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl) | 242 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl) |
243 { | 243 { |
244 // type has already been resolved | |
245 if (fdecl->type->ir.type != 0) | |
246 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get()); | |
247 | |
244 // handle for C vararg intrinsics | 248 // handle for C vararg intrinsics |
245 if (fdecl->isVaIntrinsic()) | 249 if (fdecl->isVaIntrinsic()) |
246 return DtoVaFunctionType(fdecl); | 250 return DtoVaFunctionType(fdecl); |
247 | |
248 // type has already been resolved | |
249 if (fdecl->type->ir.type != 0) | |
250 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get()); | |
251 | 251 |
252 Type *dthis=0, *dnest=0; | 252 Type *dthis=0, *dnest=0; |
253 | 253 |
254 if (fdecl->needThis()) { | 254 if (fdecl->needThis()) { |
255 if (AggregateDeclaration* ad = fdecl->isMember2()) { | 255 if (AggregateDeclaration* ad = fdecl->isMember2()) { |
297 ////////////////////////////////////////////////////////////////////////////////////////// | 297 ////////////////////////////////////////////////////////////////////////////////////////// |
298 | 298 |
299 void DtoResolveFunction(FuncDeclaration* fdecl) | 299 void DtoResolveFunction(FuncDeclaration* fdecl) |
300 { | 300 { |
301 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) { | 301 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) { |
302 Logger::println("Ignoring unittest %s", fdecl->toPrettyChars()); | |
302 return; // ignore declaration completely | 303 return; // ignore declaration completely |
303 } | 304 } |
304 | 305 |
305 // is imported and we don't have access? | 306 // is imported and we don't have access? |
306 if (fdecl->getModule() != gIR->dmodule) | 307 if (fdecl->getModule() != gIR->dmodule) |
307 { | 308 { |
308 if (fdecl->prot() == PROTprivate) | 309 if (fdecl->prot() == PROTprivate) |
310 { | |
311 Logger::println("Ignoring private imported function %s", fdecl->toPrettyChars()); | |
309 return; | 312 return; |
310 } | 313 } |
311 | 314 } |
312 if (fdecl->ir.resolved) return; | |
313 fdecl->ir.resolved = true; | |
314 | |
315 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); | |
316 LOG_SCOPE; | |
317 | 315 |
318 //printf("resolve function: %s\n", fdecl->toPrettyChars()); | 316 //printf("resolve function: %s\n", fdecl->toPrettyChars()); |
319 | 317 |
320 if (fdecl->parent) | 318 if (fdecl->parent) |
321 if (TemplateInstance* tinst = fdecl->parent->isTemplateInstance()) | 319 if (TemplateInstance* tinst = fdecl->parent->isTemplateInstance()) |
323 TemplateDeclaration* tempdecl = tinst->tempdecl; | 321 TemplateDeclaration* tempdecl = tinst->tempdecl; |
324 if (tempdecl->llvmInternal == LLVMva_arg) | 322 if (tempdecl->llvmInternal == LLVMva_arg) |
325 { | 323 { |
326 Logger::println("magic va_arg found"); | 324 Logger::println("magic va_arg found"); |
327 fdecl->llvmInternal = LLVMva_arg; | 325 fdecl->llvmInternal = LLVMva_arg; |
326 fdecl->ir.resolved = true; | |
328 fdecl->ir.declared = true; | 327 fdecl->ir.declared = true; |
329 fdecl->ir.initialized = true; | 328 fdecl->ir.initialized = true; |
330 fdecl->ir.defined = true; | 329 fdecl->ir.defined = true; |
331 return; // this gets mapped to an instruction so a declaration makes no sence | 330 return; // this gets mapped to an instruction so a declaration makes no sence |
332 } | 331 } |
345 } | 344 } |
346 } | 345 } |
347 | 346 |
348 DtoFunctionType(fdecl); | 347 DtoFunctionType(fdecl); |
349 | 348 |
349 if (fdecl->ir.resolved) return; | |
350 fdecl->ir.resolved = true; | |
351 | |
352 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); | |
353 LOG_SCOPE; | |
354 | |
350 // queue declaration | 355 // queue declaration |
351 if (!fdecl->isAbstract()) | 356 if (!fdecl->isAbstract()) |
352 gIR->declareList.push_back(fdecl); | 357 { |
358 Logger::println("Ignoring declaration of abstract function %s", fdecl->toPrettyChars()); | |
359 DtoDeclareFunction(fdecl); | |
360 } | |
353 } | 361 } |
354 | 362 |
355 ////////////////////////////////////////////////////////////////////////////////////////// | 363 ////////////////////////////////////////////////////////////////////////////////////////// |
356 | 364 |
357 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl) | 365 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl) |
567 | 575 |
568 if (fdecl->isUnitTestDeclaration() && !declareOnly) | 576 if (fdecl->isUnitTestDeclaration() && !declareOnly) |
569 gIR->unitTests.push_back(fdecl); | 577 gIR->unitTests.push_back(fdecl); |
570 | 578 |
571 if (!declareOnly) | 579 if (!declareOnly) |
572 gIR->defineList.push_back(fdecl); | 580 Type::sir->addFunctionBody(fdecl->ir.irFunc); |
573 else | 581 else |
574 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage); | 582 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage); |
575 | |
576 if (Logger::enabled()) | |
577 Logger::cout() << "func decl: " << *func << '\n'; | |
578 } | 583 } |
579 | 584 |
580 ////////////////////////////////////////////////////////////////////////////////////////// | 585 ////////////////////////////////////////////////////////////////////////////////////////// |
581 | 586 |
582 // FIXME: this isn't too pretty! | 587 // FIXME: this isn't too pretty! |