dc8954eb84cb4eb184842209aa46a3c654d5deec
[mate.git] / Mate / Debug.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 #include "debug.h"
4
5 module Mate.Debug where
6
7 {- we cannot use `PrintfType' from Text.Printf, as it isn't exported.
8  - so we implement a `VarArgsFake' here.
9  - http://www.haskell.org/haskellwiki/Varargs -}
10 class VarArgsFake t where
11   varFake :: [String] -> t
12
13 instance VarArgsFake (IO a) where
14   varFake _ = return undefined
15
16 instance (Show a, VarArgsFake r) => VarArgsFake (a -> r) where
17   varFake _ _ = varFake []
18
19 -- note: with -O2 GHC is able to completely optimize away such a `printfFake' call
20 printfFake :: String -> (VarArgsFake t) => t
21 printfFake _ = varFake []
22
23
24 -- see counterpart at `debug.h'
25 #ifndef DBG_JIT
26 printfJit :: String -> (VarArgsFake t) => t
27 printfJit = printfFake
28 #endif
29
30 #ifndef DBG_BB
31 printfBb :: String -> (VarArgsFake t) => t
32 printfBb = printfFake
33 #endif
34
35 #ifndef DBG_MP
36 printfMp :: String -> (VarArgsFake t) => t
37 printfMp = printfFake
38 #endif
39
40 #ifndef DBG_CP
41 printfCp :: String -> (VarArgsFake t) => t
42 printfCp = printfFake
43 #endif
44
45 #ifndef DBG_STR
46 printfStr :: String -> (VarArgsFake t) => t
47 printfStr = printfFake
48 #endif