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