Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the key internal types for Kansas Lava, and some basic utilities (like Show instances) for these types.
- data Type
- typeWidth :: Type -> Int
- isTypeSigned :: Type -> Bool
- data StdLogicType
- toStdLogicType :: Type -> StdLogicType
- fromStdLogicType :: StdLogicType -> Type
- data Id
- newtype Box a = Box a
- data Entity s = Entity Id [(String, Type)] [(String, Type, Driver s)]
- newtype E = E (Entity E)
- entityFind :: Show a => String -> Entity a -> (Type, Driver a)
- data Driver s
- newtype D a = D {}
- class Clock clk
- data CLK
- newtype RepValue = RepValue {
- unRepValue :: [Maybe Bool]
- showRepValue :: Type -> RepValue -> String
- appendRepValue :: RepValue -> RepValue -> RepValue
- isValidRepValue :: RepValue -> Bool
- getValidRepValue :: RepValue -> Maybe [Bool]
- chooseRepValue :: RepValue -> RepValue
- cmpRepValue :: RepValue -> RepValue -> Bool
- data BitPat w = BitPat {}
- (&) :: (Size w1, Size w2, Size w, w ~ ADD w1 w2, w1 ~ SUB w w2, w2 ~ SUB w w1) => BitPat w1 -> BitPat w2 -> BitPat w
- bits :: String -> BitPat w
- bool :: BitPat X1 -> Bool
- every :: forall w. Size w => [BitPat w]
- bitPatToInteger :: BitPat w -> Maybe Integer
- data KLEG = KLEG {}
- visitEntities :: KLEG -> (Unique -> Entity Unique -> Maybe a) -> [a]
- mapEntities :: KLEG -> (Unique -> Entity Unique -> Maybe (Entity Unique)) -> KLEG
- allocEntities :: KLEG -> [Unique]
- data Signature = Signature {
- sigInputs :: [(String, Type)]
- sigOutputs :: [(String, Type)]
- sigGenerics :: [(String, Integer)]
- circuitSignature :: KLEG -> Signature
- data Witness w = Witness
- class Dual a where
- dual :: a -> a -> a
- data a :> b = a :> b
- data Synthesis
Types
Type captures HDL-representable types.
B | Bit |
S Int | Signed vector, with a width. |
U Int | Unsigned vector, with a width. |
V Int | std_logic_vector, with a width. |
ClkTy | Clock Signal |
GenericTy | generics in VHDL, argument must be integer |
RomTy Int | a constant array of values. |
TupleTy [Type] | Tuple, represented as a larger std_logic_vector |
MatrixTy Int Type | Matrix, for example a vhdl array. |
SampledTy Int Int | Our "floating" values. The first number is the precisionscale (+- N) The second number is the bits used to represent this number |
isTypeSigned :: Type -> Bool Source
isTypeSigned
determines if a type has a signed representation. This is
necessary for the implementation of isSigned
in the Bits
type class.
data StdLogicType Source
StdLogicType
is the type for std_logic things,
typically input/output arguments to VHDL entities.
toStdLogicType :: Type -> StdLogicType Source
toStdLogic maps Lava Types to a StdLogicType
fromStdLogicType :: StdLogicType -> Type Source
fromStdLogic maps StdLogicTypes to Lava types.
Id
Id is the name/tag of a block of compuation.
Prim String | built in thing |
External String | VHDL entity |
Function [(RepValue, RepValue)] | anonymous function |
ClockId String | An environment box |
Comment [String] | An identity; also a multi-line comments |
BlackBox (Box Dynamic) |
|
Box wraps a dynamic, so that we can define custom Eq/Ord instances.
Box a |
Entity
E
is the knot-tyed version of Entity.
entityFind :: Show a => String -> Entity a -> (Type, Driver a) Source
entityFind finds an input in a list, avoiding the need to have ordering.
Driver
A Driver
is a specific driven wire
(signal in VHDL),
which types contains a value that changes over time.
Port String s | a specific port on the entity |
Pad String | an input pad |
ClkDom String | the clock domain (the clock enable, resolved via context) |
Lit RepValue | A representable Value (including unknowns, aka X in VHDL) |
Generic Integer | A generic argument, always fully defined |
Lits [RepValue] | A list of values, typically constituting a ROM initialization. |
Error String | A call to err, in Datatype format for reification purposes |
Ways of intepreting Signal
RepValue
A RepValue is a value that can be represented using a bit encoding. The least significant bit is at the front of the list.
RepValue | |
|
showRepValue :: Type -> RepValue -> String Source
appendRepValue :: RepValue -> RepValue -> RepValue Source
appendRepValue
joins two RepValue
; the least significant value first.
TODO: reverse this!
isValidRepValue :: RepValue -> Bool Source
isValidRepValue
checks to see is a RepValue
is completely valid.
getValidRepValue :: RepValue -> Maybe [Bool] Source
getValidRepValue
Returns a binary rep, or Nothing is *any* bits are X
.
chooseRepValue :: RepValue -> RepValue Source
chooseRepValue
turns a RepValue with (optional) unknow values,
and chooses a representation for the RepValue.
cmpRepValue :: RepValue -> RepValue -> Bool Source
cmpRepValue
compares a golden value with another value, returning the bits that are different.
The first value may contain X
, in which case *any* value in that bit location will
match. This means that cmpRepValue
is not commutative.
BitPat
(&) :: (Size w1, Size w2, Size w, w ~ ADD w1 w2, w1 ~ SUB w w2, w2 ~ SUB w w1) => BitPat w1 -> BitPat w2 -> BitPat w infixl 6 Source
&
is a sized append for BitPat.
bitPatToInteger :: BitPat w -> Maybe Integer Source
KLEG
visitEntities :: KLEG -> (Unique -> Entity Unique -> Maybe a) -> [a] Source
Map a function across all of the entities in a KLEG, accumulating the results in a list.
mapEntities :: KLEG -> (Unique -> Entity Unique -> Maybe (Entity Unique)) -> KLEG Source
Map a function across a KLEG, modifying each Entity for which the function returns a Just. Any entities that the function returns Nothing for will be removed from the resulting KLEG.
allocEntities :: KLEG -> [Unique] Source
Generate a list of Unique ids that are guaranteed not to conflict with any ids already in the KLEG.
A Signature
is the structure-level type of a KLEG.
Signature | |
|
circuitSignature :: KLEG -> Signature Source
Calculate a signature from a KLEG.
Witness
Create a type witness, to help resolve some of the type issues. Really, we are using this in a system-F style. (As suggested by an anonymous TFP referee, as a better alternative to using 'error "witness"').
Dual shallow/deep
Select the shallow embedding from one circuit, and the deep embedding from another.
Take the shallow value from the first argument, and the deep value from the second.
Our version of tuples
Alternative definition for (,). Constructor is right-associative.
a :> b infixr 5 |