diff options
Diffstat (limited to 'pyGHDL/dom/_Translate.py')
-rw-r--r-- | pyGHDL/dom/_Translate.py | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index e93b20b07..9435010ab 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -5,14 +5,25 @@ from pydecor import export from pyVHDLModel.VHDLModel import Constraint, Direction, Expression, SubTypeOrSymbol from pyGHDL.libghdl import utils, name_table -from pyGHDL.libghdl.utils import flist_iter -from pyGHDL.libghdl.vhdl import nodes -from pyGHDL.dom._Utils import NodeToName, GetIirKindOfNode -from pyGHDL.dom.Common import DOMException -from pyGHDL.dom.Range import Range, RangeExpression -from pyGHDL.dom.Symbol import SimpleObjectSymbol, SimpleSubTypeSymbol, ConstrainedSubTypeSymbol +from pyGHDL.libghdl.utils import flist_iter +from pyGHDL.libghdl.vhdl import nodes +from pyGHDL.dom._Utils import NodeToName, GetIirKindOfNode +from pyGHDL.dom.Common import DOMException +from pyGHDL.dom.Range import Range, RangeExpression +from pyGHDL.dom.Symbol import ( + SimpleObjectSymbol, + SimpleSubTypeSymbol, + ConstrainedSubTypeSymbol, +) from pyGHDL.dom.Literal import IntegerLiteral, CharacterLiteral, FloatingPointLiteral -from pyGHDL.dom.Expression import SubtractionExpression, AdditionExpression, MultiplyExpression, DivisionExpression, InverseExpression, ExponentiationExpression +from pyGHDL.dom.Expression import ( + SubtractionExpression, + AdditionExpression, + MultiplyExpression, + DivisionExpression, + InverseExpression, + ExponentiationExpression, +) __all__ = [] @@ -22,29 +33,32 @@ def GetSubtypeIndicationFromNode(node, entity: str, name: str) -> SubTypeOrSymbo subTypeIndication = nodes.Get_Subtype_Indication(node) subTypeKind = GetIirKindOfNode(subTypeIndication) - if (subTypeKind == nodes.Iir_Kind.Simple_Name): + if subTypeKind == nodes.Iir_Kind.Simple_Name: subTypeName = NodeToName(subTypeIndication) subType = SimpleSubTypeSymbol(subTypeName) - elif (subTypeKind == nodes.Iir_Kind.Array_Subtype_Definition): + elif subTypeKind == nodes.Iir_Kind.Array_Subtype_Definition: typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndication) typeMarkName = NodeToName(typeMark) constraints = GetArrayConstraintsFromSubtypeIndication(subTypeIndication) subType = ConstrainedSubTypeSymbol(typeMarkName, constraints) - elif (subTypeKind == nodes.Iir_Kind.Subtype_Definition): + elif subTypeKind == nodes.Iir_Kind.Subtype_Definition: raise DOMException( "Unknown handling of subtype kind '{kind}' of subtype indication '{indication}' while parsing {entity} '{name}'.".format( - kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name) + kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name + ) ) else: raise DOMException( "Unknown subtype kind '{kind}' of subtype indication '{indication}' while parsing {entity} '{name}'.".format( - kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name) + kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name + ) ) return subType + @export def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constraint]: constraints = [] @@ -58,7 +72,7 @@ def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constrai r = Range( GetExpressionFromNode(leftBound), GetExpressionFromNode(rightBound), - Direction.DownTo if direction else Direction.To + Direction.DownTo if direction else Direction.To, ) constraints.append(RangeExpression(r)) elif constraintKind == nodes.Iir_Kind.Attribute_Name: @@ -68,7 +82,10 @@ def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constrai else: raise DOMException( "Unknown constraint kind '{kind}' for constraint '{constraint}' in subtype indication '{indication}'.".format( - kind=constraintKind, constraint=constraint, indication=subTypeIndication) + kind=constraintKind, + constraint=constraint, + indication=subTypeIndication, + ) ) return constraints @@ -117,9 +134,11 @@ def GetExpressionFromNode(node) -> Expression: else: raise DOMException( "Unknown expression kind '{kindName}'({kind}) in expression '{expr}'.".format( - kind=kind, kindName=kind.name, expr=node) + kind=kind, kindName=kind.name, expr=node + ) ) + # FIXME: rewrite to generator @export def GetGenericsFromChainedNodes(nodeChain): @@ -135,11 +154,13 @@ def GetGenericsFromChainedNodes(nodeChain): else: raise DOMException( "Unknown generic kind '{kindName}'({kind}) in generic '{generic}'.".format( - kind=kind, kindName=kind.name, generic=generic) + kind=kind, kindName=kind.name, generic=generic + ) ) return result + # FIXME: rewrite to generator @export def GetPortsFromChainedNodes(nodeChain): @@ -155,11 +176,13 @@ def GetPortsFromChainedNodes(nodeChain): else: raise DOMException( "Unknown port kind '{kindName}'({kind}) in port '{port}'.".format( - kind=kind, kindName=kind.name, port=port) + kind=kind, kindName=kind.name, port=port + ) ) return result + def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): result = [] for item in utils.chain_iter(nodeChain): @@ -168,7 +191,9 @@ def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): from pyGHDL.dom.Object import Constant constantName = NodeToName(item) - subTypeIndication = GetSubtypeIndicationFromNode(item, "constant", constantName) + subTypeIndication = GetSubtypeIndicationFromNode( + item, "constant", constantName + ) defaultExpression = GetExpressionFromNode(nodes.Get_Default_Value(item)) constant = Constant(constantName, subTypeIndication, defaultExpression) @@ -202,7 +227,8 @@ def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): else: raise DOMException( "Unknown declared item kind '{kindName}'({kind}) in {entity} '{name}'.".format( - kind=kind, kindName=kind.name, entity=entity, name=name) + kind=kind, kindName=kind.name, entity=entity, name=name + ) ) return result |