{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Trustworthy #-}
-- | The Hyle IR: a pure, first-order, monomorphic, total language over
--   width-indexed bitvectors, plus a synchronous device construct (registers,
--   sequential-extern instances, parallel wire equations). The syntax and
--   semantics are specified in doc/hyle.md; this module is the AST and the
--   pretty printer for the concrete syntax (doc/hyle.md, section 10).
module ReWire.Hyle.Syntax
      ( Size, Index, Name, GId, Value
      , SizeAnnotated (..)
      , Op (..), opName, opResultSize
      , Exp (..)
      , Sig (..), Defn (..)
      , ExternKind (..), Extern (..), externResultSize
      , Register (..), Instance (..), Stmt (..), Device (..)
      , Program (..)
      , Blind (..)
      , nil, isNil, cat, gather
      , reservedWords
      ) where

import ReWire.Annotation (Annote, Annotated (ann), noAnn, annProv, Provenance (..), Span (..), Blind (..))
import ReWire.BitVector (BV (..), width, showHex')
import ReWire.Orphans ()
import ReWire.Pretty (text, Pretty (pretty), Doc, vsep, hsep, nest, parens, brackets, punctuate, dquotes, squote, align, (<+>), TextShow (showt), FromGeneric (..), comma, hcat)

import qualified ReWire.BitVector as BV

import Data.Char (isAlpha, isAlphaNum)
import Data.Data (Typeable, Data (..))
import Data.Hashable (Hashable)
import Data.HashSet (HashSet)
import Data.List (intersperse)
import Data.Text (Text)
import GHC.Generics (Generic)
import Numeric.Natural (Natural)

import qualified Data.HashSet as Set
import qualified Data.Text    as T

type Value = Integer
type Size  = Word
type Index = Word
type GId   = Text
type Name  = Text

class SizeAnnotated a where
      sizeOf :: a -> Size

---

-- | Primitive operations (doc/hyle.md, section 3.3). Static parameters
--   (target widths, replication counts) are part of the operator.
data Op = Add | Sub | Mul | UDiv | UMod | Pow
        | And | Or | XOr | Not
        | Shl | LShr | AShr
        | Eq | Ne | ULt | ULe | UGt | UGe | SLt | SLe | SGt | SGe
        | RedAnd | RedOr | RedXOr
        | ZExt !Size | SExt !Size | Trunc !Size
        | Rep !Natural
      deriving (Op -> Op -> Bool
(Op -> Op -> Bool) -> (Op -> Op -> Bool) -> Eq Op
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Op -> Op -> Bool
== :: Op -> Op -> Bool
$c/= :: Op -> Op -> Bool
/= :: Op -> Op -> Bool
Eq, Eq Op
Eq Op =>
(Op -> Op -> Ordering)
-> (Op -> Op -> Bool)
-> (Op -> Op -> Bool)
-> (Op -> Op -> Bool)
-> (Op -> Op -> Bool)
-> (Op -> Op -> Op)
-> (Op -> Op -> Op)
-> Ord Op
Op -> Op -> Bool
Op -> Op -> Ordering
Op -> Op -> Op
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
$ccompare :: Op -> Op -> Ordering
compare :: Op -> Op -> Ordering
$c< :: Op -> Op -> Bool
< :: Op -> Op -> Bool
$c<= :: Op -> Op -> Bool
<= :: Op -> Op -> Bool
$c> :: Op -> Op -> Bool
> :: Op -> Op -> Bool
$c>= :: Op -> Op -> Bool
>= :: Op -> Op -> Bool
$cmax :: Op -> Op -> Op
max :: Op -> Op -> Op
$cmin :: Op -> Op -> Op
min :: Op -> Op -> Op
Ord, (forall x. Op -> Rep Op x)
-> (forall x. Rep Op x -> Op) -> Generic Op
forall x. Rep Op x -> Op
forall x. Op -> Rep Op x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Op -> Rep Op x
from :: forall x. Op -> Rep Op x
$cto :: forall x. Rep Op x -> Op
to :: forall x. Rep Op x -> Op
Generic, Int -> Op -> ShowS
[Op] -> ShowS
Op -> String
(Int -> Op -> ShowS)
-> (Op -> String) -> ([Op] -> ShowS) -> Show Op
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Op -> ShowS
showsPrec :: Int -> Op -> ShowS
$cshow :: Op -> String
show :: Op -> String
$cshowList :: [Op] -> ShowS
showList :: [Op] -> ShowS
Show, Typeable, Typeable Op
Typeable Op =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Op -> c Op)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Op)
-> (Op -> Constr)
-> (Op -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Op))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Op))
-> ((forall b. Data b => b -> b) -> Op -> Op)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r)
-> (forall u. (forall d. Data d => d -> u) -> Op -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Op -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Op -> m Op)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Op -> m Op)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Op -> m Op)
-> Data Op
Op -> Constr
Op -> DataType
(forall b. Data b => b -> b) -> Op -> Op
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Op -> u
forall u. (forall d. Data d => d -> u) -> Op -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Op -> m Op
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Op -> m Op
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Op
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Op -> c Op
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Op)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Op)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Op -> c Op
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Op -> c Op
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Op
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Op
$ctoConstr :: Op -> Constr
toConstr :: Op -> Constr
$cdataTypeOf :: Op -> DataType
dataTypeOf :: Op -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Op)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Op)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Op)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Op)
$cgmapT :: (forall b. Data b => b -> b) -> Op -> Op
gmapT :: (forall b. Data b => b -> b) -> Op -> Op
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Op -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Op -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Op -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Op -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Op -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Op -> m Op
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Op -> m Op
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Op -> m Op
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Op -> m Op
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Op -> m Op
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Op -> m Op
Data)
      deriving Int -> Op -> Text
Int -> Op -> Text
Int -> Op -> Builder
[Op] -> Text
[Op] -> Text
[Op] -> Builder
Op -> Text
Op -> Text
Op -> Builder
(Int -> Op -> Builder)
-> (Op -> Builder)
-> ([Op] -> Builder)
-> (Int -> Op -> Text)
-> (Op -> Text)
-> ([Op] -> Text)
-> (Int -> Op -> Text)
-> (Op -> Text)
-> ([Op] -> Text)
-> TextShow Op
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Op -> Builder
showbPrec :: Int -> Op -> Builder
$cshowb :: Op -> Builder
showb :: Op -> Builder
$cshowbList :: [Op] -> Builder
showbList :: [Op] -> Builder
$cshowtPrec :: Int -> Op -> Text
showtPrec :: Int -> Op -> Text
$cshowt :: Op -> Text
showt :: Op -> Text
$cshowtList :: [Op] -> Text
showtList :: [Op] -> Text
$cshowtlPrec :: Int -> Op -> Text
showtlPrec :: Int -> Op -> Text
$cshowtl :: Op -> Text
showtl :: Op -> Text
$cshowtlList :: [Op] -> Text
showtlList :: [Op] -> Text
TextShow via FromGeneric Op

instance Hashable Op

-- | The operator name in the concrete syntax (static arguments printed
--   separately).
opName :: Op -> Text
opName :: Op -> Text
opName = \ case
      Op
Add     -> Text
"add"
      Op
Sub     -> Text
"sub"
      Op
Mul     -> Text
"mul"
      Op
UDiv    -> Text
"udiv"
      Op
UMod    -> Text
"umod"
      Op
Pow     -> Text
"pow"
      Op
And     -> Text
"and"
      Op
Or      -> Text
"or"
      Op
XOr     -> Text
"xor"
      Op
Not     -> Text
"not"
      Op
Shl     -> Text
"shl"
      Op
LShr    -> Text
"lshr"
      Op
AShr    -> Text
"ashr"
      Op
Eq      -> Text
"eq"
      Op
Ne      -> Text
"ne"
      Op
ULt     -> Text
"ult"
      Op
ULe     -> Text
"ule"
      Op
UGt     -> Text
"ugt"
      Op
UGe     -> Text
"uge"
      Op
SLt     -> Text
"slt"
      Op
SLe     -> Text
"sle"
      Op
SGt     -> Text
"sgt"
      Op
SGe     -> Text
"sge"
      Op
RedAnd  -> Text
"redand"
      Op
RedOr   -> Text
"redor"
      Op
RedXOr  -> Text
"redxor"
      ZExt Size
_  -> Text
"zext"
      SExt Size
_  -> Text
"sext"
      Trunc Size
_ -> Text
"trunc"
      Rep Natural
_   -> Text
"rep"

-- | The typing rule for each operator (doc/hyle.md, section 3.3): given the
--   operand widths, the result width, or Nothing if the operands are
--   ill-typed.
opResultSize :: Op -> [Size] -> Maybe Size
opResultSize :: Op -> [Size] -> Maybe Size
opResultSize Op
op [Size]
szs = case (Op
op, [Size]
szs) of
      (Op
Add        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Sub        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Mul        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
UDiv       , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
UMod       , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Pow        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
And        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Or         , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
XOr        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Not        , [Size
a])                       -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Shl        , [Size
a, Size
_])                    -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
LShr       , [Size
a, Size
_])                    -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
AShr       , [Size
a, Size
_])                    -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
a
      (Op
Eq         , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
Ne         , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
ULt        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
ULe        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
UGt        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
UGe        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
SLt        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
SLe        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
SGt        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
SGe        , [Size
a, Size
b]) | Size
a Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
b           -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
RedAnd     , [Size
_])                       -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
RedOr      , [Size
_])                       -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (Op
RedXOr     , [Size
_])                       -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
1
      (ZExt Size
m     , [Size
a]) | Size
a Size -> Size -> Bool
forall a. Ord a => a -> a -> Bool
<= Size
m              -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
m
      (SExt Size
m     , [Size
a]) | Size
a Size -> Size -> Bool
forall a. Ord a => a -> a -> Bool
>= Size
1, Size
a Size -> Size -> Bool
forall a. Ord a => a -> a -> Bool
<= Size
m      -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
m
      (Trunc Size
m    , [Size
a]) | Size
m Size -> Size -> Bool
forall a. Ord a => a -> a -> Bool
<= Size
a              -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Size
m
      (Rep Natural
k      , [Size
a])                       -> Size -> Maybe Size
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Size -> Maybe Size) -> Size -> Maybe Size
forall a b. (a -> b) -> a -> b
$ Natural -> Size
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
k Size -> Size -> Size
forall a. Num a => a -> a -> a
* Size
a
      (Op, [Size])
_                                        -> Maybe Size
forall a. Maybe a
Nothing

---

data Exp = Lit   Annote !BV
         | Undef Annote !Size
         | Var   Annote !Size !Name
         | Cat   Annote !Exp !Exp
         | Slice Annote !Index !Size !Exp         -- ^ e[offset +: width], LSB-indexed.
         | Prim  Annote !Size !Op ![Exp]
         | Call  Annote !Size !GId ![Exp]
         | XCall Annote !Size !Name ![Natural] ![Exp] -- ^ Combinational extern call with generic arguments.
         | If    Annote !Size !Exp !Exp !Exp
         | Let   Annote !Size !Name !Exp !Exp
      deriving (Eq Exp
Eq Exp =>
(Exp -> Exp -> Ordering)
-> (Exp -> Exp -> Bool)
-> (Exp -> Exp -> Bool)
-> (Exp -> Exp -> Bool)
-> (Exp -> Exp -> Bool)
-> (Exp -> Exp -> Exp)
-> (Exp -> Exp -> Exp)
-> Ord Exp
Exp -> Exp -> Bool
Exp -> Exp -> Ordering
Exp -> Exp -> Exp
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
$ccompare :: Exp -> Exp -> Ordering
compare :: Exp -> Exp -> Ordering
$c< :: Exp -> Exp -> Bool
< :: Exp -> Exp -> Bool
$c<= :: Exp -> Exp -> Bool
<= :: Exp -> Exp -> Bool
$c> :: Exp -> Exp -> Bool
> :: Exp -> Exp -> Bool
$c>= :: Exp -> Exp -> Bool
>= :: Exp -> Exp -> Bool
$cmax :: Exp -> Exp -> Exp
max :: Exp -> Exp -> Exp
$cmin :: Exp -> Exp -> Exp
min :: Exp -> Exp -> Exp
Ord, Int -> Exp -> ShowS
[Exp] -> ShowS
Exp -> String
(Int -> Exp -> ShowS)
-> (Exp -> String) -> ([Exp] -> ShowS) -> Show Exp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Exp -> ShowS
showsPrec :: Int -> Exp -> ShowS
$cshow :: Exp -> String
show :: Exp -> String
$cshowList :: [Exp] -> ShowS
showList :: [Exp] -> ShowS
Show, Typeable, Typeable Exp
Typeable Exp =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Exp -> c Exp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Exp)
-> (Exp -> Constr)
-> (Exp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Exp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Exp))
-> ((forall b. Data b => b -> b) -> Exp -> Exp)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r)
-> (forall u. (forall d. Data d => d -> u) -> Exp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Exp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Exp -> m Exp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Exp -> m Exp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Exp -> m Exp)
-> Data Exp
Exp -> Constr
Exp -> DataType
(forall b. Data b => b -> b) -> Exp -> Exp
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Exp -> u
forall u. (forall d. Data d => d -> u) -> Exp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Exp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Exp -> c Exp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Exp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Exp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Exp -> c Exp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Exp -> c Exp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Exp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Exp
$ctoConstr :: Exp -> Constr
toConstr :: Exp -> Constr
$cdataTypeOf :: Exp -> DataType
dataTypeOf :: Exp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Exp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Exp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Exp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Exp)
$cgmapT :: (forall b. Data b => b -> b) -> Exp -> Exp
gmapT :: (forall b. Data b => b -> b) -> Exp -> Exp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Exp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Exp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Exp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Exp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Exp -> m Exp
Data, (forall x. Exp -> Rep Exp x)
-> (forall x. Rep Exp x -> Exp) -> Generic Exp
forall x. Rep Exp x -> Exp
forall x. Exp -> Rep Exp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Exp -> Rep Exp x
from :: forall x. Exp -> Rep Exp x
$cto :: forall x. Rep Exp x -> Exp
to :: forall x. Rep Exp x -> Exp
Generic)
      deriving Int -> Exp -> Text
Int -> Exp -> Text
Int -> Exp -> Builder
[Exp] -> Text
[Exp] -> Text
[Exp] -> Builder
Exp -> Text
Exp -> Text
Exp -> Builder
(Int -> Exp -> Builder)
-> (Exp -> Builder)
-> ([Exp] -> Builder)
-> (Int -> Exp -> Text)
-> (Exp -> Text)
-> ([Exp] -> Text)
-> (Int -> Exp -> Text)
-> (Exp -> Text)
-> ([Exp] -> Text)
-> TextShow Exp
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Exp -> Builder
showbPrec :: Int -> Exp -> Builder
$cshowb :: Exp -> Builder
showb :: Exp -> Builder
$cshowbList :: [Exp] -> Builder
showbList :: [Exp] -> Builder
$cshowtPrec :: Int -> Exp -> Text
showtPrec :: Int -> Exp -> Text
$cshowt :: Exp -> Text
showt :: Exp -> Text
$cshowtList :: [Exp] -> Text
showtList :: [Exp] -> Text
$cshowtlPrec :: Int -> Exp -> Text
showtlPrec :: Int -> Exp -> Text
$cshowtl :: Exp -> Text
showtl :: Exp -> Text
$cshowtlList :: [Exp] -> Text
showtlList :: [Exp] -> Text
TextShow via FromGeneric Exp

instance Hashable Exp

instance Eq Exp where
      Lit   Annote
a BV
bv          == :: Exp -> Exp -> Bool
== Lit   Annote
a' BV
bv'            = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& BV
bv BV -> BV -> Bool
BV.==. BV
bv'
      Undef Annote
a Size
sz          == Undef Annote
a' Size
sz'            = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz'
      Var   Annote
a Size
sz Text
x        == Var   Annote
a' Size
sz' Text
x'         = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
x'
      Cat   Annote
a Exp
e1 Exp
e2       == Cat   Annote
a' Exp
e1' Exp
e2'        = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Exp
e1 Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e1' Bool -> Bool -> Bool
&& Exp
e2 Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e2'
      Slice Annote
a Size
i Size
k Exp
e       == Slice Annote
a' Size
i' Size
k' Exp
e'       = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
i Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
i' Bool -> Bool -> Bool
&& Size
k Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
k' Bool -> Bool -> Bool
&& Exp
e Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e'
      Prim  Annote
a Size
sz Op
op [Exp]
es    == Prim  Annote
a' Size
sz' Op
op' [Exp]
es'    = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Op
op Op -> Op -> Bool
forall a. Eq a => a -> a -> Bool
== Op
op' Bool -> Bool -> Bool
&& [Exp]
es [Exp] -> [Exp] -> Bool
forall a. Eq a => a -> a -> Bool
== [Exp]
es'
      Call  Annote
a Size
sz Text
g [Exp]
es     == Call  Annote
a' Size
sz' Text
g' [Exp]
es'     = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Text
g Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
g' Bool -> Bool -> Bool
&& [Exp]
es [Exp] -> [Exp] -> Bool
forall a. Eq a => a -> a -> Bool
== [Exp]
es'
      XCall Annote
a Size
sz Text
x [Natural]
cs [Exp]
es  == XCall Annote
a' Size
sz' Text
x' [Natural]
cs' [Exp]
es' = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
x' Bool -> Bool -> Bool
&& [Natural]
cs [Natural] -> [Natural] -> Bool
forall a. Eq a => a -> a -> Bool
== [Natural]
cs' Bool -> Bool -> Bool
&& [Exp]
es [Exp] -> [Exp] -> Bool
forall a. Eq a => a -> a -> Bool
== [Exp]
es'
      If    Annote
a Size
sz Exp
c Exp
t Exp
e    == If    Annote
a' Size
sz' Exp
c' Exp
t' Exp
e'   = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Exp
c Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
c' Bool -> Bool -> Bool
&& Exp
t Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
t' Bool -> Bool -> Bool
&& Exp
e Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e'
      Let   Annote
a Size
sz Text
x Exp
e1 Exp
e2  == Let   Annote
a' Size
sz' Text
x' Exp
e1' Exp
e2' = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
x' Bool -> Bool -> Bool
&& Exp
e1 Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e1' Bool -> Bool -> Bool
&& Exp
e2 Exp -> Exp -> Bool
forall a. Eq a => a -> a -> Bool
== Exp
e2'
      Exp
_                   == Exp
_                       = Bool
False

instance SizeAnnotated Exp where
      sizeOf :: Exp -> Size
sizeOf = \ case
            Lit   Annote
_ BV
bv        -> Int -> Size
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Size) -> Int -> Size
forall a b. (a -> b) -> a -> b
$ BV -> Int
width BV
bv
            Undef Annote
_ Size
sz        -> Size
sz
            Var   Annote
_ Size
sz Text
_      -> Size
sz
            Cat   Annote
_ Exp
e1 Exp
e2     -> Exp -> Size
forall a. SizeAnnotated a => a -> Size
sizeOf Exp
e1 Size -> Size -> Size
forall a. Num a => a -> a -> a
+ Exp -> Size
forall a. SizeAnnotated a => a -> Size
sizeOf Exp
e2
            Slice Annote
_ Size
_ Size
k Exp
_     -> Size
k
            Prim  Annote
_ Size
sz Op
_ [Exp]
_    -> Size
sz
            Call  Annote
_ Size
sz Text
_ [Exp]
_    -> Size
sz
            XCall Annote
_ Size
sz Text
_ [Natural]
_ [Exp]
_  -> Size
sz
            If    Annote
_ Size
sz Exp
_ Exp
_ Exp
_  -> Size
sz
            Let   Annote
_ Size
sz Text
_ Exp
_ Exp
_  -> Size
sz

instance Annotated Exp where
      ann :: Exp -> Annote
ann = \ case
            Lit   Annote
a BV
_         -> Annote
a
            Undef Annote
a Size
_         -> Annote
a
            Var   Annote
a Size
_ Text
_       -> Annote
a
            Cat   Annote
a Exp
_ Exp
_       -> Annote
a
            Slice Annote
a Size
_ Size
_ Exp
_     -> Annote
a
            Prim  Annote
a Size
_ Op
_ [Exp]
_     -> Annote
a
            Call  Annote
a Size
_ Text
_ [Exp]
_     -> Annote
a
            XCall Annote
a Size
_ Text
_ [Natural]
_ [Exp]
_   -> Annote
a
            If    Annote
a Size
_ Exp
_ Exp
_ Exp
_   -> Annote
a
            Let   Annote
a Size
_ Text
_ Exp
_ Exp
_   -> Annote
a

-- | The unique width-0 value.
nil :: Exp
nil :: Exp
nil = Annote -> BV -> Exp
Lit Annote
noAnn BV
BV.nil

isNil :: Exp -> Bool
isNil :: Exp -> Bool
isNil Exp
e = Exp -> Size
forall a. SizeAnnotated a => a -> Size
sizeOf Exp
e Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
0

-- | Concatenate a list of expressions, dropping width-0 components.
cat :: [Exp] -> Exp
cat :: [Exp] -> Exp
cat = (\ case
            []         -> Exp
nil
            es :: [Exp]
es@(Exp
e : [Exp]
_) -> (Exp -> Exp -> Exp) -> [Exp] -> Exp
forall a. (a -> a -> a) -> [a] -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (Annote -> Exp -> Exp -> Exp
Cat (Annote -> Exp -> Exp -> Exp) -> Annote -> Exp -> Exp -> Exp
forall a b. (a -> b) -> a -> b
$ Exp -> Annote
forall a. Annotated a => a -> Annote
ann Exp
e) [Exp]
es
      ) ([Exp] -> Exp) -> ([Exp] -> [Exp]) -> [Exp] -> Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Exp -> Bool) -> [Exp] -> [Exp]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Exp -> Bool) -> Exp -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Exp -> Bool
isNil)

-- | Flatten nested concatenations, dropping width-0 components.
gather :: Exp -> [Exp]
gather :: Exp -> [Exp]
gather = (Exp -> Bool) -> [Exp] -> [Exp]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Exp -> Bool) -> Exp -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Exp -> Bool
isNil) ([Exp] -> [Exp]) -> (Exp -> [Exp]) -> Exp -> [Exp]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \ case
      Cat Annote
_ Exp
e1 Exp
e2 -> Exp -> [Exp]
gather Exp
e1 [Exp] -> [Exp] -> [Exp]
forall a. Semigroup a => a -> a -> a
<> Exp -> [Exp]
gather Exp
e2
      Exp
e           -> [Exp
e]

---

data Sig = Sig Annote ![Size] !Size
      deriving (Sig -> Sig -> Bool
(Sig -> Sig -> Bool) -> (Sig -> Sig -> Bool) -> Eq Sig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Sig -> Sig -> Bool
== :: Sig -> Sig -> Bool
$c/= :: Sig -> Sig -> Bool
/= :: Sig -> Sig -> Bool
Eq, Eq Sig
Eq Sig =>
(Sig -> Sig -> Ordering)
-> (Sig -> Sig -> Bool)
-> (Sig -> Sig -> Bool)
-> (Sig -> Sig -> Bool)
-> (Sig -> Sig -> Bool)
-> (Sig -> Sig -> Sig)
-> (Sig -> Sig -> Sig)
-> Ord Sig
Sig -> Sig -> Bool
Sig -> Sig -> Ordering
Sig -> Sig -> Sig
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
$ccompare :: Sig -> Sig -> Ordering
compare :: Sig -> Sig -> Ordering
$c< :: Sig -> Sig -> Bool
< :: Sig -> Sig -> Bool
$c<= :: Sig -> Sig -> Bool
<= :: Sig -> Sig -> Bool
$c> :: Sig -> Sig -> Bool
> :: Sig -> Sig -> Bool
$c>= :: Sig -> Sig -> Bool
>= :: Sig -> Sig -> Bool
$cmax :: Sig -> Sig -> Sig
max :: Sig -> Sig -> Sig
$cmin :: Sig -> Sig -> Sig
min :: Sig -> Sig -> Sig
Ord, (forall x. Sig -> Rep Sig x)
-> (forall x. Rep Sig x -> Sig) -> Generic Sig
forall x. Rep Sig x -> Sig
forall x. Sig -> Rep Sig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Sig -> Rep Sig x
from :: forall x. Sig -> Rep Sig x
$cto :: forall x. Rep Sig x -> Sig
to :: forall x. Rep Sig x -> Sig
Generic, Int -> Sig -> ShowS
[Sig] -> ShowS
Sig -> String
(Int -> Sig -> ShowS)
-> (Sig -> String) -> ([Sig] -> ShowS) -> Show Sig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Sig -> ShowS
showsPrec :: Int -> Sig -> ShowS
$cshow :: Sig -> String
show :: Sig -> String
$cshowList :: [Sig] -> ShowS
showList :: [Sig] -> ShowS
Show, Typeable, Typeable Sig
Typeable Sig =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Sig -> c Sig)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Sig)
-> (Sig -> Constr)
-> (Sig -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Sig))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Sig))
-> ((forall b. Data b => b -> b) -> Sig -> Sig)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r)
-> (forall u. (forall d. Data d => d -> u) -> Sig -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Sig -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Sig -> m Sig)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Sig -> m Sig)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Sig -> m Sig)
-> Data Sig
Sig -> Constr
Sig -> DataType
(forall b. Data b => b -> b) -> Sig -> Sig
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Sig -> u
forall u. (forall d. Data d => d -> u) -> Sig -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Sig
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Sig -> c Sig
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Sig)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Sig)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Sig -> c Sig
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Sig -> c Sig
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Sig
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Sig
$ctoConstr :: Sig -> Constr
toConstr :: Sig -> Constr
$cdataTypeOf :: Sig -> DataType
dataTypeOf :: Sig -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Sig)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Sig)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Sig)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Sig)
$cgmapT :: (forall b. Data b => b -> b) -> Sig -> Sig
gmapT :: (forall b. Data b => b -> b) -> Sig -> Sig
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sig -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Sig -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Sig -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Sig -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Sig -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Sig -> m Sig
Data)
      deriving Int -> Sig -> Text
Int -> Sig -> Text
Int -> Sig -> Builder
[Sig] -> Text
[Sig] -> Text
[Sig] -> Builder
Sig -> Text
Sig -> Text
Sig -> Builder
(Int -> Sig -> Builder)
-> (Sig -> Builder)
-> ([Sig] -> Builder)
-> (Int -> Sig -> Text)
-> (Sig -> Text)
-> ([Sig] -> Text)
-> (Int -> Sig -> Text)
-> (Sig -> Text)
-> ([Sig] -> Text)
-> TextShow Sig
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Sig -> Builder
showbPrec :: Int -> Sig -> Builder
$cshowb :: Sig -> Builder
showb :: Sig -> Builder
$cshowbList :: [Sig] -> Builder
showbList :: [Sig] -> Builder
$cshowtPrec :: Int -> Sig -> Text
showtPrec :: Int -> Sig -> Text
$cshowt :: Sig -> Text
showt :: Sig -> Text
$cshowtList :: [Sig] -> Text
showtList :: [Sig] -> Text
$cshowtlPrec :: Int -> Sig -> Text
showtlPrec :: Int -> Sig -> Text
$cshowtl :: Sig -> Text
showtl :: Sig -> Text
$cshowtlList :: [Sig] -> Text
showtlList :: [Sig] -> Text
TextShow via FromGeneric Sig

instance Hashable Sig

instance Annotated Sig where
      ann :: Sig -> Annote
ann (Sig Annote
a [Size]
_ Size
_) = Annote
a

instance SizeAnnotated Sig where
      sizeOf :: Sig -> Size
sizeOf (Sig Annote
_ [Size]
_ Size
s) = Size
s

data Defn = Defn
      { Defn -> Annote
defnAnnote   :: Annote
      , Defn -> Text
defnName     :: !GId
      , Defn -> Sig
defnSig      :: !Sig
      , Defn -> [Text]
defnParams   :: ![Name] -- ^ Same length as the Sig's argument list.
      , Defn -> Exp
defnBody     :: !Exp
      , Defn -> Bool
defnNoInline :: !Bool           -- ^ Exempt from backend inlining (including --flatten); a real attribute, visible to Eq.
      , Defn -> Blind [Text]
defnDoc      :: !(Blind [Text]) -- ^ Display-only doc lines ('--|'); invisible to Eq/Ord/Hashable.
      }
      deriving (Defn -> Defn -> Bool
(Defn -> Defn -> Bool) -> (Defn -> Defn -> Bool) -> Eq Defn
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Defn -> Defn -> Bool
== :: Defn -> Defn -> Bool
$c/= :: Defn -> Defn -> Bool
/= :: Defn -> Defn -> Bool
Eq, Eq Defn
Eq Defn =>
(Defn -> Defn -> Ordering)
-> (Defn -> Defn -> Bool)
-> (Defn -> Defn -> Bool)
-> (Defn -> Defn -> Bool)
-> (Defn -> Defn -> Bool)
-> (Defn -> Defn -> Defn)
-> (Defn -> Defn -> Defn)
-> Ord Defn
Defn -> Defn -> Bool
Defn -> Defn -> Ordering
Defn -> Defn -> Defn
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
$ccompare :: Defn -> Defn -> Ordering
compare :: Defn -> Defn -> Ordering
$c< :: Defn -> Defn -> Bool
< :: Defn -> Defn -> Bool
$c<= :: Defn -> Defn -> Bool
<= :: Defn -> Defn -> Bool
$c> :: Defn -> Defn -> Bool
> :: Defn -> Defn -> Bool
$c>= :: Defn -> Defn -> Bool
>= :: Defn -> Defn -> Bool
$cmax :: Defn -> Defn -> Defn
max :: Defn -> Defn -> Defn
$cmin :: Defn -> Defn -> Defn
min :: Defn -> Defn -> Defn
Ord, Int -> Defn -> ShowS
[Defn] -> ShowS
Defn -> String
(Int -> Defn -> ShowS)
-> (Defn -> String) -> ([Defn] -> ShowS) -> Show Defn
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Defn -> ShowS
showsPrec :: Int -> Defn -> ShowS
$cshow :: Defn -> String
show :: Defn -> String
$cshowList :: [Defn] -> ShowS
showList :: [Defn] -> ShowS
Show, Typeable, Typeable Defn
Typeable Defn =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Defn -> c Defn)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Defn)
-> (Defn -> Constr)
-> (Defn -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Defn))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Defn))
-> ((forall b. Data b => b -> b) -> Defn -> Defn)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r)
-> (forall u. (forall d. Data d => d -> u) -> Defn -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Defn -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Defn -> m Defn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Defn -> m Defn)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Defn -> m Defn)
-> Data Defn
Defn -> Constr
Defn -> DataType
(forall b. Data b => b -> b) -> Defn -> Defn
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Defn -> u
forall u. (forall d. Data d => d -> u) -> Defn -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Defn
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Defn -> c Defn
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Defn)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Defn)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Defn -> c Defn
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Defn -> c Defn
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Defn
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Defn
$ctoConstr :: Defn -> Constr
toConstr :: Defn -> Constr
$cdataTypeOf :: Defn -> DataType
dataTypeOf :: Defn -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Defn)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Defn)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Defn)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Defn)
$cgmapT :: (forall b. Data b => b -> b) -> Defn -> Defn
gmapT :: (forall b. Data b => b -> b) -> Defn -> Defn
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Defn -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Defn -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Defn -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Defn -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Defn -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Defn -> m Defn
Data, (forall x. Defn -> Rep Defn x)
-> (forall x. Rep Defn x -> Defn) -> Generic Defn
forall x. Rep Defn x -> Defn
forall x. Defn -> Rep Defn x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Defn -> Rep Defn x
from :: forall x. Defn -> Rep Defn x
$cto :: forall x. Rep Defn x -> Defn
to :: forall x. Rep Defn x -> Defn
Generic)
      deriving Int -> Defn -> Text
Int -> Defn -> Text
Int -> Defn -> Builder
[Defn] -> Text
[Defn] -> Text
[Defn] -> Builder
Defn -> Text
Defn -> Text
Defn -> Builder
(Int -> Defn -> Builder)
-> (Defn -> Builder)
-> ([Defn] -> Builder)
-> (Int -> Defn -> Text)
-> (Defn -> Text)
-> ([Defn] -> Text)
-> (Int -> Defn -> Text)
-> (Defn -> Text)
-> ([Defn] -> Text)
-> TextShow Defn
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Defn -> Builder
showbPrec :: Int -> Defn -> Builder
$cshowb :: Defn -> Builder
showb :: Defn -> Builder
$cshowbList :: [Defn] -> Builder
showbList :: [Defn] -> Builder
$cshowtPrec :: Int -> Defn -> Text
showtPrec :: Int -> Defn -> Text
$cshowt :: Defn -> Text
showt :: Defn -> Text
$cshowtList :: [Defn] -> Text
showtList :: [Defn] -> Text
$cshowtlPrec :: Int -> Defn -> Text
showtlPrec :: Int -> Defn -> Text
$cshowtl :: Defn -> Text
showtl :: Defn -> Text
$cshowtlList :: [Defn] -> Text
showtlList :: [Defn] -> Text
TextShow via FromGeneric Defn

instance Hashable Defn

instance SizeAnnotated Defn where
      sizeOf :: Defn -> Size
sizeOf (Defn Annote
_ Text
_ (Sig Annote
_ [Size]
_ Size
s) [Text]
_ Exp
_ Bool
_ Blind [Text]
_) = Size
s

instance Annotated Defn where
      ann :: Defn -> Annote
ann = Defn -> Annote
defnAnnote

---

-- | Sequential externs carry the names of their clock and reset ports (either
--   may be absent); combinational externs have neither.
data ExternKind = Comb | Seq !(Maybe Name) !(Maybe Name)
      deriving (ExternKind -> ExternKind -> Bool
(ExternKind -> ExternKind -> Bool)
-> (ExternKind -> ExternKind -> Bool) -> Eq ExternKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ExternKind -> ExternKind -> Bool
== :: ExternKind -> ExternKind -> Bool
$c/= :: ExternKind -> ExternKind -> Bool
/= :: ExternKind -> ExternKind -> Bool
Eq, Eq ExternKind
Eq ExternKind =>
(ExternKind -> ExternKind -> Ordering)
-> (ExternKind -> ExternKind -> Bool)
-> (ExternKind -> ExternKind -> Bool)
-> (ExternKind -> ExternKind -> Bool)
-> (ExternKind -> ExternKind -> Bool)
-> (ExternKind -> ExternKind -> ExternKind)
-> (ExternKind -> ExternKind -> ExternKind)
-> Ord ExternKind
ExternKind -> ExternKind -> Bool
ExternKind -> ExternKind -> Ordering
ExternKind -> ExternKind -> ExternKind
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
$ccompare :: ExternKind -> ExternKind -> Ordering
compare :: ExternKind -> ExternKind -> Ordering
$c< :: ExternKind -> ExternKind -> Bool
< :: ExternKind -> ExternKind -> Bool
$c<= :: ExternKind -> ExternKind -> Bool
<= :: ExternKind -> ExternKind -> Bool
$c> :: ExternKind -> ExternKind -> Bool
> :: ExternKind -> ExternKind -> Bool
$c>= :: ExternKind -> ExternKind -> Bool
>= :: ExternKind -> ExternKind -> Bool
$cmax :: ExternKind -> ExternKind -> ExternKind
max :: ExternKind -> ExternKind -> ExternKind
$cmin :: ExternKind -> ExternKind -> ExternKind
min :: ExternKind -> ExternKind -> ExternKind
Ord, (forall x. ExternKind -> Rep ExternKind x)
-> (forall x. Rep ExternKind x -> ExternKind) -> Generic ExternKind
forall x. Rep ExternKind x -> ExternKind
forall x. ExternKind -> Rep ExternKind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ExternKind -> Rep ExternKind x
from :: forall x. ExternKind -> Rep ExternKind x
$cto :: forall x. Rep ExternKind x -> ExternKind
to :: forall x. Rep ExternKind x -> ExternKind
Generic, Int -> ExternKind -> ShowS
[ExternKind] -> ShowS
ExternKind -> String
(Int -> ExternKind -> ShowS)
-> (ExternKind -> String)
-> ([ExternKind] -> ShowS)
-> Show ExternKind
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ExternKind -> ShowS
showsPrec :: Int -> ExternKind -> ShowS
$cshow :: ExternKind -> String
show :: ExternKind -> String
$cshowList :: [ExternKind] -> ShowS
showList :: [ExternKind] -> ShowS
Show, Typeable, Typeable ExternKind
Typeable ExternKind =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> ExternKind -> c ExternKind)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ExternKind)
-> (ExternKind -> Constr)
-> (ExternKind -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ExternKind))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ExternKind))
-> ((forall b. Data b => b -> b) -> ExternKind -> ExternKind)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ExternKind -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ExternKind -> r)
-> (forall u. (forall d. Data d => d -> u) -> ExternKind -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ExternKind -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ExternKind -> m ExternKind)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ExternKind -> m ExternKind)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ExternKind -> m ExternKind)
-> Data ExternKind
ExternKind -> Constr
ExternKind -> DataType
(forall b. Data b => b -> b) -> ExternKind -> ExternKind
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ExternKind -> u
forall u. (forall d. Data d => d -> u) -> ExternKind -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExternKind
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExternKind -> c ExternKind
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExternKind)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExternKind)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExternKind -> c ExternKind
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ExternKind -> c ExternKind
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExternKind
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ExternKind
$ctoConstr :: ExternKind -> Constr
toConstr :: ExternKind -> Constr
$cdataTypeOf :: ExternKind -> DataType
dataTypeOf :: ExternKind -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExternKind)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ExternKind)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExternKind)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ExternKind)
$cgmapT :: (forall b. Data b => b -> b) -> ExternKind -> ExternKind
gmapT :: (forall b. Data b => b -> b) -> ExternKind -> ExternKind
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ExternKind -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ExternKind -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> ExternKind -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ExternKind -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ExternKind -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ExternKind -> m ExternKind
Data)
      deriving Int -> ExternKind -> Text
Int -> ExternKind -> Text
Int -> ExternKind -> Builder
[ExternKind] -> Text
[ExternKind] -> Text
[ExternKind] -> Builder
ExternKind -> Text
ExternKind -> Text
ExternKind -> Builder
(Int -> ExternKind -> Builder)
-> (ExternKind -> Builder)
-> ([ExternKind] -> Builder)
-> (Int -> ExternKind -> Text)
-> (ExternKind -> Text)
-> ([ExternKind] -> Text)
-> (Int -> ExternKind -> Text)
-> (ExternKind -> Text)
-> ([ExternKind] -> Text)
-> TextShow ExternKind
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> ExternKind -> Builder
showbPrec :: Int -> ExternKind -> Builder
$cshowb :: ExternKind -> Builder
showb :: ExternKind -> Builder
$cshowbList :: [ExternKind] -> Builder
showbList :: [ExternKind] -> Builder
$cshowtPrec :: Int -> ExternKind -> Text
showtPrec :: Int -> ExternKind -> Text
$cshowt :: ExternKind -> Text
showt :: ExternKind -> Text
$cshowtList :: [ExternKind] -> Text
showtList :: [ExternKind] -> Text
$cshowtlPrec :: Int -> ExternKind -> Text
showtlPrec :: Int -> ExternKind -> Text
$cshowtl :: ExternKind -> Text
showtl :: ExternKind -> Text
$cshowtlList :: [ExternKind] -> Text
showtlList :: [ExternKind] -> Text
TextShow via FromGeneric ExternKind

instance Hashable ExternKind

data Extern = Extern
      { Extern -> Annote
extAnnote   :: Annote
      , Extern -> Text
extName     :: !Name
      , Extern -> [Text]
extGenerics :: ![Name]
      , Extern -> ExternKind
extKind     :: !ExternKind
      , Extern -> [(Text, Size)]
extInputs   :: ![(Name, Size)]
      , Extern -> [(Text, Size)]
extOutputs  :: ![(Name, Size)]
      , Extern -> Maybe Text
extModel    :: !(Maybe GId)   -- ^ Combinational externs only.
      }
      deriving (Extern -> Extern -> Bool
(Extern -> Extern -> Bool)
-> (Extern -> Extern -> Bool) -> Eq Extern
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Extern -> Extern -> Bool
== :: Extern -> Extern -> Bool
$c/= :: Extern -> Extern -> Bool
/= :: Extern -> Extern -> Bool
Eq, Eq Extern
Eq Extern =>
(Extern -> Extern -> Ordering)
-> (Extern -> Extern -> Bool)
-> (Extern -> Extern -> Bool)
-> (Extern -> Extern -> Bool)
-> (Extern -> Extern -> Bool)
-> (Extern -> Extern -> Extern)
-> (Extern -> Extern -> Extern)
-> Ord Extern
Extern -> Extern -> Bool
Extern -> Extern -> Ordering
Extern -> Extern -> Extern
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
$ccompare :: Extern -> Extern -> Ordering
compare :: Extern -> Extern -> Ordering
$c< :: Extern -> Extern -> Bool
< :: Extern -> Extern -> Bool
$c<= :: Extern -> Extern -> Bool
<= :: Extern -> Extern -> Bool
$c> :: Extern -> Extern -> Bool
> :: Extern -> Extern -> Bool
$c>= :: Extern -> Extern -> Bool
>= :: Extern -> Extern -> Bool
$cmax :: Extern -> Extern -> Extern
max :: Extern -> Extern -> Extern
$cmin :: Extern -> Extern -> Extern
min :: Extern -> Extern -> Extern
Ord, Int -> Extern -> ShowS
[Extern] -> ShowS
Extern -> String
(Int -> Extern -> ShowS)
-> (Extern -> String) -> ([Extern] -> ShowS) -> Show Extern
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Extern -> ShowS
showsPrec :: Int -> Extern -> ShowS
$cshow :: Extern -> String
show :: Extern -> String
$cshowList :: [Extern] -> ShowS
showList :: [Extern] -> ShowS
Show, Typeable, Typeable Extern
Typeable Extern =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Extern -> c Extern)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Extern)
-> (Extern -> Constr)
-> (Extern -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Extern))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extern))
-> ((forall b. Data b => b -> b) -> Extern -> Extern)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Extern -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Extern -> r)
-> (forall u. (forall d. Data d => d -> u) -> Extern -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Extern -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Extern -> m Extern)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Extern -> m Extern)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Extern -> m Extern)
-> Data Extern
Extern -> Constr
Extern -> DataType
(forall b. Data b => b -> b) -> Extern -> Extern
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Extern -> u
forall u. (forall d. Data d => d -> u) -> Extern -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extern
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extern -> c Extern
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extern)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extern)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extern -> c Extern
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Extern -> c Extern
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extern
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Extern
$ctoConstr :: Extern -> Constr
toConstr :: Extern -> Constr
$cdataTypeOf :: Extern -> DataType
dataTypeOf :: Extern -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extern)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Extern)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extern)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Extern)
$cgmapT :: (forall b. Data b => b -> b) -> Extern -> Extern
gmapT :: (forall b. Data b => b -> b) -> Extern -> Extern
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Extern -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Extern -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Extern -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Extern -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Extern -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Extern -> m Extern
Data, (forall x. Extern -> Rep Extern x)
-> (forall x. Rep Extern x -> Extern) -> Generic Extern
forall x. Rep Extern x -> Extern
forall x. Extern -> Rep Extern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Extern -> Rep Extern x
from :: forall x. Extern -> Rep Extern x
$cto :: forall x. Rep Extern x -> Extern
to :: forall x. Rep Extern x -> Extern
Generic)
      deriving Int -> Extern -> Text
Int -> Extern -> Text
Int -> Extern -> Builder
[Extern] -> Text
[Extern] -> Text
[Extern] -> Builder
Extern -> Text
Extern -> Text
Extern -> Builder
(Int -> Extern -> Builder)
-> (Extern -> Builder)
-> ([Extern] -> Builder)
-> (Int -> Extern -> Text)
-> (Extern -> Text)
-> ([Extern] -> Text)
-> (Int -> Extern -> Text)
-> (Extern -> Text)
-> ([Extern] -> Text)
-> TextShow Extern
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Extern -> Builder
showbPrec :: Int -> Extern -> Builder
$cshowb :: Extern -> Builder
showb :: Extern -> Builder
$cshowbList :: [Extern] -> Builder
showbList :: [Extern] -> Builder
$cshowtPrec :: Int -> Extern -> Text
showtPrec :: Int -> Extern -> Text
$cshowt :: Extern -> Text
showt :: Extern -> Text
$cshowtList :: [Extern] -> Text
showtList :: [Extern] -> Text
$cshowtlPrec :: Int -> Extern -> Text
showtlPrec :: Int -> Extern -> Text
$cshowtl :: Extern -> Text
showtl :: Extern -> Text
$cshowtlList :: [Extern] -> Text
showtlList :: [Extern] -> Text
TextShow via FromGeneric Extern

instance Hashable Extern

instance Annotated Extern where
      ann :: Extern -> Annote
ann = Extern -> Annote
extAnnote

-- | The width of a call to the extern: its outputs, concatenated.
externResultSize :: Extern -> Size
externResultSize :: Extern -> Size
externResultSize = [Size] -> Size
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([Size] -> Size) -> (Extern -> [Size]) -> Extern -> Size
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Text, Size) -> Size) -> [(Text, Size)] -> [Size]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Size) -> Size
forall a b. (a, b) -> b
snd ([(Text, Size)] -> [Size])
-> (Extern -> [(Text, Size)]) -> Extern -> [Size]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extern -> [(Text, Size)]
extOutputs

instance SizeAnnotated Extern where
      sizeOf :: Extern -> Size
sizeOf = Extern -> Size
externResultSize

---

data Register = Register Annote !Name !Size !BV
      deriving (Eq Register
Eq Register =>
(Register -> Register -> Ordering)
-> (Register -> Register -> Bool)
-> (Register -> Register -> Bool)
-> (Register -> Register -> Bool)
-> (Register -> Register -> Bool)
-> (Register -> Register -> Register)
-> (Register -> Register -> Register)
-> Ord Register
Register -> Register -> Bool
Register -> Register -> Ordering
Register -> Register -> Register
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
$ccompare :: Register -> Register -> Ordering
compare :: Register -> Register -> Ordering
$c< :: Register -> Register -> Bool
< :: Register -> Register -> Bool
$c<= :: Register -> Register -> Bool
<= :: Register -> Register -> Bool
$c> :: Register -> Register -> Bool
> :: Register -> Register -> Bool
$c>= :: Register -> Register -> Bool
>= :: Register -> Register -> Bool
$cmax :: Register -> Register -> Register
max :: Register -> Register -> Register
$cmin :: Register -> Register -> Register
min :: Register -> Register -> Register
Ord, Int -> Register -> ShowS
[Register] -> ShowS
Register -> String
(Int -> Register -> ShowS)
-> (Register -> String) -> ([Register] -> ShowS) -> Show Register
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Register -> ShowS
showsPrec :: Int -> Register -> ShowS
$cshow :: Register -> String
show :: Register -> String
$cshowList :: [Register] -> ShowS
showList :: [Register] -> ShowS
Show, Typeable, Typeable Register
Typeable Register =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Register -> c Register)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Register)
-> (Register -> Constr)
-> (Register -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Register))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Register))
-> ((forall b. Data b => b -> b) -> Register -> Register)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Register -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Register -> r)
-> (forall u. (forall d. Data d => d -> u) -> Register -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Register -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Register -> m Register)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Register -> m Register)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Register -> m Register)
-> Data Register
Register -> Constr
Register -> DataType
(forall b. Data b => b -> b) -> Register -> Register
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Register -> u
forall u. (forall d. Data d => d -> u) -> Register -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Register -> m Register
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Register -> m Register
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Register
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Register -> c Register
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Register)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Register)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Register -> c Register
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Register -> c Register
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Register
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Register
$ctoConstr :: Register -> Constr
toConstr :: Register -> Constr
$cdataTypeOf :: Register -> DataType
dataTypeOf :: Register -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Register)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Register)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Register)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Register)
$cgmapT :: (forall b. Data b => b -> b) -> Register -> Register
gmapT :: (forall b. Data b => b -> b) -> Register -> Register
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Register -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Register -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Register -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Register -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Register -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Register -> m Register
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Register -> m Register
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Register -> m Register
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Register -> m Register
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Register -> m Register
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Register -> m Register
Data, (forall x. Register -> Rep Register x)
-> (forall x. Rep Register x -> Register) -> Generic Register
forall x. Rep Register x -> Register
forall x. Register -> Rep Register x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Register -> Rep Register x
from :: forall x. Register -> Rep Register x
$cto :: forall x. Rep Register x -> Register
to :: forall x. Rep Register x -> Register
Generic)
      deriving Int -> Register -> Text
Int -> Register -> Text
Int -> Register -> Builder
[Register] -> Text
[Register] -> Text
[Register] -> Builder
Register -> Text
Register -> Text
Register -> Builder
(Int -> Register -> Builder)
-> (Register -> Builder)
-> ([Register] -> Builder)
-> (Int -> Register -> Text)
-> (Register -> Text)
-> ([Register] -> Text)
-> (Int -> Register -> Text)
-> (Register -> Text)
-> ([Register] -> Text)
-> TextShow Register
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Register -> Builder
showbPrec :: Int -> Register -> Builder
$cshowb :: Register -> Builder
showb :: Register -> Builder
$cshowbList :: [Register] -> Builder
showbList :: [Register] -> Builder
$cshowtPrec :: Int -> Register -> Text
showtPrec :: Int -> Register -> Text
$cshowt :: Register -> Text
showt :: Register -> Text
$cshowtList :: [Register] -> Text
showtList :: [Register] -> Text
$cshowtlPrec :: Int -> Register -> Text
showtlPrec :: Int -> Register -> Text
$cshowtl :: Register -> Text
showtl :: Register -> Text
$cshowtlList :: [Register] -> Text
showtlList :: [Register] -> Text
TextShow via FromGeneric Register

instance Hashable Register

instance Eq Register where
      Register Annote
a Text
x Size
sz BV
bv == :: Register -> Register -> Bool
== Register Annote
a' Text
x' Size
sz' BV
bv' = Annote
a Annote -> Annote -> Bool
forall a. Eq a => a -> a -> Bool
== Annote
a' Bool -> Bool -> Bool
&& Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
x' Bool -> Bool -> Bool
&& Size
sz Size -> Size -> Bool
forall a. Eq a => a -> a -> Bool
== Size
sz' Bool -> Bool -> Bool
&& BV
bv BV -> BV -> Bool
BV.==. BV
bv'

instance Annotated Register where
      ann :: Register -> Annote
ann (Register Annote
a Text
_ Size
_ BV
_) = Annote
a

instance SizeAnnotated Register where
      sizeOf :: Register -> Size
sizeOf (Register Annote
_ Text
_ Size
sz BV
_) = Size
sz

data Instance = Instance Annote !Name !Name ![Natural] -- ^ Instance name, extern name, generic arguments.
      deriving (Instance -> Instance -> Bool
(Instance -> Instance -> Bool)
-> (Instance -> Instance -> Bool) -> Eq Instance
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Instance -> Instance -> Bool
== :: Instance -> Instance -> Bool
$c/= :: Instance -> Instance -> Bool
/= :: Instance -> Instance -> Bool
Eq, Eq Instance
Eq Instance =>
(Instance -> Instance -> Ordering)
-> (Instance -> Instance -> Bool)
-> (Instance -> Instance -> Bool)
-> (Instance -> Instance -> Bool)
-> (Instance -> Instance -> Bool)
-> (Instance -> Instance -> Instance)
-> (Instance -> Instance -> Instance)
-> Ord Instance
Instance -> Instance -> Bool
Instance -> Instance -> Ordering
Instance -> Instance -> Instance
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
$ccompare :: Instance -> Instance -> Ordering
compare :: Instance -> Instance -> Ordering
$c< :: Instance -> Instance -> Bool
< :: Instance -> Instance -> Bool
$c<= :: Instance -> Instance -> Bool
<= :: Instance -> Instance -> Bool
$c> :: Instance -> Instance -> Bool
> :: Instance -> Instance -> Bool
$c>= :: Instance -> Instance -> Bool
>= :: Instance -> Instance -> Bool
$cmax :: Instance -> Instance -> Instance
max :: Instance -> Instance -> Instance
$cmin :: Instance -> Instance -> Instance
min :: Instance -> Instance -> Instance
Ord, Int -> Instance -> ShowS
[Instance] -> ShowS
Instance -> String
(Int -> Instance -> ShowS)
-> (Instance -> String) -> ([Instance] -> ShowS) -> Show Instance
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Instance -> ShowS
showsPrec :: Int -> Instance -> ShowS
$cshow :: Instance -> String
show :: Instance -> String
$cshowList :: [Instance] -> ShowS
showList :: [Instance] -> ShowS
Show, Typeable, Typeable Instance
Typeable Instance =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Instance -> c Instance)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Instance)
-> (Instance -> Constr)
-> (Instance -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Instance))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Instance))
-> ((forall b. Data b => b -> b) -> Instance -> Instance)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Instance -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Instance -> r)
-> (forall u. (forall d. Data d => d -> u) -> Instance -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Instance -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Instance -> m Instance)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Instance -> m Instance)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Instance -> m Instance)
-> Data Instance
Instance -> Constr
Instance -> DataType
(forall b. Data b => b -> b) -> Instance -> Instance
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Instance -> u
forall u. (forall d. Data d => d -> u) -> Instance -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Instance
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Instance -> c Instance
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Instance)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Instance)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Instance -> c Instance
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Instance -> c Instance
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Instance
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Instance
$ctoConstr :: Instance -> Constr
toConstr :: Instance -> Constr
$cdataTypeOf :: Instance -> DataType
dataTypeOf :: Instance -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Instance)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Instance)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Instance)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Instance)
$cgmapT :: (forall b. Data b => b -> b) -> Instance -> Instance
gmapT :: (forall b. Data b => b -> b) -> Instance -> Instance
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Instance -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Instance -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Instance -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Instance -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Instance -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Instance -> m Instance
Data, (forall x. Instance -> Rep Instance x)
-> (forall x. Rep Instance x -> Instance) -> Generic Instance
forall x. Rep Instance x -> Instance
forall x. Instance -> Rep Instance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Instance -> Rep Instance x
from :: forall x. Instance -> Rep Instance x
$cto :: forall x. Rep Instance x -> Instance
to :: forall x. Rep Instance x -> Instance
Generic)
      deriving Int -> Instance -> Text
Int -> Instance -> Text
Int -> Instance -> Builder
[Instance] -> Text
[Instance] -> Text
[Instance] -> Builder
Instance -> Text
Instance -> Text
Instance -> Builder
(Int -> Instance -> Builder)
-> (Instance -> Builder)
-> ([Instance] -> Builder)
-> (Int -> Instance -> Text)
-> (Instance -> Text)
-> ([Instance] -> Text)
-> (Int -> Instance -> Text)
-> (Instance -> Text)
-> ([Instance] -> Text)
-> TextShow Instance
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Instance -> Builder
showbPrec :: Int -> Instance -> Builder
$cshowb :: Instance -> Builder
showb :: Instance -> Builder
$cshowbList :: [Instance] -> Builder
showbList :: [Instance] -> Builder
$cshowtPrec :: Int -> Instance -> Text
showtPrec :: Int -> Instance -> Text
$cshowt :: Instance -> Text
showt :: Instance -> Text
$cshowtList :: [Instance] -> Text
showtList :: [Instance] -> Text
$cshowtlPrec :: Int -> Instance -> Text
showtlPrec :: Int -> Instance -> Text
$cshowtl :: Instance -> Text
showtl :: Instance -> Text
$cshowtlList :: [Instance] -> Text
showtlList :: [Instance] -> Text
TextShow via FromGeneric Instance

instance Hashable Instance

instance Annotated Instance where
      ann :: Instance -> Annote
ann (Instance Annote
a Text
_ Text
_ [Natural]
_) = Annote
a

data Stmt = SLet    Annote !Name !Exp
          | SOutput Annote !Name !Exp
          | SNext   Annote !Name !Exp
          | SInstIn Annote !Name !Name !Exp -- ^ Instance name, port name.
      deriving (Stmt -> Stmt -> Bool
(Stmt -> Stmt -> Bool) -> (Stmt -> Stmt -> Bool) -> Eq Stmt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Stmt -> Stmt -> Bool
== :: Stmt -> Stmt -> Bool
$c/= :: Stmt -> Stmt -> Bool
/= :: Stmt -> Stmt -> Bool
Eq, Eq Stmt
Eq Stmt =>
(Stmt -> Stmt -> Ordering)
-> (Stmt -> Stmt -> Bool)
-> (Stmt -> Stmt -> Bool)
-> (Stmt -> Stmt -> Bool)
-> (Stmt -> Stmt -> Bool)
-> (Stmt -> Stmt -> Stmt)
-> (Stmt -> Stmt -> Stmt)
-> Ord Stmt
Stmt -> Stmt -> Bool
Stmt -> Stmt -> Ordering
Stmt -> Stmt -> Stmt
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
$ccompare :: Stmt -> Stmt -> Ordering
compare :: Stmt -> Stmt -> Ordering
$c< :: Stmt -> Stmt -> Bool
< :: Stmt -> Stmt -> Bool
$c<= :: Stmt -> Stmt -> Bool
<= :: Stmt -> Stmt -> Bool
$c> :: Stmt -> Stmt -> Bool
> :: Stmt -> Stmt -> Bool
$c>= :: Stmt -> Stmt -> Bool
>= :: Stmt -> Stmt -> Bool
$cmax :: Stmt -> Stmt -> Stmt
max :: Stmt -> Stmt -> Stmt
$cmin :: Stmt -> Stmt -> Stmt
min :: Stmt -> Stmt -> Stmt
Ord, Int -> Stmt -> ShowS
[Stmt] -> ShowS
Stmt -> String
(Int -> Stmt -> ShowS)
-> (Stmt -> String) -> ([Stmt] -> ShowS) -> Show Stmt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Stmt -> ShowS
showsPrec :: Int -> Stmt -> ShowS
$cshow :: Stmt -> String
show :: Stmt -> String
$cshowList :: [Stmt] -> ShowS
showList :: [Stmt] -> ShowS
Show, Typeable, Typeable Stmt
Typeable Stmt =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Stmt -> c Stmt)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Stmt)
-> (Stmt -> Constr)
-> (Stmt -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Stmt))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Stmt))
-> ((forall b. Data b => b -> b) -> Stmt -> Stmt)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r)
-> (forall u. (forall d. Data d => d -> u) -> Stmt -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Stmt -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Stmt -> m Stmt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Stmt -> m Stmt)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Stmt -> m Stmt)
-> Data Stmt
Stmt -> Constr
Stmt -> DataType
(forall b. Data b => b -> b) -> Stmt -> Stmt
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Stmt -> u
forall u. (forall d. Data d => d -> u) -> Stmt -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Stmt
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Stmt -> c Stmt
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Stmt)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Stmt)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Stmt -> c Stmt
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Stmt -> c Stmt
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Stmt
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Stmt
$ctoConstr :: Stmt -> Constr
toConstr :: Stmt -> Constr
$cdataTypeOf :: Stmt -> DataType
dataTypeOf :: Stmt -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Stmt)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Stmt)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Stmt)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Stmt)
$cgmapT :: (forall b. Data b => b -> b) -> Stmt -> Stmt
gmapT :: (forall b. Data b => b -> b) -> Stmt -> Stmt
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Stmt -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Stmt -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Stmt -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Stmt -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Stmt -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Stmt -> m Stmt
Data, (forall x. Stmt -> Rep Stmt x)
-> (forall x. Rep Stmt x -> Stmt) -> Generic Stmt
forall x. Rep Stmt x -> Stmt
forall x. Stmt -> Rep Stmt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Stmt -> Rep Stmt x
from :: forall x. Stmt -> Rep Stmt x
$cto :: forall x. Rep Stmt x -> Stmt
to :: forall x. Rep Stmt x -> Stmt
Generic)
      deriving Int -> Stmt -> Text
Int -> Stmt -> Text
Int -> Stmt -> Builder
[Stmt] -> Text
[Stmt] -> Text
[Stmt] -> Builder
Stmt -> Text
Stmt -> Text
Stmt -> Builder
(Int -> Stmt -> Builder)
-> (Stmt -> Builder)
-> ([Stmt] -> Builder)
-> (Int -> Stmt -> Text)
-> (Stmt -> Text)
-> ([Stmt] -> Text)
-> (Int -> Stmt -> Text)
-> (Stmt -> Text)
-> ([Stmt] -> Text)
-> TextShow Stmt
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Stmt -> Builder
showbPrec :: Int -> Stmt -> Builder
$cshowb :: Stmt -> Builder
showb :: Stmt -> Builder
$cshowbList :: [Stmt] -> Builder
showbList :: [Stmt] -> Builder
$cshowtPrec :: Int -> Stmt -> Text
showtPrec :: Int -> Stmt -> Text
$cshowt :: Stmt -> Text
showt :: Stmt -> Text
$cshowtList :: [Stmt] -> Text
showtList :: [Stmt] -> Text
$cshowtlPrec :: Int -> Stmt -> Text
showtlPrec :: Int -> Stmt -> Text
$cshowtl :: Stmt -> Text
showtl :: Stmt -> Text
$cshowtlList :: [Stmt] -> Text
showtlList :: [Stmt] -> Text
TextShow via FromGeneric Stmt

instance Hashable Stmt

instance Annotated Stmt where
      ann :: Stmt -> Annote
ann = \ case
            SLet    Annote
a Text
_ Exp
_   -> Annote
a
            SOutput Annote
a Text
_ Exp
_   -> Annote
a
            SNext   Annote
a Text
_ Exp
_   -> Annote
a
            SInstIn Annote
a Text
_ Text
_ Exp
_ -> Annote
a

data Device = Device
      { Device -> Annote
devAnnote    :: Annote
      , Device -> Text
devName      :: !Name
      , Device -> [(Text, Size)]
devInputs    :: ![(Name, Size)]
      , Device -> [(Text, Size)]
devOutputs   :: ![(Name, Size)]
      , Device -> [Register]
devRegisters :: ![Register]
      , Device -> [Instance]
devInstances :: ![Instance]
      , Device -> [Stmt]
devBody      :: ![Stmt]
      , Device -> Blind [(Text, Integer)]
devTags      :: !(Blind [(Text, Integer)]) -- ^ Display names for the '__resumption_tag' register's values; invisible to Eq/Ord/Hashable.
      }
      deriving (Device -> Device -> Bool
(Device -> Device -> Bool)
-> (Device -> Device -> Bool) -> Eq Device
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Device -> Device -> Bool
== :: Device -> Device -> Bool
$c/= :: Device -> Device -> Bool
/= :: Device -> Device -> Bool
Eq, Eq Device
Eq Device =>
(Device -> Device -> Ordering)
-> (Device -> Device -> Bool)
-> (Device -> Device -> Bool)
-> (Device -> Device -> Bool)
-> (Device -> Device -> Bool)
-> (Device -> Device -> Device)
-> (Device -> Device -> Device)
-> Ord Device
Device -> Device -> Bool
Device -> Device -> Ordering
Device -> Device -> Device
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
$ccompare :: Device -> Device -> Ordering
compare :: Device -> Device -> Ordering
$c< :: Device -> Device -> Bool
< :: Device -> Device -> Bool
$c<= :: Device -> Device -> Bool
<= :: Device -> Device -> Bool
$c> :: Device -> Device -> Bool
> :: Device -> Device -> Bool
$c>= :: Device -> Device -> Bool
>= :: Device -> Device -> Bool
$cmax :: Device -> Device -> Device
max :: Device -> Device -> Device
$cmin :: Device -> Device -> Device
min :: Device -> Device -> Device
Ord, Int -> Device -> ShowS
[Device] -> ShowS
Device -> String
(Int -> Device -> ShowS)
-> (Device -> String) -> ([Device] -> ShowS) -> Show Device
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Device -> ShowS
showsPrec :: Int -> Device -> ShowS
$cshow :: Device -> String
show :: Device -> String
$cshowList :: [Device] -> ShowS
showList :: [Device] -> ShowS
Show, Typeable, Typeable Device
Typeable Device =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Device -> c Device)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Device)
-> (Device -> Constr)
-> (Device -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Device))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Device))
-> ((forall b. Data b => b -> b) -> Device -> Device)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Device -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Device -> r)
-> (forall u. (forall d. Data d => d -> u) -> Device -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Device -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Device -> m Device)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Device -> m Device)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Device -> m Device)
-> Data Device
Device -> Constr
Device -> DataType
(forall b. Data b => b -> b) -> Device -> Device
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Device -> u
forall u. (forall d. Data d => d -> u) -> Device -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Device -> m Device
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Device -> m Device
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Device
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Device -> c Device
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Device)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Device)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Device -> c Device
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Device -> c Device
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Device
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Device
$ctoConstr :: Device -> Constr
toConstr :: Device -> Constr
$cdataTypeOf :: Device -> DataType
dataTypeOf :: Device -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Device)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Device)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Device)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Device)
$cgmapT :: (forall b. Data b => b -> b) -> Device -> Device
gmapT :: (forall b. Data b => b -> b) -> Device -> Device
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Device -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Device -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Device -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Device -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Device -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Device -> m Device
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Device -> m Device
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Device -> m Device
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Device -> m Device
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Device -> m Device
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Device -> m Device
Data, (forall x. Device -> Rep Device x)
-> (forall x. Rep Device x -> Device) -> Generic Device
forall x. Rep Device x -> Device
forall x. Device -> Rep Device x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Device -> Rep Device x
from :: forall x. Device -> Rep Device x
$cto :: forall x. Rep Device x -> Device
to :: forall x. Rep Device x -> Device
Generic)
      deriving Int -> Device -> Text
Int -> Device -> Text
Int -> Device -> Builder
[Device] -> Text
[Device] -> Text
[Device] -> Builder
Device -> Text
Device -> Text
Device -> Builder
(Int -> Device -> Builder)
-> (Device -> Builder)
-> ([Device] -> Builder)
-> (Int -> Device -> Text)
-> (Device -> Text)
-> ([Device] -> Text)
-> (Int -> Device -> Text)
-> (Device -> Text)
-> ([Device] -> Text)
-> TextShow Device
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Device -> Builder
showbPrec :: Int -> Device -> Builder
$cshowb :: Device -> Builder
showb :: Device -> Builder
$cshowbList :: [Device] -> Builder
showbList :: [Device] -> Builder
$cshowtPrec :: Int -> Device -> Text
showtPrec :: Int -> Device -> Text
$cshowt :: Device -> Text
showt :: Device -> Text
$cshowtList :: [Device] -> Text
showtList :: [Device] -> Text
$cshowtlPrec :: Int -> Device -> Text
showtlPrec :: Int -> Device -> Text
$cshowtl :: Device -> Text
showtl :: Device -> Text
$cshowtlList :: [Device] -> Text
showtlList :: [Device] -> Text
TextShow via FromGeneric Device

instance Hashable Device

instance Annotated Device where
      ann :: Device -> Annote
ann = Device -> Annote
devAnnote

data Program = Program
      { Program -> [Extern]
progExterns :: ![Extern]
      , Program -> [Defn]
progDefns   :: ![Defn]
      , Program -> Device
progDevice  :: !Device
      }
      deriving (Program -> Program -> Bool
(Program -> Program -> Bool)
-> (Program -> Program -> Bool) -> Eq Program
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Program -> Program -> Bool
== :: Program -> Program -> Bool
$c/= :: Program -> Program -> Bool
/= :: Program -> Program -> Bool
Eq, Eq Program
Eq Program =>
(Program -> Program -> Ordering)
-> (Program -> Program -> Bool)
-> (Program -> Program -> Bool)
-> (Program -> Program -> Bool)
-> (Program -> Program -> Bool)
-> (Program -> Program -> Program)
-> (Program -> Program -> Program)
-> Ord Program
Program -> Program -> Bool
Program -> Program -> Ordering
Program -> Program -> Program
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
$ccompare :: Program -> Program -> Ordering
compare :: Program -> Program -> Ordering
$c< :: Program -> Program -> Bool
< :: Program -> Program -> Bool
$c<= :: Program -> Program -> Bool
<= :: Program -> Program -> Bool
$c> :: Program -> Program -> Bool
> :: Program -> Program -> Bool
$c>= :: Program -> Program -> Bool
>= :: Program -> Program -> Bool
$cmax :: Program -> Program -> Program
max :: Program -> Program -> Program
$cmin :: Program -> Program -> Program
min :: Program -> Program -> Program
Ord, Int -> Program -> ShowS
[Program] -> ShowS
Program -> String
(Int -> Program -> ShowS)
-> (Program -> String) -> ([Program] -> ShowS) -> Show Program
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Program -> ShowS
showsPrec :: Int -> Program -> ShowS
$cshow :: Program -> String
show :: Program -> String
$cshowList :: [Program] -> ShowS
showList :: [Program] -> ShowS
Show, Typeable, Typeable Program
Typeable Program =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> Program -> c Program)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Program)
-> (Program -> Constr)
-> (Program -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Program))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Program))
-> ((forall b. Data b => b -> b) -> Program -> Program)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Program -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Program -> r)
-> (forall u. (forall d. Data d => d -> u) -> Program -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Program -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Program -> m Program)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Program -> m Program)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Program -> m Program)
-> Data Program
Program -> Constr
Program -> DataType
(forall b. Data b => b -> b) -> Program -> Program
forall a.
Typeable a =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Program -> u
forall u. (forall d. Data d => d -> u) -> Program -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Program -> m Program
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Program -> m Program
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Program
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Program -> c Program
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Program)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Program)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Program -> c Program
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Program -> c Program
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Program
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Program
$ctoConstr :: Program -> Constr
toConstr :: Program -> Constr
$cdataTypeOf :: Program -> DataType
dataTypeOf :: Program -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Program)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Program)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Program)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Program)
$cgmapT :: (forall b. Data b => b -> b) -> Program -> Program
gmapT :: (forall b. Data b => b -> b) -> Program -> Program
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Program -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Program -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Program -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Program -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Program -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Program -> m Program
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Program -> m Program
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Program -> m Program
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Program -> m Program
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Program -> m Program
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Program -> m Program
Data, (forall x. Program -> Rep Program x)
-> (forall x. Rep Program x -> Program) -> Generic Program
forall x. Rep Program x -> Program
forall x. Program -> Rep Program x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Program -> Rep Program x
from :: forall x. Program -> Rep Program x
$cto :: forall x. Rep Program x -> Program
to :: forall x. Rep Program x -> Program
Generic)
      deriving Int -> Program -> Text
Int -> Program -> Text
Int -> Program -> Builder
[Program] -> Text
[Program] -> Text
[Program] -> Builder
Program -> Text
Program -> Text
Program -> Builder
(Int -> Program -> Builder)
-> (Program -> Builder)
-> ([Program] -> Builder)
-> (Int -> Program -> Text)
-> (Program -> Text)
-> ([Program] -> Text)
-> (Int -> Program -> Text)
-> (Program -> Text)
-> ([Program] -> Text)
-> TextShow Program
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Program -> Builder
showbPrec :: Int -> Program -> Builder
$cshowb :: Program -> Builder
showb :: Program -> Builder
$cshowbList :: [Program] -> Builder
showbList :: [Program] -> Builder
$cshowtPrec :: Int -> Program -> Text
showtPrec :: Int -> Program -> Text
$cshowt :: Program -> Text
showt :: Program -> Text
$cshowtList :: [Program] -> Text
showtList :: [Program] -> Text
$cshowtlPrec :: Int -> Program -> Text
showtlPrec :: Int -> Program -> Text
$cshowtl :: Program -> Text
showtl :: Program -> Text
$cshowtlList :: [Program] -> Text
showtlList :: [Program] -> Text
TextShow via FromGeneric Program

instance Hashable Program

---
--- Pretty printing (the concrete syntax; see doc/hyle.md, section 10).
---

-- | Keywords and operator names: rejected as bare identifiers by the
--   parser, and printed quoted when used as identifiers.
reservedWords :: HashSet Text
reservedWords :: HashSet Text
reservedWords = [Text] -> HashSet Text
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList ([Text] -> HashSet Text) -> [Text] -> HashSet Text
forall a b. (a -> b) -> a -> b
$
      [ Text
"let", Text
"in", Text
"if", Text
"then", Text
"else", Text
"undef"
      , Text
"extern", Text
"generic", Text
"clock", Text
"reset", Text
"input", Text
"output", Text
"model"
      , Text
"device", Text
"register", Text
"init", Text
"instance", Text
"of", Text
"next"
      ] [Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> (Op -> Text) -> [Op] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Op -> Text
opName [ Op
Add, Op
Sub, Op
Mul, Op
UDiv, Op
UMod, Op
Pow, Op
And, Op
Or, Op
XOr, Op
Not
                      , Op
Shl, Op
LShr, Op
AShr
                      , Op
Eq, Op
Ne, Op
ULt, Op
ULe, Op
UGt, Op
UGe, Op
SLt, Op
SLe, Op
SGt, Op
SGe
                      , Op
RedAnd, Op
RedOr, Op
RedXOr, Size -> Op
ZExt Size
0, Size -> Op
SExt Size
0, Size -> Op
Trunc Size
0, Natural -> Op
Rep Natural
0
                      ]

-- | Soft keywords, added after the format was in the wild: the parser
--   still accepts them as bare identifiers (files written before they
--   existed must keep parsing, and their clause positions are
--   unambiguous), but the printer quotes them so new output can't be
--   misread.
softKeywords :: HashSet Text
softKeywords :: HashSet Text
softKeywords = [Text] -> HashSet Text
forall a. (Eq a, Hashable a) => [a] -> HashSet a
Set.fromList [Text
"noinline", Text
"tag"]

-- | True for names that can print bare: an identifier-class name that
--   isn't a (soft) keyword. Everything else prints in double quotes.
bareName :: Name -> Bool
bareName :: Text -> Bool
bareName Text
x = case Text -> Maybe (Char, Text)
T.uncons Text
x of
      Just (Char
c, Text
cs) -> (Char -> Bool
isAlpha Char
c Bool -> Bool -> Bool
|| Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
"_$" :: String))
                   Bool -> Bool -> Bool
&& (Char -> Bool) -> Text -> Bool
T.all (\ Char
c' -> Char -> Bool
isAlphaNum Char
c' Bool -> Bool -> Bool
|| Char
c' Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
"_.$'" :: String)) Text
cs
                   Bool -> Bool -> Bool
&& Bool -> Bool
not (Text
x Text -> HashSet Text -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`Set.member` HashSet Text
reservedWords)
                   Bool -> Bool -> Bool
&& Bool -> Bool
not (Text
x Text -> HashSet Text -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`Set.member` HashSet Text
softKeywords)
      Maybe (Char, Text)
Nothing      -> Bool
False

ppName :: Name -> Doc an
ppName :: forall an. Text -> Doc an
ppName Text
x | Text -> Bool
bareName Text
x = Text -> Doc an
forall an. Text -> Doc an
text Text
x
         | Bool
otherwise  = Doc an -> Doc an
forall ann. Doc ann -> Doc ann
dquotes (Doc an -> Doc an) -> Doc an -> Doc an
forall a b. (a -> b) -> a -> b
$ Text -> Doc an
forall an. Text -> Doc an
text (Text -> Doc an) -> Text -> Doc an
forall a b. (a -> b) -> a -> b
$ (Char -> Text) -> Text -> Text
T.concatMap Char -> Text
esc Text
x
      where esc :: Char -> Text
            esc :: Char -> Text
esc = \ case
                  Char
'"'  -> Text
"\\\""
                  Char
'\\' -> Text
"\\\\"
                  Char
c    -> Char -> Text
T.singleton Char
c

ppTy :: Size -> Doc an
ppTy :: forall an. Size -> Doc an
ppTy Size
sz = Doc an -> Doc an
forall ann. Doc ann -> Doc ann
brackets (Doc an -> Doc an) -> Doc an -> Doc an
forall a b. (a -> b) -> a -> b
$ Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
sz

ppLit :: BV -> Doc an
ppLit :: forall an. BV -> Doc an
ppLit BV
bv | BV -> Int
width BV
bv Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Text -> Doc an
forall an. Text -> Doc an
text Text
"0'"
         | Bool
otherwise     = Int -> Doc an
forall ann. Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (BV -> Int
width BV
bv) Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> Doc an
forall ann. Doc ann
squote Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> Text -> Doc an
forall an. Text -> Doc an
text (BV -> Text
showHex' BV
bv)

ppPort :: (Name, Size) -> Doc an
ppPort :: forall an. (Text, Size) -> Doc an
ppPort (Text
x, Size
sz) = Text -> Doc an
forall an. Text -> Doc an
ppName Text
x Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
":" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Size -> Doc an
forall an. Size -> Doc an
ppTy Size
sz

-- | Provenance comment: one '--@ file:l:c-l:c' line when the annotation
--   carries a source span (re-parsed to the same span by Hyle.Parse; rwc
--   only emits these in .rwc output under --locators).
ppSpan :: Annote -> [Doc an]
ppSpan :: forall an. Annote -> [Doc an]
ppSpan Annote
a = case Annote -> Provenance
annProv Annote
a of
      FromSource (Span String
f (Int
l1, Int
c1) (Int
l2, Int
c2)) ->
            [ Text -> Doc an
forall an. Text -> Doc an
text (Text -> Doc an) -> Text -> Doc an
forall a b. (a -> b) -> a -> b
$ Text
"--@ " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
T.pack String
f Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. TextShow a => a -> Text
showt Int
l1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. TextShow a => a -> Text
showt Int
c1
                                        Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. TextShow a => a -> Text
showt Int
l2 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. TextShow a => a -> Text
showt Int
c2 ]
      Provenance
_ -> []

-- | Doc comments: one '--| \<text\>' line per doc entry (entries are split at
--   newlines so every printed line carries the marker and re-parses).
ppDocs :: Blind [Text] -> [Doc an]
ppDocs :: forall an. Blind [Text] -> [Doc an]
ppDocs (Blind [Text]
docs) = (Text -> Doc an) -> [Text] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map (\ Text
d -> Text -> Doc an
forall an. Text -> Doc an
text (Text -> Doc an) -> Text -> Doc an
forall a b. (a -> b) -> a -> b
$ Text
"--| " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
d) ([Text] -> [Doc an]) -> [Text] -> [Doc an]
forall a b. (a -> b) -> a -> b
$ (Text -> [Text]) -> [Text] -> [Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Text -> [Text]
T.lines [Text]
docs

-- | Expression at top (let/if) level.
ppExp :: Exp -> Doc an
ppExp :: forall an. Exp -> Doc an
ppExp = \ case
      Let Annote
_ Size
_ Text
x Exp
e1 Exp
e2  -> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
vsep [ Text -> Doc an
forall an. Text -> Doc an
text Text
"let" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
ppName Text
x Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"=" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
e1 Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"in", Exp -> Doc an
forall an. Exp -> Doc an
ppExp Exp
e2 ]
      If Annote
_ Size
_ Exp
c Exp
t Exp
e     -> Int -> Doc an -> Doc an
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc an -> Doc an) -> Doc an -> Doc an
forall a b. (a -> b) -> a -> b
$ [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
vsep [ Text -> Doc an
forall an. Text -> Doc an
text Text
"if" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
c Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"then" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
t, Text -> Doc an
forall an. Text -> Doc an
text Text
"else" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppExpUnderElse Exp
e ]
      Exp
e                -> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
e

-- | An if-chain prints flat (else if ...); other exps under "else" print at
--   top level.
ppExpUnderElse :: Exp -> Doc an
ppExpUnderElse :: forall an. Exp -> Doc an
ppExpUnderElse = \ case
      If Annote
_ Size
_ Exp
c Exp
t Exp
e -> Text -> Doc an
forall an. Text -> Doc an
text Text
"if" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
c Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"then" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppCat Exp
t Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"else" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc an
forall an. Exp -> Doc an
ppExpUnderElse Exp
e
      Exp
e            -> Exp -> Doc an
forall an. Exp -> Doc an
ppExp Exp
e

-- | Expression at concatenation level.
ppCat :: Exp -> Doc an
ppCat :: forall an. Exp -> Doc an
ppCat Exp
e = case Exp -> [Exp]
gather Exp
e of
      []  -> BV -> Doc an
forall an. BV -> Doc an
ppLit BV
BV.nil -- e is nil or a concatenation of nils
      [Exp
a] -> Exp -> Doc an
forall an. Exp -> Doc an
ppApp Exp
a
      [Exp]
es  -> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
hsep ([Doc an] -> Doc an) -> [Doc an] -> Doc an
forall a b. (a -> b) -> a -> b
$ Doc an -> [Doc an] -> [Doc an]
forall ann. Doc ann -> [Doc ann] -> [Doc ann]
punctuate (Text -> Doc an
forall an. Text -> Doc an
text Text
" #") ([Doc an] -> [Doc an]) -> [Doc an] -> [Doc an]
forall a b. (a -> b) -> a -> b
$ (Exp -> Doc an) -> [Exp] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Doc an
forall an. Exp -> Doc an
ppApp [Exp]
es

-- | Expression at application level.
ppApp :: Exp -> Doc an
ppApp :: forall an. Exp -> Doc an
ppApp = \ case
      Prim Annote
_ Size
_ Op
op [Exp]
es   -> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
hsep ([Doc an] -> Doc an) -> [Doc an] -> Doc an
forall a b. (a -> b) -> a -> b
$ Text -> Doc an
forall an. Text -> Doc an
text (Op -> Text
opName Op
op) Doc an -> [Doc an] -> [Doc an]
forall a. a -> [a] -> [a]
: Op -> [Doc an]
forall an. Op -> [Doc an]
ppOpArgs Op
op [Doc an] -> [Doc an] -> [Doc an]
forall a. Semigroup a => a -> a -> a
<> (Exp -> Doc an) -> [Exp] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Doc an
forall an. Exp -> Doc an
ppAtom [Exp]
es
      Call Annote
_ Size
_ Text
g [Exp]
es    -> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
hsep ([Doc an] -> Doc an) -> [Doc an] -> Doc an
forall a b. (a -> b) -> a -> b
$ Text -> Doc an
forall an. Text -> Doc an
ppName Text
g Doc an -> [Doc an] -> [Doc an]
forall a. a -> [a] -> [a]
: (Exp -> Doc an) -> [Exp] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Doc an
forall an. Exp -> Doc an
ppAtom [Exp]
es
      XCall Annote
_ Size
_ Text
x [Natural]
cs [Exp]
es -> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
hsep ([Doc an] -> Doc an) -> [Doc an] -> Doc an
forall a b. (a -> b) -> a -> b
$ (Text -> Doc an
forall an. Text -> Doc an
ppName Text
x Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> [Natural] -> Doc an
forall an. [Natural] -> Doc an
ppGenerics [Natural]
cs) Doc an -> [Doc an] -> [Doc an]
forall a. a -> [a] -> [a]
: (Exp -> Doc an) -> [Exp] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map Exp -> Doc an
forall an. Exp -> Doc an
ppAtom [Exp]
es
      Exp
e                -> Exp -> Doc an
forall an. Exp -> Doc an
ppAtom Exp
e
      where ppOpArgs :: Op -> [Doc an]
            ppOpArgs :: forall an. Op -> [Doc an]
ppOpArgs = \ case
                  ZExt Size
m  -> [Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
m]
                  SExt Size
m  -> [Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
m]
                  Trunc Size
m -> [Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
m]
                  Rep Natural
k   -> [Natural -> Doc an
forall ann. Natural -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Natural
k]
                  Op
_       -> []

ppGenerics :: [Natural] -> Doc an
ppGenerics :: forall an. [Natural] -> Doc an
ppGenerics = \ case
      [] -> Doc an
forall a. Monoid a => a
mempty
      [Natural]
cs -> Text -> Doc an
forall an. Text -> Doc an
text Text
"<" Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> [Doc an] -> Doc an
forall ann. [Doc ann] -> Doc ann
hcat (Doc an -> [Doc an] -> [Doc an]
forall ann. Doc ann -> [Doc ann] -> [Doc ann]
punctuate Doc an
forall ann. Doc ann
comma ([Doc an] -> [Doc an]) -> [Doc an] -> [Doc an]
forall a b. (a -> b) -> a -> b
$ (Natural -> Doc an) -> [Natural] -> [Doc an]
forall a b. (a -> b) -> [a] -> [b]
map Natural -> Doc an
forall ann. Natural -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty [Natural]
cs) Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> Text -> Doc an
forall an. Text -> Doc an
text Text
">"

-- | Expression at atom level: parenthesize anything that isn't atomic.
ppAtom :: Exp -> Doc an
ppAtom :: forall an. Exp -> Doc an
ppAtom = \ case
      Lit Annote
_ BV
bv        -> BV -> Doc an
forall an. BV -> Doc an
ppLit BV
bv
      Var Annote
_ Size
_ Text
x       -> Text -> Doc an
forall an. Text -> Doc an
ppName Text
x
      Slice Annote
_ Size
i Size
k Exp
e   -> Exp -> Doc an
forall an. Exp -> Doc an
ppAtom Exp
e Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> Doc an -> Doc an
forall ann. Doc ann -> Doc ann
brackets (Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
i Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"+:" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
k)
      Undef Annote
_ Size
sz      -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann
parens (Doc an -> Doc an) -> Doc an -> Doc an
forall a b. (a -> b) -> a -> b
$ Text -> Doc an
forall an. Text -> Doc an
text Text
"undef" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Size -> Doc an
forall an. Size -> Doc an
forall a ann. Pretty a => a -> Doc ann
pretty Size
sz
      Call Annote
_ Size
_ Text
g []   -> Text -> Doc an
forall an. Text -> Doc an
ppName Text
g
      XCall Annote
_ Size
_ Text
x [Natural]
cs [] -> Text -> Doc an
forall an. Text -> Doc an
ppName Text
x Doc an -> Doc an -> Doc an
forall a. Semigroup a => a -> a -> a
<> [Natural] -> Doc an
forall an. [Natural] -> Doc an
ppGenerics [Natural]
cs
      Exp
e               -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann
parens (Doc an -> Doc an) -> Doc an -> Doc an
forall a b. (a -> b) -> a -> b
$ Exp -> Doc an
forall an. Exp -> Doc an
ppExp Exp
e

instance Pretty Exp where
      pretty :: forall an. Exp -> Doc an
pretty = Exp -> Doc ann
forall an. Exp -> Doc an
ppExp

instance Pretty Op where
      pretty :: forall ann. Op -> Doc ann
pretty = Text -> Doc ann
forall an. Text -> Doc an
text (Text -> Doc ann) -> (Op -> Text) -> Op -> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Op -> Text
opName

instance Pretty Sig where
      pretty :: forall ann. Sig -> Doc ann
pretty (Sig Annote
_ [Size]
args Size
res) = Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens ([Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ Doc ann -> [Doc ann] -> [Doc ann]
forall ann. Doc ann -> [Doc ann] -> [Doc ann]
punctuate Doc ann
forall ann. Doc ann
comma ([Doc ann] -> [Doc ann]) -> [Doc ann] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ (Size -> Doc ann) -> [Size] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Size -> Doc ann
forall an. Size -> Doc an
ppTy [Size]
args) Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
"->" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Size -> Doc ann
forall an. Size -> Doc an
ppTy Size
res

instance Pretty Defn where
      pretty :: forall ann. Defn -> Doc ann
pretty (Defn Annote
a Text
n Sig
sig [Text]
ps Exp
e Bool
ni Blind [Text]
docs) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$
            Annote -> [Doc ann]
forall an. Annote -> [Doc an]
ppSpan Annote
a
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> Blind [Text] -> [Doc ann]
forall an. Blind [Text] -> [Doc an]
ppDocs Blind [Text]
docs
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> [ Text -> Doc ann
forall an. Text -> Doc an
ppName Text
n Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
":" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Sig -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Sig -> Doc ann
pretty Sig
sig
               , Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep [ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ([ Text -> Doc ann
forall an. Text -> Doc an
text Text
"noinline" | Bool
ni ] [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (Text -> Doc ann
forall an. Text -> Doc an
ppName Text
n Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
: (Text -> Doc ann) -> [Text] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Doc ann
forall an. Text -> Doc an
ppName [Text]
ps)) Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
"=", Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
align (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Exp -> Doc ann
forall an. Exp -> Doc an
ppExp Exp
e ]
               ]

instance Pretty ExternKind where
      pretty :: forall ann. ExternKind -> Doc ann
pretty = \ case
            ExternKind
Comb      -> Doc ann
forall a. Monoid a => a
mempty
            Seq Maybe Text
c Maybe Text
r   -> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> (Text -> [Doc ann]) -> Maybe Text -> [Doc ann]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ Text
c' -> [Text -> Doc ann
forall an. Text -> Doc an
text Text
"clock" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
c']) Maybe Text
c
                             [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> [Doc ann] -> (Text -> [Doc ann]) -> Maybe Text -> [Doc ann]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ Text
r' -> [Text -> Doc ann
forall an. Text -> Doc an
text Text
"reset" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
r']) Maybe Text
r

instance Pretty Extern where
      pretty :: forall ann. Extern -> Doc ann
pretty (Extern Annote
_ Text
n [Text]
gs ExternKind
k [(Text, Size)]
ins [(Text, Size)]
outs Maybe Text
m) = Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$
            [ Text -> Doc ann
forall an. Text -> Doc an
text Text
"extern" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
n ]
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (case [Text]
gs of
                  [] -> []
                  [Text]
_  -> [Text -> Doc ann
forall an. Text -> Doc an
text Text
"generic" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep (Doc ann -> [Doc ann] -> [Doc ann]
forall ann. Doc ann -> [Doc ann] -> [Doc ann]
punctuate Doc ann
forall ann. Doc ann
comma ([Doc ann] -> [Doc ann]) -> [Doc ann] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ (Text -> Doc ann) -> [Text] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Doc ann
forall an. Text -> Doc an
ppName [Text]
gs)])
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (case ExternKind
k of
                  ExternKind
Comb -> []
                  ExternKind
_    -> [ExternKind -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. ExternKind -> Doc ann
pretty ExternKind
k])
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> ((Text, Size) -> Doc ann) -> [(Text, Size)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Text, Size)
p -> Text -> Doc ann
forall an. Text -> Doc an
text Text
"input" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (Text, Size) -> Doc ann
forall an. (Text, Size) -> Doc an
ppPort (Text, Size)
p) [(Text, Size)]
ins
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> ((Text, Size) -> Doc ann) -> [(Text, Size)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Text, Size)
p -> Text -> Doc ann
forall an. Text -> Doc an
text Text
"output" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (Text, Size) -> Doc ann
forall an. (Text, Size) -> Doc an
ppPort (Text, Size)
p) [(Text, Size)]
outs
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> [Doc ann] -> (Text -> [Doc ann]) -> Maybe Text -> [Doc ann]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ Text
g -> [Text -> Doc ann
forall an. Text -> Doc an
text Text
"model" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
g]) Maybe Text
m

instance Pretty Register where
      pretty :: forall ann. Register -> Doc ann
pretty (Register Annote
a Text
x Size
sz BV
bv) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ Annote -> [Doc ann]
forall an. Annote -> [Doc an]
ppSpan Annote
a
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> [ Text -> Doc ann
forall an. Text -> Doc an
text Text
"register" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
":" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Size -> Doc ann
forall an. Size -> Doc an
ppTy Size
sz Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
"init" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> BV -> Doc ann
forall an. BV -> Doc an
ppLit BV
bv ]

instance Pretty Instance where
      pretty :: forall ann. Instance -> Doc ann
pretty (Instance Annote
_ Text
x Text
ex [Natural]
cs) = Text -> Doc ann
forall an. Text -> Doc an
text Text
"instance" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
"of" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
ex Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> [Natural] -> Doc ann
forall an. [Natural] -> Doc an
ppGenerics [Natural]
cs

instance Pretty Stmt where
      pretty :: forall ann. Stmt -> Doc ann
pretty = \ case
            SLet    Annote
_ Text
x Exp
e   -> Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Text -> Doc ann
forall an. Text -> Doc an
text Text
"let" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
"=" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc ann
forall an. Exp -> Doc an
ppExp Exp
e
            SOutput Annote
_ Text
x Exp
e   -> Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
":=" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc ann
forall an. Exp -> Doc an
ppExp Exp
e
            SNext   Annote
_ Text
x Exp
e   -> Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Text -> Doc ann
forall an. Text -> Doc an
text Text
"next" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
":=" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc ann
forall an. Exp -> Doc an
ppExp Exp
e
            SInstIn Annote
_ Text
x Text
p Exp
e -> Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Text -> Doc ann
forall an. Text -> Doc an
ppName Text
x Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall an. Text -> Doc an
text Text
"." Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
p Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
text Text
":=" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Exp -> Doc ann
forall an. Exp -> Doc an
ppExp Exp
e

instance Pretty Device where
      pretty :: forall ann. Device -> Doc ann
pretty (Device Annote
_ Text
n [(Text, Size)]
ins [(Text, Size)]
outs [Register]
regs [Instance]
insts [Stmt]
body (Blind [(Text, Integer)]
tags)) = Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
nest Int
6 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$
            [ Text -> Doc ann
forall an. Text -> Doc an
text Text
"device" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc ann
forall an. Text -> Doc an
ppName Text
n ]
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> ((Text, Size) -> Doc ann) -> [(Text, Size)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Text, Size)
p -> Text -> Doc ann
forall an. Text -> Doc an
text Text
"input" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (Text, Size) -> Doc ann
forall an. (Text, Size) -> Doc an
ppPort (Text, Size)
p) [(Text, Size)]
ins
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> ((Text, Size) -> Doc ann) -> [(Text, Size)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Text, Size)
p -> Text -> Doc ann
forall an. Text -> Doc an
text Text
"output" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (Text, Size) -> Doc ann
forall an. (Text, Size) -> Doc an
ppPort (Text, Size)
p) [(Text, Size)]
outs
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (Register -> Doc ann) -> [Register] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Register -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Register -> Doc ann
pretty [Register]
regs
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> ((Text, Integer) -> Doc ann) -> [(Text, Integer)] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Integer) -> Doc ann
forall an. (Text, Integer) -> Doc an
ppTag [(Text, Integer)]
tags
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (Instance -> Doc ann) -> [Instance] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Instance -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Instance -> Doc ann
pretty [Instance]
insts
            [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (Stmt -> Doc ann) -> [Stmt] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Stmt -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Stmt -> Doc ann
pretty [Stmt]
body
            where ppTag :: (Text, Integer) -> Doc an
                  ppTag :: forall an. (Text, Integer) -> Doc an
ppTag (Text
x, Integer
v) = Text -> Doc an
forall an. Text -> Doc an
text Text
"tag" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
ppName Text
x Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Text -> Doc an
forall an. Text -> Doc an
text Text
"=" Doc an -> Doc an -> Doc an
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Integer -> Doc an
forall ann. Integer -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Integer
v

instance Pretty Program where
      pretty :: forall ann. Program -> Doc ann
pretty (Program [Extern]
exts [Defn]
ds Device
dev) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep ([Doc ann] -> Doc ann) -> [Doc ann] -> Doc ann
forall a b. (a -> b) -> a -> b
$ Doc ann -> [Doc ann] -> [Doc ann]
forall a. a -> [a] -> [a]
intersperse (Text -> Doc ann
forall an. Text -> Doc an
text Text
"") ([Doc ann] -> [Doc ann]) -> [Doc ann] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$
            (Extern -> Doc ann) -> [Extern] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Extern -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Extern -> Doc ann
pretty [Extern]
exts [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> (Defn -> Doc ann) -> [Defn] -> [Doc ann]
forall a b. (a -> b) -> [a] -> [b]
map Defn -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Defn -> Doc ann
pretty [Defn]
ds [Doc ann] -> [Doc ann] -> [Doc ann]
forall a. Semigroup a => a -> a -> a
<> [Device -> Doc ann
forall a ann. Pretty a => a -> Doc ann
forall ann. Device -> Doc ann
pretty Device
dev]