Mercurial > projects > ldc
comparison gen/classes.cpp @ 244:a95056b3c996 trunk
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
Did a lot of smaller cleans up here and there.
Replaced more llvm::Foo with LLFoo for common stuff.
Split up tollvm.cpp.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 09:37:08 +0200 |
parents | 0806379a5eca |
children | 23d0d9855cad |
comparison
equal
deleted
inserted
replaced
243:4d006f7b2ada | 244:a95056b3c996 |
---|---|
6 #include "init.h" | 6 #include "init.h" |
7 #include "declaration.h" | 7 #include "declaration.h" |
8 | 8 |
9 #include "gen/irstate.h" | 9 #include "gen/irstate.h" |
10 #include "gen/tollvm.h" | 10 #include "gen/tollvm.h" |
11 #include "gen/llvmhelpers.h" | |
11 #include "gen/arrays.h" | 12 #include "gen/arrays.h" |
12 #include "gen/logger.h" | 13 #include "gen/logger.h" |
13 #include "gen/classes.h" | 14 #include "gen/classes.h" |
14 #include "gen/structs.h" | 15 #include "gen/structs.h" |
15 #include "gen/functions.h" | 16 #include "gen/functions.h" |
197 else { | 198 else { |
198 // commit the field | 199 // commit the field |
199 fieldtypes.push_back(fieldtype); | 200 fieldtypes.push_back(fieldtype); |
200 irstruct->defaultFields.push_back(fieldinit); | 201 irstruct->defaultFields.push_back(fieldinit); |
201 if (fieldpad) { | 202 if (fieldpad) { |
202 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad)); | 203 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
203 irstruct->defaultFields.push_back(NULL); | 204 irstruct->defaultFields.push_back(NULL); |
204 idx++; | 205 idx++; |
205 } | 206 } |
206 | 207 |
207 idx++; | 208 idx++; |
216 } | 217 } |
217 } | 218 } |
218 fieldtypes.push_back(fieldtype); | 219 fieldtypes.push_back(fieldtype); |
219 irstruct->defaultFields.push_back(fieldinit); | 220 irstruct->defaultFields.push_back(fieldinit); |
220 if (fieldpad) { | 221 if (fieldpad) { |
221 fieldtypes.push_back(llvm::ArrayType::get(llvm::Type::Int8Ty, fieldpad)); | 222 fieldtypes.push_back(llvm::ArrayType::get(LLType::Int8Ty, fieldpad)); |
222 irstruct->defaultFields.push_back(NULL); | 223 irstruct->defaultFields.push_back(NULL); |
223 } | 224 } |
224 } | 225 } |
225 | 226 |
226 // populate interface map | 227 // populate interface map |
496 assert(cd->ir.irStruct->vtbl != 0); | 497 assert(cd->ir.irStruct->vtbl != 0); |
497 fieldinits.push_back(cd->ir.irStruct->vtbl); | 498 fieldinits.push_back(cd->ir.irStruct->vtbl); |
498 } | 499 } |
499 | 500 |
500 // then comes monitor | 501 // then comes monitor |
501 fieldinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); | 502 fieldinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); |
502 | 503 |
503 // go through the field inits and build the default initializer | 504 // go through the field inits and build the default initializer |
504 size_t nfi = irstruct->defaultFields.size(); | 505 size_t nfi = irstruct->defaultFields.size(); |
505 for (size_t i=0; i<nfi; ++i) { | 506 for (size_t i=0; i<nfi; ++i) { |
506 LLConstant* c; | 507 LLConstant* c; |
509 assert(c); | 510 assert(c); |
510 } | 511 } |
511 else { | 512 else { |
512 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2)); | 513 const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2)); |
513 assert(arrty); | 514 assert(arrty); |
514 std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); | 515 std::vector<LLConstant*> vals(arrty->getNumElements(), llvm::ConstantInt::get(LLType::Int8Ty, 0, false)); |
515 c = llvm::ConstantArray::get(arrty, vals); | 516 c = llvm::ConstantArray::get(arrty, vals); |
516 } | 517 } |
517 fieldinits.push_back(c); | 518 fieldinits.push_back(c); |
518 } | 519 } |
519 | 520 |
626 assert(id->ir.irStruct->classInfo); | 627 assert(id->ir.irStruct->classInfo); |
627 LLConstant* c = id->ir.irStruct->classInfo; | 628 LLConstant* c = id->ir.irStruct->classInfo; |
628 infoInits.push_back(c); | 629 infoInits.push_back(c); |
629 | 630 |
630 // vtbl | 631 // vtbl |
631 const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); | 632 const LLType* byteptrptrty = getPtrToType(getPtrToType(LLType::Int8Ty)); |
632 c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty); | 633 c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty); |
633 c = DtoConstSlice(DtoConstSize_t(b->vtbl.dim), c); | 634 c = DtoConstSlice(DtoConstSize_t(b->vtbl.dim), c); |
634 infoInits.push_back(c); | 635 infoInits.push_back(c); |
635 | 636 |
636 // offset | 637 // offset |
704 assert(id->ir.irStruct->classInfo); | 705 assert(id->ir.irStruct->classInfo); |
705 LLConstant* c = id->ir.irStruct->classInfo; | 706 LLConstant* c = id->ir.irStruct->classInfo; |
706 infoInits.push_back(c); | 707 infoInits.push_back(c); |
707 | 708 |
708 // vtbl | 709 // vtbl |
709 const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); | 710 const LLType* byteptrptrty = getPtrToType(getPtrToType(LLType::Int8Ty)); |
710 c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty)); | 711 c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty)); |
711 infoInits.push_back(c); | 712 infoInits.push_back(c); |
712 | 713 |
713 // offset | 714 // offset |
714 assert(iri->index >= 0); | 715 assert(iri->index >= 0); |
863 | 864 |
864 // copy the rest from the static initializer | 865 // copy the rest from the static initializer |
865 assert(tc->sym->ir.irStruct->init); | 866 assert(tc->sym->ir.irStruct->init); |
866 assert(dst->getType() == tc->sym->ir.irStruct->init->getType()); | 867 assert(dst->getType() == tc->sym->ir.irStruct->init->getType()); |
867 | 868 |
868 const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); | |
869 | |
870 LLValue* dstarr = DtoGEPi(dst,0,2,"tmp"); | 869 LLValue* dstarr = DtoGEPi(dst,0,2,"tmp"); |
871 dstarr = DtoBitCast(dstarr, arrty); | |
872 | |
873 LLValue* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp"); | 870 LLValue* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp"); |
874 srcarr = DtoBitCast(srcarr, arrty); | 871 |
875 | 872 DtoMemCpy(dstarr, srcarr, DtoConstSize_t(n)); |
876 llvm::Function* fn = LLVM_DeclareMemCpy32(); | |
877 std::vector<LLValue*> llargs; | |
878 llargs.resize(4); | |
879 llargs[0] = dstarr; | |
880 llargs[1] = srcarr; | |
881 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); | |
882 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | |
883 | |
884 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
885 } | 873 } |
886 | 874 |
887 ////////////////////////////////////////////////////////////////////////////////////////// | 875 ////////////////////////////////////////////////////////////////////////////////////////// |
888 | 876 |
889 DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem) | 877 DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem) |
1341 { | 1329 { |
1342 // construct the function | 1330 // construct the function |
1343 std::vector<const LLType*> paramTypes; | 1331 std::vector<const LLType*> paramTypes; |
1344 paramTypes.push_back(getPtrToType(cd->type->ir.type->get())); | 1332 paramTypes.push_back(getPtrToType(cd->type->ir.type->get())); |
1345 | 1333 |
1346 const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false); | 1334 const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy, paramTypes, false); |
1347 | 1335 |
1348 if (cd->dtors.dim == 0) { | 1336 if (cd->dtors.dim == 0) { |
1349 return llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)); | 1337 return llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty)); |
1350 } | 1338 } |
1351 else if (cd->dtors.dim == 1) { | 1339 else if (cd->dtors.dim == 1) { |
1352 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; | 1340 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; |
1353 DtoForceDeclareDsymbol(d); | 1341 DtoForceDeclareDsymbol(d); |
1354 assert(d->ir.irFunc->func); | 1342 assert(d->ir.irFunc->func); |
1355 return llvm::ConstantExpr::getBitCast(isaConstant(d->ir.irFunc->func), getPtrToType(llvm::Type::Int8Ty)); | 1343 return llvm::ConstantExpr::getBitCast(isaConstant(d->ir.irFunc->func), getPtrToType(LLType::Int8Ty)); |
1356 } | 1344 } |
1357 | 1345 |
1358 std::string gname("_D"); | 1346 std::string gname("_D"); |
1359 gname.append(cd->mangle()); | 1347 gname.append(cd->mangle()); |
1360 gname.append("12__destructorMFZv"); | 1348 gname.append("12__destructorMFZv"); |
1373 assert(d->ir.irFunc->func); | 1361 assert(d->ir.irFunc->func); |
1374 builder.CreateCall(d->ir.irFunc->func, thisptr); | 1362 builder.CreateCall(d->ir.irFunc->func, thisptr); |
1375 } | 1363 } |
1376 builder.CreateRetVoid(); | 1364 builder.CreateRetVoid(); |
1377 | 1365 |
1378 return llvm::ConstantExpr::getBitCast(func, getPtrToType(llvm::Type::Int8Ty)); | 1366 return llvm::ConstantExpr::getBitCast(func, getPtrToType(LLType::Int8Ty)); |
1379 } | 1367 } |
1380 | 1368 |
1381 static uint build_classinfo_flags(ClassDeclaration* cd) | 1369 static uint build_classinfo_flags(ClassDeclaration* cd) |
1382 { | 1370 { |
1383 // adapted from original dmd code | 1371 // adapted from original dmd code |
1460 // monitor | 1448 // monitor |
1461 c = cinfo->ir.irStruct->constInit->getOperand(1); | 1449 c = cinfo->ir.irStruct->constInit->getOperand(1); |
1462 inits.push_back(c); | 1450 inits.push_back(c); |
1463 | 1451 |
1464 // byte[] init | 1452 // byte[] init |
1465 const LLType* byteptrty = getPtrToType(llvm::Type::Int8Ty); | 1453 const LLType* byteptrty = getPtrToType(LLType::Int8Ty); |
1466 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { | 1454 if (cd->isInterfaceDeclaration() || cd->isAbstract()) { |
1467 c = cinfo->ir.irStruct->constInit->getOperand(2); | 1455 c = cinfo->ir.irStruct->constInit->getOperand(2); |
1468 } | 1456 } |
1469 else { | 1457 else { |
1470 c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->init, byteptrty); | 1458 c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->init, byteptrty); |