{-# LANGUAGE CPP #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
module Clash.Magic
(
prefixName
, suffixName
, suffixNameP
, suffixNameFromNat
, suffixNameFromNatP
, setName
, nameHint
, deDup
, noDeDup
, clashSimulation
, SimOnly (..)
, clashCompileError
) where
import Data.String.Interpolate (__i)
import GHC.Magic (noinline)
import GHC.Stack (HasCallStack, withFrozenCallStack)
import Clash.NamedTypes ((:::))
import GHC.TypeLits (Nat,Symbol)
import Clash.Promoted.Symbol (SSymbol)
import Clash.Annotations.Primitive (Primitive(..), hasBlackBox)
prefixName
:: forall (name :: Symbol) a . a -> name ::: a
prefixName :: a -> a
prefixName = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE prefixName #-}
suffixName
:: forall (name :: Symbol) a . a -> name ::: a
suffixName :: a -> a
suffixName = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE suffixName #-}
suffixNameFromNat
:: forall (name :: Nat) a . a -> name ::: a
suffixNameFromNat :: a -> a
suffixNameFromNat = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE suffixNameFromNat #-}
suffixNameP
:: forall (name :: Symbol) a . a -> name ::: a
suffixNameP :: a -> a
suffixNameP = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE suffixNameP #-}
suffixNameFromNatP
:: forall (name :: Nat) a . a -> name ::: a
suffixNameFromNatP :: a -> a
suffixNameFromNatP = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE suffixNameFromNatP #-}
setName
:: forall (name :: Symbol) a . a -> name ::: a
setName :: a -> a
setName = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE setName #-}
nameHint
:: SSymbol sym
-> a -> a
nameHint :: SSymbol sym -> a -> a
nameHint = SSymbol sym -> a -> a
seq
{-# CLASH_OPAQUE nameHint #-}
{-# ANN nameHint hasBlackBox #-}
deDup
:: forall a . a -> a
deDup :: a -> a
deDup = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE deDup #-}
noDeDup
:: forall a . a -> a
noDeDup :: a -> a
noDeDup = a -> a
forall a. a -> a
id
{-# CLASH_OPAQUE noDeDup #-}
clashSimulation :: Bool
clashSimulation :: Bool
clashSimulation = Bool -> Bool
forall a. a -> a
noinline Bool
True
{-# CLASH_OPAQUE clashSimulation #-}
data SimOnly a = SimOnly a
deriving (SimOnly a -> SimOnly a -> Bool
(SimOnly a -> SimOnly a -> Bool)
-> (SimOnly a -> SimOnly a -> Bool) -> Eq (SimOnly a)
forall a. Eq a => SimOnly a -> SimOnly a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimOnly a -> SimOnly a -> Bool
$c/= :: forall a. Eq a => SimOnly a -> SimOnly a -> Bool
== :: SimOnly a -> SimOnly a -> Bool
$c== :: forall a. Eq a => SimOnly a -> SimOnly a -> Bool
Eq, Eq (SimOnly a)
Eq (SimOnly a)
-> (SimOnly a -> SimOnly a -> Ordering)
-> (SimOnly a -> SimOnly a -> Bool)
-> (SimOnly a -> SimOnly a -> Bool)
-> (SimOnly a -> SimOnly a -> Bool)
-> (SimOnly a -> SimOnly a -> Bool)
-> (SimOnly a -> SimOnly a -> SimOnly a)
-> (SimOnly a -> SimOnly a -> SimOnly a)
-> Ord (SimOnly a)
SimOnly a -> SimOnly a -> Bool
SimOnly a -> SimOnly a -> Ordering
SimOnly a -> SimOnly a -> SimOnly a
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
forall a. Ord a => Eq (SimOnly a)
forall a. Ord a => SimOnly a -> SimOnly a -> Bool
forall a. Ord a => SimOnly a -> SimOnly a -> Ordering
forall a. Ord a => SimOnly a -> SimOnly a -> SimOnly a
min :: SimOnly a -> SimOnly a -> SimOnly a
$cmin :: forall a. Ord a => SimOnly a -> SimOnly a -> SimOnly a
max :: SimOnly a -> SimOnly a -> SimOnly a
$cmax :: forall a. Ord a => SimOnly a -> SimOnly a -> SimOnly a
>= :: SimOnly a -> SimOnly a -> Bool
$c>= :: forall a. Ord a => SimOnly a -> SimOnly a -> Bool
> :: SimOnly a -> SimOnly a -> Bool
$c> :: forall a. Ord a => SimOnly a -> SimOnly a -> Bool
<= :: SimOnly a -> SimOnly a -> Bool
$c<= :: forall a. Ord a => SimOnly a -> SimOnly a -> Bool
< :: SimOnly a -> SimOnly a -> Bool
$c< :: forall a. Ord a => SimOnly a -> SimOnly a -> Bool
compare :: SimOnly a -> SimOnly a -> Ordering
$ccompare :: forall a. Ord a => SimOnly a -> SimOnly a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (SimOnly a)
Ord, SimOnly a -> Bool
(a -> m) -> SimOnly a -> m
(a -> b -> b) -> b -> SimOnly a -> b
(forall m. Monoid m => SimOnly m -> m)
-> (forall m a. Monoid m => (a -> m) -> SimOnly a -> m)
-> (forall m a. Monoid m => (a -> m) -> SimOnly a -> m)
-> (forall a b. (a -> b -> b) -> b -> SimOnly a -> b)
-> (forall a b. (a -> b -> b) -> b -> SimOnly a -> b)
-> (forall b a. (b -> a -> b) -> b -> SimOnly a -> b)
-> (forall b a. (b -> a -> b) -> b -> SimOnly a -> b)
-> (forall a. (a -> a -> a) -> SimOnly a -> a)
-> (forall a. (a -> a -> a) -> SimOnly a -> a)
-> (forall a. SimOnly a -> [a])
-> (forall a. SimOnly a -> Bool)
-> (forall a. SimOnly a -> Int)
-> (forall a. Eq a => a -> SimOnly a -> Bool)
-> (forall a. Ord a => SimOnly a -> a)
-> (forall a. Ord a => SimOnly a -> a)
-> (forall a. Num a => SimOnly a -> a)
-> (forall a. Num a => SimOnly a -> a)
-> Foldable SimOnly
forall a. Eq a => a -> SimOnly a -> Bool
forall a. Num a => SimOnly a -> a
forall a. Ord a => SimOnly a -> a
forall m. Monoid m => SimOnly m -> m
forall a. SimOnly a -> Bool
forall a. SimOnly a -> Int
forall a. SimOnly a -> [a]
forall a. (a -> a -> a) -> SimOnly a -> a
forall m a. Monoid m => (a -> m) -> SimOnly a -> m
forall b a. (b -> a -> b) -> b -> SimOnly a -> b
forall a b. (a -> b -> b) -> b -> SimOnly 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 :: SimOnly a -> a
$cproduct :: forall a. Num a => SimOnly a -> a
sum :: SimOnly a -> a
$csum :: forall a. Num a => SimOnly a -> a
minimum :: SimOnly a -> a
$cminimum :: forall a. Ord a => SimOnly a -> a
maximum :: SimOnly a -> a
$cmaximum :: forall a. Ord a => SimOnly a -> a
elem :: a -> SimOnly a -> Bool
$celem :: forall a. Eq a => a -> SimOnly a -> Bool
length :: SimOnly a -> Int
$clength :: forall a. SimOnly a -> Int
null :: SimOnly a -> Bool
$cnull :: forall a. SimOnly a -> Bool
toList :: SimOnly a -> [a]
$ctoList :: forall a. SimOnly a -> [a]
foldl1 :: (a -> a -> a) -> SimOnly a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> SimOnly a -> a
foldr1 :: (a -> a -> a) -> SimOnly a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> SimOnly a -> a
foldl' :: (b -> a -> b) -> b -> SimOnly a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> SimOnly a -> b
foldl :: (b -> a -> b) -> b -> SimOnly a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> SimOnly a -> b
foldr' :: (a -> b -> b) -> b -> SimOnly a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> SimOnly a -> b
foldr :: (a -> b -> b) -> b -> SimOnly a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> SimOnly a -> b
foldMap' :: (a -> m) -> SimOnly a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> SimOnly a -> m
foldMap :: (a -> m) -> SimOnly a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> SimOnly a -> m
fold :: SimOnly m -> m
$cfold :: forall m. Monoid m => SimOnly m -> m
Foldable, Functor SimOnly
Foldable SimOnly
Functor SimOnly
-> Foldable SimOnly
-> (forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> SimOnly a -> f (SimOnly b))
-> (forall (f :: Type -> Type) a.
Applicative f =>
SimOnly (f a) -> f (SimOnly a))
-> (forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> SimOnly a -> m (SimOnly b))
-> (forall (m :: Type -> Type) a.
Monad m =>
SimOnly (m a) -> m (SimOnly a))
-> Traversable SimOnly
(a -> f b) -> SimOnly a -> f (SimOnly 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 =>
SimOnly (m a) -> m (SimOnly a)
forall (f :: Type -> Type) a.
Applicative f =>
SimOnly (f a) -> f (SimOnly a)
forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> SimOnly a -> m (SimOnly b)
forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> SimOnly a -> f (SimOnly b)
sequence :: SimOnly (m a) -> m (SimOnly a)
$csequence :: forall (m :: Type -> Type) a.
Monad m =>
SimOnly (m a) -> m (SimOnly a)
mapM :: (a -> m b) -> SimOnly a -> m (SimOnly b)
$cmapM :: forall (m :: Type -> Type) a b.
Monad m =>
(a -> m b) -> SimOnly a -> m (SimOnly b)
sequenceA :: SimOnly (f a) -> f (SimOnly a)
$csequenceA :: forall (f :: Type -> Type) a.
Applicative f =>
SimOnly (f a) -> f (SimOnly a)
traverse :: (a -> f b) -> SimOnly a -> f (SimOnly b)
$ctraverse :: forall (f :: Type -> Type) a b.
Applicative f =>
(a -> f b) -> SimOnly a -> f (SimOnly b)
$cp2Traversable :: Foldable SimOnly
$cp1Traversable :: Functor SimOnly
Traversable)
{-# ANN SimOnly hasBlackBox #-}
instance Functor SimOnly where
fmap :: (a -> b) -> SimOnly a -> SimOnly b
fmap a -> b
f (SimOnly a
a) = b -> SimOnly b
forall a. a -> SimOnly a
SimOnly (a -> b
f a
a)
instance Applicative SimOnly where
pure :: a -> SimOnly a
pure = a -> SimOnly a
forall a. a -> SimOnly a
SimOnly
(SimOnly a -> b
f) <*> :: SimOnly (a -> b) -> SimOnly a -> SimOnly b
<*> (SimOnly a
a) = b -> SimOnly b
forall a. a -> SimOnly a
SimOnly (a -> b
f a
a)
instance Monad SimOnly where
(SimOnly a
a) >>= :: SimOnly a -> (a -> SimOnly b) -> SimOnly b
>>= a -> SimOnly b
f = a -> SimOnly b
f a
a
instance Semigroup a => Semigroup (SimOnly a) where
(SimOnly a
a) <> :: SimOnly a -> SimOnly a -> SimOnly a
<> (SimOnly a
b) = a -> SimOnly a
forall a. a -> SimOnly a
SimOnly (a
a a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
b)
instance Monoid a => Monoid (SimOnly a) where
mempty :: SimOnly a
mempty = a -> SimOnly a
forall a. a -> SimOnly a
SimOnly a
forall a. Monoid a => a
mempty
clashCompileError :: forall a . HasCallStack => String -> a
clashCompileError :: String -> a
clashCompileError String
msg = (HasCallStack => a) -> a
forall a. HasCallStack => (HasCallStack => a) -> a
withFrozenCallStack ((HasCallStack => a) -> a) -> (HasCallStack => a) -> a
forall a b. (a -> b) -> a -> b
$ String -> a
forall a. HasCallStack => String -> a
error String
msg
{-# CLASH_OPAQUE clashCompileError #-}
{-# ANN clashCompileError (
let primName = 'clashCompileError
in InlineYamlPrimitive [minBound..] [__i|
BlackBoxHaskell:
name: #{primName}
templateFunction: Clash.Primitives.Magic.clashCompileErrorBBF
|]) #-}