comparison gen/functions.cpp @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents 5825d48b27d1
children 44a95ac7368a
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
187 return llvm::cast<llvm::FunctionType>(fdecl->type->llvmType->get()); 187 return llvm::cast<llvm::FunctionType>(fdecl->type->llvmType->get());
188 } 188 }
189 189
190 const llvm::Type* thisty = NULL; 190 const llvm::Type* thisty = NULL;
191 if (fdecl->needThis()) { 191 if (fdecl->needThis()) {
192 if (AggregateDeclaration* ad = fdecl->isMember()) { 192 if (AggregateDeclaration* ad = fdecl->isMember2()) {
193 Logger::print("isMember = this is: %s\n", ad->type->toChars()); 193 Logger::println("isMember = this is: %s", ad->type->toChars());
194 thisty = DtoType(ad->type); 194 thisty = DtoType(ad->type);
195 //Logger::cout() << "this llvm type: " << *thisty << '\n'; 195 //Logger::cout() << "this llvm type: " << *thisty << '\n';
196 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->recty.get())) 196 if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->recty.get()))
197 thisty = llvm::PointerType::get(thisty); 197 thisty = llvm::PointerType::get(thisty);
198 } 198 }
199 else 199 else {
200 assert(0); 200 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind());
201 assert(0);
202 }
201 } 203 }
202 else if (fdecl->isNested()) { 204 else if (fdecl->isNested()) {
203 thisty = llvm::PointerType::get(llvm::Type::Int8Ty); 205 thisty = llvm::PointerType::get(llvm::Type::Int8Ty);
204 } 206 }
205 207
243 } 245 }
244 246
245 if (fdecl->llvmResolved) return; 247 if (fdecl->llvmResolved) return;
246 fdecl->llvmResolved = true; 248 fdecl->llvmResolved = true;
247 249
248 Logger::println("DtoResolveFunction(%s)", fdecl->toPrettyChars()); 250 Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
249 LOG_SCOPE; 251 LOG_SCOPE;
250 252
251 if (fdecl->llvmRunTimeHack) { 253 if (fdecl->llvmRunTimeHack) {
252 gIR->declareList.push_back(fdecl); 254 gIR->declareList.push_back(fdecl);
253 TypeFunction* tf = (TypeFunction*)fdecl->type; 255 TypeFunction* tf = (TypeFunction*)fdecl->type;
287 void DtoDeclareFunction(FuncDeclaration* fdecl) 289 void DtoDeclareFunction(FuncDeclaration* fdecl)
288 { 290 {
289 if (fdecl->llvmDeclared) return; 291 if (fdecl->llvmDeclared) return;
290 fdecl->llvmDeclared = true; 292 fdecl->llvmDeclared = true;
291 293
292 Logger::println("DtoDeclareFunction(%s)", fdecl->toPrettyChars()); 294 Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
293 LOG_SCOPE; 295 LOG_SCOPE;
294 296
295 assert(!fdecl->isAbstract()); 297 assert(!fdecl->isAbstract());
296 298
297 // intrinsic sanity check 299 // intrinsic sanity check
349 func->setCallingConv(DtoCallingConv(f->linkage)); 351 func->setCallingConv(DtoCallingConv(f->linkage));
350 352
351 // template instances should have weak linkage 353 // template instances should have weak linkage
352 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic && fdecl->parent && DtoIsTemplateInstance(fdecl->parent)) 354 if (!vafunc && fdecl->llvmInternal != LLVMintrinsic && fdecl->parent && DtoIsTemplateInstance(fdecl->parent))
353 func->setLinkage(llvm::GlobalValue::WeakLinkage); 355 func->setLinkage(llvm::GlobalValue::WeakLinkage);
356
357 // extern(C) functions are always external
358 if (f->linkage == LINKc)
359 func->setLinkage(llvm::GlobalValue::ExternalLinkage);
360
361 // intrinsics are always external C
362 if (fdecl->llvmInternal == LLVMintrinsic)
363 {
364 func->setLinkage(llvm::GlobalValue::ExternalLinkage);
365 func->setCallingConv(llvm::CallingConv::C);
366 }
354 367
355 fdecl->llvmValue = func; 368 fdecl->llvmValue = func;
356 assert(llvm::isa<llvm::FunctionType>(f->llvmType->get())); 369 assert(llvm::isa<llvm::FunctionType>(f->llvmType->get()));
357 370
358 // main 371 // main
425 if (fd->llvmDefined) return; 438 if (fd->llvmDefined) return;
426 fd->llvmDefined = true; 439 fd->llvmDefined = true;
427 440
428 assert(fd->llvmDeclared); 441 assert(fd->llvmDeclared);
429 442
430 Logger::println("DtoDefineFunc(%s)", fd->toPrettyChars()); 443 Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars());
431 LOG_SCOPE; 444 LOG_SCOPE;
432 445
433 // debug info 446 // debug info
434 if (global.params.symdebug) { 447 if (global.params.symdebug) {
435 Module* mo = fd->getModule(); 448 Module* mo = fd->getModule();
493 llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint); 506 llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint);
494 gIR->ir->CreateStore(a,v); 507 gIR->ir->CreateStore(a,v);
495 vd->llvmValue = v; 508 vd->llvmValue = v;
496 } 509 }
497 else { 510 else {
498 Logger::attention("some unknown argument: %s", arg ? arg->toChars() : 0); 511 Logger::attention(fd->loc, "some unknown argument: %s", arg ? arg->toChars() : 0);
499 } 512 }
500 } 513 }
501 514
502 // debug info 515 // debug info
503 if (global.params.symdebug) DtoDwarfFuncStart(fd); 516 if (global.params.symdebug) DtoDwarfFuncStart(fd);