comparison gen/functions.cpp @ 133:44a95ac7368a trunk

[svn r137] Many fixes towards tango.io.Console working, but not quite there yet... In particular, assertions has been fixed to include file/line info, and much more!
author lindquist
date Mon, 14 Jan 2008 05:11:54 +0100
parents 1700239cab2e
children 0e28624814e8
comparison
equal deleted inserted replaced
132:1700239cab2e 133:44a95ac7368a
45 } 45 }
46 else { 46 else {
47 assert(rt); 47 assert(rt);
48 Type* rtfin = DtoDType(rt); 48 Type* rtfin = DtoDType(rt);
49 if (DtoIsPassedByRef(rt)) { 49 if (DtoIsPassedByRef(rt)) {
50 rettype = llvm::PointerType::get(DtoType(rt)); 50 rettype = getPtrToType(DtoType(rt));
51 actualRettype = llvm::Type::VoidTy; 51 actualRettype = llvm::Type::VoidTy;
52 f->llvmRetInPtr = retinptr = true; 52 f->llvmRetInPtr = retinptr = true;
53 } 53 }
54 else { 54 else {
55 rettype = DtoType(rt); 55 rettype = DtoType(rt);
75 ti->toObjFile(); 75 ti->toObjFile();
76 DtoForceConstInitDsymbol(ti); 76 DtoForceConstInitDsymbol(ti);
77 assert(ti->llvmConstInit); 77 assert(ti->llvmConstInit);
78 std::vector<const llvm::Type*> types; 78 std::vector<const llvm::Type*> types;
79 types.push_back(DtoSize_t()); 79 types.push_back(DtoSize_t());
80 types.push_back(llvm::PointerType::get(llvm::PointerType::get(ti->llvmConstInit->getType()))); 80 types.push_back(getPtrToType(getPtrToType(ti->llvmConstInit->getType())));
81 const llvm::Type* t1 = llvm::StructType::get(types); 81 const llvm::Type* t1 = llvm::StructType::get(types);
82 paramvec.push_back(llvm::PointerType::get(t1)); 82 paramvec.push_back(getPtrToType(t1));
83 paramvec.push_back(llvm::PointerType::get(llvm::Type::Int8Ty)); 83 paramvec.push_back(getPtrToType(llvm::Type::Int8Ty));
84 } 84 }
85 85
86 size_t n = Argument::dim(f->parameters); 86 size_t n = Argument::dim(f->parameters);
87 87
88 for (int i=0; i < n; ++i) { 88 for (int i=0; i < n; ++i) {
92 assert(argT); 92 assert(argT);
93 93
94 const llvm::Type* at = DtoType(argT); 94 const llvm::Type* at = DtoType(argT);
95 if (isaStruct(at)) { 95 if (isaStruct(at)) {
96 Logger::println("struct param"); 96 Logger::println("struct param");
97 paramvec.push_back(llvm::PointerType::get(at)); 97 paramvec.push_back(getPtrToType(at));
98 } 98 }
99 else if (isaArray(at)) { 99 else if (isaArray(at)) {
100 Logger::println("sarray param"); 100 Logger::println("sarray param");
101 assert(argT->ty == Tsarray); 101 assert(argT->ty == Tsarray);
102 //paramvec.push_back(llvm::PointerType::get(at->getContainedType(0))); 102 //paramvec.push_back(getPtrToType(at->getContainedType(0)));
103 paramvec.push_back(llvm::PointerType::get(at)); 103 paramvec.push_back(getPtrToType(at));
104 } 104 }
105 else if (llvm::isa<llvm::OpaqueType>(at)) { 105 else if (llvm::isa<llvm::OpaqueType>(at)) {
106 Logger::println("opaque param"); 106 Logger::println("opaque param");
107 assert(argT->ty == Tstruct || argT->ty == Tclass); 107 assert(argT->ty == Tstruct || argT->ty == Tclass);
108 paramvec.push_back(llvm::PointerType::get(at)); 108 paramvec.push_back(getPtrToType(at));
109 } 109 }
110 else { 110 else {
111 if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) { 111 if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
112 Logger::println("by ref param"); 112 Logger::println("by ref param");
113 at = llvm::PointerType::get(at); 113 at = getPtrToType(at);
114 } 114 }
115 else { 115 else {
116 Logger::println("in param"); 116 Logger::println("in param");
117 } 117 }
118 paramvec.push_back(at); 118 paramvec.push_back(at);
144 } 144 }
145 145
146 TypeFunction* f = (TypeFunction*)fdecl->type; 146 TypeFunction* f = (TypeFunction*)fdecl->type;
147 assert(f != 0); 147 assert(f != 0);
148 148
149 const llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty); 149 const llvm::PointerType* i8pty = getPtrToType(llvm::Type::Int8Ty);
150 std::vector<const llvm::Type*> args; 150 std::vector<const llvm::Type*> args;
151 151
152 if (fdecl->llvmInternal == LLVMva_start) { 152 if (fdecl->llvmInternal == LLVMva_start) {
153 args.push_back(i8pty); 153 args.push_back(i8pty);
154 } 154 }
192 if (AggregateDeclaration* ad = fdecl->isMember2()) { 192 if (AggregateDeclaration* ad = fdecl->isMember2()) {
193 Logger::println("isMember = this is: %s", 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 = getPtrToType(thisty);
198 } 198 }
199 else { 199 else {
200 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); 200 Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind());
201 assert(0); 201 assert(0);
202 } 202 }
203 } 203 }
204 else if (fdecl->isNested()) { 204 else if (fdecl->isNested()) {
205 thisty = llvm::PointerType::get(llvm::Type::Int8Ty); 205 thisty = getPtrToType(llvm::Type::Int8Ty);
206 } 206 }
207 207
208 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, fdecl->isMain()); 208 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, fdecl->isMain());
209 209
210 return functype; 210 return functype;
240 240
241 void DtoResolveFunction(FuncDeclaration* fdecl) 241 void DtoResolveFunction(FuncDeclaration* fdecl)
242 { 242 {
243 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) { 243 if (!global.params.useUnitTests && fdecl->isUnitTestDeclaration()) {
244 return; // ignore declaration completely 244 return; // ignore declaration completely
245 }
246
247 // is imported and we don't have access?
248 if (fdecl->getModule() != gIR->dmodule)
249 {
250 if (fdecl->prot() == PROTprivate)
251 return;
245 } 252 }
246 253
247 if (fdecl->llvmResolved) return; 254 if (fdecl->llvmResolved) return;
248 fdecl->llvmResolved = true; 255 fdecl->llvmResolved = true;
249 256
425 if (fdecl->isUnitTestDeclaration()) 432 if (fdecl->isUnitTestDeclaration())
426 gIR->unitTests.push_back(fdecl); 433 gIR->unitTests.push_back(fdecl);
427 434
428 if (!declareOnly) 435 if (!declareOnly)
429 gIR->defineList.push_back(fdecl); 436 gIR->defineList.push_back(fdecl);
437 else
438 assert(func->getLinkage() != llvm::GlobalValue::InternalLinkage);
430 439
431 Logger::cout() << "func decl: " << *func << '\n'; 440 Logger::cout() << "func decl: " << *func << '\n';
432 } 441 }
433 442
434 ////////////////////////////////////////////////////////////////////////////////////////// 443 //////////////////////////////////////////////////////////////////////////////////////////
635 assert(ir.emitMain && ir.mainFunc); 644 assert(ir.emitMain && ir.mainFunc);
636 645
637 // parameter types 646 // parameter types
638 std::vector<const llvm::Type*> pvec; 647 std::vector<const llvm::Type*> pvec;
639 pvec.push_back((const llvm::Type*)llvm::Type::Int32Ty); 648 pvec.push_back((const llvm::Type*)llvm::Type::Int32Ty);
640 const llvm::Type* chPtrType = (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty); 649 const llvm::Type* chPtrType = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty);
641 pvec.push_back((const llvm::Type*)llvm::PointerType::get(chPtrType)); 650 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType));
642 pvec.push_back((const llvm::Type*)llvm::PointerType::get(chPtrType)); 651 pvec.push_back((const llvm::Type*)getPtrToType(chPtrType));
643 const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty; 652 const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty;
644 653
645 llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false); 654 llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false);
646 llvm::Function* func = new llvm::Function(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module); 655 llvm::Function* func = new llvm::Function(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module);
647 656