| Copyright | (C) 2025-2026 QBayLogic B.V. |
|---|---|
| License | BSD2 (see the file LICENSE) |
| Maintainer | QBayLogic B.V. <devops@qbaylogic.com> |
| Safe Haskell | None |
| Language | Haskell2010 |
Clash.Shockwaves.Internal.Waveform
Description
The Waveform class, functions derived from it, special Waveform variants such as
WaveformLUT, and Waveform instances for default types.
Synopsis
- defaultRender :: Value -> Render
- tStyled :: WaveStyle -> Translator -> Translator
- tDup :: SubSignal -> Translator -> Translator
- tRef :: Waveform a => Translator
- tConst :: Render -> Translator
- tLut :: (Waveform a, WaveformLUT a) => Maybe LUT -> Translator
- tGeneratedLut :: (Waveform a, WaveformLUT a) => Translator
- tStaticLut :: (Waveform a, WaveformLUT a) => LUT -> Translator
- class (Typeable a, BitPack a) => Waveform a where
- typeName :: TypeName
- translator :: Translator
- constructorStyles :: [WaveStyle]
- width :: Int
- defaultTranslator :: (Waveform a, WaveformG (Rep a ())) => Translator
- translate :: (Waveform a, BitPack a) => a -> Translation
- translateBin :: Waveform a => BitList -> Translation
- addTypes :: Waveform a => TypeMap -> TypeMap
- constructorStyles' :: Waveform a => [WaveStyle]
- hasGeneratedLut :: Waveform a => Bool
- structure :: Waveform a => Structure
- addValue :: Waveform a => a -> [LUTMap -> LUTMap]
- noConstructorSubsignals :: Bool -> Translator -> Translator
- renameFields :: [[String]] -> Translator -> Translator
- renameConstructors :: [String] -> Translator -> Translator
- inheritSingleFieldStyle :: Translator -> Translator
- withConstructorStyles :: [WaveStyle] -> Translator -> Translator
- class WaveformG a where
- translatorG :: Int -> Translator
- constrTranslatorsG :: [Translator]
- fieldTranslatorsG :: [(SubSignal, Translator)]
- widthG :: Int
- translateWithG :: Render -> a -> [(SubSignal, Translation)]
- translateFieldsG :: a -> [(SubSignal, Translation)]
- left :: forall {k1} a (b :: k1 -> Type) (k2 :: k1). (a :*: b) k2 -> a k2
- right :: forall {k1} (a :: k1 -> Type) b (k2 :: k1). (a :*: b) k2 -> b k2
- class (Typeable a, BitPack a) => WaveformLUT a where
- structureL :: Structure
- translateL :: a -> Translation
- staticL :: Maybe [(a, Translation)]
- staticLutL :: WaveformLUT a => Maybe LUT
- staticLut :: BitPack a => [(a, Translation)] -> LUT
- translateStaticL :: (Waveform a, WaveformLUT a) => a -> Translation
- safeTranslation :: Translation -> Translation
- translateWith :: (a -> Render) -> (Render -> a -> [(SubSignal, Translation)]) -> a -> Translation
- renderShow :: (Show a, Generic a, PrecG (Rep a ())) => a -> Render
- renderWith :: (a -> Value) -> (a -> WaveStyle) -> (a -> Prec) -> a -> Render
- translateAtomWith :: (a -> Value) -> a -> Translation
- translateAtomShow :: Show a => a -> Translation
- translateAtomSigWith :: Show a => (a -> Value) -> a -> Translation
- translateAtomSigShow :: Show a => a -> Translation
- splitL :: (Generic a, WaveformG (Rep a ())) => Render -> a -> [(SubSignal, Translation)]
- noSplit :: Render -> a -> [(SubSignal, Translation)]
- precL :: (PrecG (Rep a ()), Generic a) => a -> Prec
- newtype WaveformForLut a = WaveformForLut a
- class Generic a => PrecG a where
- class PrecF (f :: FixityI) where
- class (BitPack a, Typeable a) => WaveformConst a where
- newtype WaveformForConst a = WfConst a
- newtype WaveformForNumber (f :: NumberFormat) (s :: Maybe NSPair) a = WaveformForNumber a
- type NSPair = (Nat, Symbol)
- type DecSpacer = 'Just '(3, "_")
- type HexSpacer = 'Just '(2, "_")
- type OctSpacer = 'Just '(4, "_")
- type BinSpacer = 'Just '(8, "_")
- type SpacerEvery (n :: k) = 'Just '(n, "_")
- type NoSpacer = 'Nothing :: Maybe NSPair
- class KnownNFormat (f :: NumberFormat) where
- formatVal :: proxy f -> NumberFormat
- class KnownNSpacer (f :: Maybe NSPair) where
- type family RTreeIsLeaf (d :: Natural) :: Bool where ...
- class WaveformRTree (isLeaf :: Bool) (d :: k) (a :: k1) where
- tupleTranslator :: (BitPack t, WaveformG (Rep t ())) => Translator
Documentation
defaultRender :: Value -> Render Source #
tStyled :: WaveStyle -> Translator -> Translator Source #
Wrap a Translator in a TStyled variant translator with the
provided style.
tDup :: SubSignal -> Translator -> Translator Source #
Wrap a Translator in a TDuplicate variant translator with the
provided subsignal name.
tRef :: Waveform a => Translator Source #
Generate a translator reference for a type.
Also checks whether the translator width matches the value of bitSize for
the type: if not, the function errors.
tConst :: Render -> Translator Source #
Create a constant translator that consumes 0 bits and has no subsignals.
tLut :: (Waveform a, WaveformLUT a) => Maybe LUT -> Translator Source #
Create a LUT translator for a type, using either the static LUT or the translation
function specified in WaveformLUT
tGeneratedLut :: (Waveform a, WaveformLUT a) => Translator Source #
Create a LUT translator for a type, using the translation function of WaveformLUT.
tStaticLut :: (Waveform a, WaveformLUT a) => LUT -> Translator Source #
Create a LUT translator for a type, using the static LUT in WaveformLUT.
class (Typeable a, BitPack a) => Waveform a where Source #
Waveform is the main class for making types displayable in the waveform viewer.
The class is responsible for defining an appropriate translator and subsignal
structure, as well as registering types.
To make a LUT approache possible, the class must also be able to translate values, and to register individual values.
By default, Generic is used to automatically derive this behaviour.
Extra classes are provided to help implement lookup tables or common types,
like numerical translators. Custom implementations are also very possible.
Minimal complete definition
Nothing
Methods
Provide the type name. Overriding this value is only really useful for derive via strategies.
translator :: Translator Source #
The translator used for the data type. Must match the structure value.
default translator :: WaveformG (Rep a ()) => Translator Source #
constructorStyles :: [WaveStyle] Source #
List of styles used for constructors.
Since assigning different constructors different colors is a very common usecase
of the waveform style,
this list can be overridden to provides styles for the constructors, in order.
To not change a style, use WSDefault.
Deprecated: Use bitSize instead
Defines the width of the translator based on bitSize
Instances
defaultTranslator :: (Waveform a, WaveformG (Rep a ())) => Translator Source #
Return the default translator that is derived for a data type. This default can be modified to obtain a slightly different translator.
translate :: (Waveform a, BitPack a) => a -> Translation Source #
Function to translate values. This function creates a translation from the binary representation of the data using translateBin, and the translator.
translateBin :: Waveform a => BitList -> Translation Source #
Translate binary data. Normally, this simply translates the value according to the translator. For LUTs, this involves translating the value back to the original type and translating it using a specially defined translation function.
constructorStyles' :: Waveform a => [WaveStyle] Source #
Helper function that fills the constructorStyles list with WSDefault.
hasGeneratedLut :: Waveform a => Bool Source #
Check if the type requires values to be added to LUTs.
addValue :: Waveform a => a -> [LUTMap -> LUTMap] Source #
Add all (sub) values that use TLut to their respective LUTs.
noConstructorSubsignals :: Bool -> Translator -> Translator Source #
Remove constructor subsignals from a (generated) translator.
This results in all constructor field subsignals becoming direct subsignals of the toplevel signal.
Set rename to True to add the constructor's name as a prefix to the signal name.
Essentially, this function searches through TStyled and TSum for any TDuplicate translators to remove.
If renaming subsignals, it then searches through TStyled to rename subsignals in TProduct.
renameFields :: [[String]] -> Translator -> Translator Source #
Rename constructor fields. This is particularly useful for non-record types.
The input is a list of a list of field names, per constructor.
Errors if the number of constructors/fields does not match the structure of the Translator.
For translators other than TProduct, use an empty list of fieldnames.
renameConstructors :: [String] -> Translator -> Translator Source #
Rename the constructors subsignals of a data type. Errors if the number of constructor subsignal names provided is incorrect, or when called on a translator that does not have a sum translator.
inheritSingleFieldStyle :: Translator -> Translator Source #
Wrap constructors with a single field in the WSInherit 0 style.
Ignores any structures that are wrapped in a TStyled translator.
withConstructorStyles :: [WaveStyle] -> Translator -> Translator Source #
class WaveformG a where Source #
A class for obtaining the required behaviour of Waveform through GHC.Generics.
The exact details might change later; use at your own risk.
Methods
translatorG :: Int -> Translator Source #
Given a bitsize and list of styles for the constructors, provide a translator.
Defined only for full types and constructors
constrTranslatorsG :: [Translator] Source #
Return a list of translators for constructors as subsignals.
Defined for constructors, :+: and types with multiple constructors.
fieldTranslatorsG :: [(SubSignal, Translator)] Source #
Return a list of translators for fields.
Defined for fields, :*:, constructors, and types with a single constructor.
Product type subsignals are labeled (numbered) for types and constructors only.
Bitsize of a type. Only used to determine the width of constructors (and their fields).
Defined for constructors, :*:, and fields.
translateWithG :: Render -> a -> [(SubSignal, Translation)] Source #
For LUTs.
Create translation subsignals from supplied Render value.
Duplicate the value if there are multiple constructors, and just translate the fields.
If getting the constructor fails, create no subsignals.
Defined for types, :+: and constructors.
translateFieldsG :: a -> [(SubSignal, Translation)] Source #
For LUTs. Translate all fields of a (the) constructor.
Defined for constructors, :*:, fields and types with 1 constructor.
Instances
left :: forall {k1} a (b :: k1 -> Type) (k2 :: k1). (a :*: b) k2 -> a k2 Source #
Lazily get left field.
right :: forall {k1} (a :: k1 -> Type) b (k2 :: k1). (a :*: b) k2 -> b k2 Source #
Lazily get right field.
class (Typeable a, BitPack a) => WaveformLUT a where Source #
Class for easily defining custom translations for a type by using LUTs.
To use this class, a type must derive Waveform via WaveformForLut.
Bye default, the implementation uses Generic for defining subsignals
and operator precedence, and Show for displaying the value.
Minimal complete definition
Nothing
Methods
structureL :: Structure Source #
Provides the hierarchy of subsignals.
translateL :: a -> Translation Source #
Translate a value. The translations must adhere to the structure defined in structureL.
This function must be robust to undefined values!
default translateL :: (Generic a, Show a, WaveformG (Rep a ()), PrecG (Rep a ())) => a -> Translation Source #
staticL :: Maybe [(a, Translation)] Source #
A static lookup table.
To use a static lookup table rather than one created from the values found during simulation,
set this to a list of values and their translations. Set translateL and structureL to undefined.
Instances
| WaveformLUT Bit Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
| BitPack Char => WaveformLUT Char Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
| WaveformLUT Double Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
| WaveformLUT Float Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
| KnownDomain dom => WaveformLUT (CREWave dom) Source # | Control the style of a combined disable and reset through style variable
|
Defined in Clash.Shockwaves.Internal.Trace.CRE | |
| (BitPack (Fixed r i f), KnownNat i, KnownNat f, Show (Fixed r i f), Typeable r) => WaveformLUT (Fixed r i f) Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
staticLutL :: WaveformLUT a => Maybe LUT Source #
Return the static LUT of a type with WaveformLUT
staticLut :: BitPack a => [(a, Translation)] -> LUT Source #
Turn a list of (value,translation) pairs into a LUT
translateStaticL :: (Waveform a, WaveformLUT a) => a -> Translation Source #
Translate a value from a type with a static LUT
safeTranslation :: Translation -> Translation Source #
Make sure a Translation is fully defined. If not, return a Translation with "undefined".
translateWith :: (a -> Render) -> (Render -> a -> [(SubSignal, Translation)]) -> a -> Translation Source #
Given a function that renders a value, and a function that (given this Render)
prodices the subsignals, create a translation.
If rendering fails, "undefined" is displayed. If creating the subsignals fails, no subsignals are shown.
renderWith :: (a -> Value) -> (a -> WaveStyle) -> (a -> Prec) -> a -> Render Source #
Display a value with the provided functions for creating the text value, style and operator precedence.
translateAtomWith :: (a -> Value) -> a -> Translation Source #
Display an atomic value (such as a number) using the provided function to obtain the value. (normal wavestyle, precedence 11).
translateAtomShow :: Show a => a -> Translation Source #
Display an atomic value (like a number) with Show. See translateAtomWith.
translateAtomSigWith :: Show a => (a -> Value) -> a -> Translation Source #
Render an atomic value representing a signed number.
If the render value is found to start with -, the precedence is set to 0.
translateAtomSigShow :: Show a => a -> Translation Source #
Render an atomic value representing a signed number using show.
See translateAtomSigWith.
splitL :: (Generic a, WaveformG (Rep a ())) => Render -> a -> [(SubSignal, Translation)] Source #
Create subsignals for the constructors and fields. Constructor translations are a copy of the toplevel render value provided.
newtype WaveformForLut a Source #
Type for deriving Waveform for types implementing WaveformLUT.
type T = ... deriving (...) deriving via WaveformForLut T instance Waveform T isntance WaveformLUT T where ...
Constructors
| WaveformForLut a |
Instances
class Generic a => PrecG a where Source #
Helper class for determining the precedence and number of fields of a value's constructor.
Minimal complete definition
Methods
Operator precedence of a value.
Return the number of fields of a constructor. This is needed to determine whether a constructor is atomic or not.
Instances
| PrecG (U1 k2) Source # | |
| PrecG (V1 k2) Source # | |
| (PrecG (a k2), PrecG (b k2)) => PrecG ((a :*: b) k2) Source # | |
| (PrecG (a k2), PrecG (b k2)) => PrecG ((a :+: b) k2) Source # | |
| (PrecG (fields k2), PrecF fix) => PrecG (C1 ('MetaCons name fix 'False) fields k2) Source # | |
| (PrecG (fields k2), PrecF fix) => PrecG (C1 ('MetaCons name fix 'True) fields k2) Source # | |
| PrecG (c k2) => PrecG (D1 m1 c k2) Source # | |
| PrecG (S1 ('MetaSel n p q r) t k2) Source # | |
class PrecF (f :: FixityI) where Source #
Class for obtaining the runtime precedence of a typelevel fixity value.
class (BitPack a, Typeable a) => WaveformConst a where Source #
Helper class for defining a constant translation value. To use this, derive Waveform via WaveformForConst.
Minimal complete definition
Methods
constTrans :: Translation Source #
The constant translation value. Overwrite this if the translation has subsignals.
Constant render value. Overwrite this if the constant value has no subsignals.
Instances
| WaveformConst () Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
| (KnownNat n, BitPack (SNat n)) => WaveformConst (SNat n) Source # | |
Defined in Clash.Shockwaves.Internal.Waveform | |
newtype WaveformForConst a Source #
Helper class for deriving Waveform for types implementing WaveformConst.
Constructors
| WfConst a |
Instances
| BitPack a => BitPack (WaveformForConst a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform Associated Types
Methods pack :: WaveformForConst a -> BitVector (BitSize (WaveformForConst a)) # unpack :: BitVector (BitSize (WaveformForConst a)) -> WaveformForConst a # | |||||
| (WaveformConst a, BitPack a, Typeable a) => Waveform (WaveformForConst a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform | |||||
| Generic (WaveformForConst a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform Associated Types
Methods from :: WaveformForConst a -> Rep (WaveformForConst a) x # to :: Rep (WaveformForConst a) x -> WaveformForConst a # | |||||
| type BitSize (WaveformForConst a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform type BitSize (WaveformForConst a) = CLog 2 (GConstructorCount (Rep (WaveformForConst a))) + GFieldSize (Rep (WaveformForConst a)) | |||||
| type Rep (WaveformForConst a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform type Rep (WaveformForConst a) = D1 ('MetaData "WaveformForConst" "Clash.Shockwaves.Internal.Waveform" "clash-shockwaves-1.1.0-inplace" 'True) (C1 ('MetaCons "WfConst" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) | |||||
newtype WaveformForNumber (f :: NumberFormat) (s :: Maybe NSPair) a Source #
Helper class for deriving Waveform for numerical types.
Options are provided at the type level (signed, format).
Example:
deriving via WaveformForNumber NFSig ('Just '(3,"_")) instance Waveform (Signed 3)
Constructors
| WaveformForNumber a |
Instances
| BitPack a => BitPack (WaveformForNumber f s a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform Associated Types
Methods pack :: WaveformForNumber f s a -> BitVector (BitSize (WaveformForNumber f s a)) # unpack :: BitVector (BitSize (WaveformForNumber f s a)) -> WaveformForNumber f s a # | |||||
| (BitPack a, Typeable a, Typeable f, Typeable s, KnownNFormat f, KnownNSpacer s) => Waveform (WaveformForNumber f s a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform | |||||
| Generic (WaveformForNumber f s a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform Associated Types
Methods from :: WaveformForNumber f s a -> Rep (WaveformForNumber f s a) x # to :: Rep (WaveformForNumber f s a) x -> WaveformForNumber f s a # | |||||
| type BitSize (WaveformForNumber f s a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform type BitSize (WaveformForNumber f s a) = CLog 2 (GConstructorCount (Rep (WaveformForNumber f s a))) + GFieldSize (Rep (WaveformForNumber f s a)) | |||||
| type Rep (WaveformForNumber f s a) Source # | |||||
Defined in Clash.Shockwaves.Internal.Waveform type Rep (WaveformForNumber f s a) = D1 ('MetaData "WaveformForNumber" "Clash.Shockwaves.Internal.Waveform" "clash-shockwaves-1.1.0-inplace" 'True) (C1 ('MetaCons "WaveformForNumber" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) | |||||
type SpacerEvery (n :: k) = 'Just '(n, "_") Source #
Add _ every n digits.
class KnownNFormat (f :: NumberFormat) where Source #
Class for turning a type level NumberFormat into a runtime value.
Methods
formatVal :: proxy f -> NumberFormat Source #
Instances
| KnownNFormat 'NFBin Source # | |
Defined in Clash.Shockwaves.Internal.Waveform Methods formatVal :: proxy 'NFBin -> NumberFormat Source # | |
| KnownNFormat 'NFHex Source # | |
Defined in Clash.Shockwaves.Internal.Waveform Methods formatVal :: proxy 'NFHex -> NumberFormat Source # | |
| KnownNFormat 'NFOct Source # | |
Defined in Clash.Shockwaves.Internal.Waveform Methods formatVal :: proxy 'NFOct -> NumberFormat Source # | |
| KnownNFormat 'NFSig Source # | |
Defined in Clash.Shockwaves.Internal.Waveform Methods formatVal :: proxy 'NFSig -> NumberFormat Source # | |
| KnownNFormat 'NFUns Source # | |
Defined in Clash.Shockwaves.Internal.Waveform Methods formatVal :: proxy 'NFUns -> NumberFormat Source # | |
class KnownNSpacer (f :: Maybe NSPair) where Source #
Type to get the runtime value of a type-level number spacer.
Instances
| KnownNSpacer ('Nothing :: Maybe NSPair) Source # | |
| (KnownNat n, KnownSymbol s) => KnownNSpacer ('Just '(n, s)) Source # | |
type family RTreeIsLeaf (d :: Natural) :: Bool where ... Source #
Equations
| RTreeIsLeaf 0 = 'True | |
| RTreeIsLeaf d = 'False |
class WaveformRTree (isLeaf :: Bool) (d :: k) (a :: k1) where Source #
Methods
Instances
tupleTranslator :: (BitPack t, WaveformG (Rep t ())) => Translator Source #
A translator for displaying values with zero or more fields like tuples. This function will error if called for a type that has more than one constructor!