From a19a1b386c04d9a33348dedbd72f58798fdac10b Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Sat, 20 Jun 2009 16:13:57 +0000 Subject: [PATCH] Add a GHC.Debug module, with debugLn :: [Char] -> IO () --- GHC/Debug.hs | 31 +++++++++++++++++++++++++++++++ cbits/debug.c | 6 ++++++ ghc-prim.cabal | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 GHC/Debug.hs create mode 100644 cbits/debug.c diff --git a/GHC/Debug.hs b/GHC/Debug.hs new file mode 100644 index 0000000..30efc40 --- /dev/null +++ b/GHC/Debug.hs @@ -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 index 0000000..ff34c5a --- /dev/null +++ b/cbits/debug.c @@ -0,0 +1,6 @@ + +#include + +void debugLn(char *s) { + printf("%s\n", s); +} diff --git a/ghc-prim.cabal b/ghc-prim.cabal index de9fd20..4300ad8 100644 --- a/ghc-prim.cabal +++ b/ghc-prim.cabal @@ -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 -- 1.7.10.4