changeset 237:a168a2c3ea48 trunk

[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed. Tried adding a stack trace print when compiler crashes, not sure it's working though. Changed data layouts to match that of llvm-gcc. Fixed casting function pointers. Added support checks in AsmStatement.
author lindquist
date Sun, 08 Jun 2008 19:09:24 +0200
parents df1abfe27be6
children 346cba22f4b8
files dmd/mars.c dmd/mars.h gen/asmstmt.cpp gen/tollvm.cpp llvmdc.kdevelop.filelist premake.lua tango/lib/common/tango/core/Thread.d tango/lib/common/tango/llvmdc.mak tango/lib/compiler/llvmdc/adi.d tango/lib/compiler/llvmdc/lifetime.d tango/lib/compiler/llvmdc/llvmdc.mak tango/lib/gc/basic/gcbits.d tango/lib/gc/basic/llvmdc.mak tango/lib/gc/stub/llvmdc.mak
diffstat 14 files changed, 85 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mars.c	Sun Jun 08 18:20:48 2008 +0200
+++ b/dmd/mars.c	Sun Jun 08 19:09:24 2008 +0200
@@ -8,6 +8,7 @@
 // See the included readme.txt for details.
 
 #include "llvm/Target/TargetMachineRegistry.h"
+#include "llvm/System/Signals.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -180,6 +181,7 @@
   -debuglib=name    set symbolic debug library to name\n\
   -defaultlib=name  set default library to name\n\
   -dis           disassemble module after compiling\n\
+  -fp80          enable 80bit reals on x86 32bit (EXPERIMENTAL)\n\
   -g             add symbolic debug info\n\
   -gc            add symbolic debug info, pretend to be C\n\
   -H             generate 'header' file\n\
@@ -193,6 +195,7 @@
   -Llinkerflag   pass linkerflag to link\n\
   -m<arch>       emit code specific to <arch>\n\
                  x86 x86-64 ppc32 ppc64\n\
+  -noasm         do not allow use of inline asm\n\
   -nofloat       do not emit reference to floating point\n\
   -noruntime     do not allow code that generates implicit runtime calls\n\
   -noverify      do not run the validation pass before writing bitcode\n\
@@ -215,10 +218,6 @@
   -version=level compile in version code >= level\n\
   -version=ident compile in version code identified by ident\n\
   -w             enable warnings\n\
-\n\
-Experimental features:\n\
-  -inlineasm     allow use of inline asm\n\
-  -fp80          enable 80bit reals on x86 32bit\n\
 ",
 #if WIN32
 "  @cmdfile       read arguments from cmdfile\n"
@@ -230,6 +229,8 @@
 
 int main(int argc, char *argv[])
 {
+    llvm::sys::PrintStackTraceOnErrorSignal();
+
     int i;
     Array files;
     char *p;
@@ -300,6 +301,7 @@
     global.params.novalidate = 0;
     global.params.optimizeLevel = -1;
     global.params.runtimeImppath = 0;
+    global.params.useInlineAsm = 1;
 
     global.params.defaultlibname = "phobos";
     global.params.debuglibname = global.params.defaultlibname;
@@ -402,8 +404,8 @@
             global.params.llvmAnnotate = 1;
         else if (strcmp(p + 1, "fp80") == 0)
             global.params.useFP80 = 1;
-        else if (strcmp(p + 1, "inlineasm") == 0)
-            global.params.useInlineAsm = 1;
+        else if (strcmp(p + 1, "noasm") == 0)
+            global.params.useInlineAsm = 0;
 	    else if (p[1] == 'o')
 	    {
 		switch (p[2])
@@ -710,31 +712,36 @@
         //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86");
         global.params.isLE = true;
         global.params.is64bit = false;
+        global.params.cpu = ARCHx86;
         tt_arch = "i686";
-        data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
+        data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64";
         is_x86 = true;
+        
     }
     else if (strcmp(global.params.llvmArch,"x86-64")==0) {
         VersionCondition::addPredefinedGlobalIdent("X86_64");
         //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64");
         global.params.isLE = true;
         global.params.is64bit = true;
+        global.params.cpu = ARCHx86_64;
         tt_arch = "x86_64";
-        data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
+        data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else if (strcmp(global.params.llvmArch,"ppc32")==0) {
         VersionCondition::addPredefinedGlobalIdent("PPC");
         global.params.isLE = false;
         global.params.is64bit = false;
+        global.params.cpu = ARCHppc;
         tt_arch = "powerpc";
-        data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:8";
+        data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else if (strcmp(global.params.llvmArch,"ppc64")==0) {
         VersionCondition::addPredefinedGlobalIdent("PPC64");
         global.params.isLE = false;
         global.params.is64bit = true;
+        global.params.cpu = ARCHppc_64;
         tt_arch = "powerpc64";
-        data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:8";
+        data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else {
         assert(0 && "Invalid arch");
@@ -755,15 +762,14 @@
         VersionCondition::addPredefinedGlobalIdent("LLVM64");
     }
 
-    if (!is_x86 && (global.params.useFP80 || global.params.useInlineAsm)) {
-        error("the -fp80 option is only valid for the x86 32bit architecture");
-        fatal();
-    }
-
     if (global.params.useFP80) {
+        if (!is_x86) {
+            error("the -fp80 option is only valid for the x86 32bit architecture");
+            fatal();
+        }
         VersionCondition::addPredefinedGlobalIdent("LLVM_X86_FP80");
     }
-    if (global.params.useInlineAsm) {
+    if (is_x86 && global.params.useInlineAsm) {
         VersionCondition::addPredefinedGlobalIdent("D_InlineAsm");
         VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
     }
--- a/dmd/mars.h	Sun Jun 08 18:20:48 2008 +0200
+++ b/dmd/mars.h	Sun Jun 08 19:09:24 2008 +0200
@@ -291,6 +291,14 @@
     MATCHexact		// exact match
 };
 
+enum ARCH
+{
+    ARCHx86,
+    ARCHx86_64,
+    ARCHppc,
+    ARCHppc_64
+};
+
 void error(Loc loc, const char *format, ...);
 void verror(Loc loc, const char *format, va_list);
 void fatal();
--- a/gen/asmstmt.cpp	Sun Jun 08 18:20:48 2008 +0200
+++ b/gen/asmstmt.cpp	Sun Jun 08 19:09:24 2008 +0200
@@ -198,7 +198,20 @@
 
 Statement *AsmStatement::semantic(Scope *sc)
 {
-    
+    bool err = false;
+    if (global.params.cpu != ARCHx86)
+    {
+        error("inline asm is not supported for the \"%s\" architecture", global.params.llvmArch);
+        err = true;
+    }
+    if (!global.params.useInlineAsm)
+    {
+        error("inline asm is not allowed when the -noasm switch is used");
+        err = true;
+    }
+    if (err)
+        fatal();
+
     sc->func->inlineAsm = 1;
     sc->func->inlineStatus = ILSno; // %% not sure
     // %% need to set DECL_UNINLINABLE too?
@@ -262,8 +275,6 @@
 	LLValue* arg_val = 0;
 	std::string cns;
 
-std::cout << std::endl;
-
 	switch (arg->type) {
 	case Arg_Integer:
 	    arg_val = arg->expr->toElem(irs)->getRVal();
@@ -379,7 +390,7 @@
 	++p;
     }
 
-    printf("final: %.*s\n", code->insnTemplateLen, code->insnTemplate);
+    Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate);
 
     std::string insnt(code->insnTemplate, code->insnTemplateLen);
 
--- a/gen/tollvm.cpp	Sun Jun 08 18:20:48 2008 +0200
+++ b/gen/tollvm.cpp	Sun Jun 08 19:09:24 2008 +0200
@@ -1117,7 +1117,7 @@
 
     Type* totype = DtoDType(to);
     Type* fromtype = DtoDType(val->getType());
-    assert(fromtype->ty == Tpointer);
+    assert(fromtype->ty == Tpointer || fromtype->ty == Tfunction);
 
     LLValue* rval;
 
@@ -1256,7 +1256,7 @@
     else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
         return DtoCastArray(val, to);
     }
-    else if (fromtype->ty == Tpointer) {
+    else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) {
         return DtoCastPtr(val, to);
     }
     else {
--- a/llvmdc.kdevelop.filelist	Sun Jun 08 18:20:48 2008 +0200
+++ b/llvmdc.kdevelop.filelist	Sun Jun 08 19:09:24 2008 +0200
@@ -118,6 +118,7 @@
 gen/functions.h
 gen/irstate.cpp
 gen/irstate.h
+gen/linker.h
 gen/llvm.h
 gen/logger.cpp
 gen/logger.h
@@ -749,6 +750,7 @@
 tangotests/aa1.d
 tangotests/aa2.d
 tangotests/align1.d
+tangotests/apply1.d
 tangotests/arrays1.d
 tangotests/asm1.d
 tangotests/asm2.d
--- a/premake.lua	Sun Jun 08 18:20:48 2008 +0200
+++ b/premake.lua	Sun Jun 08 19:09:24 2008 +0200
@@ -26,7 +26,7 @@
 package.buildoptions = { "-x c++", "`llvm-config --cxxflags`" }
 package.linkoptions = {
     -- long but it's faster than just 'all'
-    "`llvm-config --libs core asmparser bitreader bitwriter support target transformutils scalaropts ipo instrumentation x86 powerpc`",
+    "`llvm-config --libs core asmparser bitreader bitwriter linker support target transformutils scalaropts ipo instrumentation x86 powerpc`",
     "`llvm-config --ldflags`",
 }
 package.defines = {
--- a/tango/lib/common/tango/core/Thread.d	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/common/tango/core/Thread.d	Sun Jun 08 19:09:24 2008 +0200
@@ -2260,7 +2260,10 @@
 {
     version( D_InlineAsm_X86 )
     {
-        version( X86_64 )
+        version( LLVMDC )
+        {
+        }
+        else version( X86_64 )
         {
 
         }
--- a/tango/lib/common/tango/llvmdc.mak	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/common/tango/llvmdc.mak	Sun Jun 08 19:09:24 2008 +0200
@@ -22,14 +22,14 @@
 ADD_CFLAGS=
 ADD_DFLAGS=
 
-#CFLAGS=-O $(ADD_CFLAGS)
+#CFLAGS=-O3 $(ADD_CFLAGS)
 CFLAGS=-g $(ADD_CFLAGS)
 
-#DFLAGS=-release -O -inline -w $(ADD_DFLAGS)
-DFLAGS=-g -w $(ADD_DFLAGS)
+#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
+DFLAGS=-g -w -noasm $(ADD_DFLAGS)
 
-#TFLAGS=-O -inline -w $(ADD_DFLAGS)
-TFLAGS=-g -w $(ADD_DFLAGS)
+#TFLAGS=-O3 -inline -w $(ADD_DFLAGS)
+TFLAGS=-g -w -noasm $(ADD_DFLAGS)
 
 DOCFLAGS=-version=DDoc
 
--- a/tango/lib/compiler/llvmdc/adi.d	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/compiler/llvmdc/adi.d	Sun Jun 08 19:09:24 2008 +0200
@@ -473,7 +473,11 @@
 
 extern (C) int _adCmpChar(Array a1, Array a2)
 {
-  version (D_InlineAsm_X86)
+  version(D_InlineAsm_X86)
+  {
+  //version = Asm86;
+  }
+  version (Asm86)
   {
     asm
     {   naked                   ;
--- a/tango/lib/compiler/llvmdc/lifetime.d	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/compiler/llvmdc/lifetime.d	Sun Jun 08 19:09:24 2008 +0200
@@ -29,6 +29,9 @@
 //debug=PRINTF;
 //debug=PRINTF2;
 
+// we're not allowed to jump out of asm blocks
+//version(D_InlineAsm_X86) version = Asm86;
+
 private
 {
     import tango.stdc.stdlib;
@@ -210,7 +213,7 @@
     if (length == 0 || size == 0)
         return null;
 
-    version (D_InlineAsm_X86)
+    version (Asm86)
     {
         asm
         {
@@ -249,7 +252,7 @@
         auto initializer = ti.next.init();
         auto isize = initializer.length;
         auto q = initializer.ptr;
-        version (D_InlineAsm_X86)
+        version (Asm86)
         {
             asm
             {
@@ -520,7 +523,7 @@
 
     if (newlength)
     {
-        version (D_InlineAsm_X86)
+        version (Asm86)
         {
             size_t newsize = void;
 
@@ -619,7 +622,7 @@
 
     if (newlength)
     {
-        version (D_InlineAsm_X86)
+        version (Asm86)
         {
             size_t newsize = void;
 
--- a/tango/lib/compiler/llvmdc/llvmdc.mak	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/compiler/llvmdc/llvmdc.mak	Sun Jun 08 19:09:24 2008 +0200
@@ -24,10 +24,10 @@
 CFLAGS=-g $(ADD_CFLAGS)
 
 #DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
-DFLAGS=-g -w $(ADD_DFLAGS)
+DFLAGS=-g -w -noasm $(ADD_DFLAGS)
 
 #TFLAGS=-O3 -inline -w $(ADD_DFLAGS)
-TFLAGS=-g -w $(ADD_DFLAGS)
+TFLAGS=-g -w -noasm $(ADD_DFLAGS)
 
 DOCFLAGS=-version=DDoc
 
--- a/tango/lib/gc/basic/gcbits.d	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/gc/basic/gcbits.d	Sun Jun 08 19:09:24 2008 +0200
@@ -39,6 +39,10 @@
 {
     // use the unoptimized version
 }
+else version(LLVMDC)
+{
+    // ditto
+}
 else version (D_InlineAsm_X86)
 {
     version = Asm86;
--- a/tango/lib/gc/basic/llvmdc.mak	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/gc/basic/llvmdc.mak	Sun Jun 08 19:09:24 2008 +0200
@@ -20,14 +20,14 @@
 ADD_CFLAGS=
 ADD_DFLAGS=
 
-#CFLAGS=-O $(ADD_CFLAGS)
+#CFLAGS=-O3 $(ADD_CFLAGS)
 CFLAGS=-g $(ADD_CFLAGS)
 
-#DFLAGS=-release -O -inline -w -nofloat $(ADD_DFLAGS)
-DFLAGS=-g -w -nofloat $(ADD_DFLAGS)
+#DFLAGS=-release -O3 -inline -w -nofloat $(ADD_DFLAGS)
+DFLAGS=-g -w -nofloat -noasm $(ADD_DFLAGS)
 
-TFLAGS=-O -inline -w -nofloat $(ADD_DFLAGS)
-#TFLAGS=-g -w -nofloat $(ADD_DFLAGS)
+#TFLAGS=-O3 -inline -w -nofloat $(ADD_DFLAGS)
+TFLAGS=-g -w -nofloat -noasm $(ADD_DFLAGS)
 
 DOCFLAGS=-version=DDoc
 
--- a/tango/lib/gc/stub/llvmdc.mak	Sun Jun 08 18:20:48 2008 +0200
+++ b/tango/lib/gc/stub/llvmdc.mak	Sun Jun 08 19:09:24 2008 +0200
@@ -20,15 +20,13 @@
 ADD_CFLAGS=
 ADD_DFLAGS=
 
-#CFLAGS=-O $(ADD_CFLAGS)
+#CFLAGS=-O3 $(ADD_CFLAGS)
 CFLAGS=-g $(ADD_CFLAGS)
 
-### warnings disabled because gcx has issues ###
-
-#DFLAGS=-release -O -inline $(ADD_DFLAGS)
+#DFLAGS=-release -O3 -inline -w $(ADD_DFLAGS)
 DFLAGS=-g $(ADD_DFLAGS)
 
-#TFLAGS=-O -inline $(ADD_DFLAGS)
+#TFLAGS=-O3 -inline $(ADD_DFLAGS)
 TFLAGS=-g $(ADD_DFLAGS)
 
 DOCFLAGS=-version=DDoc