comparison gen/functions.cpp @ 173:db9890b3fb64 trunk

[svn r189] moving IR data back into DMD frontend nodes
author ChristianK
date Tue, 06 May 2008 07:56:03 +0200
parents a8cd9bc1021a
children 9d44ec83acd1
comparison
equal deleted inserted replaced
172:68a7dd38c03c 173:db9890b3fb64
21 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)
22 { 22 {
23 TypeFunction* f = (TypeFunction*)type; 23 TypeFunction* f = (TypeFunction*)type;
24 assert(f != 0); 24 assert(f != 0);
25 25
26 if (gIR->irType[type].type != NULL) { 26 if (type->ir.type != NULL) {
27 return llvm::cast<llvm::FunctionType>(gIR->irType[type].type->get()); 27 return llvm::cast<llvm::FunctionType>(type->ir.type->get());
28 } 28 }
29 29
30 bool typesafeVararg = false; 30 bool typesafeVararg = false;
31 bool arrayVararg = false; 31 bool arrayVararg = false;
32 if (f->linkage == LINKd) 32 if (f->linkage == LINKd)
77 77
78 if (typesafeVararg) { 78 if (typesafeVararg) {
79 ClassDeclaration* ti = Type::typeinfo; 79 ClassDeclaration* ti = Type::typeinfo;
80 ti->toObjFile(); 80 ti->toObjFile();
81 DtoForceConstInitDsymbol(ti); 81 DtoForceConstInitDsymbol(ti);
82 assert(gIR->irDsymbol[ti].irStruct->constInit); 82 assert(ti->ir.irStruct->constInit);
83 std::vector<const llvm::Type*> types; 83 std::vector<const llvm::Type*> types;
84 types.push_back(DtoSize_t()); 84 types.push_back(DtoSize_t());
85 types.push_back(getPtrToType(getPtrToType(gIR->irDsymbol[ti].irStruct->constInit->getType()))); 85 types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType())));
86 const llvm::Type* t1 = llvm::StructType::get(types); 86 const llvm::Type* t1 = llvm::StructType::get(types);
87 paramvec.push_back(getPtrToType(t1)); 87 paramvec.push_back(getPtrToType(t1));
88 paramvec.push_back(getPtrToType(llvm::Type::Int8Ty)); 88 paramvec.push_back(getPtrToType(llvm::Type::Int8Ty));
89 } 89 }
90 else if (arrayVararg) 90 else if (arrayVararg)
133 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); 133 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
134 134
135 f->llvmRetInPtr = retinptr; 135 f->llvmRetInPtr = retinptr;
136 f->llvmUsesThis = usesthis; 136 f->llvmUsesThis = usesthis;
137 137
138 //if (!gIR->irType[f].type) 138 //if (!f->ir.type)
139 gIR->irType[f].type = new llvm::PATypeHolder(functype); 139 f->ir.type = new llvm::PATypeHolder(functype);
140 //else 140 //else
141 //assert(functype == gIR->irType[f].type->get()); 141 //assert(functype == f->ir.type->get());
142 142
143 return functype; 143 return functype;
144 } 144 }
145 145
146 ////////////////////////////////////////////////////////////////////////////////////////// 146 //////////////////////////////////////////////////////////////////////////////////////////
147 147
148 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl) 148 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
149 { 149 {
150 // type has already been resolved 150 // type has already been resolved
151 if (gIR->irType[fdecl->type].type != 0) { 151 if (fdecl->type->ir.type != 0) {
152 return llvm::cast<llvm::FunctionType>(gIR->irType[fdecl->type].type->get()); 152 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
153 } 153 }
154 154
155 TypeFunction* f = (TypeFunction*)fdecl->type; 155 TypeFunction* f = (TypeFunction*)fdecl->type;
156 assert(f != 0); 156 assert(f != 0);
157 157
170 else 170 else
171 assert(0); 171 assert(0);
172 172
173 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, args, false); 173 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
174 174
175 gIR->irType[f].type = new llvm::PATypeHolder(fty); 175 f->ir.type = new llvm::PATypeHolder(fty);
176 176
177 return fty; 177 return fty;
178 } 178 }
179 179
180 ////////////////////////////////////////////////////////////////////////////////////////// 180 //////////////////////////////////////////////////////////////////////////////////////////
190 std::vector<const llvm::Type*> args; 190 std::vector<const llvm::Type*> args;
191 return llvm::FunctionType::get(llvm::Type::VoidTy, args, false); 191 return llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
192 }*/ 192 }*/
193 193
194 // type has already been resolved 194 // type has already been resolved
195 if (gIR->irType[fdecl->type].type != 0) { 195 if (fdecl->type->ir.type != 0) {
196 return llvm::cast<llvm::FunctionType>(gIR->irType[fdecl->type].type->get()); 196 return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
197 } 197 }
198 198
199 const llvm::Type* thisty = NULL; 199 const llvm::Type* thisty = NULL;
200 if (fdecl->needThis()) { 200 if (fdecl->needThis()) {
201 if (AggregateDeclaration* ad = fdecl->isMember2()) { 201 if (AggregateDeclaration* ad = fdecl->isMember2()) {
239 assert(0); 239 assert(0);
240 240
241 llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn); 241 llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn);
242 assert(func); 242 assert(func);
243 assert(func->isIntrinsic()); 243 assert(func->isIntrinsic());
244 gIR->irDsymbol[fdecl].irFunc->func = func; 244 fdecl->ir.irFunc->func = func;
245 return func; 245 return func;
246 } 246 }
247 247
248 ////////////////////////////////////////////////////////////////////////////////////////// 248 //////////////////////////////////////////////////////////////////////////////////////////
249 249
258 { 258 {
259 if (fdecl->prot() == PROTprivate) 259 if (fdecl->prot() == PROTprivate)
260 return; 260 return;
261 } 261 }
262 262
263 if (gIR->irDsymbol[fdecl].resolved) return; 263 if (fdecl->ir.resolved) return;
264 gIR->irDsymbol[fdecl].resolved = true; 264 fdecl->ir.resolved = true;
265 265
266 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); 266 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
267 LOG_SCOPE; 267 LOG_SCOPE;
268 268
269 if (fdecl->runTimeHack) { 269 if (fdecl->runTimeHack) {
279 TemplateDeclaration* tempdecl = tinst->tempdecl; 279 TemplateDeclaration* tempdecl = tinst->tempdecl;
280 if (tempdecl->llvmInternal == LLVMva_arg) 280 if (tempdecl->llvmInternal == LLVMva_arg)
281 { 281 {
282 Logger::println("magic va_arg found"); 282 Logger::println("magic va_arg found");
283 fdecl->llvmInternal = LLVMva_arg; 283 fdecl->llvmInternal = LLVMva_arg;
284 gIR->irDsymbol[fdecl].declared = true; 284 fdecl->ir.declared = true;
285 gIR->irDsymbol[fdecl].initialized = true; 285 fdecl->ir.initialized = true;
286 gIR->irDsymbol[fdecl].defined = true; 286 fdecl->ir.defined = true;
287 return; // this gets mapped to an instruction so a declaration makes no sence 287 return; // this gets mapped to an instruction so a declaration makes no sence
288 } 288 }
289 else if (tempdecl->llvmInternal == LLVMva_start) 289 else if (tempdecl->llvmInternal == LLVMva_start)
290 { 290 {
291 Logger::println("magic va_start found"); 291 Logger::println("magic va_start found");
302 302
303 ////////////////////////////////////////////////////////////////////////////////////////// 303 //////////////////////////////////////////////////////////////////////////////////////////
304 304
305 void DtoDeclareFunction(FuncDeclaration* fdecl) 305 void DtoDeclareFunction(FuncDeclaration* fdecl)
306 { 306 {
307 if (gIR->irDsymbol[fdecl].declared) return; 307 if (fdecl->ir.declared) return;
308 gIR->irDsymbol[fdecl].declared = true; 308 fdecl->ir.declared = true;
309 309
310 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); 310 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
311 LOG_SCOPE; 311 LOG_SCOPE;
312 312
313 assert(!fdecl->isAbstract()); 313 assert(!fdecl->isAbstract());
318 fatal(); 318 fatal();
319 } 319 }
320 320
321 if (fdecl->runTimeHack) { 321 if (fdecl->runTimeHack) {
322 Logger::println("runtime hack func chars: %s", fdecl->toChars()); 322 Logger::println("runtime hack func chars: %s", fdecl->toChars());
323 if (!gIR->irDsymbol[fdecl].irFunc) { 323 if (!fdecl->ir.irFunc) {
324 gIR->irDsymbol[fdecl].irFunc = new IrFunction(fdecl); 324 fdecl->ir.irFunc = new IrFunction(fdecl);
325 gIR->irDsymbol[fdecl].irFunc->func = LLVM_D_GetRuntimeFunction(gIR->module, fdecl->toChars()); 325 fdecl->ir.irFunc->func = LLVM_D_GetRuntimeFunction(gIR->module, fdecl->toChars());
326 } 326 }
327 return; 327 return;
328 } 328 }
329 329
330 bool declareOnly = false; 330 bool declareOnly = false;
337 declareOnly = true; 337 declareOnly = true;
338 } 338 }
339 else if (fdecl->llvmInternal == LLVMva_start) 339 else if (fdecl->llvmInternal == LLVMva_start)
340 declareOnly = true; 340 declareOnly = true;
341 341
342 if (!gIR->irDsymbol[fdecl].irFunc) { 342 if (!fdecl->ir.irFunc) {
343 gIR->irDsymbol[fdecl].irFunc = new IrFunction(fdecl); 343 fdecl->ir.irFunc = new IrFunction(fdecl);
344 } 344 }
345 345
346 // mangled name 346 // mangled name
347 char* mangled_name; 347 char* mangled_name;
348 if (fdecl->llvmInternal == LLVMintrinsic) 348 if (fdecl->llvmInternal == LLVMintrinsic)
365 func = new llvm::Function(functype, DtoLinkage(fdecl), mangled_name, gIR->module); 365 func = new llvm::Function(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
366 else 366 else
367 assert(func->getFunctionType() == functype); 367 assert(func->getFunctionType() == functype);
368 368
369 // add func to IRFunc 369 // add func to IRFunc
370 gIR->irDsymbol[fdecl].irFunc->func = func; 370 fdecl->ir.irFunc->func = func;
371 371
372 // calling convention 372 // calling convention
373 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic) 373 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic)
374 func->setCallingConv(DtoCallingConv(f->linkage)); 374 func->setCallingConv(DtoCallingConv(f->linkage));
375 else // fall back to C, it should be the right thing to do 375 else // fall back to C, it should be the right thing to do
376 func->setCallingConv(llvm::CallingConv::C); 376 func->setCallingConv(llvm::CallingConv::C);
377 377
378 gIR->irDsymbol[fdecl].irFunc->func = func; 378 fdecl->ir.irFunc->func = func;
379 assert(llvm::isa<llvm::FunctionType>(gIR->irType[f].type->get())); 379 assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
380 380
381 // main 381 // main
382 if (fdecl->isMain()) { 382 if (fdecl->isMain()) {
383 gIR->mainFunc = func; 383 gIR->mainFunc = func;
384 } 384 }
398 // name parameters 398 // name parameters
399 llvm::Function::arg_iterator iarg = func->arg_begin(); 399 llvm::Function::arg_iterator iarg = func->arg_begin();
400 int k = 0; 400 int k = 0;
401 if (f->llvmRetInPtr) { 401 if (f->llvmRetInPtr) {
402 iarg->setName("retval"); 402 iarg->setName("retval");
403 gIR->irDsymbol[fdecl].irFunc->retArg = iarg; 403 fdecl->ir.irFunc->retArg = iarg;
404 ++iarg; 404 ++iarg;
405 } 405 }
406 if (f->llvmUsesThis) { 406 if (f->llvmUsesThis) {
407 iarg->setName("this"); 407 iarg->setName("this");
408 gIR->irDsymbol[fdecl].irFunc->thisVar = iarg; 408 fdecl->ir.irFunc->thisVar = iarg;
409 assert(gIR->irDsymbol[fdecl].irFunc->thisVar); 409 assert(fdecl->ir.irFunc->thisVar);
410 ++iarg; 410 ++iarg;
411 } 411 }
412 412
413 if (f->linkage == LINKd && f->varargs == 1) { 413 if (f->linkage == LINKd && f->varargs == 1) {
414 iarg->setName("_arguments"); 414 iarg->setName("_arguments");
415 gIR->irDsymbol[fdecl].irFunc->_arguments = iarg; 415 fdecl->ir.irFunc->_arguments = iarg;
416 ++iarg; 416 ++iarg;
417 iarg->setName("_argptr"); 417 iarg->setName("_argptr");
418 gIR->irDsymbol[fdecl].irFunc->_argptr = iarg; 418 fdecl->ir.irFunc->_argptr = iarg;
419 ++iarg; 419 ++iarg;
420 } 420 }
421 421
422 for (; iarg != func->arg_end(); ++iarg) 422 for (; iarg != func->arg_end(); ++iarg)
423 { 423 {
424 if (fdecl->parameters && fdecl->parameters->dim > k) 424 if (fdecl->parameters && fdecl->parameters->dim > k)
425 { 425 {
426 Dsymbol* argsym = (Dsymbol*)fdecl->parameters->data[k++]; 426 Dsymbol* argsym = (Dsymbol*)fdecl->parameters->data[k++];
427 VarDeclaration* argvd = argsym->isVarDeclaration(); 427 VarDeclaration* argvd = argsym->isVarDeclaration();
428 assert(argvd); 428 assert(argvd);
429 assert(!gIR->irDsymbol[argvd].irLocal); 429 assert(!argvd->ir.irLocal);
430 gIR->irDsymbol[argvd].irLocal = new IrLocal(argvd); 430 argvd->ir.irLocal = new IrLocal(argvd);
431 gIR->irDsymbol[argvd].irLocal->value = iarg; 431 argvd->ir.irLocal->value = iarg;
432 iarg->setName(argvd->ident->toChars()); 432 iarg->setName(argvd->ident->toChars());
433 } 433 }
434 else 434 else
435 { 435 {
436 iarg->setName("unnamed"); 436 iarg->setName("unnamed");
451 451
452 ////////////////////////////////////////////////////////////////////////////////////////// 452 //////////////////////////////////////////////////////////////////////////////////////////
453 453
454 void DtoDefineFunc(FuncDeclaration* fd) 454 void DtoDefineFunc(FuncDeclaration* fd)
455 { 455 {
456 if (gIR->irDsymbol[fd].defined) return; 456 if (fd->ir.defined) return;
457 gIR->irDsymbol[fd].defined = true; 457 fd->ir.defined = true;
458 458
459 assert(gIR->irDsymbol[fd].declared); 459 assert(fd->ir.declared);
460 460
461 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars()); 461 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
462 LOG_SCOPE; 462 LOG_SCOPE;
463 463
464 // debug info 464 // debug info
465 if (global.params.symdebug) { 465 if (global.params.symdebug) {
466 Module* mo = fd->getModule(); 466 Module* mo = fd->getModule();
467 gIR->irDsymbol[fd].irFunc->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo)); 467 fd->ir.irFunc->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo));
468 } 468 }
469 469
470 Type* t = DtoDType(fd->type); 470 Type* t = DtoDType(fd->type);
471 TypeFunction* f = (TypeFunction*)t; 471 TypeFunction* f = (TypeFunction*)t;
472 assert(gIR->irType[f].type); 472 assert(f->ir.type);
473 473
474 llvm::Function* func = gIR->irDsymbol[fd].irFunc->func; 474 llvm::Function* func = fd->ir.irFunc->func;
475 const llvm::FunctionType* functype = func->getFunctionType(); 475 const llvm::FunctionType* functype = func->getFunctionType();
476 476
477 // only members of the current module or template instances maybe be defined 477 // only members of the current module or template instances maybe be defined
478 if (fd->getModule() == gIR->dmodule || DtoIsTemplateInstance(fd->parent)) 478 if (fd->getModule() == gIR->dmodule || DtoIsTemplateInstance(fd->parent))
479 { 479 {
480 gIR->irDsymbol[fd].DModule = gIR->dmodule; 480 fd->ir.DModule = gIR->dmodule;
481 481
482 // function definition 482 // function definition
483 if (fd->fbody != 0) 483 if (fd->fbody != 0)
484 { 484 {
485 Logger::println("Doing function body for: %s", fd->toChars()); 485 Logger::println("Doing function body for: %s", fd->toChars());
486 assert(gIR->irDsymbol[fd].irFunc); 486 assert(fd->ir.irFunc);
487 gIR->functions.push_back(gIR->irDsymbol[fd].irFunc); 487 gIR->functions.push_back(fd->ir.irFunc);
488 488
489 if (fd->isMain()) 489 if (fd->isMain())
490 gIR->emitMain = true; 490 gIR->emitMain = true;
491 491
492 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func); 492 llvm::BasicBlock* beginbb = new llvm::BasicBlock("entry",func);
500 gIR->func()->allocapoint = allocaPoint; 500 gIR->func()->allocapoint = allocaPoint;
501 501
502 // need result variable? (not nested) 502 // need result variable? (not nested)
503 if (fd->vresult && !fd->vresult->nestedref) { 503 if (fd->vresult && !fd->vresult->nestedref) {
504 Logger::println("non-nested vresult value"); 504 Logger::println("non-nested vresult value");
505 gIR->irDsymbol[fd->vresult].irLocal = new IrLocal(fd->vresult); 505 fd->vresult->ir.irLocal = new IrLocal(fd->vresult);
506 gIR->irDsymbol[fd->vresult].irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint); 506 fd->vresult->ir.irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint);
507 } 507 }
508 508
509 // give arguments storage 509 // give arguments storage
510 if (fd->parameters) 510 if (fd->parameters)
511 { 511 {
517 assert(vd); 517 assert(vd);
518 518
519 if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)) 519 if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))
520 continue; 520 continue;
521 521
522 llvm::Value* a = gIR->irDsymbol[vd].irLocal->value; 522 llvm::Value* a = vd->ir.irLocal->value;
523 assert(a); 523 assert(a);
524 std::string s(a->getName()); 524 std::string s(a->getName());
525 Logger::println("giving argument '%s' storage", s.c_str()); 525 Logger::println("giving argument '%s' storage", s.c_str());
526 s.append("_storage"); 526 s.append("_storage");
527 527
528 llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint); 528 llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint);
529 gIR->ir->CreateStore(a,v); 529 gIR->ir->CreateStore(a,v);
530 gIR->irDsymbol[vd].irLocal->value = v; 530 vd->ir.irLocal->value = v;
531 } 531 }
532 } 532 }
533 533
534 // debug info 534 // debug info
535 if (global.params.symdebug) DtoDwarfFuncStart(fd); 535 if (global.params.symdebug) DtoDwarfFuncStart(fd);
536 536
537 llvm::Value* parentNested = NULL; 537 llvm::Value* parentNested = NULL;
538 if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { 538 if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) {
539 if (!fd->isStatic()) // huh? 539 if (!fd->isStatic()) // huh?
540 parentNested = gIR->irDsymbol[fd2].irFunc->nestedVar; 540 parentNested = fd2->ir.irFunc->nestedVar;
541 } 541 }
542 542
543 // need result variable? (nested) 543 // need result variable? (nested)
544 if (fd->vresult && fd->vresult->nestedref) { 544 if (fd->vresult && fd->vresult->nestedref) {
545 Logger::println("nested vresult value: %s", fd->vresult->toChars()); 545 Logger::println("nested vresult value: %s", fd->vresult->toChars());
555 j++; 555 j++;
556 } 556 }
557 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { 557 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) {
558 VarDeclaration* vd = *i; 558 VarDeclaration* vd = *i;
559 Logger::println("referenced nested variable %s", vd->toChars()); 559 Logger::println("referenced nested variable %s", vd->toChars());
560 if (!gIR->irDsymbol[vd].irLocal) 560 if (!vd->ir.irLocal)
561 gIR->irDsymbol[vd].irLocal = new IrLocal(vd); 561 vd->ir.irLocal = new IrLocal(vd);
562 gIR->irDsymbol[vd].irLocal->nestedIndex = j++; 562 vd->ir.irLocal->nestedIndex = j++;
563 if (vd->isParameter()) { 563 if (vd->isParameter()) {
564 if (!gIR->irDsymbol[vd].irLocal->value) { 564 if (!vd->ir.irLocal->value) {
565 assert(vd == fd->vthis); 565 assert(vd == fd->vthis);
566 gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[fd].irFunc->thisVar; 566 vd->ir.irLocal->value = fd->ir.irFunc->thisVar;
567 } 567 }
568 assert(gIR->irDsymbol[vd].irLocal->value); 568 assert(vd->ir.irLocal->value);
569 nestTypes.push_back(gIR->irDsymbol[vd].irLocal->value->getType()); 569 nestTypes.push_back(vd->ir.irLocal->value->getType());
570 } 570 }
571 else { 571 else {
572 nestTypes.push_back(DtoType(vd->type)); 572 nestTypes.push_back(DtoType(vd->type));
573 } 573 }
574 } 574 }
575 const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); 575 const llvm::StructType* nestSType = llvm::StructType::get(nestTypes);
576 Logger::cout() << "nested var struct has type:" << *nestSType << '\n'; 576 Logger::cout() << "nested var struct has type:" << *nestSType << '\n';
577 gIR->irDsymbol[fd].irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); 577 fd->ir.irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint);
578 if (parentNested) { 578 if (parentNested) {
579 assert(gIR->irDsymbol[fd].irFunc->thisVar); 579 assert(fd->ir.irFunc->thisVar);
580 llvm::Value* ptr = gIR->ir->CreateBitCast(gIR->irDsymbol[fd].irFunc->thisVar, parentNested->getType(), "tmp"); 580 llvm::Value* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp");
581 gIR->ir->CreateStore(ptr, DtoGEPi(gIR->irDsymbol[fd].irFunc->nestedVar, 0,0, "tmp")); 581 gIR->ir->CreateStore(ptr, DtoGEPi(fd->ir.irFunc->nestedVar, 0,0, "tmp"));
582 } 582 }
583 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { 583 for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) {
584 VarDeclaration* vd = *i; 584 VarDeclaration* vd = *i;
585 if (vd->isParameter()) { 585 if (vd->isParameter()) {
586 assert(gIR->irDsymbol[vd].irLocal); 586 assert(vd->ir.irLocal);
587 gIR->ir->CreateStore(gIR->irDsymbol[vd].irLocal->value, DtoGEPi(gIR->irDsymbol[fd].irFunc->nestedVar, 0, gIR->irDsymbol[vd].irLocal->nestedIndex, "tmp")); 587 gIR->ir->CreateStore(vd->ir.irLocal->value, DtoGEPi(fd->ir.irFunc->nestedVar, 0, vd->ir.irLocal->nestedIndex, "tmp"));
588 gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[fd].irFunc->nestedVar; 588 vd->ir.irLocal->value = fd->ir.irFunc->nestedVar;
589 } 589 }
590 } 590 }
591 } 591 }
592 592
593 // copy _argptr to a memory location 593 // copy _argptr to a memory location
594 if (f->linkage == LINKd && f->varargs == 1) 594 if (f->linkage == LINKd && f->varargs == 1)
595 { 595 {
596 llvm::Value* argptrmem = new llvm::AllocaInst(gIR->irDsymbol[fd].irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); 596 llvm::Value* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint());
597 new llvm::StoreInst(gIR->irDsymbol[fd].irFunc->_argptr, argptrmem, gIR->scopebb()); 597 new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb());
598 gIR->irDsymbol[fd].irFunc->_argptr = argptrmem; 598 fd->ir.irFunc->_argptr = argptrmem;
599 } 599 }
600 600
601 // output function body 601 // output function body
602 fd->fbody->toIR(gIR); 602 fd->fbody->toIR(gIR);
603 603