pyGHDL.dom._Translate
This module offers helper functions to translate often used IIR substructures to pyGHDL.dom (pyVHDLModel) constructs.
Functions
GetArrayConstraintsFromSubtypeIndication(): Translates the index constraints of an array subtype indication to a list of ranges.GetRecordConstraintsFromSubtypeIndication(): Translates the element constraints of a record subtype indication to a dictionary.GetTypeFromNode(): Translates a type declaration to the matchingpyGHDL.dom.Typeclass.GetAnonymousTypeFromNode(): Translates an anonymous type declaration to the matchingpyGHDL.dom.Typeclass.GetSubtypeIndicationFromNode(): Extracts the subtype indication from an IIR node and translates it to aSymbol.GetSubtypeIndicationFromIndicationNode(): Translate a subtype indication to aSymbol.GetSimpleTypeFromNode(): Translates a subtype indication that is just a type mark to a simple subtype symbol.GetScalarConstrainedSubtypeFromNode(): Translate a scalar subtype indication IIR node to a subtype symbol.GetArrayConstrainedSubtypeFromNode(): Translates an array subtype indication with an index constraint to a constrained array subtype symbol.GetRecordConstrainedSubtypeFromNode(): Translates a record subtype indication with an element constraint to a constrained record subtype symbol.GetSubtypeFromNode(): Translates a subtype declaration to aSubtype.GetRangeFromNode(): Translate a range IIR node to aSimpleRange.GetDiscreteRangeFromNode(): Translate a discrete range IIR node to aRange.GetExpressionFromNode(): Translates an expression IIR node to anBaseExpression.GetModeViewElementsFromChainedNodes(): Translates a chain of mode view elements (IIR nodes) to a sequence ofGetGenericsFromChainedNodes(): Translates a chain of generics (IIR nodes) to a sequence ofpyVHDLModel.Interface.GenericInterfaceItem.GetPortsFromChainedNodes(): Translates a chain of ports (IIR nodes) to a sequence ofpyVHDLModel.Interface.PortInterfaceItem.GetParameterFromChainedNodes(): Translates a chain of parameters (IIR nodes) to a sequence ofpyVHDLModel.Interface.ParameterInterfaceItem.
Functions
- pyGHDL.dom._Translate.GetName(node)[source]
Translates a name IIR node to a
Name.A name can be a simple name or complex name consisting of selected, parenthesis, attribute, … names. Complex names are composed as a chain of name objects, which can be traversed using the
Prefixproperty.
- pyGHDL.dom._Translate.GetArrayConstraintsFromSubtypeIndication(subtypeIndication)[source]
Translates the index constraints of an array subtype indication to a list of ranges.
A constraint is either a range expression (
0 to 7) or a name denoting a range (v'range,my_range).- Parameters:
subtypeIndication (
TypeVar(Iir, bound=c_int)) – The IIR node of the array subtype indication.- Return type:
- Returns:
List of the translated index constraints, one per dimension.
- Raises:
DOMException – If a constraint is neither a range expression nor a name.
- pyGHDL.dom._Translate.GetRecordConstraintsFromSubtypeIndication(subtypeIndication)[source]
Translates the element constraints of a record subtype indication to a dictionary.
The dictionary is keyed by a
RecordElementSymbolnaming the constrained element; the values are not translated yet.- Parameters:
subtypeIndication (
TypeVar(Iir, bound=c_int)) – The IIR node of the record subtype indication.- Return type:
- Returns:
Mapping from record element symbol to its constraint.
- Raises:
DOMException – If an element of the chain is not a record element constraint.
- pyGHDL.dom._Translate.GetTypeFromNode(node)[source]
Translates a type declaration to the matching
pyGHDL.dom.Typeclass.The doc-comment attaches to the type declaration, not to the type definition inside it, so it is read here and handed to whichever class parses the definition. A declaration without a definition is an incomplete type.
- Parameters:
node (
TypeVar(Iir, bound=c_int)) – The IIR node of the type declaration.- Return type:
- Returns:
The translated type.
- Raises:
DOMException – If the type definition’s kind is not handled.
- pyGHDL.dom._Translate.GetAnonymousTypeFromNode(node)[source]
Translates an anonymous type declaration to the matching
pyGHDL.dom.Typeclass.GHDL creates an anonymous type declaration for the type definitions that have no name of their own - an integer or physical type behind a subtype, for instance.
- Parameters:
node (
TypeVar(Iir, bound=c_int)) – The IIR node of the anonymous type declaration.- Return type:
- Returns:
The translated type.
- Raises:
DOMException – If the type definition’s kind is not handled.
- pyGHDL.dom._Translate.GetSubtypeIndicationFromNode(node, entity, name)[source]
Extracts the subtype indication from an IIR node and translates it to a
Symbol.Note
This function calls
GetSubtypeIndicationFromIndicationNode().This function should be used directly if
nodes.Get_Subtype_Indication(...)was already called or a subtype indication is return by another getter.- Parameters:
node (
TypeVar(Iir, bound=c_int)) – The IIR node to get the subtype indication from.entity (
str) – The entity kind the subtype indication is extracted from (e.g. constant). Used in exception messages.name (
str) – The entity’s name the subtype indication is extracted from (e.g.BITS). Used in exception messages.
- Return type:
- Returns:
A symbol representing a reference to a type/subtype and possible array or record constraints.
- pyGHDL.dom._Translate.GetSubtypeIndicationFromIndicationNode(subtypeIndicationNode, entity, name)[source]
Translate a subtype indication to a
Symbol.- Parameters:
subtypeIndicationNode (
TypeVar(Iir, bound=c_int)) – The subtype indication IIR node.entity (
str) – The entity kind the subtype indication is extracted from (e.g. constant). Used in exception messages.name (
str) – The entity’s name the subtype indication is extracted from (e.g.BITS). Used in exception messages.
- Return type:
- Returns:
A symbol referencing a type or subtype, with array or record constraints.
- pyGHDL.dom._Translate.GetSimpleTypeFromNode(subtypeIndicationNode)[source]
Translates a subtype indication that is just a type mark to a simple subtype symbol.
- pyGHDL.dom._Translate.GetScalarConstrainedSubtypeFromNode(subtypeIndicationNode)[source]
Translate a scalar subtype indication IIR node to a subtype symbol.
A
Subtype_Definitionnode carries a type mark and optionally a range constraint, because the node is also used for a subtype indication that only adds a resolution indication (subtype resolvedBit is resolveBit myBit;). Without a range constraint the result is aSimpleSubtypeSymbol; with one it is aConstrainedScalarSubtypeSymbol, whose constraint is mandatory.- Parameters:
subtypeIndicationNode (
TypeVar(Iir, bound=c_int)) – The subtype indication IIR node.- Return type:
- Returns:
The translated subtype symbol.
- Raises:
DOMException – If the range constraint’s IIR node isn’t a known range.
- pyGHDL.dom._Translate.GetArrayConstrainedSubtypeFromNode(subtypeIndicationNode)[source]
Translates an array subtype indication with an index constraint to a constrained array subtype symbol.
- pyGHDL.dom._Translate.GetRecordConstrainedSubtypeFromNode(subtypeIndicationNode)[source]
Translates a record subtype indication with an element constraint to a constrained record subtype symbol.
- pyGHDL.dom._Translate.GetSubtypeFromNode(subtypeNode)[source]
Translates a subtype declaration to a
Subtype.
- pyGHDL.dom._Translate.GetRangeFromNode(node)[source]
Translate a range IIR node to a
SimpleRange.
- pyGHDL.dom._Translate.GetDiscreteRangeFromNode(discreteRangeNode, entity)[source]
Translate a discrete range IIR node to a
Range.A discrete range is either an explicit range (
0 to 7,vector'range) or a discrete subtype indication - a type mark (bit), optionally with a range constraint (integer range 0 to 7). Everything but the explicit-bounds form becomes aRangeFromNamewrapping the referenced symbol.Shared by for..loop statements, for..generate statements and aggregate choices, which all use the same VHDL
discrete_rangegrammar rule.- Parameters:
- Return type:
- Returns:
The translated range.
- Raises:
DOMException – If the IIR node’s kind isn’t a known discrete range.
- pyGHDL.dom._Translate.GetExpressionFromNode(node)[source]
Translates an expression IIR node to an
BaseExpression.
- pyGHDL.dom._Translate.GetModeViewElementsFromChainedNodes(nodeChain)[source]
Translates a chain of mode view elements (IIR nodes) to a sequence of
pyVHDLModel.Interface.ModeViewElement.- Parameters:
nodeChain (
TypeVar(Iir, bound=c_int)) – The IIR node representing the first mode view element in the chain.- Return type:
- Returns:
A generator returning mode view elements.
Note
Unlike declarations/interface items (where the last node in a
Has_Identifier_Listgroup owns the shared subtype/value and earlier ones are Null), mode view elements are the other way around: the first node in the group (Has_Identifier_List == True) owns the realMode/Mode_View_Name- subsequent nodes only contribute their identifier, ending with the node whereHas_Identifier_ListbecomesFalse. Verified against real GHDL analysis forx, y : out;:xhasHas_Identifier_List=True,Mode=out;yhasHas_Identifier_List=False,Mode=<unset>.
- pyGHDL.dom._Translate.GetGenericsFromChainedNodes(nodeChain)[source]
Translates a chain of generics (IIR nodes) to a sequence of
pyVHDLModel.Interface.GenericInterfaceItem.
- pyGHDL.dom._Translate.GetPortsFromChainedNodes(nodeChain)[source]
Translates a chain of ports (IIR nodes) to a sequence of
pyVHDLModel.Interface.PortInterfaceItem.