{-|
Copyright  :  (C) 2019, Myrtle Software Ltd
License    :  BSD2 (see the file LICENSE)
Maintainer :  QBayLogic B.V. <devops@qbaylogic.com>

Verification
-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}

#if __GLASGOW_HASKELL__ < 806
{-# LANGUAGE TypeInType #-}
#endif

module Clash.Verification.Internal
 ( AssertionResult(..)
 , Property(..)
 , Assertion(..)
 , RenderAs(..)
 , IsTemporal(..)
 , AssertionValue(toAssertionValue)
 , Assertion'(..)
 , Property'(..)
 , toTemporal
 , isTemporal
 , assertion
 )
 where

import           Data.Text                      (Text)

import Clash.Annotations.BitRepresentation
  (ConstrRepr(..), DataReprAnn(..), liftQ)
import           Clash.Signal.Internal          (Domain, Signal)

-- | Render target for HDL
data RenderAs
  = PSL
  -- ^ Property Specification Language
  | SVA
  -- ^ SystemVerilog Assertions
  | AutoRenderAs
  -- ^ Use SVA for SystemVerilog, PSL for others
  deriving (Int -> RenderAs -> ShowS
[RenderAs] -> ShowS
RenderAs -> String
(Int -> RenderAs -> ShowS)
-> (RenderAs -> String) -> ([RenderAs] -> ShowS) -> Show RenderAs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RenderAs] -> ShowS
$cshowList :: [RenderAs] -> ShowS
show :: RenderAs -> String
$cshow :: RenderAs -> String
showsPrec :: Int -> RenderAs -> ShowS
$cshowsPrec :: Int -> RenderAs -> ShowS
Show, RenderAs -> RenderAs -> Bool
(RenderAs -> RenderAs -> Bool)
-> (RenderAs -> RenderAs -> Bool) -> Eq RenderAs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RenderAs -> RenderAs -> Bool
$c/= :: RenderAs -> RenderAs -> Bool
== :: RenderAs -> RenderAs -> Bool
$c== :: RenderAs -> RenderAs -> Bool
Eq)

data IsTemporal
  = IsNotTemporal
  | IsTemporal
  deriving (IsTemporal -> IsTemporal -> Bool
(IsTemporal -> IsTemporal -> Bool)
-> (IsTemporal -> IsTemporal -> Bool) -> Eq IsTemporal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IsTemporal -> IsTemporal -> Bool
$c/= :: IsTemporal -> IsTemporal -> Bool
== :: IsTemporal -> IsTemporal -> Bool
$c== :: IsTemporal -> IsTemporal -> Bool
Eq, Eq IsTemporal
Eq IsTemporal
-> (IsTemporal -> IsTemporal -> Ordering)
-> (IsTemporal -> IsTemporal -> Bool)
-> (IsTemporal -> IsTemporal -> Bool)
-> (IsTemporal -> IsTemporal -> Bool)
-> (IsTemporal -> IsTemporal -> Bool)
-> (IsTemporal -> IsTemporal -> IsTemporal)
-> (IsTemporal -> IsTemporal -> IsTemporal)
-> Ord IsTemporal
IsTemporal -> IsTemporal -> Bool
IsTemporal -> IsTemporal -> Ordering
IsTemporal -> IsTemporal -> IsTemporal
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IsTemporal -> IsTemporal -> IsTemporal
$cmin :: IsTemporal -> IsTemporal -> IsTemporal
max :: IsTemporal -> IsTemporal -> IsTemporal
$cmax :: IsTemporal -> IsTemporal -> IsTemporal
>= :: IsTemporal -> IsTemporal -> Bool
$c>= :: IsTemporal -> IsTemporal -> Bool
> :: IsTemporal -> IsTemporal -> Bool
$c> :: IsTemporal -> IsTemporal -> Bool
<= :: IsTemporal -> IsTemporal -> Bool
$c<= :: IsTemporal -> IsTemporal -> Bool
< :: IsTemporal -> IsTemporal -> Bool
$c< :: IsTemporal -> IsTemporal -> Bool
compare :: IsTemporal -> IsTemporal -> Ordering
$ccompare :: IsTemporal -> IsTemporal -> Ordering
$cp1Ord :: Eq IsTemporal
Ord)

-- | Internal version of 'Assertion'.
data Assertion' a
  = CvPure a
  -- ^ (Bootstrapping) signal of booleans
  | CvToTemporal (Assertion' a)
  -- ^ Tag to force a non-temporal assertion to a temporal one
  | CvLit Bool
  -- ^ Boolean literal

  | CvNot (Assertion' a)
  -- ^ Logical not
  | CvAnd (Assertion' a) (Assertion' a)
  -- ^ Logical and
  | CvOr (Assertion' a) (Assertion' a)
  -- ^ Logical or
  | CvImplies (Assertion' a) (Assertion' a)
  -- ^ Logical implies

  | CvNext Word (Assertion' a)
  -- ^ Moves start point of assertion /n/ cycles forward
  | CvBefore (Assertion' a) (Assertion' a)
  -- ^ Before @CvBefore a b@ is the same as @CvAnd a (CvNext 1 b)@
  | CvTemporalImplies Word (Assertion' a) (Assertion' a)
  -- ^ Temporal implies @CvTemporalImplies n a b@:
  --
  --   n | n == 0    -> same as @CvImplies a b@
  --     | otherwise -> same as @CvImplies a (CvNextN n b)@
  --
  | CvAlways (Assertion' a)
  -- ^ Assertion should _always_ hold
  | CvNever (Assertion' a)
  -- ^ Assertion should _never_ hold (not supported by SVA)
  deriving (Int -> Assertion' a -> ShowS
[Assertion' a] -> ShowS
Assertion' a -> String
(Int -> Assertion' a -> ShowS)
-> (Assertion' a -> String)
-> ([Assertion' a] -> ShowS)
-> Show (Assertion' a)
forall a. Show a => Int -> Assertion' a -> ShowS
forall a. Show a => [Assertion' a] -> ShowS
forall a. Show a => Assertion' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Assertion' a] -> ShowS
$cshowList :: forall a. Show a => [Assertion' a] -> ShowS
show :: Assertion' a -> String
$cshow :: forall a. Show a => Assertion' a -> String
showsPrec :: Int -> Assertion' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Assertion' a -> ShowS
Show, a -> Assertion' b -> Assertion' a
(a -> b) -> Assertion' a -> Assertion' b
(forall a b. (a -> b) -> Assertion' a -> Assertion' b)
-> (forall a b. a -> Assertion' b -> Assertion' a)
-> Functor Assertion'
forall a b. a -> Assertion' b -> Assertion' a
forall a b. (a -> b) -> Assertion' a -> Assertion' b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Assertion' b -> Assertion' a
$c<$ :: forall a b. a -> Assertion' b -> Assertion' a
fmap :: (a -> b) -> Assertion' a -> Assertion' b
$cfmap :: forall a b. (a -> b) -> Assertion' a -> Assertion' b
Functor, Assertion' a -> Bool
(a -> m) -> Assertion' a -> m
(a -> b -> b) -> b -> Assertion' a -> b
(forall m. Monoid m => Assertion' m -> m)
-> (forall m a. Monoid m => (a -> m) -> Assertion' a -> m)
-> (forall m a. Monoid m => (a -> m) -> Assertion' a -> m)
-> (forall a b. (a -> b -> b) -> b -> Assertion' a -> b)
-> (forall a b. (a -> b -> b) -> b -> Assertion' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Assertion' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Assertion' a -> b)
-> (forall a. (a -> a -> a) -> Assertion' a -> a)
-> (forall a. (a -> a -> a) -> Assertion' a -> a)
-> (forall a. Assertion' a -> [a])
-> (forall a. Assertion' a -> Bool)
-> (forall a. Assertion' a -> Int)
-> (forall a. Eq a => a -> Assertion' a -> Bool)
-> (forall a. Ord a => Assertion' a -> a)
-> (forall a. Ord a => Assertion' a -> a)
-> (forall a. Num a => Assertion' a -> a)
-> (forall a. Num a => Assertion' a -> a)
-> Foldable Assertion'
forall a. Eq a => a -> Assertion' a -> Bool
forall a. Num a => Assertion' a -> a
forall a. Ord a => Assertion' a -> a
forall m. Monoid m => Assertion' m -> m
forall a. Assertion' a -> Bool
forall a. Assertion' a -> Int
forall a. Assertion' a -> [a]
forall a. (a -> a -> a) -> Assertion' a -> a
forall m a. Monoid m => (a -> m) -> Assertion' a -> m
forall b a. (b -> a -> b) -> b -> Assertion' a -> b
forall a b. (a -> b -> b) -> b -> Assertion' a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Assertion' a -> a
$cproduct :: forall a. Num a => Assertion' a -> a
sum :: Assertion' a -> a
$csum :: forall a. Num a => Assertion' a -> a
minimum :: Assertion' a -> a
$cminimum :: forall a. Ord a => Assertion' a -> a
maximum :: Assertion' a -> a
$cmaximum :: forall a. Ord a => Assertion' a -> a
elem :: a -> Assertion' a -> Bool
$celem :: forall a. Eq a => a -> Assertion' a -> Bool
length :: Assertion' a -> Int
$clength :: forall a. Assertion' a -> Int
null :: Assertion' a -> Bool
$cnull :: forall a. Assertion' a -> Bool
toList :: Assertion' a -> [a]
$ctoList :: forall a. Assertion' a -> [a]
foldl1 :: (a -> a -> a) -> Assertion' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Assertion' a -> a
foldr1 :: (a -> a -> a) -> Assertion' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Assertion' a -> a
foldl' :: (b -> a -> b) -> b -> Assertion' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Assertion' a -> b
foldl :: (b -> a -> b) -> b -> Assertion' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Assertion' a -> b
foldr' :: (a -> b -> b) -> b -> Assertion' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Assertion' a -> b
foldr :: (a -> b -> b) -> b -> Assertion' a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Assertion' a -> b
foldMap' :: (a -> m) -> Assertion' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Assertion' a -> m
foldMap :: (a -> m) -> Assertion' a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Assertion' a -> m
fold :: Assertion' m -> m
$cfold :: forall m. Monoid m => Assertion' m -> m
Foldable, Functor Assertion'
Foldable Assertion'
Functor Assertion'
-> Foldable Assertion'
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> Assertion' a -> f (Assertion' b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    Assertion' (f a) -> f (Assertion' a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> Assertion' a -> m (Assertion' b))
-> (forall (m :: Type -> Type) a.
    Monad m =>
    Assertion' (m a) -> m (Assertion' a))
-> Traversable Assertion'
(a -> f b) -> Assertion' a -> f (Assertion' b)
forall (t :: Type -> Type).
Functor t
-> Foldable t
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a.
Monad m =>
Assertion' (m a) -> m (Assertion' a)
forall (f :: Type -> Type) a.
Applicative f =>
Assertion' (f a) -> f (Assertion' a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Assertion' a -> m (Assertion' b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Assertion' a -> f (Assertion' b)
sequence :: Assertion' (m a) -> m (Assertion' a)
$csequence :: forall (m :: Type -> Type) a.
Monad m =>
Assertion' (m a) -> m (Assertion' a)
mapM :: (a -> m b) -> Assertion' a -> m (Assertion' b)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Assertion' a -> m (Assertion' b)
sequenceA :: Assertion' (f a) -> f (Assertion' a)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
Assertion' (f a) -> f (Assertion' a)
traverse :: (a -> f b) -> Assertion' a -> f (Assertion' b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Assertion' a -> f (Assertion' b)
$cp2Traversable :: Foldable Assertion'
$cp1Traversable :: Functor Assertion'
Traversable)

-- | Internal version of 'Property'. All user facing will instantiate @a@
-- with @(Maybe Text, Signal dom Bool)@. Blackboxes will instantiate it with
-- @(Maybe Text, Term)@ instead.
data Property' a
  = CvAssert (Assertion' a)
  | CvCover (Assertion' a)
  deriving (Int -> Property' a -> ShowS
[Property' a] -> ShowS
Property' a -> String
(Int -> Property' a -> ShowS)
-> (Property' a -> String)
-> ([Property' a] -> ShowS)
-> Show (Property' a)
forall a. Show a => Int -> Property' a -> ShowS
forall a. Show a => [Property' a] -> ShowS
forall a. Show a => Property' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Property' a] -> ShowS
$cshowList :: forall a. Show a => [Property' a] -> ShowS
show :: Property' a -> String
$cshow :: forall a. Show a => Property' a -> String
showsPrec :: Int -> Property' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Property' a -> ShowS
Show, a -> Property' b -> Property' a
(a -> b) -> Property' a -> Property' b
(forall a b. (a -> b) -> Property' a -> Property' b)
-> (forall a b. a -> Property' b -> Property' a)
-> Functor Property'
forall a b. a -> Property' b -> Property' a
forall a b. (a -> b) -> Property' a -> Property' b
forall (f :: Type -> Type).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Property' b -> Property' a
$c<$ :: forall a b. a -> Property' b -> Property' a
fmap :: (a -> b) -> Property' a -> Property' b
$cfmap :: forall a b. (a -> b) -> Property' a -> Property' b
Functor, Property' a -> Bool
(a -> m) -> Property' a -> m
(a -> b -> b) -> b -> Property' a -> b
(forall m. Monoid m => Property' m -> m)
-> (forall m a. Monoid m => (a -> m) -> Property' a -> m)
-> (forall m a. Monoid m => (a -> m) -> Property' a -> m)
-> (forall a b. (a -> b -> b) -> b -> Property' a -> b)
-> (forall a b. (a -> b -> b) -> b -> Property' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Property' a -> b)
-> (forall b a. (b -> a -> b) -> b -> Property' a -> b)
-> (forall a. (a -> a -> a) -> Property' a -> a)
-> (forall a. (a -> a -> a) -> Property' a -> a)
-> (forall a. Property' a -> [a])
-> (forall a. Property' a -> Bool)
-> (forall a. Property' a -> Int)
-> (forall a. Eq a => a -> Property' a -> Bool)
-> (forall a. Ord a => Property' a -> a)
-> (forall a. Ord a => Property' a -> a)
-> (forall a. Num a => Property' a -> a)
-> (forall a. Num a => Property' a -> a)
-> Foldable Property'
forall a. Eq a => a -> Property' a -> Bool
forall a. Num a => Property' a -> a
forall a. Ord a => Property' a -> a
forall m. Monoid m => Property' m -> m
forall a. Property' a -> Bool
forall a. Property' a -> Int
forall a. Property' a -> [a]
forall a. (a -> a -> a) -> Property' a -> a
forall m a. Monoid m => (a -> m) -> Property' a -> m
forall b a. (b -> a -> b) -> b -> Property' a -> b
forall a b. (a -> b -> b) -> b -> Property' a -> b
forall (t :: Type -> Type).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Property' a -> a
$cproduct :: forall a. Num a => Property' a -> a
sum :: Property' a -> a
$csum :: forall a. Num a => Property' a -> a
minimum :: Property' a -> a
$cminimum :: forall a. Ord a => Property' a -> a
maximum :: Property' a -> a
$cmaximum :: forall a. Ord a => Property' a -> a
elem :: a -> Property' a -> Bool
$celem :: forall a. Eq a => a -> Property' a -> Bool
length :: Property' a -> Int
$clength :: forall a. Property' a -> Int
null :: Property' a -> Bool
$cnull :: forall a. Property' a -> Bool
toList :: Property' a -> [a]
$ctoList :: forall a. Property' a -> [a]
foldl1 :: (a -> a -> a) -> Property' a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Property' a -> a
foldr1 :: (a -> a -> a) -> Property' a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Property' a -> a
foldl' :: (b -> a -> b) -> b -> Property' a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Property' a -> b
foldl :: (b -> a -> b) -> b -> Property' a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Property' a -> b
foldr' :: (a -> b -> b) -> b -> Property' a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Property' a -> b
foldr :: (a -> b -> b) -> b -> Property' a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Property' a -> b
foldMap' :: (a -> m) -> Property' a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Property' a -> m
foldMap :: (a -> m) -> Property' a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Property' a -> m
fold :: Property' m -> m
$cfold :: forall m. Monoid m => Property' m -> m
Foldable, Functor Property'
Foldable Property'
Functor Property'
-> Foldable Property'
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> Property' a -> f (Property' b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    Property' (f a) -> f (Property' a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> Property' a -> m (Property' b))
-> (forall (m :: Type -> Type) a.
    Monad m =>
    Property' (m a) -> m (Property' a))
-> Traversable Property'
(a -> f b) -> Property' a -> f (Property' b)
forall (t :: Type -> Type).
Functor t
-> Foldable t
-> (forall (f :: Type -> Type) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: Type -> Type) a.
    Applicative f =>
    t (f a) -> f (t a))
-> (forall (m :: Type -> Type) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: Type -> Type) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: Type -> Type) a.
Monad m =>
Property' (m a) -> m (Property' a)
forall (f :: Type -> Type) a.
Applicative f =>
Property' (f a) -> f (Property' a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Property' a -> m (Property' b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Property' a -> f (Property' b)
sequence :: Property' (m a) -> m (Property' a)
$csequence :: forall (m :: Type -> Type) a.
Monad m =>
Property' (m a) -> m (Property' a)
mapM :: (a -> m b) -> Property' a -> m (Property' b)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> Property' a -> m (Property' b)
sequenceA :: Property' (f a) -> f (Property' a)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
Property' (f a) -> f (Property' a)
traverse :: (a -> f b) -> Property' a -> f (Property' b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> Property' a -> f (Property' b)
$cp2Traversable :: Foldable Property'
$cp1Traversable :: Functor Property'
Traversable)

data Assertion (dom :: Domain) =
  Assertion IsTemporal (Assertion' (Maybe Text, Signal dom Bool))

toTemporal :: Assertion dom -> Assertion' (Maybe Text, Signal dom Bool)
toTemporal :: Assertion dom -> Assertion' (Maybe Text, Signal dom Bool)
toTemporal (Assertion IsTemporal
IsTemporal Assertion' (Maybe Text, Signal dom Bool)
a) = Assertion' (Maybe Text, Signal dom Bool)
a
toTemporal (Assertion IsTemporal
IsNotTemporal Assertion' (Maybe Text, Signal dom Bool)
a) = Assertion' (Maybe Text, Signal dom Bool)
-> Assertion' (Maybe Text, Signal dom Bool)
forall a. Assertion' a -> Assertion' a
CvToTemporal Assertion' (Maybe Text, Signal dom Bool)
a
{-# INLINE toTemporal #-}

isTemporal :: Assertion dom -> IsTemporal
isTemporal :: Assertion dom -> IsTemporal
isTemporal (Assertion IsTemporal
it Assertion' (Maybe Text, Signal dom Bool)
_assert) = IsTemporal
it
{-# INLINE isTemporal #-}

assertion :: Assertion dom -> Assertion' (Maybe Text, Signal dom Bool)
assertion :: Assertion dom -> Assertion' (Maybe Text, Signal dom Bool)
assertion (Assertion IsTemporal
_it Assertion' (Maybe Text, Signal dom Bool)
assert) = Assertion' (Maybe Text, Signal dom Bool)
assert
{-# INLINE assertion #-}

-- | A property is a temporal or basic assertion that's specified to either
-- used as an _assert_ or _cover_ statement. See
-- 'Clash.Explicit.Verification.assert' and 'Clash.Explicit.Verification.cover'.
newtype Property (dom :: Domain) =
  Property (Property' (Maybe Text, Signal dom Bool))

-- | A result of some property. Besides carrying the actual boolean result, it
-- carries some properties used to make reports.
data AssertionResult = AssertionResult
  { AssertionResult -> String
cvPropName :: !String  -- I'd like text, but Clash complains :[
  -- ^ Name of property belonging to this result
  , AssertionResult -> Bool
cvPass :: !Bool
  -- ^ False whenever property is violated, True otherwise
  }
  deriving (AssertionResult -> AssertionResult -> Bool
(AssertionResult -> AssertionResult -> Bool)
-> (AssertionResult -> AssertionResult -> Bool)
-> Eq AssertionResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssertionResult -> AssertionResult -> Bool
$c/= :: AssertionResult -> AssertionResult -> Bool
== :: AssertionResult -> AssertionResult -> Bool
$c== :: AssertionResult -> AssertionResult -> Bool
Eq)
{-# ANN module (
  DataReprAnn
    $(liftQ [t| AssertionResult |])
    0
    [ ConstrRepr 'AssertionResult 0 0 [0b0, 0b0]
    ]) #-}
{- Marked as zero-width so Clash won't stumble on the fact it's unrepresentable. ^ -}

-- | An AssertionValue is a bool-like value or stream that can be used in
-- property specifications. Clash implements two: a stream of booleans
-- (Signal dom Bool), and the result of a property expression (Assertion
-- dom).
class AssertionValue dom a | a -> dom where
  -- | Convert given type into a Assertion.
  toAssertionValue :: a -> Assertion dom

-- | Stream of booleans, originating from a circuit
instance AssertionValue dom (Signal dom Bool) where
  toAssertionValue :: Signal dom Bool -> Assertion dom
toAssertionValue Signal dom Bool
s = IsTemporal
-> Assertion' (Maybe Text, Signal dom Bool) -> Assertion dom
forall (dom :: Domain).
IsTemporal
-> Assertion' (Maybe Text, Signal dom Bool) -> Assertion dom
Assertion IsTemporal
IsNotTemporal ((Maybe Text, Signal dom Bool)
-> Assertion' (Maybe Text, Signal dom Bool)
forall a. a -> Assertion' a
CvPure (Maybe Text
forall a. Maybe a
Nothing, Signal dom Bool
s))
  {-# INLINE toAssertionValue #-}

-- | Result of a property specification
instance AssertionValue dom (Assertion dom) where
  toAssertionValue :: Assertion dom -> Assertion dom
toAssertionValue = Assertion dom -> Assertion dom
forall a. a -> a
id
  {-# INLINE toAssertionValue #-}