changeset 304:3ebc136702dd trunk

[svn r325] Removed dead code. Added license info to code from GDC (David Friedman permitted us to use the files under the Artistic License). Added asmLabel check to DtoGoto to avoid jumping into inline asm. Doesn't work currently as LabelDsymbol::asmLabel is never set to true.
author ChristianK
date Wed, 25 Jun 2008 23:42:38 +0200
parents 4aa2b6753059
children 2b72433d5c8c
files dmd/statement.c dmd/statement.h gen/asmstmt.cpp gen/d-asm-i386.h gen/llvmhelpers.cpp gen/statements.cpp
diffstat 6 files changed, 12 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/statement.c	Wed Jun 25 20:42:30 2008 +0200
+++ b/dmd/statement.c	Wed Jun 25 23:42:38 2008 +0200
@@ -3605,7 +3605,7 @@
 	: Dsymbol(ident)
 {
     statement = NULL;
-    asmLabelNum = 0;
+    asmLabel = false;
 }
 
 LabelDsymbol *LabelDsymbol::isLabel()		// is this a LabelDsymbol()?
--- a/dmd/statement.h	Wed Jun 25 20:42:30 2008 +0200
+++ b/dmd/statement.h	Wed Jun 25 23:42:38 2008 +0200
@@ -767,7 +767,7 @@
 {
     LabelStatement *statement;
 // LLVMDC
-    unsigned asmLabelNum;       // for inline assembler labels
+    bool asmLabel;       // for labels inside inline assembler
 
     LabelDsymbol(Identifier *ident);
     LabelDsymbol *isLabel();
--- a/gen/asmstmt.cpp	Wed Jun 25 20:42:30 2008 +0200
+++ b/gen/asmstmt.cpp	Wed Jun 25 23:42:38 2008 +0200
@@ -1,6 +1,5 @@
-// Taken from GDC source tree, licence unclear?
-//
-// Taken from an earlier version of DMD -- why is it missing from 0.79?
+// Taken from GDC source tree. Original by David Friedman.
+// Released under the Artistic License found in dmd/artistic.txt
 
 #include "gen/llvm.h"
 #include "llvm/InlineAsm.h"
@@ -131,69 +130,6 @@
     return FALSE;
 }
 
-/* GCC does not support jumps from asm statements.  When optimization
-   is turned on, labels referenced only from asm statements will not
-   be output at the correct location.  There are ways around this:
-
-   1) Reference the label with a reachable goto statement
-   2) Have reachable computed goto in the function
-   3) Hack cfgbuild.c to act as though there is a computed goto.
-
-   These are all pretty bad, but if would be nice to be able to tell
-   GCC not to optimize in this case (even on per label/block basis).
-
-   The current solution is output our own private labels (as asm
-   statements) along with the "real" label.  If the label happens to
-   be referred to by a goto statement, the "real" label will also be
-   output in the correct location.
-
-   Also had to add 'asmLabelNum' to LabelDsymbol to indicate it needs
-   special processing.
-
-   (junk) d-lang.cc:916:case LABEL_DECL: // C doesn't do this.  D needs this for referencing labels in inline assembler since there may be not goto referencing it.
-
-*/
-
-static unsigned d_priv_asm_label_serial = 0;
-
-// may need to make this target-specific
-static void d_format_priv_asm_label(char * buf, unsigned n)
-{
-    //ASM_GENERATE_INTERNAL_LABEL(buf, "LDASM", n);//inserts a '*' for use with assemble_name
-    assert(0);
-    sprintf(buf, ".LDASM%u", n);
-}
-
-void
-d_expand_priv_asm_label(IRState * irs, unsigned n)
-{
-/*    char buf[64];
-    d_format_priv_asm_label(buf, n);
-    strcat(buf, ":");
-    tree insnt = build_string(strlen(buf), buf);
-#if D_GCC_VER < 40
-    expand_asm(insnt, 1);
-#else
-    tree t = d_build_asm_stmt(insnt, NULL_TREE, NULL_TREE, NULL_TREE);
-    ASM_VOLATILE_P( t ) = 1;
-    ASM_INPUT_P( t) = 1; // what is this doing?
-    irs->addExp(t);
-#endif*/
-}
-
-
-// StringExp::toIR usually adds a NULL.  We don't want that...
-
-/*static tree
-naturalString(Expression * e)
-{
-    // don't fail, just an error?
-    assert(e->op == TOKstring);
-    StringExp * s = (StringExp *) e;
-    assert(s->sz == 1);
-    return build_string(s->len, (char *) s->string);
-}*/
-
 
 #include "d-asm-i386.h"
 
--- a/gen/d-asm-i386.h	Wed Jun 25 20:42:30 2008 +0200
+++ b/gen/d-asm-i386.h	Wed Jun 25 23:42:38 2008 +0200
@@ -1,4 +1,5 @@
-// Taken from GDC source, GPL!
+// Taken from GDC source tree. Original by David Friedman.
+// Released under the Artistic License found in dmd/artistic.txt
 
 #include "dmd/id.h"
 
@@ -1418,16 +1419,7 @@
     asmcode->args.push( new AsmArg(type, e, mode) );
     }
 
-    void addLabel(unsigned n) {
-    // No longer taking the address of the actual label -- doesn't seem like it would help.
-    char buf[64];
-    
-    d_format_priv_asm_label(buf, n);
-    insnTemplate->writestring(buf);
-    }
-
     void addLabel(char* id) {
-    //insnTemplate->writestring(".LDASM_");
     insnTemplate->writestring(id);
     }
 
@@ -1906,15 +1898,10 @@
 			   the %an format must be used with the "p" constraint.
 			*/
 			if (isDollar(e)) {
-			    unsigned lbl_num = ++d_priv_asm_label_serial;
-			    addLabel(lbl_num);
-			    asmcode->dollarLabel = lbl_num; // could make the dollar label part of the same asm..
+			    error("dollar labels are not supported", stmt->loc.toChars());
+			    asmcode->dollarLabel = 1;
 			} else if (e->op == TOKdsymbol) {
 			    LabelDsymbol * lbl = (LabelDsymbol *) ((DsymbolExp *) e)->s;
-			    // this can probably be removed
-			    if (! lbl->asmLabelNum)
-				lbl->asmLabelNum = ++d_priv_asm_label_serial;
-
 			    stmt->isBranchToLabel = lbl;
 
 			    use_star = false;
--- a/gen/llvmhelpers.cpp	Wed Jun 25 20:42:30 2008 +0200
+++ b/gen/llvmhelpers.cpp	Wed Jun 25 23:42:38 2008 +0200
@@ -158,6 +158,10 @@
 {
     assert(!gIR->scopereturned());
 
+    // if the target label is inside inline asm, error
+    if(target->asmLabel)
+        error("cannot goto into inline asm block", loc->toChars());
+
     if (target->statement->llvmBB == NULL)
         target->statement->llvmBB = llvm::BasicBlock::Create("label", gIR->topfunc());
 
--- a/gen/statements.cpp	Wed Jun 25 20:42:30 2008 +0200
+++ b/gen/statements.cpp	Wed Jun 25 23:42:38 2008 +0200
@@ -1045,7 +1045,6 @@
     if (p->asmBlock)
     {
         IRAsmStmt* a = new IRAsmStmt;
-//        a->code = ".LDASM_";
         a->code += ident->toChars();
         a->code += ":";
         p->asmBlock->s.push_back(a);