Mercurial > projects > ldc
comparison gen/statements.cpp @ 1554:d6e8d5db259f
LLVMContext changes up to r77366
author | Benjamin Kramer <benny.kra@gmail.com> |
---|---|
date | Thu, 30 Jul 2009 15:25:10 +0200 |
parents | 327eef051d50 |
children | 1d5c3354b3c2 |
comparison
equal
deleted
inserted
replaced
1553:f55ca8a1598c | 1554:d6e8d5db259f |
---|---|
813 inits[i] = c->str->toConstElem(p); | 813 inits[i] = c->str->toConstElem(p); |
814 } | 814 } |
815 // build static array for ptr or final array | 815 // build static array for ptr or final array |
816 const LLType* elemTy = DtoType(condition->type); | 816 const LLType* elemTy = DtoType(condition->type); |
817 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); | 817 const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); |
818 LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits); | 818 LLConstant* arrInit = LLConstantArray::get(arrTy, inits); |
819 llvm::GlobalVariable* arr = new llvm::GlobalVariable(*gIR->module, arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, ".string_switch_table_data"); | 819 llvm::GlobalVariable* arr = new llvm::GlobalVariable(*gIR->module, arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, ".string_switch_table_data"); |
820 | 820 |
821 const LLType* elemPtrTy = getPtrToType(elemTy); | 821 const LLType* elemPtrTy = getPtrToType(elemTy); |
822 LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); | 822 LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); |
823 | 823 |
1028 LLValue* keyvar; | 1028 LLValue* keyvar; |
1029 if (key) | 1029 if (key) |
1030 keyvar = DtoRawVarDeclaration(key); | 1030 keyvar = DtoRawVarDeclaration(key); |
1031 else | 1031 else |
1032 keyvar = DtoRawAlloca(keytype, 0, "foreachkey"); // FIXME: align? | 1032 keyvar = DtoRawAlloca(keytype, 0, "foreachkey"); // FIXME: align? |
1033 LLValue* zerokey = gIR->context().getConstantInt(keytype,0,false); | 1033 LLValue* zerokey = LLConstantInt::get(keytype,0,false); |
1034 | 1034 |
1035 // value | 1035 // value |
1036 Logger::println("value = %s", value->toPrettyChars()); | 1036 Logger::println("value = %s", value->toPrettyChars()); |
1037 LLValue* valvar = NULL; | 1037 LLValue* valvar = NULL; |
1038 if (!value->isRef() && !value->isOut()) { | 1038 if (!value->isRef() && !value->isOut()) { |
1085 if (op == TOKforeach) { | 1085 if (op == TOKforeach) { |
1086 done = p->ir->CreateICmpULT(load, niters, "tmp"); | 1086 done = p->ir->CreateICmpULT(load, niters, "tmp"); |
1087 } | 1087 } |
1088 else if (op == TOKforeach_reverse) { | 1088 else if (op == TOKforeach_reverse) { |
1089 done = p->ir->CreateICmpUGT(load, zerokey, "tmp"); | 1089 done = p->ir->CreateICmpUGT(load, zerokey, "tmp"); |
1090 load = p->ir->CreateSub(load, gIR->context().getConstantInt(keytype, 1, false), "tmp"); | 1090 load = p->ir->CreateSub(load, LLConstantInt::get(keytype, 1, false), "tmp"); |
1091 DtoStore(load, keyvar); | 1091 DtoStore(load, keyvar); |
1092 } | 1092 } |
1093 llvm::BranchInst::Create(bodybb, endbb, done, p->scopebb()); | 1093 llvm::BranchInst::Create(bodybb, endbb, done, p->scopebb()); |
1094 | 1094 |
1095 // init body | 1095 // init body |
1096 p->scope() = IRScope(bodybb,nextbb); | 1096 p->scope() = IRScope(bodybb,nextbb); |
1097 | 1097 |
1098 // get value for this iteration | 1098 // get value for this iteration |
1099 LLConstant* zero = gIR->context().getConstantInt(keytype,0,false); | 1099 LLConstant* zero = LLConstantInt::get(keytype,0,false); |
1100 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); | 1100 LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); |
1101 LLValue* gep = DtoGEP1(val,loadedKey); | 1101 LLValue* gep = DtoGEP1(val,loadedKey); |
1102 | 1102 |
1103 if (!value->isRef() && !value->isOut()) { | 1103 if (!value->isRef() && !value->isOut()) { |
1104 // Copy value to local variable, and use it as the value variable. | 1104 // Copy value to local variable, and use it as the value variable. |
1122 | 1122 |
1123 // next | 1123 // next |
1124 p->scope() = IRScope(nextbb,endbb); | 1124 p->scope() = IRScope(nextbb,endbb); |
1125 if (op == TOKforeach) { | 1125 if (op == TOKforeach) { |
1126 LLValue* load = DtoLoad(keyvar); | 1126 LLValue* load = DtoLoad(keyvar); |
1127 load = p->ir->CreateAdd(load, gIR->context().getConstantInt(keytype, 1, false), "tmp"); | 1127 load = p->ir->CreateAdd(load, LLConstantInt::get(keytype, 1, false), "tmp"); |
1128 DtoStore(load, keyvar); | 1128 DtoStore(load, keyvar); |
1129 } | 1129 } |
1130 llvm::BranchInst::Create(condbb, p->scopebb()); | 1130 llvm::BranchInst::Create(condbb, p->scopebb()); |
1131 | 1131 |
1132 // end | 1132 // end |