Mercurial > projects > ldc
comparison gen/functions.cpp @ 988:2667e3a145be
- Fixed LLVM style CL args for D2.
- Moved main() into its own file gen/main.cpp
- Fixed basic cross compilation
- removed the option for setting OS
- added support for llc's mattr, mcpu and mtriple switches
- added basic ABI abstraction for return value rewrites, it's not perfect and will probably be completely rewritten once I get to handling parameter rewrites as well.
- x86-64 extern(C) abi for cfloat returns now match (llvm-)gcc.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Thu, 26 Feb 2009 14:11:49 +0100 |
parents | 89729c76b8ff |
children | 7a0238db1962 |
comparison
equal
deleted
inserted
replaced
987:73ff89728d85 | 988:2667e3a145be |
---|---|
18 #include "gen/logger.h" | 18 #include "gen/logger.h" |
19 #include "gen/functions.h" | 19 #include "gen/functions.h" |
20 #include "gen/todebug.h" | 20 #include "gen/todebug.h" |
21 #include "gen/classes.h" | 21 #include "gen/classes.h" |
22 #include "gen/dvalue.h" | 22 #include "gen/dvalue.h" |
23 #include "gen/abi.h" | |
23 | 24 |
24 #include <algorithm> | 25 #include <algorithm> |
25 | 26 |
26 const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, const LLType* nesttype, bool ismain) | 27 const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, const LLType* nesttype, bool ismain) |
27 { | 28 { |
51 bool usesnest = false; | 52 bool usesnest = false; |
52 | 53 |
53 // parameter types | 54 // parameter types |
54 std::vector<const LLType*> paramvec; | 55 std::vector<const LLType*> paramvec; |
55 | 56 |
57 // special case main | |
56 if (ismain) | 58 if (ismain) |
57 { | 59 { |
58 rettype = LLType::Int32Ty; | 60 rettype = LLType::Int32Ty; |
59 actualRettype = rettype; | 61 actualRettype = rettype; |
60 if (Argument::dim(f->parameters) == 0) | 62 if (Argument::dim(f->parameters) == 0) |
61 { | 63 { |
62 const LLType* arrTy = DtoArrayType(LLType::Int8Ty); | 64 const LLType* arrTy = DtoArrayType(LLType::Int8Ty); |
63 const LLType* arrArrTy = DtoArrayType(arrTy); | 65 const LLType* arrArrTy = DtoArrayType(arrTy); |
64 paramvec.push_back(arrArrTy); | 66 paramvec.push_back(arrArrTy); |
65 } | 67 } |
66 } | 68 } |
67 else{ | 69 // default handling |
70 else | |
71 { | |
68 assert(rt); | 72 assert(rt); |
69 if (DtoIsReturnedInArg(rt)) { | 73 if (gABI->returnInArg(rt)) |
74 { | |
70 rettype = getPtrToType(DtoType(rt)); | 75 rettype = getPtrToType(DtoType(rt)); |
71 actualRettype = LLType::VoidTy; | 76 actualRettype = LLType::VoidTy; |
72 f->retInPtr = retinptr = true; | 77 f->retInPtr = retinptr = true; |
73 } | 78 } |
74 else { | 79 else |
80 { | |
75 rettype = DtoType(rt); | 81 rettype = DtoType(rt); |
76 actualRettype = rettype; | 82 // do abi specific transformations |
77 } | 83 actualRettype = gABI->getRetType(f, rettype); |
78 | 84 } |
85 | |
86 // FIXME: should probably be part of the abi | |
79 if (unsigned ea = DtoShouldExtend(rt)) | 87 if (unsigned ea = DtoShouldExtend(rt)) |
80 { | 88 { |
81 f->retAttrs |= ea; | 89 f->retAttrs |= ea; |
82 } | 90 } |
83 } | 91 } |
84 | 92 |
93 // build up parameter list | |
85 if (retinptr) { | 94 if (retinptr) { |
86 //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n'; | 95 //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n'; |
87 paramvec.push_back(rettype); | 96 paramvec.push_back(rettype); |
88 } | 97 } |
89 | 98 |
99 // this/context param | |
90 if (thistype) { | 100 if (thistype) { |
91 paramvec.push_back(thistype); | 101 paramvec.push_back(thistype); |
92 usesthis = true; | 102 usesthis = true; |
93 } | 103 } |
94 else if (nesttype) { | 104 else if (nesttype) { |
95 paramvec.push_back(nesttype); | 105 paramvec.push_back(nesttype); |
96 usesnest = true; | 106 usesnest = true; |
97 } | 107 } |
98 | 108 |
109 // dstyle vararg | |
99 if (dVararg) { | 110 if (dVararg) { |
100 paramvec.push_back(DtoType(Type::typeinfo->type->arrayOf())); // _arguments | 111 paramvec.push_back(DtoType(Type::typeinfo->type->arrayOf())); // _arguments |
101 paramvec.push_back(getVoidPtrType()); // _argptr | 112 paramvec.push_back(getVoidPtrType()); // _argptr |
102 } | 113 } |
103 | 114 |