pyGHDL.dom._Translate

This module offers helper functions to translate often used IIR substructures to pyGHDL.dom (pyVHDLModel) constructs.

Functions


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 Prefix property.

Parameters:

node (TypeVar(Iir, bound= c_int)) – The name IIR node to translate.

Return type:

Name

Returns:

A name object.

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:

List

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 RecordElementSymbol naming 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:

Dict

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.Type class.

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:

BaseType

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.Type class.

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:

BaseType

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:

Symbol

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:

Symbol

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.

Parameters:

subtypeIndicationNode (TypeVar(Iir, bound= c_int)) – The IIR node of the subtype indication.

Return type:

SimpleSubtypeSymbol

Returns:

A subtype symbol referencing the type mark.

pyGHDL.dom._Translate.GetScalarConstrainedSubtypeFromNode(subtypeIndicationNode)[source]

Translate a scalar subtype indication IIR node to a subtype symbol.

A Subtype_Definition node 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 a SimpleSubtypeSymbol; with one it is a ConstrainedScalarSubtypeSymbol, whose constraint is mandatory.

Parameters:

subtypeIndicationNode (TypeVar(Iir, bound= c_int)) – The subtype indication IIR node.

Return type:

SimpleSubtypeSymbol | ConstrainedScalarSubtypeSymbol

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.

Parameters:

subtypeIndicationNode (TypeVar(Iir, bound= c_int)) – The IIR node of the array subtype indication.

Return type:

ConstrainedArraySubtypeSymbol

Returns:

A subtype symbol carrying the type mark and one range per dimension.

pyGHDL.dom._Translate.GetRecordConstrainedSubtypeFromNode(subtypeIndicationNode)[source]

Translates a record subtype indication with an element constraint to a constrained record subtype symbol.

Parameters:

subtypeIndicationNode (TypeVar(Iir, bound= c_int)) – The IIR node of the record subtype indication.

Return type:

ConstrainedRecordSubtypeSymbol

Returns:

A subtype symbol carrying the type mark and the constrained elements.

pyGHDL.dom._Translate.GetSubtypeFromNode(subtypeNode)[source]

Translates a subtype declaration to a Subtype.

Parameters:

subtypeNode (TypeVar(Iir, bound= c_int)) – The IIR node of the subtype declaration.

Return type:

Symbol

Returns:

The translated subtype, carrying the symbol of its subtype indication.

pyGHDL.dom._Translate.GetRangeFromNode(node)[source]

Translate a range IIR node to a SimpleRange.

Parameters:

node (TypeVar(Iir, bound= c_int)) – The IIR node representing a range.

Return type:

SimpleRange

Returns:

The translated range object.

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 a RangeFromName wrapping the referenced symbol.

Shared by for..loop statements, for..generate statements and aggregate choices, which all use the same VHDL discrete_range grammar rule.

Parameters:
  • discreteRangeNode (TypeVar(Iir, bound= c_int)) – The IIR node representing a discrete range.

  • entity (str) – The construct the discrete range appears in (e.g. for..loop). Used in exception messages.

Return type:

Range

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.

Parameters:

node (TypeVar(Iir, bound= c_int)) – The IIR node representing an expression.

Return type:

BaseExpression | QualifiedExpression | FunctionCall | TypeConversion | Literal

Returns:

The translated expression.

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:

Generator[ModeViewElement, None, None]

Returns:

A generator returning mode view elements.

Note

Unlike declarations/interface items (where the last node in a Has_Identifier_List group 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 real Mode/ Mode_View_Name - subsequent nodes only contribute their identifier, ending with the node where Has_Identifier_List becomes False. Verified against real GHDL analysis for x, y : out;: x has Has_Identifier_List=True, Mode=out; y has Has_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.

Parameters:

nodeChain (TypeVar(Iir, bound= c_int)) – The IIR node representing the first generic in the chain.

Return type:

Generator[GenericInterfaceItemMixin, None, None]

Returns:

A generator returning generic interface items.

pyGHDL.dom._Translate.GetPortsFromChainedNodes(nodeChain)[source]

Translates a chain of ports (IIR nodes) to a sequence of pyVHDLModel.Interface.PortInterfaceItem.

Parameters:

nodeChain (TypeVar(Iir, bound= c_int)) – The IIR node representing the first port in the chain.

Return type:

Generator[PortInterfaceItemMixin, None, None]

Returns:

A generator returning port interface items.

pyGHDL.dom._Translate.GetParameterFromChainedNodes(nodeChain)[source]

Translates a chain of parameters (IIR nodes) to a sequence of pyVHDLModel.Interface.ParameterInterfaceItem.

Parameters:

nodeChain (TypeVar(Iir, bound= c_int)) – The IIR node representing the first parameter in the chain.

Return type:

Generator[ParameterInterfaceItemMixin, None, None]

Returns:

A generator returning parameter interface items.