{-# LANGUAGE CPP #-}

module Clash.Debug
  ( debugIsOn
  , traceIf
  , traceWith
  , traceShowWith
  , module Debug.Trace
  ) where

import Debug.Trace

debugIsOn :: Bool
#if defined(DEBUG)
debugIsOn :: Bool
debugIsOn = Bool
True
#else
debugIsOn = False
#endif

-- | Performs trace when first argument evaluates to 'True'
traceIf :: Bool -> String -> a -> a
traceIf :: Bool -> String -> a -> a
traceIf Bool
True  String
msg = String -> a -> a
forall a. String -> a -> a
trace String
msg
traceIf Bool
False String
_   = a -> a
forall a. a -> a
id
{-# INLINE traceIf #-}

traceWith :: (a -> String) -> a -> a
traceWith :: (a -> String) -> a -> a
traceWith a -> String
f a
a = String -> a -> a
forall a. String -> a -> a
trace (a -> String
f a
a) a
a

traceShowWith :: Show b => (a -> b) -> a -> a
traceShowWith :: (a -> b) -> a -> a
traceShowWith a -> b
f a
a = String -> a -> a
forall a. String -> a -> a
trace (b -> String
forall a. Show a => a -> String
show (a -> b
f a
a)) a
a