Mercurial > projects > ldc
comparison gen/tocall.cpp @ 530:d30c40f1128d
Make class invariants work.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Thu, 21 Aug 2008 15:19:45 +0200 |
parents | 642f6fa854e5 |
children | fbb1a366cfbc |
comparison
equal
deleted
inserted
replaced
529:cef0cbcf7d22 | 530:d30c40f1128d |
---|---|
111 | 111 |
112 // number of non variadic args | 112 // number of non variadic args |
113 int begin = tf->parameters->dim; | 113 int begin = tf->parameters->dim; |
114 Logger::println("num non vararg params = %d", begin); | 114 Logger::println("num non vararg params = %d", begin); |
115 | 115 |
116 // get n args in arguments list | |
117 size_t n_arguments = arguments ? arguments->dim : 0; | |
118 | |
116 // build struct with argument types (non variadic args) | 119 // build struct with argument types (non variadic args) |
117 for (int i=begin; i<arguments->dim; i++) | 120 for (int i=begin; i<n_arguments; i++) |
118 { | 121 { |
119 Expression* argexp = (Expression*)arguments->data[i]; | 122 Expression* argexp = (Expression*)arguments->data[i]; |
120 vtypes.push_back(DtoType(argexp->type)); | 123 vtypes.push_back(DtoType(argexp->type)); |
121 size_t sz = getABITypeSize(vtypes.back()); | 124 size_t sz = getABITypeSize(vtypes.back()); |
122 if (sz < PTRSIZE) | 125 if (sz < PTRSIZE) |
125 const LLStructType* vtype = LLStructType::get(vtypes); | 128 const LLStructType* vtype = LLStructType::get(vtypes); |
126 Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n'; | 129 Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n'; |
127 LLValue* mem = DtoAlloca(vtype,"_argptr_storage"); | 130 LLValue* mem = DtoAlloca(vtype,"_argptr_storage"); |
128 | 131 |
129 // store arguments in the struct | 132 // store arguments in the struct |
130 for (int i=begin,k=0; i<arguments->dim; i++,k++) | 133 for (int i=begin,k=0; i<n_arguments; i++,k++) |
131 { | 134 { |
132 Expression* argexp = (Expression*)arguments->data[i]; | 135 Expression* argexp = (Expression*)arguments->data[i]; |
133 if (global.params.llvmAnnotate) | 136 if (global.params.llvmAnnotate) |
134 DtoAnnotation(argexp->toChars()); | 137 DtoAnnotation(argexp->toChars()); |
135 LLValue* argdst = DtoGEPi(mem,0,k); | 138 LLValue* argdst = DtoGEPi(mem,0,k); |
145 llvm::GlobalVariable* typeinfomem = | 148 llvm::GlobalVariable* typeinfomem = |
146 new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module); | 149 new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module); |
147 Logger::cout() << "_arguments storage: " << *typeinfomem << '\n'; | 150 Logger::cout() << "_arguments storage: " << *typeinfomem << '\n'; |
148 | 151 |
149 std::vector<LLConstant*> vtypeinfos; | 152 std::vector<LLConstant*> vtypeinfos; |
150 for (int i=begin,k=0; i<arguments->dim; i++,k++) | 153 for (int i=begin,k=0; i<n_arguments; i++,k++) |
151 { | 154 { |
152 Expression* argexp = (Expression*)arguments->data[i]; | 155 Expression* argexp = (Expression*)arguments->data[i]; |
153 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type)); | 156 vtypeinfos.push_back(DtoTypeInfoOf(argexp->type)); |
154 } | 157 } |
155 | 158 |
217 // get callee llvm value | 220 // get callee llvm value |
218 LLValue* callable = DtoCallableValue(fnval); | 221 LLValue* callable = DtoCallableValue(fnval); |
219 const LLFunctionType* callableTy = DtoExtractFunctionType(callable->getType()); | 222 const LLFunctionType* callableTy = DtoExtractFunctionType(callable->getType()); |
220 assert(callableTy); | 223 assert(callableTy); |
221 | 224 |
225 // get n arguments | |
226 size_t n_arguments = arguments ? arguments->dim : 0; | |
227 | |
222 // get llvm argument iterator, for types | 228 // get llvm argument iterator, for types |
223 LLFunctionType::param_iterator argbegin = callableTy->param_begin(); | 229 LLFunctionType::param_iterator argbegin = callableTy->param_begin(); |
224 LLFunctionType::param_iterator argiter = argbegin; | 230 LLFunctionType::param_iterator argiter = argbegin; |
225 | 231 |
226 // parameter attributes | 232 // parameter attributes |
278 // handle the rest of the arguments based on param passing style | 284 // handle the rest of the arguments based on param passing style |
279 | 285 |
280 // variadic instrinsics need some custom casts | 286 // variadic instrinsics need some custom casts |
281 if (va_intrinsic) | 287 if (va_intrinsic) |
282 { | 288 { |
283 size_t n = arguments->dim; | 289 for (int i=0; i<n_arguments; i++) |
284 for (int i=0; i<n; i++) | |
285 { | 290 { |
286 Expression* exp = (Expression*)arguments->data[i]; | 291 Expression* exp = (Expression*)arguments->data[i]; |
287 DValue* expelem = exp->toElem(gIR); | 292 DValue* expelem = exp->toElem(gIR); |
288 // cast to va_list* | 293 // cast to va_list* |
289 LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType()); | 294 LLValue* val = DtoBitCast(expelem->getLVal(), getVoidPtrType()); |
300 | 305 |
301 // otherwise we're looking at a normal function call | 306 // otherwise we're looking at a normal function call |
302 else | 307 else |
303 { | 308 { |
304 Logger::println("doing normal arguments"); | 309 Logger::println("doing normal arguments"); |
305 for (int i=0; i<arguments->dim; i++) { | 310 for (int i=0; i<n_arguments; i++) { |
306 int j = argiter-argbegin; | 311 int j = argiter-argbegin; |
307 Argument* fnarg = Argument::getNth(tf->parameters, i); | 312 Argument* fnarg = Argument::getNth(tf->parameters, i); |
308 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]); | 313 DValue* argval = DtoArgument(fnarg, (Expression*)arguments->data[i]); |
309 LLValue* arg = argval->getRVal(); | 314 LLValue* arg = argval->getRVal(); |
310 if (fnarg) // can fnarg ever be null in this block? | 315 if (fnarg) // can fnarg ever be null in this block? |