コード例 #1
0
    def parse(cls, useNode: Iir):
        from pyGHDL.dom._Translate import GetNameFromNode

        uses = [GetNameFromNode(nodes.Get_Selected_Name(useNode))]
        for use in utils.chain_iter(nodes.Get_Use_Clause_Chain(useNode)):
            uses.append(GetNameFromNode(nodes.Get_Selected_Name(use)))

        return cls(useNode, uses)
コード例 #2
0
    def parse(cls, contextNode: Iir):
        from pyGHDL.dom._Translate import GetNameFromNode

        contexts = [GetNameFromNode(nodes.Get_Selected_Name(contextNode))]
        for context in utils.chain_iter(
                nodes.Get_Context_Reference_Chain(contextNode)):
            contexts.append(GetNameFromNode(nodes.Get_Selected_Name(context)))

        return cls(contextNode, contexts)
コード例 #3
0
ファイル: Expression.py プロジェクト: umarcor/ghdl
    def parse(cls, node: Iir) -> "Aggregate":
        from pyGHDL.dom._Translate import (
            GetExpressionFromNode,
            GetRangeFromNode,
            GetNameFromNode,
        )

        choices = []

        choicesChain = nodes.Get_Association_Choices_Chain(node)
        for item in utils.chain_iter(choicesChain):
            kind = GetIirKindOfNode(item)
            value = GetExpressionFromNode(nodes.Get_Associated_Expr(item))

            if kind == nodes.Iir_Kind.Choice_By_None:
                choices.append(SimpleAggregateElement(item, value))
            elif kind == nodes.Iir_Kind.Choice_By_Expression:
                index = GetExpressionFromNode(nodes.Get_Choice_Expression(item))
                choices.append(IndexedAggregateElement(item, index, value))
            elif kind == nodes.Iir_Kind.Choice_By_Range:
                choiceRange = nodes.Get_Choice_Range(item)
                rangeKind = GetIirKindOfNode(choiceRange)
                if rangeKind == nodes.Iir_Kind.Range_Expression:
                    rng = GetRangeFromNode(choiceRange)
                elif rangeKind in (
                    nodes.Iir_Kind.Attribute_Name,
                    nodes.Iir_Kind.Parenthesis_Name,
                ):
                    rng = GetNameFromNode(choiceRange)
                else:
                    pos = Position.parse(item)
                    raise DOMException(
                        "Unknown discete range kind '{kind}' in for...generate statement at line {line}.".format(
                            kind=rangeKind.name, line=pos.Line
                        )
                    )

                choices.append(RangedAggregateElement(item, rng, value))
            elif kind == nodes.Iir_Kind.Choice_By_Name:
                name = GetNameFromNode(nodes.Get_Choice_Name(item))
                symbol = Symbol(item, name)
                choices.append(NamedAggregateElement(item, symbol, value))
            elif kind == nodes.Iir_Kind.Choice_By_Others:
                choices.append(OthersAggregateElement(item, value))
            else:
                raise DOMException(
                    "Unknown choice kind '{kind}' in aggregate '{aggr}'.".format(kind=kind.name, aggr=node)
                )

        return cls(node, choices)
コード例 #4
0
ファイル: Sequential.py プロジェクト: umarcor/ghdl
    def parse(cls, loopNode: Iir, label: str) -> "ForLoopStatement":
        from pyGHDL.dom._Utils import GetIirKindOfNode
        from pyGHDL.dom._Translate import (
            GetSequentialStatementsFromChainedNodes,
            GetRangeFromNode,
            GetNameFromNode,
        )

        spec = nodes.Get_Parameter_Specification(loopNode)
        loopIndex = GetNameOfNode(spec)

        discreteRange = nodes.Get_Discrete_Range(spec)
        rangeKind = GetIirKindOfNode(discreteRange)
        if rangeKind == nodes.Iir_Kind.Range_Expression:
            rng = GetRangeFromNode(discreteRange)
        elif rangeKind in (
            nodes.Iir_Kind.Attribute_Name,
            nodes.Iir_Kind.Parenthesis_Name,
        ):
            rng = GetNameFromNode(discreteRange)
        else:
            pos = Position.parse(loopNode)
            raise DOMException(
                "Unknown discete range kind '{kind}' in for...loop statement at line {line}.".format(
                    kind=rangeKind.name, line=pos.Line
                )
            )

        statementChain = nodes.Get_Sequential_Statement_Chain(loopNode)
        statements = GetSequentialStatementsFromChainedNodes(statementChain, "for", label)

        return cls(loopNode, loopIndex, rng, statements, label)
コード例 #5
0
ファイル: Type.py プロジェクト: umarcor/ghdl
    def parse(cls, typeName: str, typeDefinitionNode: Iir) -> "PhysicalType":
        from pyGHDL.dom._Utils import GetIirKindOfNode, GetNameOfNode
        from pyGHDL.dom._Translate import GetRangeFromNode, GetNameFromNode

        rangeConstraint = nodes.Get_Range_Constraint(typeDefinitionNode)
        rangeKind = GetIirKindOfNode(rangeConstraint)
        if rangeKind == nodes.Iir_Kind.Range_Expression:
            rng = GetRangeFromNode(rangeConstraint)
        elif rangeKind in (
                nodes.Iir_Kind.Attribute_Name,
                nodes.Iir_Kind.Parenthesis_Name,
        ):
            rng = GetNameFromNode(rangeConstraint)
        else:
            pos = Position.parse(typeDefinitionNode)
            raise DOMException(
                "Unknown range kind '{kind}' in physical type definition at line {line}."
                .format(kind=rangeKind.name, line=pos.Line))

        primaryUnit = nodes.Get_Primary_Unit(typeDefinitionNode)
        primaryUnitName = GetNameOfNode(primaryUnit)

        units = []
        for secondaryUnit in utils.chain_iter(
                nodes.Get_Unit_Chain(typeDefinitionNode)):
            secondaryUnitName = GetNameOfNode(secondaryUnit)
            if secondaryUnit == primaryUnit:
                continue

            physicalLiteral = PhysicalIntegerLiteral.parse(
                nodes.Get_Physical_Literal(secondaryUnit))

            units.append((secondaryUnitName, physicalLiteral))

        return cls(typeDefinitionNode, typeName, rng, primaryUnitName, units)
コード例 #6
0
    def parse(cls, instantiationNode: Iir, instantiatedUnit: Iir, label: str) -> "EntityInstantiation":
        from pyGHDL.dom._Translate import (
            GetNameFromNode,
            GetGenericMapAspect,
            GetPortMapAspect,
        )

        entityId = nodes.Get_Entity_Name(instantiatedUnit)
        entityName = GetNameFromNode(entityId)

        architectureName = None
        architectureId = nodes.Get_Architecture(instantiatedUnit)
        if architectureId != nodes.Null_Iir:
            architectureName = GetNameOfNode(architectureId)

        genericAssociations = GetGenericMapAspect(nodes.Get_Generic_Map_Aspect_Chain(instantiationNode))
        portAssociations = GetPortMapAspect(nodes.Get_Port_Map_Aspect_Chain(instantiationNode))

        return cls(
            instantiationNode,
            label,
            entityName,
            architectureName,
            genericAssociations,
            portAssociations,
        )
コード例 #7
0
ファイル: Sequential.py プロジェクト: umarcor/ghdl
    def parse(cls, callNode: Iir, label: str) -> "SequentialProcedureCall":
        from pyGHDL.dom._Translate import GetNameFromNode, GetParameterMapAspect

        cNode = nodes.Get_Procedure_Call(callNode)

        prefix = nodes.Get_Prefix(cNode)
        procedureName = GetNameFromNode(prefix)
        parameterAssociations = GetParameterMapAspect(nodes.Get_Parameter_Association_Chain(cNode))

        return cls(callNode, procedureName, parameterAssociations, label)
コード例 #8
0
ファイル: Sequential.py プロジェクト: umarcor/ghdl
    def parse(cls, assignmentNode: Iir, label: str = None) -> "SequentialSimpleSignalAssignment":
        from pyGHDL.dom._Translate import GetNameFromNode

        target = nodes.Get_Target(assignmentNode)
        targetName = GetNameFromNode(target)

        waveform = []
        for wave in utils.chain_iter(nodes.Get_Waveform_Chain(assignmentNode)):
            waveform.append(WaveformElement.parse(wave))

        return cls(assignmentNode, targetName, waveform, label)
コード例 #9
0
    def parse(cls, attributeNode: Iir) -> "AttributeSpecification":
        attributeDesignator = nodes.Get_Attribute_Designator(attributeNode)
        attributeName = GetNameFromNode(attributeDesignator)

        names = []
        entityNameList = nodes.Get_Entity_Name_List(attributeNode)
        for name in utils.flist_iter(entityNameList):
            nameKind = GetIirKindOfNode(name)
            if nameKind == nodes.Iir_Kind.Simple_Name:
                names.append(SimpleName(name, GetNameOfNode(name)))
            elif nameKind == nodes.Iir_Kind.Signature:
                print(
                    "[NOT IMPLEMENTED] Signature name in attribute specifications."
                )
            else:
                position = Position.parse(name)
                raise DOMException(
                    "Unknown name kind '{kind}' in attribute specification '{attr}' at {file}:{line}:{column}."
                    .format(
                        kind=nameKind.name,
                        attr=attributeNode,
                        file=position.Filename,
                        line=position.Line,
                        column=position.Column,
                    ))

        entityClassToken = nodes.Get_Entity_Class(attributeNode)
        try:
            entityClass = _TOKEN_TRANSLATION[entityClassToken]
        except KeyError:
            position = Position.parse(attributeNode)
            raise DOMException(
                "Unknown token '{token}' in attribute specification for entity class '{entityClass}' at {file}:{line}:{column}."
                .format(
                    token=entityClassToken.name,
                    entityClass=attributeNode,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                ))

        expression = GetExpressionFromNode(nodes.Get_Expression(attributeNode))

        return cls(attributeNode, names, attributeName, entityClass,
                   expression)
コード例 #10
0
    def parse(cls, instantiationNode: Iir, instantiatedUnit: Iir, label: str) -> "ComponentInstantiation":
        from pyGHDL.dom._Translate import (
            GetNameFromNode,
            GetGenericMapAspect,
            GetPortMapAspect,
        )

        componentName = GetNameFromNode(instantiatedUnit)
        genericAssociations = GetGenericMapAspect(nodes.Get_Generic_Map_Aspect_Chain(instantiationNode))
        portAssociations = GetPortMapAspect(nodes.Get_Port_Map_Aspect_Chain(instantiationNode))

        return cls(
            instantiationNode,
            label,
            componentName,
            genericAssociations,
            portAssociations,
        )
コード例 #11
0
ファイル: Concurrent.py プロジェクト: hexagon-oss/ghdl
    def parse(cls, generateNode: Iir, label: str) -> "ForGenerateStatement":
        from pyGHDL.dom._Utils import GetIirKindOfNode
        from pyGHDL.dom._Translate import (
            GetDeclaredItemsFromChainedNodes,
            GetConcurrentStatementsFromChainedNodes,
            GetRangeFromNode,
            GetNameFromNode,
        )

        spec = nodes.Get_Parameter_Specification(generateNode)
        loopIndex = GetNameOfNode(spec)

        discreteRange = nodes.Get_Discrete_Range(spec)
        rangeKind = GetIirKindOfNode(discreteRange)
        if rangeKind == nodes.Iir_Kind.Range_Expression:
            rng = GetRangeFromNode(discreteRange)
        elif rangeKind in (
                nodes.Iir_Kind.Attribute_Name,
                nodes.Iir_Kind.Parenthesis_Name,
        ):
            rng = GetNameFromNode(discreteRange)
        else:
            pos = Position.parse(generateNode)
            raise DOMException(
                "Unknown discete range kind '{kind}' in for...generate statement at line {line}."
                .format(kind=rangeKind.name, line=pos.Line))

        body = nodes.Get_Generate_Statement_Body(generateNode)
        declarationChain = nodes.Get_Declaration_Chain(body)
        declaredItems = GetDeclaredItemsFromChainedNodes(
            declarationChain, "for-generate", label)

        statementChain = nodes.Get_Concurrent_Statement_Chain(body)
        statements = GetConcurrentStatementsFromChainedNodes(
            statementChain, "for-generate", label)

        return cls(generateNode, label, loopIndex, rng, declaredItems,
                   statements)
コード例 #12
0
ファイル: Sequential.py プロジェクト: umarcor/ghdl
    def parse(cls, caseNode: Iir, label: str) -> "CaseStatement":
        from pyGHDL.dom._Utils import GetIirKindOfNode
        from pyGHDL.dom._Translate import (
            GetExpressionFromNode,
            GetRangeFromNode,
            GetNameFromNode,
        )

        expression = GetExpressionFromNode(nodes.Get_Expression(caseNode))

        cases = []
        choices = None
        alternative = nodes.Get_Case_Statement_Alternative_Chain(caseNode)
        cNode = alternative

        while alternative != nodes.Null_Iir:
            choiceKind = GetIirKindOfNode(alternative)
            sameAlternative = nodes.Get_Same_Alternative_Flag(alternative)

            if choiceKind in (
                nodes.Iir_Kind.Choice_By_Name,
                nodes.Iir_Kind.Choice_By_Expression,
            ):
                choiceExpression = GetExpressionFromNode(nodes.Get_Choice_Expression(alternative))

                choice = IndexedChoice(alternative, choiceExpression)
                if sameAlternative:
                    choices.append(choice)
                    alternative = nodes.Get_Chain(alternative)
                    continue
            elif choiceKind is nodes.Iir_Kind.Choice_By_Range:
                choiceRange = nodes.Get_Choice_Range(alternative)
                choiceRangeKind = GetIirKindOfNode(choiceRange)
                if choiceRangeKind == nodes.Iir_Kind.Range_Expression:
                    rng = GetRangeFromNode(choiceRange)
                elif choiceRangeKind in (
                    nodes.Iir_Kind.Attribute_Name,
                    nodes.Iir_Kind.Parenthesis_Name,
                ):
                    rng = GetNameFromNode(choiceRange)
                else:
                    pos = Position.parse(alternative)
                    raise DOMException(
                        "Unknown choice range kind '{kind}' in case statement at line {line}.".format(
                            kind=choiceRangeKind.name, line=pos.Line
                        )
                    )

                choice = RangedChoice(alternative, rng)
                if sameAlternative:
                    choices.append(choice)
                    alternative = nodes.Get_Chain(alternative)
                    continue
            elif choiceKind is nodes.Iir_Kind.Choice_By_Others:
                if choices is not None:
                    cases.append(Case.parse(alternative, choices, label))
                    choices = None
                cases.append(OthersCase.parse(alternative, label))
                alternative = nodes.Get_Chain(alternative)
                cNode = alternative
                continue
            else:
                pos = Position.parse(alternative)
                raise DOMException(
                    "Unknown choice kind '{kind}' in case statement at line {line}.".format(
                        kind=choiceKind.name, line=pos.Line
                    )
                )

            if choices is not None:
                cases.append(Case.parse(cNode, choices, label))

            cNode = alternative
            choices = [
                choice,
            ]

            alternative = nodes.Get_Chain(alternative)

        if choices is not None:
            cases.append(Case.parse(cNode, choices, label))

        return cls(caseNode, label, expression, cases)
コード例 #13
0
    def parse(cls, node: Iir):
        from pyGHDL.dom._Translate import GetNameFromNode

        name = GetNameFromNode(node)

        return cls(node, name)