Mercurial > projects > ldc
comparison gen/statements.cpp @ 244:a95056b3c996 trunk
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
Did a lot of smaller cleans up here and there.
Replaced more llvm::Foo with LLFoo for common stuff.
Split up tollvm.cpp.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 09:37:08 +0200 |
parents | 9760f54af0b7 |
children | 88252a1af660 |
comparison
equal
deleted
inserted
replaced
243:4d006f7b2ada | 244:a95056b3c996 |
---|---|
18 #include "port.h" | 18 #include "port.h" |
19 | 19 |
20 #include "gen/irstate.h" | 20 #include "gen/irstate.h" |
21 #include "gen/logger.h" | 21 #include "gen/logger.h" |
22 #include "gen/tollvm.h" | 22 #include "gen/tollvm.h" |
23 #include "gen/llvmhelpers.h" | |
23 #include "gen/runtime.h" | 24 #include "gen/runtime.h" |
24 #include "gen/arrays.h" | 25 #include "gen/arrays.h" |
25 #include "gen/todebug.h" | 26 #include "gen/todebug.h" |
26 #include "gen/dvalue.h" | 27 #include "gen/dvalue.h" |
27 | 28 |
72 Logger::println("ReturnStatement::toIR(): %s", loc.toChars()); | 73 Logger::println("ReturnStatement::toIR(): %s", loc.toChars()); |
73 LOG_SCOPE; | 74 LOG_SCOPE; |
74 | 75 |
75 if (exp) | 76 if (exp) |
76 { | 77 { |
77 if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { | 78 if (p->topfunc()->getReturnType() == LLType::VoidTy) { |
78 IrFunction* f = p->func(); | 79 IrFunction* f = p->func(); |
79 assert(f->type->llvmRetInPtr); | 80 assert(f->type->llvmRetInPtr); |
80 assert(f->decl->ir.irFunc->retArg); | 81 assert(f->decl->ir.irFunc->retArg); |
81 | 82 |
82 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); | 83 if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); |
126 llvm::ReturnInst::Create(v, p->scopebb()); | 127 llvm::ReturnInst::Create(v, p->scopebb()); |
127 } | 128 } |
128 } | 129 } |
129 else | 130 else |
130 { | 131 { |
131 assert(p->topfunc()->getReturnType() == llvm::Type::VoidTy); | 132 assert(p->topfunc()->getReturnType() == LLType::VoidTy); |
132 emit_finallyblocks(p, enclosingtryfinally, NULL); | 133 emit_finallyblocks(p, enclosingtryfinally, NULL); |
133 | 134 |
134 if (gIR->func()->inVolatile) { | 135 if (gIR->func()->inVolatile) { |
135 // store-load barrier | 136 // store-load barrier |
136 DtoMemoryBarrier(false, false, true, false); | 137 DtoMemoryBarrier(false, false, true, false); |
185 | 186 |
186 llvm::BasicBlock* ifbb = llvm::BasicBlock::Create("if", gIR->topfunc(), oldend); | 187 llvm::BasicBlock* ifbb = llvm::BasicBlock::Create("if", gIR->topfunc(), oldend); |
187 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endif", gIR->topfunc(), oldend); | 188 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("endif", gIR->topfunc(), oldend); |
188 llvm::BasicBlock* elsebb = elsebody ? llvm::BasicBlock::Create("else", gIR->topfunc(), endbb) : endbb; | 189 llvm::BasicBlock* elsebb = elsebody ? llvm::BasicBlock::Create("else", gIR->topfunc(), endbb) : endbb; |
189 | 190 |
190 if (cond_val->getType() != llvm::Type::Int1Ty) { | 191 if (cond_val->getType() != LLType::Int1Ty) { |
191 Logger::cout() << "if conditional: " << *cond_val << '\n'; | 192 Logger::cout() << "if conditional: " << *cond_val << '\n'; |
192 cond_val = DtoBoolean(cond_val); | 193 cond_val = DtoBoolean(cond_val); |
193 } | 194 } |
194 LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); | 195 LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); |
195 | 196 |
890 assert(val); | 891 assert(val); |
891 } | 892 } |
892 else { | 893 else { |
893 Logger::println("foreach over dynamic array"); | 894 Logger::println("foreach over dynamic array"); |
894 val = aggrval->getRVal(); | 895 val = aggrval->getRVal(); |
895 niters = DtoGEPi(val,0,0,"tmp",p->scopebb()); | 896 niters = DtoGEPi(val,0,0); |
896 niters = p->ir->CreateLoad(niters, "numiterations"); | 897 niters = DtoLoad(niters, "numiterations"); |
897 val = DtoGEPi(val,0,1,"tmp",p->scopebb()); | 898 val = DtoGEPi(val,0,1); |
898 val = p->ir->CreateLoad(val, "collection"); | 899 val = DtoLoad(val, "collection"); |
899 } | 900 } |
900 } | 901 } |
901 else | 902 else |
902 { | 903 { |
903 assert(0 && "aggregate type is not Tarray or Tsarray"); | 904 assert(0 && "aggregate type is not Tarray or Tsarray"); |
933 | 934 |
934 // condition | 935 // condition |
935 p->scope() = IRScope(condbb,bodybb); | 936 p->scope() = IRScope(condbb,bodybb); |
936 | 937 |
937 LLValue* done = 0; | 938 LLValue* done = 0; |
938 LLValue* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb()); | 939 LLValue* load = DtoLoad(keyvar); |
939 if (op == TOKforeach) { | 940 if (op == TOKforeach) { |
940 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_ULT, load, niters, "tmp", p->scopebb()); | 941 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_ULT, load, niters, "tmp", p->scopebb()); |
941 } | 942 } |
942 else if (op == TOKforeach_reverse) { | 943 else if (op == TOKforeach_reverse) { |
943 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_UGT, load, zerokey, "tmp", p->scopebb()); | 944 done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_UGT, load, zerokey, "tmp", p->scopebb()); |