X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FDebug.hs;h=7acd3cd34abc3270d15f57a5f7aa7a06b731db1a;hb=dc7082de1fff3158da5682d683502128b5f6cc0b;hp=b5ee6896cd1c07bc513be8af6b59fe8d4c060a18;hpb=8d1996a73234eed84ba68dae7ef09b4faec2a7ea;p=mate.git diff --git a/Mate/Debug.hs b/Mate/Debug.hs index b5ee689..7acd3cd 100644 --- a/Mate/Debug.hs +++ b/Mate/Debug.hs @@ -1,47 +1,45 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" -module Mate.Debug where - -{- we cannot use `PrintfType' from Text.Printf, as it isn't exported. - - so we implement a `VarArgsFake' here. - - http://www.haskell.org/haskellwiki/Varargs -} -class VarArgsFake t where - varFake :: [String] -> t - -instance VarArgsFake (IO a) where - varFake _ = return undefined - -instance (Show a, VarArgsFake r) => VarArgsFake (a -> r) where - varFake _ = \_ -> varFake [] - -printf_fake :: String -> (VarArgsFake t) => t -printf_fake _ = varFake [] - - --- see counterpart at `debug.h' -#ifndef DBG_JIT -printf_jit :: String -> (VarArgsFake t) => t -printf_jit = printf_fake -#endif - -#ifndef DBG_BB -printf_bb :: String -> (VarArgsFake t) => t -printf_bb = printf_fake -#endif - -#ifndef DBG_MP -printf_mp :: String -> (VarArgsFake t) => t -printf_mp = printf_fake -#endif - -#ifndef DBG_CP -printf_cp :: String -> (VarArgsFake t) => t -printf_cp = printf_fake -#endif - -#ifndef DBG_STR -printf_str :: String -> (VarArgsFake t) => t -printf_str = printf_fake -#endif +module Mate.Debug + ( printfJit + , printfBb + , printfMp + , printfCp + , printfStr + , printfInfo + , mateDEBUG + , printf -- TODO: delete me + ) where + +import Text.Printf +import System.IO +import System.IO.Unsafe + + +{-# NOINLINE logHandle #-} +-- TODO(bernhard): use MVar if threaded +logHandle :: Handle +logHandle = unsafePerformIO $ openFile "mate.log" WriteMode + +{-# INLINE mateDEBUG #-} +mateDEBUG :: Bool +mateDEBUG = False + +{-# INLINE printString #-} +printString :: String -> String -> IO () +printString prefix str = if mateDEBUG + then hPutStr logHandle . (++) prefix $ str + else return () + + +printfJit, printfBb, printfMp, printfCp, printfStr, printfInfo :: String -> IO () +{- +-- TODO(bernhard): +-- http://stackoverflow.com/questions/12123082/function-composition-with-text-printf-printf +-} +printfJit = printString "Jit: " +printfBb = printString "Bb: " +printfMp = printString "Mp: " +printfCp = printString "Cp: " +printfStr = printString "Str: " +printfInfo = printString "Info: "