Mercurial > projects > ldc
comparison gen/classes.cpp @ 205:9d44ec83acd1 trunk
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
Fixed: Implemented volatile statements. Uses the LLVM memory barrier intrinsic, closes #21 .
author | lindquist |
---|---|
date | Tue, 13 May 2008 17:58:11 +0200 |
parents | 8f9191180c7a |
children | c4c9b4ac021b |
comparison
equal
deleted
inserted
replaced
204:11fe364b9a3e | 205:9d44ec83acd1 |
---|---|
881 llargs[0] = dstarr; | 881 llargs[0] = dstarr; |
882 llargs[1] = srcarr; | 882 llargs[1] = srcarr; |
883 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); | 883 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); |
884 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 884 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
885 | 885 |
886 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | 886 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); |
887 } | 887 } |
888 | 888 |
889 ////////////////////////////////////////////////////////////////////////////////////////// | 889 ////////////////////////////////////////////////////////////////////////////////////////// |
890 | 890 |
891 DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem) | 891 DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem) |
909 const llvm::Type* aty = fn->getFunctionType()->getParamType(i+1); | 909 const llvm::Type* aty = fn->getFunctionType()->getParamType(i+1); |
910 if (a->getType() != aty) | 910 if (a->getType() != aty) |
911 a = DtoBitCast(a, aty); | 911 a = DtoBitCast(a, aty); |
912 ctorargs.push_back(a); | 912 ctorargs.push_back(a); |
913 } | 913 } |
914 llvm::CallInst* call = new llvm::CallInst(fn, ctorargs.begin(), ctorargs.end(), "tmp", gIR->scopebb()); | 914 llvm::CallInst* call = llvm::CallInst::Create(fn, ctorargs.begin(), ctorargs.end(), "tmp", gIR->scopebb()); |
915 call->setCallingConv(DtoCallingConv(LINKd)); | 915 call->setCallingConv(DtoCallingConv(LINKd)); |
916 | 916 |
917 return new DImValue(type, call, false); | 917 return new DImValue(type, call, false); |
918 } | 918 } |
919 | 919 |
924 Array* arr = &tc->sym->dtors; | 924 Array* arr = &tc->sym->dtors; |
925 for (size_t i=0; i<arr->dim; i++) | 925 for (size_t i=0; i<arr->dim; i++) |
926 { | 926 { |
927 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; | 927 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; |
928 assert(fd->ir.irFunc->func); | 928 assert(fd->ir.irFunc->func); |
929 new llvm::CallInst(fd->ir.irFunc->func, instance, "", gIR->scopebb()); | 929 llvm::CallInst::Create(fd->ir.irFunc->func, instance, "", gIR->scopebb()); |
930 } | 930 } |
931 } | 931 } |
932 | 932 |
933 ////////////////////////////////////////////////////////////////////////////////////////// | 933 ////////////////////////////////////////////////////////////////////////////////////////// |
934 | 934 |
1160 ptr = DtoGEP(ptr, idxs, "tmp"); | 1160 ptr = DtoGEP(ptr, idxs, "tmp"); |
1161 if (ptr->getType() != llt) | 1161 if (ptr->getType() != llt) |
1162 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); | 1162 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
1163 //Logger::cout() << "indexing: " << *ptr << '\n'; | 1163 //Logger::cout() << "indexing: " << *ptr << '\n'; |
1164 if (vd->ir.irField->indexOffset) | 1164 if (vd->ir.irField->indexOffset) |
1165 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb()); | 1165 ptr = llvm::GetElementPtrInst::Create(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb()); |
1166 //Logger::cout() << "indexing: " << *ptr << '\n'; | 1166 //Logger::cout() << "indexing: " << *ptr << '\n'; |
1167 return ptr; | 1167 return ptr; |
1168 } | 1168 } |
1169 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { | 1169 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { |
1170 TypeStruct* ts = (TypeStruct*)vdtype; | 1170 TypeStruct* ts = (TypeStruct*)vdtype; |
1173 if (vd->ir.irField->indexOffset) { | 1173 if (vd->ir.irField->indexOffset) { |
1174 Logger::println("has union field offset"); | 1174 Logger::println("has union field offset"); |
1175 ptr = DtoGEP(ptr, idxs, "tmp"); | 1175 ptr = DtoGEP(ptr, idxs, "tmp"); |
1176 if (ptr->getType() != llt) | 1176 if (ptr->getType() != llt) |
1177 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); | 1177 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
1178 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb()); | 1178 ptr = llvm::GetElementPtrInst::Create(ptr, DtoConstUint(vd->ir.irField->indexOffset), "tmp", gIR->scopebb()); |
1179 std::vector<unsigned> tmp; | 1179 std::vector<unsigned> tmp; |
1180 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); | 1180 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); |
1181 } | 1181 } |
1182 else { | 1182 else { |
1183 const llvm::Type* sty = getPtrToType(DtoType(vd->type)); | 1183 const llvm::Type* sty = getPtrToType(DtoType(vd->type)); |
1196 assert(0); | 1196 assert(0); |
1197 | 1197 |
1198 size_t llt_sz = getABITypeSize(llt->getContainedType(0)); | 1198 size_t llt_sz = getABITypeSize(llt->getContainedType(0)); |
1199 assert(os % llt_sz == 0); | 1199 assert(os % llt_sz == 0); |
1200 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); | 1200 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); |
1201 return new llvm::GetElementPtrInst(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb()); | 1201 return llvm::GetElementPtrInst::Create(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb()); |
1202 } | 1202 } |
1203 | 1203 |
1204 ////////////////////////////////////////////////////////////////////////////////////////// | 1204 ////////////////////////////////////////////////////////////////////////////////////////// |
1205 | 1205 |
1206 llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl) | 1206 llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl) |
1358 | 1358 |
1359 std::string gname("_D"); | 1359 std::string gname("_D"); |
1360 gname.append(cd->mangle()); | 1360 gname.append(cd->mangle()); |
1361 gname.append("12__destructorMFZv"); | 1361 gname.append("12__destructorMFZv"); |
1362 | 1362 |
1363 llvm::Function* func = new llvm::Function(fnTy, DtoInternalLinkage(cd), gname, gIR->module); | 1363 llvm::Function* func = llvm::Function::Create(fnTy, DtoInternalLinkage(cd), gname, gIR->module); |
1364 llvm::Value* thisptr = func->arg_begin(); | 1364 llvm::Value* thisptr = func->arg_begin(); |
1365 thisptr->setName("this"); | 1365 thisptr->setName("this"); |
1366 | 1366 |
1367 llvm::BasicBlock* bb = new llvm::BasicBlock("entry", func); | 1367 llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", func); |
1368 LLVMBuilder builder(bb); | 1368 IRBuilder builder(bb); |
1369 | 1369 |
1370 for (size_t i = 0; i < cd->dtors.dim; i++) | 1370 for (size_t i = 0; i < cd->dtors.dim; i++) |
1371 { | 1371 { |
1372 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; | 1372 DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; |
1373 DtoForceDeclareDsymbol(d); | 1373 DtoForceDeclareDsymbol(d); |