{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
module PlutusTx.Trace (
  trace,
  traceError,
  traceIfFalse,
  traceIfTrue,
  traceBool
  ) where

import PlutusTx.Bool
import PlutusTx.Builtins as Builtins

{-# INLINABLE traceError #-}
-- | Log a message and then terminate the evaluation with an error.
traceError :: Builtins.BuiltinString -> a
traceError :: BuiltinString -> a
traceError BuiltinString
str = () -> a
forall a. () -> a
error (BuiltinString -> () -> ()
forall a. BuiltinString -> a -> a
trace BuiltinString
str ())

{-# INLINABLE traceIfFalse #-}
-- | Emit the given 'BuiltinString' only if the argument evaluates to 'False'.
traceIfFalse :: Builtins.BuiltinString -> Bool -> Bool
traceIfFalse :: BuiltinString -> Bool -> Bool
traceIfFalse BuiltinString
str Bool
a = if Bool
a then Bool
True else BuiltinString -> Bool -> Bool
forall a. BuiltinString -> a -> a
trace BuiltinString
str Bool
False

{-# INLINABLE traceIfTrue #-}
-- | Emit the given 'BuiltinString' only if the argument evaluates to 'True'.
traceIfTrue :: Builtins.BuiltinString -> Bool -> Bool
traceIfTrue :: BuiltinString -> Bool -> Bool
traceIfTrue BuiltinString
str Bool
a = if Bool
a then BuiltinString -> Bool -> Bool
forall a. BuiltinString -> a -> a
trace BuiltinString
str Bool
True else Bool
False

{-# INLINABLE traceBool #-}
-- | Emit one of two 'BuiltinString' depending on whether or not the argument
-- evaluates to 'True' or 'False'.
traceBool :: BuiltinString -> BuiltinString -> Bool -> Bool
traceBool :: BuiltinString -> BuiltinString -> Bool -> Bool
traceBool BuiltinString
trueLabel BuiltinString
falseLabel Bool
c = if Bool
c then BuiltinString -> Bool -> Bool
forall a. BuiltinString -> a -> a
trace BuiltinString
trueLabel Bool
True else BuiltinString -> Bool -> Bool
forall a. BuiltinString -> a -> a
trace BuiltinString
falseLabel Bool
False