diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-20 16:52:45 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-22 12:26:59 +0200 |
commit | d9241cf7156ff2e8b1ce8258e780eb9c8bf1e38f (patch) | |
tree | a7dc7ee647f350d47fafaa372a70bc56a28c537f /pyGHDL | |
parent | 045fb20734c477fe5191ac0b6de51fa272c64f41 (diff) | |
download | ghdl-d9241cf7156ff2e8b1ce8258e780eb9c8bf1e38f.tar.gz ghdl-d9241cf7156ff2e8b1ce8258e780eb9c8bf1e38f.tar.bz2 ghdl-d9241cf7156ff2e8b1ce8258e780eb9c8bf1e38f.zip |
Added concatenation and string literal.
Diffstat (limited to 'pyGHDL')
-rw-r--r-- | pyGHDL/dom/Expression.py | 31 | ||||
-rw-r--r-- | pyGHDL/dom/Literal.py | 10 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 28 |
3 files changed, 42 insertions, 27 deletions
diff --git a/pyGHDL/dom/Expression.py b/pyGHDL/dom/Expression.py index fec347b57..75d288a83 100644 --- a/pyGHDL/dom/Expression.py +++ b/pyGHDL/dom/Expression.py @@ -32,19 +32,6 @@ # ============================================================================ from typing import List -from pyGHDL.dom.Aggregates import ( - OthersAggregateElement, - SimpleAggregateElement, - RangedAggregateElement, - IndexedAggregateElement, - NamedAggregateElement, -) -from pyGHDL.dom.Symbol import EnumerationLiteralSymbol -from pyGHDL.libghdl import utils - -from pyGHDL.dom.Common import DOMException -from pyGHDL.dom._Utils import GetIirKindOfNode -from pyGHDL.libghdl.vhdl import nodes from pydecor import export from pyVHDLModel.VHDLModel import ( @@ -86,6 +73,20 @@ from pyVHDLModel.VHDLModel import ( AggregateElement, ) +from pyGHDL.libghdl import utils +from pyGHDL.libghdl.vhdl import nodes +from pyGHDL.dom._Utils import GetIirKindOfNode +from pyGHDL.dom.Common import DOMException +from pyGHDL.dom.Symbol import EnumerationLiteralSymbol +from pyGHDL.dom.Aggregates import ( + OthersAggregateElement, + SimpleAggregateElement, + RangedAggregateElement, + IndexedAggregateElement, + NamedAggregateElement, +) + + __all__ = [] @@ -391,7 +392,7 @@ class Aggregate(VHDLModel_Aggregate): @classmethod def parse(cls, node): - from pyGHDL.dom._Translate import GetExpressionFromNode + from pyGHDL.dom._Translate import GetExpressionFromNode, GetRangeFromNode choices = [] @@ -406,7 +407,7 @@ class Aggregate(VHDLModel_Aggregate): value = GetExpressionFromNode(nodes.Get_Associated_Expr(item)) choices.append(IndexedAggregateElement(index, value)) elif kind == nodes.Iir_Kind.Choice_By_Range: - r = GetExpressionFromNode(nodes.Get_Choice_Range(item)) + r = GetRangeFromNode(nodes.Get_Choice_Range(item)) value = GetExpressionFromNode(nodes.Get_Associated_Expr(item)) choices.append(RangedAggregateElement(r, value)) elif kind == nodes.Iir_Kind.Choice_By_Name: diff --git a/pyGHDL/dom/Literal.py b/pyGHDL/dom/Literal.py index 7c722583b..334355b35 100644 --- a/pyGHDL/dom/Literal.py +++ b/pyGHDL/dom/Literal.py @@ -39,6 +39,7 @@ from pyVHDLModel.VHDLModel import ( IntegerLiteral as VHDLModel_IntegerLiteral, FloatingPointLiteral as VHDLModel_FloatingPointLiteral, CharacterLiteral as VHDLModel_CharacterLiteral, + StringLiteral as VHDLModel_StringLiteral, ) __all__ = [] @@ -67,3 +68,12 @@ class CharacterLiteral(VHDLModel_CharacterLiteral): identifier = nodes.Get_Identifier(node) value = name_table.Get_Character(identifier) return cls(value) + + +@export +class StringLiteral(VHDLModel_StringLiteral): + @classmethod + def parse(cls, node): + stringID = nodes.Get_String8_Id(node) + value = name_table.Get_Name_Ptr(stringID) + return cls(value) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index 24f056f33..a18f738df 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -46,7 +46,7 @@ from pyGHDL.dom.Symbol import ( SimpleSubTypeSymbol, ConstrainedSubTypeSymbol, ) -from pyGHDL.dom.Literal import IntegerLiteral, CharacterLiteral, FloatingPointLiteral +from pyGHDL.dom.Literal import IntegerLiteral, CharacterLiteral, FloatingPointLiteral, StringLiteral from pyGHDL.dom.Expression import ( SubtractionExpression, AdditionExpression, @@ -56,7 +56,7 @@ from pyGHDL.dom.Expression import ( ExponentiationExpression, Aggregate, NegationExpression, - ParenthesisExpression, + ParenthesisExpression, ConcatenationExpression, ) __all__ = [] @@ -101,16 +101,7 @@ def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constrai for constraint in flist_iter(nodes.Get_Index_Constraint_List(subTypeIndication)): constraintKind = GetIirKindOfNode(constraint) if constraintKind == nodes.Iir_Kind.Range_Expression: - direction = nodes.Get_Direction(constraint) - leftBound = nodes.Get_Left_Limit_Expr(constraint) - rightBound = nodes.Get_Right_Limit_Expr(constraint) - - r = Range( - GetExpressionFromNode(leftBound), - GetExpressionFromNode(rightBound), - Direction.DownTo if direction else Direction.To, - ) - constraints.append(RangeExpression(r)) + constraints.append(RangeExpression(GetRangeFromNode(constraint))) elif constraintKind == nodes.Iir_Kind.Attribute_Name: raise DOMException("[NOT IMPLEMENTED] Attribute name as range.") elif constraintKind == nodes.Iir_Kind.Simple_Name: @@ -132,8 +123,10 @@ __EXPRESSION_TRANSLATION = { nodes.Iir_Kind.Integer_Literal: IntegerLiteral, nodes.Iir_Kind.Floating_Point_Literal: FloatingPointLiteral, nodes.Iir_Kind.Character_Literal: CharacterLiteral, + nodes.Iir_Kind.String_Literal8: StringLiteral, nodes.Iir_Kind.Negation_Operator: NegationExpression, nodes.Iir_Kind.Addition_Operator: AdditionExpression, + nodes.Iir_Kind.Concatenation_Operator: ConcatenationExpression, nodes.Iir_Kind.Not_Operator: InverseExpression, nodes.Iir_Kind.Parenthesis_Expression: ParenthesisExpression, nodes.Iir_Kind.Substraction_Operator: SubtractionExpression, @@ -143,6 +136,17 @@ __EXPRESSION_TRANSLATION = { nodes.Iir_Kind.Aggregate: Aggregate, } +@export +def GetRangeFromNode(node) -> Range: + direction = nodes.Get_Direction(node) + leftBound = nodes.Get_Left_Limit_Expr(node) + rightBound = nodes.Get_Right_Limit_Expr(node) + + return Range( + GetExpressionFromNode(leftBound), + GetExpressionFromNode(rightBound), + Direction.DownTo if direction else Direction.To, + ) @export def GetExpressionFromNode(node) -> Expression: |