comparison gen/llvmhelpers.cpp @ 305:2b72433d5c8c trunk

[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support. Fixed problems with label collisions when using labels inside inline asm. LabelStatement is now easily reached given its Identifier, which should be useful elsewhere too. Enabled inline asm for building the lib/compiler/llvmdc runtime code, fixing branches out of asm makes this possible.
author lindquist
date Fri, 27 Jun 2008 22:04:35 +0200
parents 3ebc136702dd
children d59c363fccad
comparison
equal deleted inserted replaced
304:3ebc136702dd 305:2b72433d5c8c
150 gIR->ir->CreateUnreachable(); 150 gIR->ir->CreateUnreachable();
151 } 151 }
152 152
153 /****************************************************************************************/ 153 /****************************************************************************************/
154 /*//////////////////////////////////////////////////////////////////////////////////////// 154 /*////////////////////////////////////////////////////////////////////////////////////////
155 // LABEL HELPER
156 ////////////////////////////////////////////////////////////////////////////////////////*/
157 LabelStatement* DtoLabelStatement(Identifier* ident)
158 {
159 FuncDeclaration* fd = gIR->func()->decl;
160 FuncDeclaration::LabelMap::iterator iter = fd->labmap.find(ident->toChars());
161 if (iter == fd->labmap.end())
162 {
163 if (fd->returnLabel->ident->equals(ident))
164 {
165 assert(fd->returnLabel->statement);
166 return fd->returnLabel->statement;
167 }
168 return NULL;
169 }
170 return iter->second;
171 }
172
173 /****************************************************************************************/
174 /*////////////////////////////////////////////////////////////////////////////////////////
155 // GOTO HELPER 175 // GOTO HELPER
156 ////////////////////////////////////////////////////////////////////////////////////////*/ 176 ////////////////////////////////////////////////////////////////////////////////////////*/
157 void DtoGoto(Loc* loc, LabelDsymbol* target, TryFinallyStatement* enclosingtryfinally) 177 void DtoGoto(Loc* loc, Identifier* target, TryFinallyStatement* enclosingtryfinally)
158 { 178 {
159 assert(!gIR->scopereturned()); 179 assert(!gIR->scopereturned());
160 180
181 LabelStatement* lblstmt = DtoLabelStatement(target);
182 assert(lblstmt != NULL);
183
161 // if the target label is inside inline asm, error 184 // if the target label is inside inline asm, error
162 if(target->asmLabel) 185 if(lblstmt->asmLabel)
163 error("cannot goto into inline asm block", loc->toChars()); 186 error("cannot goto into inline asm block", loc->toChars());
164 187
165 if (target->statement->llvmBB == NULL) 188 if (lblstmt->llvmBB == NULL)
166 target->statement->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc()); 189 lblstmt->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc());
167 190
168 // find finallys between goto and label 191 // find finallys between goto and label
169 TryFinallyStatement* endfinally = enclosingtryfinally; 192 TryFinallyStatement* endfinally = enclosingtryfinally;
170 while(endfinally != NULL && endfinally != target->statement->enclosingtryfinally) { 193 while(endfinally != NULL && endfinally != lblstmt->enclosingtryfinally) {
171 endfinally = endfinally->enclosingtryfinally; 194 endfinally = endfinally->enclosingtryfinally;
172 } 195 }
173 196
174 // error if didn't find tf statement of label 197 // error if didn't find tf statement of label
175 if(endfinally != target->statement->enclosingtryfinally) 198 if(endfinally != lblstmt->enclosingtryfinally)
176 error("cannot goto into try block", loc->toChars()); 199 error("cannot goto into try block", loc->toChars());
177 200
178 // emit code for finallys between goto and label 201 // emit code for finallys between goto and label
179 DtoFinallyBlocks(enclosingtryfinally, endfinally); 202 DtoFinallyBlocks(enclosingtryfinally, endfinally);
180 203
181 llvm::BranchInst::Create(target->statement->llvmBB, gIR->scopebb()); 204 llvm::BranchInst::Create(lblstmt->llvmBB, gIR->scopebb());
182 } 205 }
183 206
184 /****************************************************************************************/ 207 /****************************************************************************************/
185 /*//////////////////////////////////////////////////////////////////////////////////////// 208 /*////////////////////////////////////////////////////////////////////////////////////////
186 // TRY FINALLY HELPER 209 // TRY FINALLY HELPER