Mercurial > projects > ldc
comparison gen/tollvm.c @ 34:4648206ca213 trunk
[svn r38] * resizing dynamic arrays support
* throw is replaced with assert(0)
* catch is ignored
* better foreach support
* various bugfixes
author | lindquist |
---|---|
date | Tue, 09 Oct 2007 02:50:00 +0200 |
parents | 2841234d2aea |
children | 8b0e809563df |
comparison
equal
deleted
inserted
replaced
33:bc641b23a714 | 34:4648206ca213 |
---|---|
995 | 995 |
996 llvm::AllocaInst* allocainst = new llvm::AllocaInst(l->val->getType(), l->val->getName()+"_storage", gIR->topallocapoint()); | 996 llvm::AllocaInst* allocainst = new llvm::AllocaInst(l->val->getType(), l->val->getName()+"_storage", gIR->topallocapoint()); |
997 l->mem = allocainst; | 997 l->mem = allocainst; |
998 l->vardecl->llvmValue = l->mem; | 998 l->vardecl->llvmValue = l->mem; |
999 } | 999 } |
1000 | |
1001 ////////////////////////////////////////////////////////////////////////////////////////// | |
1002 | |
1003 llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, const llvm::Type* ty) | |
1004 { | |
1005 /*size_t sz = gTargetData->getTypeSize(ty); | |
1006 llvm::ConstantInt* n = llvm::ConstantInt::get(LLVM_DtoSize_t(), sz, false); | |
1007 if (ptr == 0) { | |
1008 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
1009 ptr = llvm::ConstantPointerNull::get(i8pty); | |
1010 } | |
1011 return LLVM_DtoRealloc(ptr, n);*/ | |
1012 return NULL; | |
1013 } | |
1014 | |
1015 ////////////////////////////////////////////////////////////////////////////////////////// | |
1016 | |
1017 llvm::Value* LLVM_DtoRealloc(llvm::Value* ptr, llvm::Value* n) | |
1018 { | |
1019 assert(ptr); | |
1020 assert(n); | |
1021 | |
1022 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_realloc"); | |
1023 assert(fn); | |
1024 | |
1025 llvm::Value* newptr = ptr; | |
1026 | |
1027 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty); | |
1028 if (ptr->getType() != i8pty) { | |
1029 newptr = new llvm::BitCastInst(ptr,i8pty,"tmp",gIR->scopebb()); | |
1030 } | |
1031 | |
1032 std::vector<llvm::Value*> args; | |
1033 args.push_back(newptr); | |
1034 args.push_back(n); | |
1035 llvm::Value* ret = new llvm::CallInst(fn, args.begin(), args.end(), "tmprealloc", gIR->scopebb()); | |
1036 | |
1037 return ret->getType() == ptr->getType() ? ret : new llvm::BitCastInst(ret,ptr->getType(),"tmp",gIR->scopebb()); | |
1038 } | |
1039 | |
1040 ////////////////////////////////////////////////////////////////////////////////////////// | |
1041 | |
1042 void LLVM_DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg) | |
1043 { | |
1044 assert(loc); | |
1045 std::vector<llvm::Value*> llargs; | |
1046 llargs.resize(3); | |
1047 llargs[0] = cond ? LLVM_DtoBoolean(cond) : llvm::ConstantInt::getFalse(); | |
1048 llargs[1] = loc; | |
1049 llargs[2] = msg ? msg : llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); | |
1050 | |
1051 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_assert"); | |
1052 assert(fn); | |
1053 llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); | |
1054 call->setCallingConv(llvm::CallingConv::C); | |
1055 } | |
1056 | |
1057 | |
1058 | |
1059 | |
1060 | |
1061 | |
1062 |