comparison gen/classes.cpp @ 117:56a21f3e5d3e trunk

[svn r121] Finished ModuleInfo implementation. Static ctors/dtors now work according to spec. Changed class vtable types slightly in some cases. Overridden functions now always take the the type of the first class declaring the method as this parameter. This helps when using headers (w. implementation somewhere else)
author lindquist
date Mon, 26 Nov 2007 04:49:23 +0100
parents 5ba6d286c941
children 9c79b61fb638
comparison
equal deleted inserted replaced
116:fd7ad91fd713 117:56a21f3e5d3e
165 assert(dsym); 165 assert(dsym);
166 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; 166 //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n';
167 167
168 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { 168 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
169 DtoResolveFunction(fd); 169 DtoResolveFunction(fd);
170 assert(fd->type->ty == Tfunction); 170 //assert(fd->type->ty == Tfunction);
171 TypeFunction* tf = (TypeFunction*)fd->type; 171 //TypeFunction* tf = (TypeFunction*)fd->type;
172 const llvm::Type* fpty = llvm::PointerType::get(tf->llvmType->get()); 172 //const llvm::Type* fpty = llvm::PointerType::get(tf->llvmType->get());
173 sinits_ty.push_back(fpty); 173 const llvm::FunctionType* vfty = DtoBaseFunctionType(fd);
174 const llvm::Type* vfpty = llvm::PointerType::get(vfty);
175 sinits_ty.push_back(vfpty);
174 } 176 }
175 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { 177 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
176 Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars()); 178 Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars());
177 const llvm::Type* cinfoty; 179 const llvm::Type* cinfoty;
178 if (cd->isInterfaceDeclaration()) { 180 if (cd->isInterfaceDeclaration()) {
373 375
374 // get the struct (class) type 376 // get the struct (class) type
375 assert(cd->type->ty == Tclass); 377 assert(cd->type->ty == Tclass);
376 TypeClass* ts = (TypeClass*)cd->type; 378 TypeClass* ts = (TypeClass*)cd->type;
377 const llvm::StructType* structtype = isaStruct(ts->llvmType->get()); 379 const llvm::StructType* structtype = isaStruct(ts->llvmType->get());
380 const llvm::StructType* vtbltype = isaStruct(ts->llvmVtblType->get());
378 381
379 // generate initializer 382 // generate initializer
380 #if 0 383 #if 0
381 Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n'; 384 Logger::cout() << cd->toPrettyChars() << " | " << *structtype << '\n';
382 385
404 407
405 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { 408 if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
406 DtoForceDeclareDsymbol(fd); 409 DtoForceDeclareDsymbol(fd);
407 assert(fd->llvmValue); 410 assert(fd->llvmValue);
408 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue); 411 llvm::Constant* c = llvm::cast<llvm::Constant>(fd->llvmValue);
412 // cast if necessary (overridden method)
413 if (c->getType() != vtbltype->getElementType(k))
414 c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k));
409 sinits.push_back(c); 415 sinits.push_back(c);
410 } 416 }
411 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { 417 else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) {
412 assert(cd->llvmClass); 418 assert(cd->llvmClass);
413 llvm::Constant* c = cd->llvmClass; 419 llvm::Constant* c = cd->llvmClass;
1035 1041
1036 // default constructor 1042 // default constructor
1037 if (cd->defaultCtor && !cd->isInterfaceDeclaration()) { 1043 if (cd->defaultCtor && !cd->isInterfaceDeclaration()) {
1038 DtoForceDeclareDsymbol(cd->defaultCtor); 1044 DtoForceDeclareDsymbol(cd->defaultCtor);
1039 c = isaConstant(cd->defaultCtor->llvmValue); 1045 c = isaConstant(cd->defaultCtor->llvmValue);
1040 //const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(11)->getType(); 1046 const llvm::Type* toTy = cinfo->llvmInitZ->getOperand(12)->getType();
1041 c = llvm::ConstantExpr::getBitCast(c, llvm::PointerType::get(llvm::Type::Int8Ty)); // toTy); 1047 c = llvm::ConstantExpr::getBitCast(c, toTy);
1042 } 1048 }
1043 else { 1049 else {
1044 c = cinfo->llvmInitZ->getOperand(12); 1050 c = cinfo->llvmInitZ->getOperand(12);
1045 } 1051 }
1046 inits.push_back(c); 1052 inits.push_back(c);