Mercurial > projects > ldc
comparison gen/tocall.cpp @ 347:6057fdf797d8 trunk
[svn r368] Fixed custom class allocators with arbitrary user arguments. Closes #25
Removed some dead code.
Started on a more generalised approach to call misc. D functions.
author | lindquist |
---|---|
date | Sun, 13 Jul 2008 20:49:10 +0200 |
parents | |
children | ac1fcc138e42 |
comparison
equal
deleted
inserted
replaced
346:c9d5c711d65a | 347:6057fdf797d8 |
---|---|
1 #include "gen/llvm.h" | |
2 | |
3 #include "mtype.h" | |
4 #include "declaration.h" | |
5 | |
6 #include "gen/tollvm.h" | |
7 #include "gen/llvmhelpers.h" | |
8 #include "gen/irstate.h" | |
9 #include "gen/dvalue.h" | |
10 #include "gen/functions.h" | |
11 | |
12 #include "gen/logger.h" | |
13 | |
14 ////////////////////////////////////////////////////////////////////////////////////////// | |
15 | |
16 DValue* DtoCallDFunc(FuncDeclaration* fdecl, Array* arguments, TypeClass* type, LLValue* thismem) | |
17 { | |
18 Logger::println("Calling function: %s", fdecl->toPrettyChars()); | |
19 LOG_SCOPE; | |
20 | |
21 assert(fdecl); | |
22 DtoForceDeclareDsymbol(fdecl); | |
23 llvm::Function* fn = fdecl->ir.irFunc->func; | |
24 TypeFunction* tf = (TypeFunction*)DtoDType(fdecl->type); | |
25 | |
26 llvm::PAListPtr palist; | |
27 | |
28 int thisOffset = 0; | |
29 if (type || thismem) | |
30 { | |
31 assert(type && thismem); | |
32 thisOffset = 1; | |
33 } | |
34 | |
35 std::vector<LLValue*> args; | |
36 if (thisOffset) | |
37 args.push_back(thismem); | |
38 for (size_t i=0; i<arguments->dim; ++i) | |
39 { | |
40 Expression* ex = (Expression*)arguments->data[i]; | |
41 Argument* fnarg = Argument::getNth(tf->parameters, i); | |
42 DValue* argval = DtoArgument(fnarg, ex); | |
43 LLValue* a = argval->getRVal(); | |
44 const LLType* aty = fn->getFunctionType()->getParamType(i+thisOffset); | |
45 if (a->getType() != aty) | |
46 { | |
47 Logger::cout() << "expected: " << *aty << '\n'; | |
48 Logger::cout() << "got: " << *a->getType() << '\n'; | |
49 a = DtoBitCast(a, aty); | |
50 } | |
51 args.push_back(a); | |
52 if (fnarg && fnarg->llvmByVal) | |
53 palist = palist.addAttr(i+thisOffset+1, llvm::ParamAttr::ByVal); // return,this,args... | |
54 } | |
55 | |
56 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp"); | |
57 call->setCallingConv(DtoCallingConv(LINKd)); | |
58 call->setParamAttrs(palist); | |
59 | |
60 return new DImValue(type, call->get(), false); | |
61 } |