comparison gen/functions.cpp @ 157:5c17f81fc1c1 trunk

[svn r173] moved IR state previously stored in Type into IrType and a Type->IrType map; fixes #7
author ChristianK
date Thu, 01 May 2008 13:32:08 +0200
parents ccd07d9f2ce9
children 1856c62af24b
comparison
equal deleted inserted replaced
156:ccd07d9f2ce9 157:5c17f81fc1c1
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 (type->llvmType != NULL) { 26 if (gIR->irType[type].type != NULL) {
27 return llvm::cast<llvm::FunctionType>(type->llvmType->get()); 27 return llvm::cast<llvm::FunctionType>(gIR->irType[type].type->get());
28 } 28 }
29 29
30 bool typesafeVararg = false; 30 bool typesafeVararg = false;
31 if (f->linkage == LINKd && f->varargs == 1) { 31 if (f->linkage == LINKd && f->varargs == 1) {
32 typesafeVararg = true; 32 typesafeVararg = true;
124 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg); 124 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
125 125
126 f->llvmRetInPtr = retinptr; 126 f->llvmRetInPtr = retinptr;
127 f->llvmUsesThis = usesthis; 127 f->llvmUsesThis = usesthis;
128 128
129 //if (!f->llvmType) 129 //if (!gIR->irType[f].type)
130 f->llvmType = new llvm::PATypeHolder(functype); 130 gIR->irType[f].type = new llvm::PATypeHolder(functype);
131 //else 131 //else
132 //assert(functype == f->llvmType->get()); 132 //assert(functype == gIR->irType[f].type->get());
133 133
134 return functype; 134 return functype;
135 } 135 }
136 136
137 ////////////////////////////////////////////////////////////////////////////////////////// 137 //////////////////////////////////////////////////////////////////////////////////////////
138 138
139 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl) 139 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
140 { 140 {
141 // type has already been resolved 141 // type has already been resolved
142 if (fdecl->type->llvmType != 0) { 142 if (gIR->irType[fdecl->type].type != 0) {
143 return llvm::cast<llvm::FunctionType>(fdecl->type->llvmType->get()); 143 return llvm::cast<llvm::FunctionType>(gIR->irType[fdecl->type].type->get());
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
161 else 161 else
162 assert(0); 162 assert(0);
163 163
164 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, args, false); 164 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
165 165
166 f->llvmType = new llvm::PATypeHolder(fty); 166 gIR->irType[f].type = new llvm::PATypeHolder(fty);
167 167
168 return fty; 168 return fty;
169 } 169 }
170 170
171 ////////////////////////////////////////////////////////////////////////////////////////// 171 //////////////////////////////////////////////////////////////////////////////////////////
181 std::vector<const llvm::Type*> args; 181 std::vector<const llvm::Type*> args;
182 return llvm::FunctionType::get(llvm::Type::VoidTy, args, false); 182 return llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
183 }*/ 183 }*/
184 184
185 // type has already been resolved 185 // type has already been resolved
186 if (fdecl->type->llvmType != 0) { 186 if (gIR->irType[fdecl->type].type != 0) {
187 return llvm::cast<llvm::FunctionType>(fdecl->type->llvmType->get()); 187 return llvm::cast<llvm::FunctionType>(gIR->irType[fdecl->type].type->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->isMember2()) { 192 if (AggregateDeclaration* ad = fdecl->isMember2()) {
365 func->setCallingConv(DtoCallingConv(f->linkage)); 365 func->setCallingConv(DtoCallingConv(f->linkage));
366 else // fall back to C, it should be the right thing to do 366 else // fall back to C, it should be the right thing to do
367 func->setCallingConv(llvm::CallingConv::C); 367 func->setCallingConv(llvm::CallingConv::C);
368 368
369 gIR->irDsymbol[fdecl].irFunc->func = func; 369 gIR->irDsymbol[fdecl].irFunc->func = func;
370 assert(llvm::isa<llvm::FunctionType>(f->llvmType->get())); 370 assert(llvm::isa<llvm::FunctionType>(gIR->irType[f].type->get()));
371 371
372 // main 372 // main
373 if (fdecl->isMain()) { 373 if (fdecl->isMain()) {
374 gIR->mainFunc = func; 374 gIR->mainFunc = func;
375 } 375 }
460 gIR->irDsymbol[fd].irFunc->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo)); 460 gIR->irDsymbol[fd].irFunc->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo));
461 } 461 }
462 462
463 Type* t = DtoDType(fd->type); 463 Type* t = DtoDType(fd->type);
464 TypeFunction* f = (TypeFunction*)t; 464 TypeFunction* f = (TypeFunction*)t;
465 assert(f->llvmType); 465 assert(gIR->irType[f].type);
466 466
467 llvm::Function* func = gIR->irDsymbol[fd].irFunc->func; 467 llvm::Function* func = gIR->irDsymbol[fd].irFunc->func;
468 const llvm::FunctionType* functype = func->getFunctionType(); 468 const llvm::FunctionType* functype = func->getFunctionType();
469 469
470 // only members of the current module or template instances maybe be defined 470 // only members of the current module or template instances maybe be defined