comparison gen/functions.cpp @ 131:5825d48b27d1 trunk

[svn r135] * Merged DMD 1.025 * * Fixed a minor linking order mishap * * Added an command line option -annotate * * Fixed some problems with running optimizations * * Added std.stdio and dependencies to lphobos (still not 100% working, but compiles and links) * * Fixed problems with passing aggregate types to variadic functions * * Added initial code towards full GC support, currently based on malloc and friends, not all the runtime calls the GC yet for memory * * Fixed problems with resolving nested function context pointers for some heavily nested cases * * Redid function argument passing + other minor code cleanups, still lots to do on this end... *
author lindquist
date Fri, 04 Jan 2008 01:38:42 +0100
parents 8096ba7082db
children 1700239cab2e
comparison
equal deleted inserted replaced
130:a7dfa0ed966c 131:5825d48b27d1
14 #include "gen/arrays.h" 14 #include "gen/arrays.h"
15 #include "gen/logger.h" 15 #include "gen/logger.h"
16 #include "gen/functions.h" 16 #include "gen/functions.h"
17 #include "gen/todebug.h" 17 #include "gen/todebug.h"
18 #include "gen/classes.h" 18 #include "gen/classes.h"
19 #include "gen/dvalue.h"
19 20
20 const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain) 21 const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
21 { 22 {
22 TypeFunction* f = (TypeFunction*)type; 23 TypeFunction* f = (TypeFunction*)type;
23 assert(f != 0); 24 assert(f != 0);
88 Argument* arg = Argument::getNth(f->parameters, i); 89 Argument* arg = Argument::getNth(f->parameters, i);
89 // ensure scalar 90 // ensure scalar
90 Type* argT = DtoDType(arg->type); 91 Type* argT = DtoDType(arg->type);
91 assert(argT); 92 assert(argT);
92 93
93 if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
94 //assert(arg->vardecl);
95 //arg->vardecl->refparam = true;
96 }
97 else
98 arg->llvmCopy = true;
99
100 const llvm::Type* at = DtoType(argT); 94 const llvm::Type* at = DtoType(argT);
101 if (isaStruct(at)) { 95 if (isaStruct(at)) {
102 Logger::println("struct param"); 96 Logger::println("struct param");
103 paramvec.push_back(llvm::PointerType::get(at)); 97 paramvec.push_back(llvm::PointerType::get(at));
104 } 98 }
112 Logger::println("opaque param"); 106 Logger::println("opaque param");
113 assert(argT->ty == Tstruct || argT->ty == Tclass); 107 assert(argT->ty == Tstruct || argT->ty == Tclass);
114 paramvec.push_back(llvm::PointerType::get(at)); 108 paramvec.push_back(llvm::PointerType::get(at));
115 } 109 }
116 else { 110 else {
117 if (!arg->llvmCopy) { 111 if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
118 Logger::println("ref param"); 112 Logger::println("by ref param");
119 at = llvm::PointerType::get(at); 113 at = llvm::PointerType::get(at);
120 } 114 }
121 else { 115 else {
122 Logger::println("in param"); 116 Logger::println("in param");
123 } 117 }
507 501
508 // debug info 502 // debug info
509 if (global.params.symdebug) DtoDwarfFuncStart(fd); 503 if (global.params.symdebug) DtoDwarfFuncStart(fd);
510 504
511 llvm::Value* parentNested = NULL; 505 llvm::Value* parentNested = NULL;
512 if (FuncDeclaration* fd2 = fd->toParent()->isFuncDeclaration()) { 506 if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
513 if (!fd->isStatic()) 507 if (!fd->isStatic()) // huh?
514 parentNested = fd2->llvmNested; 508 parentNested = fd2->llvmNested;
515 } 509 }
516 510
517 // need result variable? (nested) 511 // need result variable? (nested)
518 if (fd->vresult && fd->vresult->nestedref) { 512 if (fd->vresult && fd->vresult->nestedref) {
720 DtoResolveDsymbol(f); 714 DtoResolveDsymbol(f);
721 return llvm::cast<llvm::FunctionType>(DtoType(f->type)); 715 return llvm::cast<llvm::FunctionType>(DtoType(f->type));
722 } 716 }
723 717
724 ////////////////////////////////////////////////////////////////////////////////////////// 718 //////////////////////////////////////////////////////////////////////////////////////////
719
720 DValue* DtoArgument(Argument* fnarg, Expression* argexp)
721 {
722 Logger::println("DtoArgument");
723 LOG_SCOPE;
724
725 DValue* arg = argexp->toElem(gIR);
726
727 // ref/out arg
728 if (fnarg && ((fnarg->storageClass & STCref) || (fnarg->storageClass & STCout)))
729 {
730 if (arg->isVar() || arg->isLRValue())
731 arg = new DImValue(argexp->type, arg->getLVal(), false);
732 else
733 arg = new DImValue(argexp->type, arg->getRVal(), false);
734 }
735 // aggregate arg
736 else if (DtoIsPassedByRef(argexp->type))
737 {
738 llvm::Value* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint());
739 DVarValue* vv = new DVarValue(argexp->type, alloc, true);
740 DtoAssign(vv, arg);
741 arg = vv;
742 }
743 // normal arg (basic/value type)
744 else
745 {
746 // nothing to do
747 }
748
749 return arg;
750 }
751
752 //////////////////////////////////////////////////////////////////////////////////////////
753
754 void DtoVariadicArgument(Expression* argexp, llvm::Value* dst)
755 {
756 Logger::println("DtoVariadicArgument");
757 LOG_SCOPE;
758 DVarValue* vv = new DVarValue(argexp->type, dst, true);
759 DtoAssign(vv, argexp->toElem(gIR));
760 }
761
762 //////////////////////////////////////////////////////////////////////////////////////////