diff 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
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Wed Jun 25 23:42:38 2008 +0200
+++ b/gen/llvmhelpers.cpp	Fri Jun 27 22:04:35 2008 +0200
@@ -152,33 +152,56 @@
 
 /****************************************************************************************/
 /*////////////////////////////////////////////////////////////////////////////////////////
+// LABEL HELPER
+////////////////////////////////////////////////////////////////////////////////////////*/
+LabelStatement* DtoLabelStatement(Identifier* ident)
+{
+    FuncDeclaration* fd = gIR->func()->decl;
+    FuncDeclaration::LabelMap::iterator iter = fd->labmap.find(ident->toChars());
+    if (iter == fd->labmap.end())
+    {
+        if (fd->returnLabel->ident->equals(ident))
+        {
+            assert(fd->returnLabel->statement);
+            return fd->returnLabel->statement;
+        }
+        return NULL;
+    }
+    return iter->second;
+}
+
+/****************************************************************************************/
+/*////////////////////////////////////////////////////////////////////////////////////////
 // GOTO HELPER
 ////////////////////////////////////////////////////////////////////////////////////////*/
-void DtoGoto(Loc* loc, LabelDsymbol* target, TryFinallyStatement* enclosingtryfinally)
+void DtoGoto(Loc* loc, Identifier* target, TryFinallyStatement* enclosingtryfinally)
 {
     assert(!gIR->scopereturned());
 
+    LabelStatement* lblstmt = DtoLabelStatement(target);
+    assert(lblstmt != NULL);
+
     // if the target label is inside inline asm, error
-    if(target->asmLabel)
+    if(lblstmt->asmLabel)
         error("cannot goto into inline asm block", loc->toChars());
 
-    if (target->statement->llvmBB == NULL)
-        target->statement->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc());
+    if (lblstmt->llvmBB == NULL)
+        lblstmt->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc());
 
     // find finallys between goto and label
     TryFinallyStatement* endfinally = enclosingtryfinally;
-    while(endfinally != NULL && endfinally != target->statement->enclosingtryfinally) {
+    while(endfinally != NULL && endfinally != lblstmt->enclosingtryfinally) {
         endfinally = endfinally->enclosingtryfinally;
     }
 
     // error if didn't find tf statement of label
-    if(endfinally != target->statement->enclosingtryfinally)
+    if(endfinally != lblstmt->enclosingtryfinally)
         error("cannot goto into try block", loc->toChars());
 
     // emit code for finallys between goto and label
     DtoFinallyBlocks(enclosingtryfinally, endfinally);
 
-    llvm::BranchInst::Create(target->statement->llvmBB, gIR->scopebb());
+    llvm::BranchInst::Create(lblstmt->llvmBB, gIR->scopebb());
 }
 
 /****************************************************************************************/