comparison gen/tollvm.c @ 54:28e99b04a132 trunk

[svn r58] Fixed cond expression resulting in a non-basic type. Fixed identity expression for dynamic arrays. Revamped the system to keep track of lvalues and rvalues and their relations. Typedef declaration now generate the custom typeinfo. Other bugfixes.
author lindquist
date Wed, 24 Oct 2007 01:37:34 +0200
parents 06ccc817acd4
children 0ccfae271c45
comparison
equal deleted inserted replaced
53:06ccc817acd4 54:28e99b04a132
1098 1098
1099 llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp) 1099 llvm::Value* LLVM_DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp)
1100 { 1100 {
1101 llvm::Value* retval = 0; 1101 llvm::Value* retval = 0;
1102 1102
1103 bool haslvals = !gIR->lvals.empty(); 1103 bool haslvals = !gIR->exps.empty();
1104 if (haslvals) 1104 if (haslvals)
1105 gIR->lvals.push_back(NULL); 1105 gIR->exps.push_back(IRExp(NULL,NULL,NULL));
1106 1106
1107 elem* arg = argexp->toElem(gIR); 1107 elem* arg = argexp->toElem(gIR);
1108 1108
1109 if (haslvals) 1109 if (haslvals)
1110 gIR->lvals.pop_back(); 1110 gIR->exps.pop_back();
1111 1111
1112 if (arg->inplace) { 1112 if (arg->inplace) {
1113 assert(arg->mem != 0); 1113 assert(arg->mem != 0);
1114 retval = arg->mem; 1114 retval = arg->mem;
1115 delete arg; 1115 delete arg;
1252 else { 1252 else {
1253 assert(lhs->getType()->getContainedType(0) == rhs->getType()); 1253 assert(lhs->getType()->getContainedType(0) == rhs->getType());
1254 gIR->ir->CreateStore(rhs, lhs); 1254 gIR->ir->CreateStore(rhs, lhs);
1255 } 1255 }
1256 } 1256 }
1257
1258 //////////////////////////////////////////////////////////////////////////////////////////
1259
1260 llvm::ConstantInt* LLVM_DtoConstSize_t(size_t i)
1261 {
1262 return llvm::ConstantInt::get(LLVM_DtoSize_t(), i, false);
1263 }
1264 llvm::ConstantInt* LLVM_DtoConstUint(unsigned i)
1265 {
1266 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
1267 }
1268
1269 //////////////////////////////////////////////////////////////////////////////////////////
1270
1271 llvm::Constant* LLVM_DtoConstString(const char* str)
1272 {
1273 std::string s(str);
1274 llvm::Constant* init = llvm::ConstantArray::get(s, true);
1275 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
1276 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
1277 llvm::Constant* idxs[2] = { LLVM_DtoConstUint(0), LLVM_DtoConstUint(0) };
1278 return LLVM_DtoConstantSlice(
1279 LLVM_DtoConstSize_t(s.length()),
1280 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
1281 );
1282 }