clash-lib-1.2.0: CAES Language for Synchronous Hardware - As a Library

Copyright(C) 2012-2016 University of Twente
2016-2017 Myrtle Software Ltd
2017 Google Inc.
LicenseBSD2 (see the file LICENSE)
MaintainerChristiaan Baaij <>
Safe HaskellNone



Functions to create BlackBox Contexts and fill in BlackBox templates



warn :: ClashOpts -> String -> IO () Source #

Emits (colorized) warning to stderr

mkBlackBoxContext Source #


:: Text

Blackbox function name

-> Id

Identifier binding the primitive/blackbox application

-> [Either Term Type]

Arguments of the primitive/blackbox application

-> NetlistMonad (BlackBoxContext, [Declaration]) 

Generate the context for a BlackBox instantiation.

isLiteral :: Term -> Bool Source #

Determine if a term represents a literal

mkArgument Source #


:: Text

Blackbox function name

-> Identifier

LHS of the original let-binder

-> Int

Argument n (zero-indexed). Used for error message.

-> Term 
-> NetlistMonad ((Expr, HWType, Bool), [Declaration]) 

extractPrimWarnOrFail Source #


:: HasCallStack 
=> Text

Name of primitive

-> NetlistMonad CompiledPrimitive 

Extract a compiled primitive from a guarded primitive. Emit a warning if the guard wants to, or fail entirely.

mkPrimitive Source #


:: Bool

Put BlackBox expression in parenthesis

-> Bool

Treat BlackBox expression as declaration

-> NetlistId

Id to assign the result to

-> PrimInfo

Primitive info

-> [Either Term Type]


-> [Declaration]

Tick declarations

-> NetlistMonad (Expr, [Declaration]) 

collectMealy Source #


:: HasCallStack 
=> Identifier

Identifier to assign the final result to

-> NetlistId

Id to assign the final result to

-> TyConMap 
-> [Term]

The arguments to mealyIO

-> NetlistMonad [Declaration] 

Turn a mealyIO expression into a two sequential processes, one "initial" process for the starting state, and one clocked sequential process.

collectBindIO :: NetlistId -> [Term] -> NetlistMonad (Expr, [Declaration]) Source #

Collect the sequential declarations for bindIO

collectAppIO :: NetlistId -> [Term] -> [Term] -> NetlistMonad (Expr, [Declaration]) Source #

Collect the sequential declarations for appIO

unSimIO :: TyConMap -> Term -> Term Source #

Unwrap the new-type wrapper for things of type SimIO, this is needed to allow applications of the `State# World` token to the underlying IO type.

XXX: this is most likely needed because Ghc2Core that threw away the cast that this unwrapping; we should really start to support casts.

mkFunInput Source #


:: HasCallStack 
=> Id

Identifier binding the encompassing primitive/blackbox application

-> Term

The function argument term

-> NetlistMonad ((Either BlackBox (Identifier, [Declaration]), WireOrReg, [BlackBoxTemplate], [BlackBoxTemplate], [((Text, Text), BlackBox)], BlackBoxContext), [Declaration]) 

Create an template instantiation text and a partial blackbox content for an argument term, given that the term is a function. Errors if the term is not a function