view runtime/ldc2.diff @ 766:af04bbae8553

D2: Fixed global constants not initialized until module constructor.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 12 Nov 2008 05:40:31 +0100
parents 9a9f403ab399
children eb1ce70ee01c
line wrap: on
line source

Index: src/common/core/bitmanip.d
===================================================================
--- src/common/core/bitmanip.d	(revision 46)
+++ src/common/core/bitmanip.d	(working copy)
@@ -171,6 +171,10 @@
      */
     uint outpl( uint port_address, uint value );
 }
+else version( LDC )
+{
+    public import ldc.bitmanip;
+}
 else
 {
     public import std.intrinsic;
Index: src/common/core/thread.d
===================================================================
--- src/common/core/thread.d	(revision 46)
+++ src/common/core/thread.d	(working copy)
@@ -275,8 +275,50 @@
         }
         body
         {
-            version( D_InlineAsm_X86 )
+            version( LDC )
             {
+                version(X86)
+                {
+                    uint eax,ecx,edx,ebx,ebp,esi,edi;
+                    asm
+                    {
+                        mov eax[EBP], EAX ;
+                        mov ecx[EBP], ECX ;
+                        mov edx[EBP], EDX ;
+                        mov ebx[EBP], EBX ;
+                        mov ebp[EBP], EBP ;
+                        mov esi[EBP], ESI ;
+                        mov edi[EBP], EDI ;
+                    }
+                }
+                else version (X86_64)
+                {
+                    ulong rax,rbx,rcx,rdx,rbp,rsi,rdi,rsp,r10,r11,r12,r13,r14,r15;
+                    asm
+                    {
+                        movq rax[RBP], RAX ;
+                        movq rbx[RBP], RBX ;
+                        movq rcx[RBP], RCX ;
+                        movq rdx[RBP], RDX ;
+                        movq rbp[RBP], RBP ;
+                        movq rsi[RBP], RSI ;
+                        movq rdi[RBP], RDI ;
+                        movq rsp[RBP], RSP ;
+                        movq r10[RBP], R10 ;
+                        movq r11[RBP], R11 ;
+                        movq r12[RBP], R12 ;
+                        movq r13[RBP], R13 ;
+                        movq r14[RBP], R14 ;
+                        movq r15[RBP], R15 ;
+                    }
+                }
+                else
+                {
+                    static assert( false, "Architecture not supported." );
+                }
+            }
+            else version( D_InlineAsm_X86 )
+            {
                 asm
                 {
                     pushad;
@@ -328,8 +370,12 @@
                 }
             }
 
-            version( D_InlineAsm_X86 )
+            version( LDC )
             {
+                // nothing to pop
+            }
+            else version( D_InlineAsm_X86 )
+            {
                 asm
                 {
                     popad;
@@ -717,7 +763,7 @@
      * represents the minimum valid priority for the scheduling policy of
      * the process.
      */
-    static const int PRIORITY_MIN;
+    static int PRIORITY_MIN;
 
 
     /**
@@ -726,7 +772,7 @@
      * represents the minimum valid priority for the scheduling policy of
      * the process.
      */
-    static const int PRIORITY_MAX;
+    static int PRIORITY_MAX;
 
 
     /**
@@ -2259,6 +2305,18 @@
             version = AsmPPC_Posix;
     }
 
+    version( LLVM_InlineAsm_X86 )
+    {
+        version( Win32 )
+            version = LLVM_AsmX86_Win32;
+        else version( Posix )
+            version = LLVM_AsmX86_Posix;
+    }
+    else version( LLVM_InlineAsm_X86_64 )
+    {
+        version( Posix )
+            version = LLVM_AsmX86_64_Posix;
+    }
 
     version( Posix )
     {
@@ -2269,6 +2327,10 @@
         version( AsmX86_Win32 ) {} else
         version( AsmX86_Posix ) {} else
         version( AsmPPC_Posix ) {} else
+        version( LLVM_AsmX86_Win32 ) {} else
+        version( LLVM_AsmX86_Posix ) {} else
+        //TODO: Enable when x86-64 Posix supports fibers
+        //version( LLVM_AsmX86_64_Posix ) {} else
         {
             // NOTE: The ucontext implementation requires architecture specific
             //       data definitions to operate so testing for it must be done
@@ -2279,10 +2341,9 @@
             import core.sys.posix.ucontext;
         }
     }
-
-    const size_t PAGESIZE;
 }
 
+const size_t PAGESIZE;
 
 static this()
 {
@@ -2423,6 +2484,28 @@
                 ret;
             }
         }
+        else version( LLVM_AsmX86_Posix )
+        {
+            asm
+            {
+                // clobber registers to save
+                inc EBX;
+                inc ESI;
+                inc EDI;
+
+                // store oldp again with more acc
+                mov EAX, oldp;
+                mov [EAX], ESP;
+                // load newp to begin context swi
+                mov ESP, newp;
+            }
+        }
+/+
+        version( LLVM_AsmX86_64_Posix )
+        {
+            //TODO: Fiber implementation here
+        }
++/
         else static if( is( ucontext_t ) )
         {
             Fiber   cfib = Fiber.getThis();
@@ -3088,6 +3171,22 @@
             push( 0x00000000 );                                     // ESI
             push( 0x00000000 );                                     // EDI
         }
+        else version( LLVM_AsmX86_Posix )
+        {
+            push( cast(size_t) &fiber_entryPoint );                 // EIP
+            push( 0x00000000 );                                     // newp
+            push( 0x00000000 );                                     // oldp
+            push( 0x00000000 );                                     // EBP
+            push( 0x00000000 );                                     // EBX
+            push( 0x00000000 );                                     // ESI
+            push( 0x00000000 );                                     // EDI
+        }
+//TODO: Implement x86-64 fibers
+/+
+        else version( LLVM_AsmX86_Posix )
+        {
+        }
++/
         else version( AsmPPC_Posix )
         {
             version( StackGrowsDown )
Index: src/gc/basic/gcx.d
===================================================================
--- src/gc/basic/gcx.d	(revision 46)
+++ src/gc/basic/gcx.d	(working copy)
@@ -55,7 +55,11 @@
 private import cstdlib = core.stdc.stdlib : calloc, free, malloc, realloc;
 private import core.stdc.string;
 
-debug private import core.stdc.stdio;
+debug(PRINTF)
+{
+    private import core.sys.posix.pthread;
+    private import core.stdc.stdio;
+}
 
 version (GNU)
 {
@@ -66,6 +70,12 @@
     private import gcc.builtins; // for __builtin_unwind_init
 }
 
+struct BlkInfo
+{
+    void*  base;
+    size_t size;
+    uint   attr;
+}
 
 private
 {
@@ -77,13 +87,6 @@
         ALL_BITS = 0b1111_1111
     }
 
-    struct BlkInfo
-    {
-        void*  base;
-        size_t size;
-        uint   attr;
-    }
-
     extern (C) void* rt_stackBottom();
     extern (C) void* rt_stackTop();
 
@@ -1468,7 +1471,7 @@
     void initialize()
     {   int dummy;
 
-        (cast(byte*)&this)[0 .. Gcx.sizeof] = 0;
+        (cast(byte*)this)[0 .. Gcx.sizeof] = 0;
         stackBottom = cast(char*)&dummy;
         log_init();
         debug (THREADINVARIANT)
Index: import/object.di
===================================================================
--- import/object.di	(revision 46)
+++ import/object.di	(working copy)
@@ -208,6 +208,13 @@
     void function() dtor;
     void function() unitTest;
 
+    // DMD actually has them too, but LDC doesn't allow the resulting type mismatch
+    version( LDC )
+    {
+        void* xgetMembers;
+        void function() ictor;
+    }
+
     static int opApply(int delegate(inout ModuleInfo));
 }
 
Index: import/core/stdc/stdarg.d
===================================================================
--- import/core/stdc/stdarg.d	(revision 46)
+++ import/core/stdc/stdarg.d	(working copy)
@@ -9,8 +9,12 @@
 module core.stdc.stdarg;
 
 
-version( GNU )
+version( LDC )
 {
+    public import ldc.cstdarg;
+}
+else version( GNU )
+{
     public import std.c.stdarg;
 }
 else
Index: import/core/bitmanip.di
===================================================================
--- import/core/bitmanip.di	(revision 46)
+++ import/core/bitmanip.di	(working copy)
@@ -171,6 +171,10 @@
      */
     uint outpl( uint port_address, uint value );
 }
+else version( LDC )
+{
+    public import ldc.bitmanip;
+}
 else
 {
     public import std.intrinsic;