X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FDebug.hs;h=7acd3cd34abc3270d15f57a5f7aa7a06b731db1a;hb=dc7082de1fff3158da5682d683502128b5f6cc0b;hp=c03bfcc74316014f3f4fdc2d9d413bc3de5da046;hpb=08cb32d77e6427a2e1bac5d9c10de4f2b26f523c;p=mate.git diff --git a/Mate/Debug.hs b/Mate/Debug.hs index c03bfcc..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 [] - -printfFake :: String -> (VarArgsFake t) => t -printfFake _ = varFake [] - - --- see counterpart at `debug.h' -#ifndef DBG_JIT -printfJit :: String -> (VarArgsFake t) => t -printfJit = printfFake -#endif - -#ifndef DBG_BB -printfBb :: String -> (VarArgsFake t) => t -printfBb = printfFake -#endif - -#ifndef DBG_MP -printfMp :: String -> (VarArgsFake t) => t -printfMp = printfFake -#endif - -#ifndef DBG_CP -printfCp :: String -> (VarArgsFake t) => t -printfCp = printfFake -#endif - -#ifndef DBG_STR -printfStr :: String -> (VarArgsFake t) => t -printfStr = printfFake -#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: "