Add a GHC.Debug module, with debugLn :: [Char] -> IO ()
authorIan Lynagh <igloo@earth.li>
Sat, 20 Jun 2009 16:13:57 +0000 (16:13 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 20 Jun 2009 16:13:57 +0000 (16:13 +0000)
GHC/Debug.hs [new file with mode: 0644]
cbits/debug.c [new file with mode: 0644]
ghc-prim.cabal

diff --git a/GHC/Debug.hs b/GHC/Debug.hs
new file mode 100644 (file)
index 0000000..30efc40
--- /dev/null
@@ -0,0 +1,31 @@
+
+module GHC.Debug (debugLn) where
+
+import GHC.Prim
+import GHC.Types
+import GHC.Unit
+
+debugLn :: [Char] -> IO ()
+debugLn xs = IO (\s0 ->
+                 -- Start with 1 so that we have space to put in a \0 at
+                 -- the end
+                 case len 1# xs of
+                 l ->
+                     case newByteArray# l s0 of
+                     (# s1, mba #) ->
+                         case write mba 0# xs s1 of
+                         s2 ->
+                             case c_debugLn mba of
+                             IO f -> f s2)
+    where len l [] = l
+          len l (_ : xs') = len (l +# 1#) xs'
+
+          write mba offset [] s = writeCharArray# mba offset '\0'# s
+          write mba offset (C# x : xs') s
+              = case writeCharArray# mba offset x s of
+                s' ->
+                    write mba (offset +# 1#) xs' s'
+
+foreign import ccall unsafe "debugLn"
+    c_debugLn :: MutableByteArray# RealWorld -> IO ()
+
diff --git a/cbits/debug.c b/cbits/debug.c
new file mode 100644 (file)
index 0000000..ff34c5a
--- /dev/null
@@ -0,0 +1,6 @@
+
+#include <stdio.h>
+
+void debugLn(char *s) {
+    printf("%s\n", s);
+}
index de9fd20..4300ad8 100644 (file)
@@ -23,6 +23,7 @@ Library {
     build-depends: rts
     exposed-modules:
         GHC.Bool
+        GHC.Debug
         GHC.Generics
         GHC.Ordering
         GHC.PrimopWrappers
@@ -37,6 +38,7 @@ Library {
     }
 
     c-sources:
+        cbits/debug.c
         cbits/longlong.c
     extensions: CPP, MagicHash, ForeignFunctionInterface, UnliftedFFITypes,
                 UnboxedTuples, EmptyDataDecls, NoImplicitPrelude