Mercurial > projects > ldc
comparison gen/toir.c @ 6:35d93ce68cf4 trunk
[svn r10] Updated for LLVM rev. 20070913
Applied fixes from wilsonk on the forum
Some tweaks to work with gc 7.0
Fixed aggregate members of aggregates
Fixed cyclic/recursive class declarations
Other minor tweaks
author | lindquist |
---|---|
date | Wed, 26 Sep 2007 19:05:18 +0200 |
parents | 3d60e549b0c2 |
children | 5e69b77a5c51 |
comparison
equal
deleted
inserted
replaced
5:3d60e549b0c2 | 6:35d93ce68cf4 |
---|---|
99 { | 99 { |
100 // dollar | 100 // dollar |
101 if (!p->arrays.empty()) | 101 if (!p->arrays.empty()) |
102 { | 102 { |
103 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 103 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
104 llvm::Value* tmp = new llvm::GetElementPtrInst(p->arrays.back(),zero,zero,"tmp",p->scopebb()); | 104 //llvm::Value* tmp = new llvm::GetElementPtrInst(p->arrays.back(),zero,zero,"tmp",p->scopebb()); |
105 llvm::Value* tmp = LLVM_DtoGEP(p->arrays.back(),zero,zero,"tmp",p->scopebb()); | |
105 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 106 e->val = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
106 e->type = elem::VAL; | 107 e->type = elem::VAL; |
107 } | 108 } |
108 // magic | 109 // magic |
109 else | 110 else |
203 elem* RealExp::toElem(IRState* p) | 204 elem* RealExp::toElem(IRState* p) |
204 { | 205 { |
205 Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars()); | 206 Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars()); |
206 LOG_SCOPE; | 207 LOG_SCOPE; |
207 elem* e = new elem; | 208 elem* e = new elem; |
208 e->val = llvm::ConstantFP::get(LLVM_DtoType(type),value); | 209 const llvm::Type* fty = LLVM_DtoType(type); |
210 if (type->ty == Tfloat32) | |
211 e->val = llvm::ConstantFP::get(fty,float(value)); | |
212 else if (type->ty == Tfloat64 || type->ty == Tfloat80) | |
213 e->val = llvm::ConstantFP::get(fty,double(value)); | |
214 else | |
215 assert(0); | |
209 e->type = elem::CONST; | 216 e->type = elem::CONST; |
210 return e; | 217 return e; |
211 } | 218 } |
212 | 219 |
213 ////////////////////////////////////////////////////////////////////////////////////////// | 220 ////////////////////////////////////////////////////////////////////////////////////////// |
249 | 256 |
250 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; | 257 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;//WeakLinkage; |
251 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,"stringliteral",gIR->module); | 258 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,"stringliteral",gIR->module); |
252 | 259 |
253 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 260 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
254 llvm::Value* arrptr = new llvm::GetElementPtrInst(gvar,zero,zero,"tmp",p->scopebb()); | 261 llvm::Value* arrptr = LLVM_DtoGEP(gvar,zero,zero,"tmp",p->scopebb()); |
255 | 262 |
256 elem* e = new elem; | 263 elem* e = new elem; |
257 | 264 |
258 if (type->ty == Tarray) { | 265 if (type->ty == Tarray) { |
259 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false); | 266 llvm::Constant* clen = llvm::ConstantInt::get(LLVM_DtoSize_t(),len,false); |
433 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); | 440 llvm::ConstantInt* cofs = llvm::cast<llvm::ConstantInt>(r->val); |
434 | 441 |
435 TypeStruct* ts = (TypeStruct*)e1->type->next; | 442 TypeStruct* ts = (TypeStruct*)e1->type->next; |
436 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, ts->sym->offsetToIndex(cofs->getZExtValue()), false); | 443 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, ts->sym->offsetToIndex(cofs->getZExtValue()), false); |
437 | 444 |
438 e->mem = new llvm::GetElementPtrInst(l->getValue(), zero, offset, "tmp", p->scopebb()); | 445 e->mem = LLVM_DtoGEP(l->getValue(), zero, offset, "tmp", p->scopebb()); |
439 e->type = elem::VAR; | 446 e->type = elem::VAR; |
440 e->field = true; | 447 e->field = true; |
441 } | 448 } |
442 else if (e1->type->ty == Tpointer) { | 449 else if (e1->type->ty == Tpointer) { |
443 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb()); | 450 e->val = new llvm::GetElementPtrInst(l->getValue(), r->getValue(), "tmp", p->scopebb()); |
804 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; | 811 //Logger::cout() << "function pointer type:\n" << *funcval << '\n'; |
805 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); | 812 llfnty = llvm::cast<llvm::FunctionType>(funcval->getType()->getContainedType(0)); |
806 } | 813 } |
807 // struct pointer - delegate | 814 // struct pointer - delegate |
808 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { | 815 else if (llvm::isa<llvm::StructType>(funcval->getType()->getContainedType(0))) { |
809 funcval = new llvm::GetElementPtrInst(funcval,zero,one,"tmp",p->scopebb()); | 816 funcval = LLVM_DtoGEP(funcval,zero,one,"tmp",p->scopebb()); |
810 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 817 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
811 const llvm::Type* ty = funcval->getType()->getContainedType(0); | 818 const llvm::Type* ty = funcval->getType()->getContainedType(0); |
812 llfnty = llvm::cast<llvm::FunctionType>(ty); | 819 llfnty = llvm::cast<llvm::FunctionType>(ty); |
813 } | 820 } |
814 // unknown | 821 // unknown |
863 ++argiter; | 870 ++argiter; |
864 } | 871 } |
865 // delegate context parameter | 872 // delegate context parameter |
866 else if (delegateCall) { | 873 else if (delegateCall) { |
867 Logger::println("Delegate Call"); | 874 Logger::println("Delegate Call"); |
868 llvm::Value* contextptr = new llvm::GetElementPtrInst(fn->mem,zero,zero,"tmp",p->scopebb()); | 875 llvm::Value* contextptr = LLVM_DtoGEP(fn->mem,zero,zero,"tmp",p->scopebb()); |
869 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); | 876 llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); |
870 ++j; | 877 ++j; |
871 ++argiter; | 878 ++argiter; |
872 } | 879 } |
873 | 880 |
1037 if (to->ty == Tpointer) { | 1044 if (to->ty == Tpointer) { |
1038 Logger::cout() << "to pointer" << '\n'; | 1045 Logger::cout() << "to pointer" << '\n'; |
1039 assert(from->next == to->next); | 1046 assert(from->next == to->next); |
1040 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1047 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1041 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1048 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1042 llvm::Value* ptr = new llvm::GetElementPtrInst(u->getValue(),zero,one,"tmp",p->scopebb()); | 1049 llvm::Value* ptr = LLVM_DtoGEP(u->getValue(),zero,one,"tmp",p->scopebb()); |
1043 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | 1050 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
1044 e->type = elem::VAL; | 1051 e->type = elem::VAL; |
1045 } | 1052 } |
1046 else if (to->ty == Tarray) { | 1053 else if (to->ty == Tarray) { |
1047 Logger::cout() << "to array" << '\n'; | 1054 Logger::cout() << "to array" << '\n'; |
1065 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); | 1072 e->mem = new llvm::BitCastInst(uval, ptrty, "tmp", p->scopebb()); |
1066 } | 1073 } |
1067 else { | 1074 else { |
1068 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1075 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1069 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1076 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1070 e->arg = new llvm::GetElementPtrInst(uval,zero,zero,"tmp",p->scopebb()); | 1077 e->arg = LLVM_DtoGEP(uval,zero,zero,"tmp",p->scopebb()); |
1071 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); | 1078 e->arg = new llvm::LoadInst(e->arg, "tmp", p->scopebb()); |
1072 | 1079 |
1073 e->mem = new llvm::GetElementPtrInst(uval,zero,one,"tmp",p->scopebb()); | 1080 e->mem = LLVM_DtoGEP(uval,zero,one,"tmp",p->scopebb()); |
1074 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb()); | 1081 e->mem = new llvm::LoadInst(e->mem, "tmp", p->scopebb()); |
1075 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; | 1082 //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; |
1076 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb()); | 1083 e->mem = new llvm::BitCastInst(e->mem, ptrty, "tmp", p->scopebb()); |
1077 } | 1084 } |
1078 } | 1085 } |
1122 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1129 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1123 llvm::Value* idx1 = llvm::ConstantInt::get(llvm::Type::Int32Ty, (uint64_t)vdt->sym->offsetToIndex(offset), false); | 1130 llvm::Value* idx1 = llvm::ConstantInt::get(llvm::Type::Int32Ty, (uint64_t)vdt->sym->offsetToIndex(offset), false); |
1124 //const llvm::Type* _typ = llvm::GetElementPtrInst::getIndexedType(LLVM_DtoType(type), idx1); | 1131 //const llvm::Type* _typ = llvm::GetElementPtrInst::getIndexedType(LLVM_DtoType(type), idx1); |
1125 llvm::Value* ptr = vd->llvmValue; | 1132 llvm::Value* ptr = vd->llvmValue; |
1126 assert(ptr); | 1133 assert(ptr); |
1127 e->mem = new llvm::GetElementPtrInst(ptr,idx0,idx1,"tmp",p->scopebb()); | 1134 e->mem = LLVM_DtoGEP(ptr,idx0,idx1,"tmp",p->scopebb()); |
1128 e->type = elem::VAL; | 1135 e->type = elem::VAL; |
1129 e->field = true; | 1136 e->field = true; |
1130 } | 1137 } |
1131 else if (vd->type->ty == Tsarray) { | 1138 else if (vd->type->ty == Tsarray) { |
1132 /*e = new elem; | 1139 /*e = new elem; |
1133 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1140 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1134 e->val = new llvm::GetElementPtrInst(vd->llvmValue,idx0,idx0,"tmp",p->scopebb());*/ | 1141 e->val = new llvm::GetElementPtrInst(vd->llvmValue,idx0,idx0,"tmp",p->scopebb());*/ |
1135 e = new elem; | 1142 e = new elem; |
1136 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1143 llvm::Value* idx0 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1137 //llvm::Value* idx1 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1144 //llvm::Value* idx1 = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1138 e->mem = new llvm::GetElementPtrInst(vd->llvmValue,idx0,idx0,"tmp",p->scopebb()); | 1145 e->mem = LLVM_DtoGEP(vd->llvmValue,idx0,idx0,"tmp",p->scopebb()); |
1139 e->type = elem::VAL; | 1146 e->type = elem::VAL; |
1140 } | 1147 } |
1141 else if (offset == 0) { | 1148 else if (offset == 0) { |
1142 /*if (!vd->llvmValue) | 1149 /*if (!vd->llvmValue) |
1143 vd->toObjFile();*/ | 1150 vd->toObjFile();*/ |
1220 } | 1227 } |
1221 assert(vdoffset != (size_t)-1); | 1228 assert(vdoffset != (size_t)-1); |
1222 assert(src != 0); | 1229 assert(src != 0); |
1223 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1230 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1224 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, vdoffset, false); | 1231 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, vdoffset, false); |
1225 llvm::Value* arrptr = new llvm::GetElementPtrInst(src,zero,offset,"tmp",p->scopebb()); | 1232 llvm::Value* arrptr = LLVM_DtoGEP(src,zero,offset,"tmp",p->scopebb()); |
1226 e->mem = arrptr; | 1233 e->mem = arrptr; |
1227 Logger::cout() << "mem: " << *e->mem << '\n'; | 1234 Logger::cout() << "mem: " << *e->mem << '\n'; |
1228 e->type = elem::VAR; | 1235 e->type = elem::VAR; |
1229 } | 1236 } |
1230 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | 1237 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) |
1244 | 1251 |
1245 const llvm::Type* vtbltype = llvm::PointerType::get(llvm::ArrayType::get(llvm::PointerType::get(llvm::Type::Int8Ty),0)); | 1252 const llvm::Type* vtbltype = llvm::PointerType::get(llvm::ArrayType::get(llvm::PointerType::get(llvm::Type::Int8Ty),0)); |
1246 | 1253 |
1247 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1254 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1248 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); | 1255 llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); |
1249 funcval = new llvm::GetElementPtrInst(e->arg, zero, zero, "tmp", p->scopebb()); | 1256 funcval = LLVM_DtoGEP(e->arg, zero, zero, "tmp", p->scopebb()); |
1250 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 1257 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
1251 funcval = new llvm::BitCastInst(funcval, vtbltype, "tmp", p->scopebb()); | 1258 funcval = new llvm::BitCastInst(funcval, vtbltype, "tmp", p->scopebb()); |
1252 funcval = new llvm::GetElementPtrInst(funcval, zero, vtblidx, "tmp", p->scopebb()); | 1259 funcval = LLVM_DtoGEP(funcval, zero, vtblidx, "tmp", p->scopebb()); |
1253 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); | 1260 funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); |
1254 funcval = new llvm::BitCastInst(funcval, fdecl->llvmValue->getType(), "tmp", p->scopebb()); | 1261 funcval = new llvm::BitCastInst(funcval, fdecl->llvmValue->getType(), "tmp", p->scopebb()); |
1255 } | 1262 } |
1256 e->val = funcval; | 1263 e->val = funcval; |
1257 e->type = elem::VAL; | 1264 e->type = elem::VAL; |
1335 | 1342 |
1336 unsigned n = elements->dim; | 1343 unsigned n = elements->dim; |
1337 for (unsigned i=0; i<n; ++i) | 1344 for (unsigned i=0; i<n; ++i) |
1338 { | 1345 { |
1339 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false); | 1346 llvm::Value* offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false); |
1340 llvm::Value* arrptr = new llvm::GetElementPtrInst(sptr,zero,offset,"tmp",p->scopebb()); | 1347 llvm::Value* arrptr = LLVM_DtoGEP(sptr,zero,offset,"tmp",p->scopebb()); |
1341 | 1348 |
1342 Expression* vx = (Expression*)elements->data[i]; | 1349 Expression* vx = (Expression*)elements->data[i]; |
1343 if (vx != 0) { | 1350 if (vx != 0) { |
1344 elem* ve = vx->toElem(p); | 1351 elem* ve = vx->toElem(p); |
1345 //Logger::cout() << *ve->val << " | " << *arrptr << '\n'; | 1352 //Logger::cout() << *ve->val << " | " << *arrptr << '\n'; |
1378 llvm::Value* arrptr = 0; | 1385 llvm::Value* arrptr = 0; |
1379 if (e1->type->ty == Tpointer) { | 1386 if (e1->type->ty == Tpointer) { |
1380 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); | 1387 arrptr = new llvm::GetElementPtrInst(l->getValue(),r->getValue(),"tmp",p->scopebb()); |
1381 } | 1388 } |
1382 else if (e1->type->ty == Tsarray) { | 1389 else if (e1->type->ty == Tsarray) { |
1383 arrptr = new llvm::GetElementPtrInst(l->mem, zero, r->getValue(),"tmp",p->scopebb()); | 1390 arrptr = LLVM_DtoGEP(l->mem, zero, r->getValue(),"tmp",p->scopebb()); |
1384 } | 1391 } |
1385 else if (e1->type->ty == Tarray) { | 1392 else if (e1->type->ty == Tarray) { |
1386 arrptr = new llvm::GetElementPtrInst(l->mem,zero,one,"tmp",p->scopebb()); | 1393 arrptr = LLVM_DtoGEP(l->mem,zero,one,"tmp",p->scopebb()); |
1387 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); | 1394 arrptr = new llvm::LoadInst(arrptr,"tmp",p->scopebb()); |
1388 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); | 1395 arrptr = new llvm::GetElementPtrInst(arrptr,r->getValue(),"tmp",p->scopebb()); |
1389 } | 1396 } |
1390 assert(arrptr); | 1397 assert(arrptr); |
1391 | 1398 |
1429 | 1436 |
1430 if (e1->type->ty == Tpointer) { | 1437 if (e1->type->ty == Tpointer) { |
1431 e->mem = v->getValue(); | 1438 e->mem = v->getValue(); |
1432 } | 1439 } |
1433 else if (e1->type->ty == Tarray) { | 1440 else if (e1->type->ty == Tarray) { |
1434 llvm::Value* tmp = new llvm::GetElementPtrInst(v->mem,zero,one,"tmp",p->scopebb()); | 1441 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1435 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 1442 e->mem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1436 } | 1443 } |
1437 else | 1444 else |
1438 assert(e->mem); | 1445 assert(e->mem); |
1439 | 1446 |
1442 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb()); | 1449 e->mem = new llvm::GetElementPtrInst(e->mem,lo->val,"tmp",p->scopebb()); |
1443 } | 1450 } |
1444 } | 1451 } |
1445 else | 1452 else |
1446 { | 1453 { |
1447 llvm::Value* tmp = new llvm::GetElementPtrInst(v->mem,zero,one,"tmp",p->scopebb()); | 1454 llvm::Value* tmp = LLVM_DtoGEP(v->mem,zero,one,"tmp",p->scopebb()); |
1448 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); | 1455 tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); |
1449 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); | 1456 e->mem = new llvm::GetElementPtrInst(tmp,lo->getValue(),"tmp",p->scopebb()); |
1450 } | 1457 } |
1451 | 1458 |
1452 elem* up = upr->toElem(p); | 1459 elem* up = upr->toElem(p); |
1832 ldval = v->getValue(); | 1839 ldval = v->getValue(); |
1833 | 1840 |
1834 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1841 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1835 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); | 1842 llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); |
1836 | 1843 |
1837 llvm::Value* ptr = new llvm::GetElementPtrInst(ldval,zero,one,"tmp",p->scopebb()); | 1844 llvm::Value* ptr = LLVM_DtoGEP(ldval,zero,one,"tmp",p->scopebb()); |
1838 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); | 1845 ptr = new llvm::LoadInst(ptr,"tmp",p->scopebb()); |
1839 new llvm::FreeInst(ptr, p->scopebb()); | 1846 new llvm::FreeInst(ptr, p->scopebb()); |
1840 LLVM_DtoNullArray(val); | 1847 LLVM_DtoNullArray(val); |
1841 } | 1848 } |
1842 else { | 1849 else { |
1858 | 1865 |
1859 elem* e = new elem; | 1866 elem* e = new elem; |
1860 elem* u = e1->toElem(p); | 1867 elem* u = e1->toElem(p); |
1861 | 1868 |
1862 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); | 1869 llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); |
1863 llvm::Value* ptr = new llvm::GetElementPtrInst(u->mem,zero,zero,"tmp",p->scopebb()); | 1870 llvm::Value* ptr = LLVM_DtoGEP(u->mem,zero,zero,"tmp",p->scopebb()); |
1864 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); | 1871 e->val = new llvm::LoadInst(ptr, "tmp", p->scopebb()); |
1865 e->type = elem::VAL; | 1872 e->type = elem::VAL; |
1866 | 1873 |
1867 delete u; | 1874 delete u; |
1868 | 1875 |
2084 | 2091 |
2085 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); | 2092 const llvm::Type* int8ptrty = llvm::PointerType::get(llvm::Type::Int8Ty); |
2086 | 2093 |
2087 llvm::Value* lval = p->toplval(); | 2094 llvm::Value* lval = p->toplval(); |
2088 | 2095 |
2089 llvm::Value* context = new llvm::GetElementPtrInst(lval,zero,zero,"tmp",p->scopebb()); | 2096 llvm::Value* context = LLVM_DtoGEP(lval,zero,zero,"tmp",p->scopebb()); |
2090 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); | 2097 llvm::Value* castcontext = new llvm::BitCastInst(u->getValue(),int8ptrty,"tmp",p->scopebb()); |
2091 new llvm::StoreInst(castcontext, context, p->scopebb()); | 2098 new llvm::StoreInst(castcontext, context, p->scopebb()); |
2092 | 2099 |
2093 llvm::Value* fptr = new llvm::GetElementPtrInst(lval,zero,one,"tmp",p->scopebb()); | 2100 llvm::Value* fptr = LLVM_DtoGEP(lval,zero,one,"tmp",p->scopebb()); |
2094 | 2101 |
2095 assert(func->llvmValue); | 2102 assert(func->llvmValue); |
2096 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); | 2103 llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); |
2097 new llvm::StoreInst(castfptr, fptr, p->scopebb()); | 2104 new llvm::StoreInst(castfptr, fptr, p->scopebb()); |
2098 | 2105 |