Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 302:bef811104734 trunk
[svn r323] Branching out of inline asm works.
Renamed emit_finallyblocks to DtoFinallyBlocks and moved to llvmhelpers.
Added enclosingtryfinally to AsmBlockStatement, so branches out of asm blocks respect finallys.
Refactored some GotoStatement code into DtoGoto.
author | ChristianK |
---|---|
date | Wed, 25 Jun 2008 20:39:09 +0200 |
parents | 895e1b50cf2a |
children | 3ebc136702dd |
comparison
equal
deleted
inserted
replaced
301:f42a1090e895 | 302:bef811104734 |
---|---|
146 llvm::CallInst* call = llvm::CallInst::Create(fn, args.begin(), args.end(), "", gIR->scopebb()); | 146 llvm::CallInst* call = llvm::CallInst::Create(fn, args.begin(), args.end(), "", gIR->scopebb()); |
147 call->setParamAttrs(palist); | 147 call->setParamAttrs(palist); |
148 | 148 |
149 // after assert is always unreachable | 149 // after assert is always unreachable |
150 gIR->ir->CreateUnreachable(); | 150 gIR->ir->CreateUnreachable(); |
151 } | |
152 | |
153 /****************************************************************************************/ | |
154 /*//////////////////////////////////////////////////////////////////////////////////////// | |
155 // GOTO HELPER | |
156 ////////////////////////////////////////////////////////////////////////////////////////*/ | |
157 void DtoGoto(Loc* loc, LabelDsymbol* target, TryFinallyStatement* enclosingtryfinally) | |
158 { | |
159 assert(!gIR->scopereturned()); | |
160 | |
161 if (target->statement->llvmBB == NULL) | |
162 target->statement->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc()); | |
163 | |
164 // find finallys between goto and label | |
165 TryFinallyStatement* endfinally = enclosingtryfinally; | |
166 while(endfinally != NULL && endfinally != target->statement->enclosingtryfinally) { | |
167 endfinally = endfinally->enclosingtryfinally; | |
168 } | |
169 | |
170 // error if didn't find tf statement of label | |
171 if(endfinally != target->statement->enclosingtryfinally) | |
172 error("cannot goto into try block", loc->toChars()); | |
173 | |
174 // emit code for finallys between goto and label | |
175 DtoFinallyBlocks(enclosingtryfinally, endfinally); | |
176 | |
177 llvm::BranchInst::Create(target->statement->llvmBB, gIR->scopebb()); | |
178 } | |
179 | |
180 /****************************************************************************************/ | |
181 /*//////////////////////////////////////////////////////////////////////////////////////// | |
182 // TRY FINALLY HELPER | |
183 ////////////////////////////////////////////////////////////////////////////////////////*/ | |
184 void DtoFinallyBlocks(TryFinallyStatement* start, TryFinallyStatement* end) | |
185 { | |
186 // verify that end encloses start | |
187 TryFinallyStatement* endfinally = start; | |
188 while(endfinally != NULL && endfinally != end) { | |
189 endfinally = endfinally->enclosingtryfinally; | |
190 } | |
191 assert(endfinally == end); | |
192 | |
193 // emit code for finallys between start and end | |
194 TryFinallyStatement* tf = start; | |
195 while(tf != end) { | |
196 tf->finalbody->toIR(gIR); | |
197 tf = tf->enclosingtryfinally; | |
198 } | |
151 } | 199 } |
152 | 200 |
153 /****************************************************************************************/ | 201 /****************************************************************************************/ |
154 /*//////////////////////////////////////////////////////////////////////////////////////// | 202 /*//////////////////////////////////////////////////////////////////////////////////////// |
155 // NESTED VARIABLE HELPERS | 203 // NESTED VARIABLE HELPERS |