codegen: handle exceptions of a method
[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 import Control.Monad
18
19
20 {-# NOINLINE logHandle #-}
21 -- TODO(bernhard): use MVar if threaded
22 logHandle :: Handle
23 logHandle = unsafePerformIO $ openFile "mate.log" WriteMode
24
25 {-# INLINE mateDEBUG #-}
26 mateDEBUG :: Bool
27 mateDEBUG = False
28
29 {-# INLINE printString #-}
30 printString :: String -> String -> IO ()
31 printString prefix str = do
32   when mateDEBUG $ hPutStr logHandle . (++) prefix $ str
33   hFlush logHandle
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: "