clash-lib-1.8.1: Clash: a functional hardware description language - As a library

Copyright | (C) 2012-2016 University of Twente
License | BSD2 (see the file LICENSE)
Maintainer | Christiaan Baaij <christiaan.baaij@gmail.com>
Safe Haskell | Safe-Inferred
Language | Haskell2010

Clash.Util

Description

Assortment of utility function used in the Clash library

Synopsis

- class Monad m => MonadUnique m where
  - getUniqueM :: m Int
- data ClashException = ClashException SrcSpan String (Maybe String)
- assertPanic :: String -> Int -> a
- pprDebugAndThen :: (String -> a) -> Doc ann -> Doc ann -> a
- pprPanic :: String -> Doc ann -> a
- callStackDoc :: HasCallStack => Doc ann
- assertPprPanic :: HasCallStack => String -> Int -> Doc ann -> a
- pprTrace :: String -> Doc ann -> a -> a
- pprTraceDebug :: String -> Doc ann -> a -> a
- warnPprTrace :: HasCallStack => Bool -> String -> Int -> Doc ann -> a -> a
- curLoc :: Q Exp
- makeCached :: (MonadState s m, Hashable k, Eq k) => k -> Lens' s (HashMap k v) -> m v -> m v
- indexNote :: HasCallStack => String -> [a] -> Int -> a
- clogBase :: Integer -> Integer -> Maybe Int
- thenCompare :: Ordering -> Ordering -> Ordering
- reportTimeDiff :: UTCTime -> UTCTime -> String
- wantedLanguageExtensions :: [Extension]
- unwantedLanguageExtensions :: [Extension]
- makeCachedU :: (MonadState s m, Uniquable k) => k -> Lens' s (UniqMap v) -> m v -> m v
- makeCachedO :: (MonadState s m, Uniquable k) => k -> Lens' s (OMap Unique v) -> m v -> m v
- indexNote' :: HasCallStack => String -> Int -> [a] -> a
- clashLibVersion :: Version
- flogBase :: Integer -> Integer -> Maybe Int
- pkgIdFromTypeable :: Typeable a => a -> String
- orElses :: [Maybe a] -> Maybe a
- hoistMaybe :: Applicative m => Maybe b -> MaybeT m b
- data SrcSpan
- noSrcSpan :: SrcSpan

# Documentation

class Monad m => MonadUnique m where Source #

A class that can generate unique numbers

Methods

getUniqueM :: m Int Source #

Get a new unique

#### Instances

Instances details

MonadUnique (RewriteMonad extra) Source # |
Instance details Defined in Clash.Rewrite.Types Methods getUniqueM :: RewriteMonad extra Int Source #
Monad m => MonadUnique (StateT Int m) Source # |
Instance details Defined in Clash.Util Methods getUniqueM :: StateT Int m Int Source #

data ClashException Source #

Constructors

ClashException SrcSpan String (Maybe String) |

#### Instances

Instances details

Exception ClashException Source # |
Instance details Defined in Clash.Util Methods toException :: ClashException -> SomeException Source # fromException :: SomeException -> Maybe ClashException Source # displayException :: ClashException -> String Source #
Show ClashException Source # |
Instance details Defined in Clash.Util Methods showsPrec :: Int -> ClashException -> ShowS Source # show :: ClashException -> String Source # showList :: [ClashException] -> ShowS Source #

assertPanic :: String -> Int -> a Source #

pprDebugAndThen :: (String -> a) -> Doc ann -> Doc ann -> a Source #

pprPanic :: String -> Doc ann -> a Source #

callStackDoc :: HasCallStack => Doc ann Source #

assertPprPanic :: HasCallStack => String -> Int -> Doc ann -> a Source #

pprTrace :: String -> Doc ann -> a -> a Source #

pprTraceDebug :: String -> Doc ann -> a -> a Source #

warnPprTrace Source #

Arguments

:: HasCallStack |
=> Bool | Trigger warning?
-> String | File name
-> Int | Line number
-> Doc ann | Message
-> a | Pass value (like trace)
-> a |

curLoc :: Q Exp Source #

Create a TH expression that returns the a formatted string containing the name of the module `curLoc` is spliced into, and the line where it was spliced.

makeCached Source #

Arguments

:: (MonadState s m, Hashable k, Eq k) |
=> k | The key the action is associated with
-> Lens' s (HashMap k v) | The Lens to the HashMap that is the cache
-> m v | The action to cache
-> m v |

Cache the result of a monadic action

indexNote Source #

Arguments

:: HasCallStack |
=> String | Error message to display
-> [a] | List to index
-> Int | Index n
-> a | Error or element n

Unsafe indexing, return a custom error message when indexing fails

clogBase :: Integer -> Integer -> Maybe Int Source #

x y -> ceiling (logBase x y), x > 1 && y > 0

thenCompare :: Ordering -> Ordering -> Ordering Source #

reportTimeDiff :: UTCTime -> UTCTime -> String Source #

wantedLanguageExtensions :: [Extension] Source #

unwantedLanguageExtensions :: [Extension] Source #

makeCachedU Source #

Arguments

:: (MonadState s m, Uniquable k) |
=> k | Key the action is associated with
-> Lens' s (UniqMap v) | Lens to the cache
-> m v | Action to cache
-> m v |

Cache the result of a monadic action using a `UniqMap`

makeCachedO Source #

Arguments

:: (MonadState s m, Uniquable k) |
=> k | Key the action is associated with
-> Lens' s (OMap Unique v) | Lens to the cache
-> m v | Action to cache
-> m v |

Cache the result of a monadic action using a `OMap`

indexNote' Source #

Arguments

:: HasCallStack |
=> String | Error message to display
-> Int | Index n
-> [a] | List to index
-> a | Error or element n

Same as `indexNote` with last two arguments swapped

clashLibVersion :: Version Source #

flogBase :: Integer -> Integer -> Maybe Int Source #

x y -> floor (logBase x y), x > 1 && y > 0

pkgIdFromTypeable :: Typeable a => a -> String Source #

Get the package id of the type of a value

    >>> pkgIdFromTypeable (0 :: Unsigned 32)
    "clash-prelude-...

orElses :: [Maybe a] -> Maybe a Source #

Left-biased choice on maybes

hoistMaybe :: Applicative m => Maybe b -> MaybeT m b Source #

data SrcSpan Source #

Source Span

A `SrcSpan` identifies either a specific portion of a text file or a human-readable description of a location.

#### Instances

Instances details

Data SrcSpan |

Instance details

Defined in GHC.Types.SrcLoc

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SrcSpan -> c SrcSpan Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SrcSpan Source #

toConstr :: SrcSpan -> Constr Source #

dataTypeOf :: SrcSpan -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SrcSpan) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SrcSpan) Source #

gmapT :: (forall b. Data b => b -> b) -> SrcSpan -> SrcSpan Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SrcSpan -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> SrcSpan -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SrcSpan -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SrcSpan -> m SrcSpan Source #

Generic SrcSpan Source # |
Instance details Defined in GHC.SrcLoc.Extra Associated Types type Rep SrcSpan :: Type -> Type Source # Methods from :: SrcSpan -> Rep SrcSpan x Source # to :: Rep SrcSpan x -> SrcSpan Source #
Show SrcSpan |
Instance details Defined in GHC.Types.SrcLoc Methods showsPrec :: Int -> SrcSpan -> ShowS Source # show :: SrcSpan -> String Source # showList :: [SrcSpan] -> ShowS Source #
Binary SrcSpan Source # |
Instance details Defined in GHC.SrcLoc.Extra Methods put :: SrcSpan -> Put Source # get :: Get SrcSpan Source # putList :: [SrcSpan] -> Put Source #
PrettyPrec SrcSpan Source # |
Instance details Defined in Clash.Core.Pretty Methods pprPrec :: Monad m => Rational -> SrcSpan -> m ClashDoc Source # pprPrec' :: Monad m => PrettyOptions -> Rational -> SrcSpan -> m ClashDoc Source #
NFData SrcSpan |
Instance details Defined in GHC.Types.SrcLoc Methods rnf :: SrcSpan -> () Source #
ToJson SrcSpan |
Instance details Defined in GHC.Types.SrcLoc Methods json :: SrcSpan -> JsonDoc Source #
Outputable SrcSpan |
Instance details Defined in GHC.Types.SrcLoc Methods ppr :: SrcSpan -> SDoc Source #
Eq SrcSpan |
Instance details Defined in GHC.Types.SrcLoc Methods (==) :: SrcSpan -> SrcSpan -> Bool Source # (/=) :: SrcSpan -> SrcSpan -> Bool Source #
Hashable SrcSpan Source # |
Instance details Defined in GHC.SrcLoc.Extra Methods hashWithSalt :: Int -> SrcSpan -> Int Source # hash :: SrcSpan -> Int Source #
Outputable e => Outputable (Located e) |
Instance details Defined in GHC.Types.SrcLoc Methods ppr :: Located e -> SDoc Source #
type Rep SrcSpan Source # |

Instance details

Defined in GHC.SrcLoc.Extra

type Rep SrcSpan = D1 ('MetaData "SrcSpan" "GHC.Types.SrcLoc" "ghc" 'False) (C1 ('MetaCons "RealSrcSpan" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 RealSrcSpan) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Maybe BufSpan))) :+: C1 ('MetaCons "UnhelpfulSpan" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 UnhelpfulSpanReason)))

noSrcSpan :: SrcSpan Source #

Built-in "bad" `SrcSpan`s for common sources of location uncertainty