hwt.hdl package¶
This package contains classes for representation of HDL languages (hdl types, RtlSignal, HdlAssignmentContainer, HdlStmCodeBlockContainer etc.).
It also contains classes for representation of complex HW structures like dense transaction template (TransTmpl, FrameTmpl).
Subpackages¶
- hwt.hdl.statements package
- hwt.hdl.types package
- Submodules
- hwt.hdl.types.array module
- hwt.hdl.types.arrayCast module
- hwt.hdl.types.arrayVal module
- hwt.hdl.types.bitValFunctions module
- hwt.hdl.types.bitVal_opReduce module
- hwt.hdl.types.bits module
- hwt.hdl.types.bitsCast module
- hwt.hdl.types.bitsVal module
- hwt.hdl.types.defs module
- hwt.hdl.types.enum module
- hwt.hdl.types.enumVal module
- hwt.hdl.types.eventCapableVal module
- hwt.hdl.types.float module
- hwt.hdl.types.floatVal module
- hwt.hdl.types.hdlType module
- hwt.hdl.types.slice module
- hwt.hdl.types.sliceUtils module
- hwt.hdl.types.sliceVal module
- hwt.hdl.types.stream module
- hwt.hdl.types.streamVal module
- hwt.hdl.types.string module
- hwt.hdl.types.stringVal module
- hwt.hdl.types.struct module
- hwt.hdl.types.structCast module
- hwt.hdl.types.structUtils module
- hwt.hdl.types.structValBase module
- hwt.hdl.types.typeCast module
- hwt.hdl.types.union module
- hwt.hdl.types.utils module
Submodules¶
hwt.hdl.constants module¶
Commonly used constants during HW devel.
hwt.hdl.frameTmpl module¶
-
class
hwt.hdl.frameTmpl.
FrameTmpl
(origin: hwt.hdl.types.hdlType.HdlType, wordWidth: int, startBitAddr: int, endBitAddr: int, transParts: List[hwt.hdl.transPart.TransPart])[source]¶ Bases:
object
Frame template is metainfomation about data structure, it’s the template of transaction for specific interface
Usuall flow of frame generatig consists of these steps:
- Describe format of data by HDL type (HStruct, HUnion …)
- Convert it to TransTmpl to resolve addresses of each field in structure
- Split parts of TransTmpl into words
- Use parts in words to assembly frames
Variables: _fieldToTPart – dictionary {HStructField: TransPart} to resolve this association, None by default, builded when packData is called and is not builded Note: others ivars described in __init__ -
_FrameTmpl__repr__getName
(transPart: hwt.hdl.transPart.TransPart, fieldWidth: int)¶ Get name string for a field
-
_FrameTmpl__repr__word
(index: int, width: int, padding: int, transParts: List[hwt.hdl.transPart.TransPart])¶
-
__init__
(origin: hwt.hdl.types.hdlType.HdlType, wordWidth: int, startBitAddr: int, endBitAddr: int, transParts: List[hwt.hdl.transPart.TransPart])[source]¶ Parameters: - origin – instance of HType (usually HStruct) from which this FrameTmpl was generated from
- wordWidth – width of word on interface where this template should be used
- startBitAddr – bit offset where this frame starts
- endBitAddr – bit offset where this frame ends (bit index of first bit behind this frame)
- transParts – instances of TransPart which are parts of this frame
-
static
_fieldToDataDict
(dtype, path, data, res)[source]¶ Construct dictionary {StructField:value} for faster lookup of values for fields
-
static
framesFromTransTmpl
(transaction: TransTmpl, wordWidth: int, maxFrameLen: Union[int, float] = inf, maxPaddingWords: Union[int, float] = inf, trimPaddingWordsOnStart: bool = False, trimPaddingWordsOnEnd: bool = False) → Generator[FrameTmpl, None, None][source]¶ Convert transaction template into FrameTmpls
Parameters: - transaction – transaction template used which are FrameTmpls created from
- wordWidth – width of data signal in target interface where frames will be used
- maxFrameLen – maximum length of frame in bits, if exceeded another frame will be created
- maxPaddingWords – maximum of continual padding words in frame, if exceed frame is split and words are cut of
- trimPaddingWordsOnStart – trim padding from start of frame at word granularity
- trimPaddingWordsOnEnd – trim padding from end of frame at word granularity
Attention: if maxPaddingWords<inf trimPaddingWordsOnEnd or trimPaddingWordsOnStart has to be True to decide where padding should be trimmed
-
packData
(data)[source]¶ Pack data into list of BitsVal of specified dataWidth
Parameters: data – dict of values for struct fields {fieldName: value} Returns: list of BitsVal which are representing values of words
-
walkWords
(showPadding: bool = False) → Generator[Tuple[int, List[Union[hwt.hdl.transPart.TransPart, hwt.hdl.frameTmplUtils.ChoicesOfFrameParts]]], None, None][source]¶ Walk enumerated words in this frame
Attention: not all indexes has to be present, only words with items will be generated when not showPadding Parameters: showPadding – padding TransParts are also present Returns: generator of tuples (wordIndex, list of TransParts in this word)
hwt.hdl.frameTmplUtils module¶
-
class
hwt.hdl.frameTmplUtils.
ChoiceOfFrameParts
(origin, tmpl)[source]¶ Bases:
list
Variables: - origin – ChoicesOfFrameParts instance
- tmpl – TransTmpl which was item generated from
-
class
hwt.hdl.frameTmplUtils.
ChoicesOfFrameParts
(startOfPart: int, origin: hwt.hdl.transTmpl.OneOfTransaction)[source]¶ Bases:
hwt.hdl.frameTmplUtils.TransPartGroup
List of ChoiceOfFrameParts One of ChoiceOfFrameParts is used to represent the word, item depends on context
Variables: - origin – OneOfTransaction instance
- startOfPart – bit addr of start of this group of frame parts
- endOfPart – bit addr of end of this group of frame parts
- _isLast – flag which means this is the last part of original union
-
class
hwt.hdl.frameTmplUtils.
TransPartGroup
[source]¶ Bases:
list
Abstract parent class for groups of TransParts
-
getBusWordBitRange
() → Tuple[int, int][source]¶ Returns: bit range which contains data of this part on bus data signal
-
-
class
hwt.hdl.frameTmplUtils.
TransTmplWordIterator
(wordWidth)[source]¶ Bases:
object
Iterator which reinterprets any structure as generator of bits of specified width
-
hwt.hdl.frameTmplUtils.
groupIntoChoices
(splitsOnWord, wordWidth: int, origin: hwt.hdl.transTmpl.OneOfTransaction)[source]¶ Parameters: splitsOnWord – list of lists of parts (fields splited on word boundaries) Returns: generators of ChoicesOfFrameParts for each word which are not crossing word boundaries
hwt.hdl.hdlObject module¶
hwt.hdl.operator module¶
-
class
hwt.hdl.operator.
Operator
(operator: hwt.hdl.operatorDefs.OpDefinition, operands: Tuple[Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue]])[source]¶ Bases:
hwt.hdl.hdlObject.HdlObject
Class of operator in expression tree
Variables: - operands – list of operands
- evalFn – function to evaluate this operator
- operator – OpDefinition instance
- result – result signal of this operator
-
__init__
(operator: hwt.hdl.operatorDefs.OpDefinition, operands: Tuple[Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue]])[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
_replace_input
(inp: hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal, replacement: hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal)[source]¶ Replace operand signal (non-recursively)
Attention: costly operation because all records in operand cache for all inputs may be potentially updated
-
_walk_public_drivers
(seen: set) → Generator[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal, None, None][source]¶ Walk all non hidden signals in an expression
-
_walk_sensitivity
(casualSensitivity: Set[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal], seen: Set[hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal], ctx: hwt.hdl.sensitivityCtx.SensitivityCtx)[source]¶ See: hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal._walk_sensitivity()
hwt.hdl.operatorDefs module¶
-
class
hwt.hdl.operatorDefs.
AllOps
[source]¶ Bases:
object
Attention: Remember that and operator “and” is & and “or” is |, “and” and “or” can not be used because they can not be overloaded Attention: These are operators of internal AST, they are not equal to verilog or vhdl operators -
ADD
= <OpDefinition ADD>¶
-
AND
= <OpDefinition AND>¶
-
BitsAsSigned
= <OpDefinition BitsAsSigned>¶
-
BitsAsUnsigned
= <OpDefinition BitsAsUnsigned>¶
-
BitsAsVec
= <OpDefinition BitsAsVec>¶
-
CALL
= <OpDefinition CALL>¶
-
CONCAT
= <OpDefinition CONCAT>¶
-
DIV
= <OpDefinition DIV>¶
-
DOT
= <OpDefinition DOT>¶
-
DOWNTO
= <OpDefinition DOWNTO>¶
-
EQ
= <OpDefinition EQ>¶
-
FALLING_EDGE
= <OpDefinition FALLING_EDGE>¶
-
GE
= <OpDefinition GE>¶
-
GT
= <OpDefinition GT>¶
-
INDEX
= <OpDefinition INDEX>¶
-
LE
= <OpDefinition LE>¶
-
LT
= <OpDefinition LT>¶
-
MINUS_UNARY
= <OpDefinition MINUS_UNARY>¶
-
MOD
= <OpDefinition MOD>¶
-
MUL
= <OpDefinition MUL>¶
-
NE
= <OpDefinition NE>¶
-
NOT
= <OpDefinition NOT>¶
-
OR
= <OpDefinition OR>¶
-
POW
= <OpDefinition POW>¶
-
RISING_EDGE
= <OpDefinition RISING_EDGE>¶
-
SUB
= <OpDefinition SUB>¶
-
TERNARY
= <OpDefinition TERNARY>¶
-
TO
= <OpDefinition TO>¶
-
XOR
= <OpDefinition XOR>¶
-
-
class
hwt.hdl.operatorDefs.
OpDefinition
(evalFn, allowsAssignTo=False)[source]¶ Bases:
object
Operator definition
Variables: - id – name of operator
- _evalFn – function which evaluates operands
-
hwt.hdl.operatorDefs.
o
¶ list of weak references to the object (if defined)
hwt.hdl.operatorUtils module¶
-
hwt.hdl.operatorUtils.
_replace_input_in_expr
(expr: Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue], toReplace: Union[Tuple[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase], Dict[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase]]) → hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase[source]¶ Returns: newly rewritten expression with the subexpression replaced, True if changed else False
-
hwt.hdl.operatorUtils.
replace_input_in_expr
(topStatement: hwt.hdl.statements.statement.HdlStatement, parentStm: hwt.hdl.statements.statement.HdlStatement, expr: Union[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.hdl.value.HValue], toReplace: Union[Tuple[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase], Dict[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase]]) → Tuple[hwt.synthesizer.rtlLevel.mainBases.RtlSignalBase, bool][source]¶ Returns: tuple (newExpression, True if expr is toReplace and should be replaced else False)
hwt.hdl.portItem module¶
-
class
hwt.hdl.portItem.
HdlPortItem
(name, direction, dtype, unit)[source]¶ Bases:
object
HDL entity/module/component port item Used to split signal paths on component boundary.
Note: src/dst are named based on input output signal direction both dst and src can be parent/component signal, it depends on direction -
__init__
(name, direction, dtype, unit)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
_walk_sensitivity
(casualSensitivity: set, seen: set, ctx: hwt.hdl.sensitivityCtx.SensitivityCtx)[source]¶ See: hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal._walk_sensitivity()
-
hwt.hdl.sensitivityCtx module¶
-
class
hwt.hdl.sensitivityCtx.
SensitivityCtx
(initSeq=None)[source]¶ Bases:
hwt.pyUtils.uniqList.UniqList
Sensitivity list used for resolution of sensitivity for statement instances
Variables: contains_ev_dependency – True if this contains event dependent sensitivity
hwt.hdl.transPart module¶
-
class
hwt.hdl.transPart.
TransPart
(parent: FrameTmpl, tmpl: Optional[hwt.hdl.transTmpl.TransTmpl], canBeRemoved: bool, startOfPart: int, endOfPart: int, inFieldOffset: int)[source]¶ Bases:
object
Container for informations about parts of TransTmpl split on databus words
Variables: - parent – instance of FrameTmpl
- tmpl – origin template which is this representation of (StructField/HdlType instance)
- canBeRemoved – True if it is padding to assert data alignment and is not actually part of data and can be removed
- isPadding – True if this TransaPart is just a padding and contains non valid data
- startOfPart – bit addr of start of this part
- endOfPart – bit addr of end of this part
- inFieldOffset – bit offset of this part in parent field
-
__init__
(parent: FrameTmpl, tmpl: Optional[hwt.hdl.transTmpl.TransTmpl], canBeRemoved: bool, startOfPart: int, endOfPart: int, inFieldOffset: int)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
getBusWordBitRange
() → Tuple[int, int][source]¶ Returns: bit range which contains data of this part on bus data signal
hwt.hdl.transTmpl module¶
-
class
hwt.hdl.transTmpl.
OneOfTransaction
(parent: hwt.hdl.transTmpl.TransTmpl, offset: int, shouldEnterFn: Callable[[hwt.hdl.transTmpl.TransTmpl], Tuple[bool, bool]], possibleTransactions: Tuple[hwt.hdl.transTmpl.TransTmpl])[source]¶ Bases:
object
Container of possible transactions for transactions deriverd from HUnion type
Variables: - parent – parent TransTmpl instance
- offset – bit addr offset in parent type structure
- shouldEnterFn – function(transTmpl) which should return (shouldEnter, shouldUse) where shouldEnter is flag that means iterator should look inside of this actual object and shouldUse flag means that this field should be used (=generator should yield it)
- possibleTransactions – tuple of TransTmpl instances from which only one can be used in same time
-
class
hwt.hdl.transTmpl.
TransTmpl
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int = 0, parent: Optional[TransTmpl] = None, origin: Optional[hwt.hdl.types.struct.HStructField] = None, rel_field_path: hwt.synthesizer.typePath.TypePath = ())[source]¶ Bases:
object
Transaction template for types of constant size
Container of informations about frames generated from any HType (HStruct etc.) * contains precalculated address range for all members of type
Note: Array/Stream items are are stored as a single instance so the memory consumption of this object is entirely independent on size of arrays which it describes.
Variables: - dtype – type of this item
- bitAddr – offset of start of this item in bits
- bitAddrEnd – end of this item in bits
- parent – object which generated this item, optional TransTmpl
- origin – object which was template for generating of this item
- itemCnt – if this transaction template is for array or stream this is item count for such an array or stream
- childrenAreChoice – flag which tells if children are sequence or only one of them can be used in same time
- rel_field_path – path in original data type relative to parent
-
__init__
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int = 0, parent: Optional[TransTmpl] = None, origin: Optional[hwt.hdl.types.struct.HStructField] = None, rel_field_path: hwt.synthesizer.typePath.TypePath = ())[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
_loadFromArray
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int) → int[source]¶ Parse HArray type to this transaction template instance
Returns: address of it’s end
-
_loadFromBits
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int)[source]¶ Parse Bits type to this transaction template instance
Returns: address of it’s end
-
_loadFromHStream
(dtype: hwt.hdl.types.stream.HStream, bitAddr: int) → int[source]¶ Parse HStream type to this transaction template instance
Returns: address of it’s end
-
_loadFromHStruct
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int)[source]¶ Parse HStruct type to this transaction template instance
Returns: address of it’s end
-
_loadFromHType
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int) → None[source]¶ Parse any HDL type to this transaction template instance
-
_loadFromUnion
(dtype: hwt.hdl.types.hdlType.HdlType, bitAddr: int) → int[source]¶ Parse HUnion type to this transaction template instance
Returns: address of it’s end
-
walkFlatten
(offset: int = 0, shouldEnterFn=<function _default_shouldEnterFn>) → Generator[Union[Tuple[Tuple[int, int], hwt.hdl.transTmpl.TransTmpl], hwt.hdl.transTmpl.OneOfTransaction], None, None][source]¶ Walk fields in instance of TransTmpl
Parameters: - offset – optional offset for all children in this TransTmpl
- shouldEnterFn – function (transTmpl) which returns True when field should be split on it’s children
- shouldEnterFn – function(transTmpl) which should return (shouldEnter, shouldUse) where shouldEnter is flag that means iterator should look inside of this actual object and shouldUse flag means that this field should be used (=generator should yield it)
Returns: generator of tuples ((startBitAddress, endBitAddress), TransTmpl instance)
hwt.hdl.value module¶
-
class
hwt.hdl.value.
HValue
(dtype: HdlType, val, vld_mask)[source]¶ Bases:
typing.Generic
Wrap around hdl value with overloaded operators http://www.rafekettler.com/magicmethods.html
operators are overloaded in every type separately
-
__init__
(dtype: HdlType, val, vld_mask)[source]¶ Parameters: - val – pythonic value representing this value
- dtype – data type object from which this value was derived from
- vld_mask – validity mask for value
-
_dtype
¶
-
classmethod
_from_py
(typeObj, val, vld_mask)[source]¶ from_py without value normalization and type checking
-
_walk_sensitivity
(casualSensitivity: set, seen: set, ctx: hwt.hdl.sensitivityCtx.SensitivityCtx)[source]¶ See: hwt.synthesizer.rtlLevel.rtlSignal.RtlSignal._walk_sensitivity()
-
val
¶
-
vld_mask
¶
-
hwt.hdl.valueUtils module¶
hwt.hdl.variables module¶
-
class
hwt.hdl.variables.
SignalItem
(name, dtype, def_val=None, virtual_only=False)[source]¶ Bases:
hwt.hdl.hdlObject.HdlObject
basic hdl signal used to design circuits
-
__init__
(name, dtype, def_val=None, virtual_only=False)[source]¶ Parameters: - name – name for better orientation in netlists (used only in serialization)
- dtype – data type of this signal
- def_val – value for initialization
- virtual_only – flag indicates that this assignments is only virtual and should not be added into netlist, because it is only for internal notation
-