debug: remove #ifdef's and use dumb logger
[mate.git] / Mate / Debug.hs
1 {-# LANGUAGE OverloadedStrings #-}
2
3 module Mate.Debug
4   ( printfJit
5   , printfBb
6   , printfMp
7   , printfCp
8   , printfStr
9   , printfInfo
10   , mateDEBUG
11   , printf -- TODO: delete me
12   ) where
13
14 import Text.Printf
15 import System.IO
16 import System.IO.Unsafe
17
18
19 {-# NOINLINE logHandle #-}
20 -- TODO(bernhard): use MVar if threaded
21 logHandle :: Handle
22 logHandle = unsafePerformIO $ openFile "mate.log" WriteMode
23
24 {-# INLINE mateDEBUG #-}
25 mateDEBUG :: Bool
26 mateDEBUG = False
27
28 {-# INLINE printString #-}
29 printString :: String -> String -> IO ()
30 printString prefix str = if mateDEBUG
31   then hPutStr logHandle . (++) prefix $ str
32   else return ()
33
34
35 printfJit, printfBb, printfMp, printfCp, printfStr, printfInfo  :: String -> IO ()
36 {-
37 -- TODO(bernhard):
38 -- http://stackoverflow.com/questions/12123082/function-composition-with-text-printf-printf
39 -}
40 printfJit  = printString "Jit: "
41 printfBb   = printString "Bb: "
42 printfMp   = printString "Mp: "
43 printfCp   = printString "Cp: "
44 printfStr  = printString "Str: "
45 printfInfo = printString "Info: "