Beispiel #1
0
    def parse(cls, typeName: str, typeDefinitionNode: Iir) -> "ProtectedType":
        from pyGHDL.dom._Utils import GetIirKindOfNode

        # FIXME: change this to a generator
        methods = []
        for item in utils.chain_iter(
                nodes.Get_Declaration_Chain(typeDefinitionNode)):
            kind = GetIirKindOfNode(item)
            if kind == nodes.Iir_Kind.Function_Declaration:
                methods.append(Function.parse(item))
            elif kind == nodes.Iir_Kind.Procedure_Declaration:
                methods.append(Procedure.parse(item))

        return cls(typeDefinitionNode, typeName, methods)
Beispiel #2
0
    def parse(cls, waitNode: Iir, label: str) -> "WaitStatement":
        from pyGHDL.dom._Utils import GetIirKindOfNode
        from pyGHDL.dom._Translate import GetExpressionFromNode

        sensitivityList = None
        sensitivityListNode = nodes.Get_Sensitivity_List(waitNode)
        if sensitivityListNode is not nodes.Null_Iir:
            print(GetIirKindOfNode(sensitivityListNode))

        conditionNode = nodes.Get_Condition_Clause(waitNode)
        condition = None if conditionNode is nodes.Null_Iir else GetExpressionFromNode(conditionNode)

        timeoutNode = nodes.Get_Timeout_Clause(waitNode)
        timeout = None if timeoutNode is nodes.Null_Iir else GetExpressionFromNode(timeoutNode)

        return cls(waitNode, sensitivityList, condition, timeout, label)
Beispiel #3
0
def GetSequentialStatementsFromChainedNodes(
        nodeChain: Iir, entity: str,
        name: str) -> Generator[SequentialStatement, None, None]:
    for statement in utils.chain_iter(nodeChain):
        label = nodes.Get_Label(statement)
        label = name_table.Get_Name_Ptr(
            label) if label != nodes.Null_Iir else None

        pos = Position.parse(statement)
        kind = GetIirKindOfNode(statement)
        if kind == nodes.Iir_Kind.If_Statement:
            yield IfStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.For_Loop_Statement:
            yield ForLoopStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Case_Statement:
            yield CaseStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Simple_Signal_Assignment_Statement:
            yield SequentialSimpleSignalAssignment.parse(statement, label)
        elif kind in (
                nodes.Iir_Kind.Variable_Assignment_Statement,
                nodes.Iir_Kind.Conditional_Variable_Assignment_Statement,
        ):
            print(
                "[NOT IMPLEMENTED] Variable assignment (label: '{label}') at line {line}"
                .format(label=label, line=pos.Line))
        elif kind == nodes.Iir_Kind.Wait_Statement:
            yield WaitStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Procedure_Call_Statement:
            yield SequentialProcedureCall.parse(statement, label)
        elif kind == nodes.Iir_Kind.Report_Statement:
            yield SequentialReportStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Assertion_Statement:
            yield SequentialAssertStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Null_Statement:
            yield NullStatement(statement, label)
        else:
            raise DOMException(
                "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}."
                .format(
                    kind=kind.name,
                    entity=entity,
                    name=name,
                    file=pos.Filename,
                    line=pos.Line,
                    column=pos.Column,
                ))
Beispiel #4
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)
Beispiel #5
0
def GetPortsFromChainedNodes(
    nodeChain: Iir, ) -> Generator[PortInterfaceItem, None, None]:

    port = nodeChain
    while port != nodes.Null_Iir:
        kind = GetIirKindOfNode(port)
        if kind == nodes.Iir_Kind.Interface_Signal_Declaration:
            from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem

            portSignal = PortSignalInterfaceItem.parse(port)

            # Lookahead for ports with multiple identifiers at once
            if nodes.Get_Has_Identifier_List(port):
                nextNode = nodes.Get_Chain(port)
                for nextPort in utils.chain_iter(nextNode):
                    # Consecutive identifiers are found, if the subtype indication is Null
                    if nodes.Get_Subtype_Indication(
                            nextPort) == nodes.Null_Iir:
                        portSignal.Identifiers.append(GetNameOfNode(nextPort))
                    else:
                        port = nextPort
                        break

                    # The last consecutive identifiers has no Identifier_List flag
                    if not nodes.Get_Has_Identifier_List(nextPort):
                        port = nodes.Get_Chain(nextPort)
                        break
                else:
                    port = nodes.Null_Iir
            else:
                port = nodes.Get_Chain(port)

            yield portSignal
            continue
        else:
            position = Position.parse(port)
            raise DOMException(
                "Unknown port kind '{kind}' in port '{port}' at {file}:{line}:{column}."
                .format(
                    kind=kind.name,
                    port=port,
                    file=position.Filename,
                    line=position.Line,
                    column=position.Column,
                ))
Beispiel #6
0
def GetExpressionFromNode(node: Iir) -> ExpressionUnion:
    kind = GetIirKindOfNode(node)

    try:
        cls = __EXPRESSION_TRANSLATION[kind]
    except KeyError:
        position = Position.parse(node)
        raise DOMException(
            "Unknown expression kind '{kind}' in expression '{expr}' at {file}:{line}:{column}."
            .format(
                kind=kind.name,
                expr=node,
                file=position.Filename,
                line=position.Line,
                column=position.Column,
            ))

    return cls.parse(node)
Beispiel #7
0
def GetAssociations(node: Iir) -> List:
    associations = []
    for item in utils.chain_iter(nodes.Get_Association_Chain(node)):
        kind = GetIirKindOfNode(item)

        if kind in (
                nodes.Iir_Kind.Association_Element_By_Expression,
                nodes.Iir_Kind.Association_Element_By_Name,
        ):
            actual = nodes.Get_Actual(item)
            expr = GetExpressionFromNode(actual)

            associations.append(expr)
        else:
            raise DOMException(
                "Unknown association kind '{kind}' in array index/slice or function call '{node}'."
                .format(kind=kind.name, node=node))

    return associations
Beispiel #8
0
def GetSubtypeIndicationFromIndicationNode(subtypeIndicationNode: Iir,
                                           entity: str,
                                           name: str) -> SubtypeOrSymbol:
    if subtypeIndicationNode is nodes.Null_Iir:
        raise ValueError("Parameter 'subtypeIndicationNode' is 'Null_Iir'.")

    kind = GetIirKindOfNode(subtypeIndicationNode)
    if kind in (
            nodes.Iir_Kind.Simple_Name,
            nodes.Iir_Kind.Selected_Name,
            nodes.Iir_Kind.Attribute_Name,
    ):
        return GetSimpleTypeFromNode(subtypeIndicationNode)
    elif kind == nodes.Iir_Kind.Subtype_Definition:
        return GetScalarConstrainedSubtypeFromNode(subtypeIndicationNode)
    elif kind == nodes.Iir_Kind.Array_Subtype_Definition:
        return GetCompositeConstrainedSubtypeFromNode(subtypeIndicationNode)
    else:
        raise DOMException(
            "Unknown kind '{kind}' for an subtype indication in a {entity} of `{name}`."
            .format(kind=kind.name, entity=entity, name=name))
Beispiel #9
0
    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)
Beispiel #10
0
def GetNameFromNode(node: Iir) -> Name:
    kind = GetIirKindOfNode(node)
    if kind == nodes.Iir_Kind.Simple_Name:
        name = GetNameOfNode(node)
        return SimpleName(node, name)
    elif kind == nodes.Iir_Kind.Selected_Name:
        name = GetNameOfNode(node)
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return SelectedName(node, name, prefixName)
    elif kind == nodes.Iir_Kind.Attribute_Name:
        name = GetNameOfNode(node)
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return AttributeName(node, name, prefixName)
    elif kind == nodes.Iir_Kind.Parenthesis_Name:
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        associations = GetAssociations(node)

        return ParenthesisName(node, prefixName, associations)
    elif kind == nodes.Iir_Kind.Selected_By_All_Name:
        prefixName = GetNameFromNode(nodes.Get_Prefix(node))
        return AllName(node, prefixName)
    else:
        raise DOMException("Unknown name kind '{kind}'".format(kind=kind.name))
Beispiel #11
0
    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)
Beispiel #12
0
def GetConcurrentStatementsFromChainedNodes(
        nodeChain: Iir, entity: str,
        name: str) -> Generator[ConcurrentStatement, None, None]:
    for statement in utils.chain_iter(nodeChain):
        label = nodes.Get_Label(statement)
        label = name_table.Get_Name_Ptr(
            label) if label != nodes.Null_Iir else None

        pos = Position.parse(statement)

        kind = GetIirKindOfNode(statement)
        if kind == nodes.Iir_Kind.Sensitized_Process_Statement:
            yield ProcessStatement.parse(statement, label, True)

        elif kind == nodes.Iir_Kind.Process_Statement:
            yield ProcessStatement.parse(statement, label, False)

        elif kind == nodes.Iir_Kind.Concurrent_Simple_Signal_Assignment:
            yield ConcurrentSimpleSignalAssignment.parse(statement, label)
        elif kind == nodes.Iir_Kind.Concurrent_Conditional_Signal_Assignment:
            print(
                "[NOT IMPLEMENTED] Concurrent (conditional) signal assignment (label: '{label}') at line {line}"
                .format(label=label, line=pos.Line))
        elif kind == nodes.Iir_Kind.Concurrent_Selected_Signal_Assignment:
            print(
                "[NOT IMPLEMENTED] Concurrent (selected) signal assignment (label: '{label}') at line {line}"
                .format(label=label, line=pos.Line))
        elif kind == nodes.Iir_Kind.Concurrent_Procedure_Call_Statement:
            yield ConcurrentProcedureCall.parse(statement, label)
        elif kind == nodes.Iir_Kind.Component_Instantiation_Statement:
            instantiatedUnit = nodes.Get_Instantiated_Unit(statement)
            instantiatedUnitKind = GetIirKindOfNode(instantiatedUnit)
            if instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Entity:
                yield EntityInstantiation.parse(statement, instantiatedUnit,
                                                label)
            elif instantiatedUnitKind == nodes.Iir_Kind.Entity_Aspect_Configuration:
                yield ConfigurationInstantiation.parse(statement,
                                                       instantiatedUnit, label)
            elif instantiatedUnitKind == nodes.Iir_Kind.Simple_Name:
                yield ComponentInstantiation.parse(statement, instantiatedUnit,
                                                   label)
            else:
                raise DOMException(
                    "Unknown instantiation kind '{kind}' in instantiation of label {label} at {file}:{line}:{column}."
                    .format(
                        kind=instantiatedUnitKind.name,
                        label=label,
                        file=pos.Filename,
                        line=pos.Line,
                        column=pos.Column,
                    ))
        elif kind == nodes.Iir_Kind.Block_Statement:
            yield ConcurrentBlockStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.If_Generate_Statement:
            yield IfGenerateStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Case_Generate_Statement:
            yield CaseGenerateStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.For_Generate_Statement:
            yield ForGenerateStatement.parse(statement, label)
        elif kind == nodes.Iir_Kind.Psl_Assert_Directive:
            yield ConcurrentAssertStatement.parse(statement, label)
        else:
            raise DOMException(
                "Unknown statement of kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}."
                .format(
                    kind=kind.name,
                    entity=entity,
                    name=name,
                    file=pos.Filename,
                    line=pos.Line,
                    column=pos.Column,
                ))
Beispiel #13
0
def GetDeclaredItemsFromChainedNodes(
        nodeChain: Iir, entity: str,
        name: str) -> Generator[ModelEntity, None, None]:
    item = nodeChain
    lastKind = None
    while item != nodes.Null_Iir:
        kind = GetIirKindOfNode(item)
        if kind == nodes.Iir_Kind.Constant_Declaration:
            from pyGHDL.dom.Object import Constant

            obj = Constant.parse(item)

        elif kind == nodes.Iir_Kind.Variable_Declaration:
            from pyGHDL.dom.Object import SharedVariable

            if nodes.Get_Shared_Flag(item):
                obj = SharedVariable.parse(item)
            else:
                obj = Variable.parse(item)
        elif kind == nodes.Iir_Kind.Signal_Declaration:
            from pyGHDL.dom.Object import Signal

            obj = Signal.parse(item)
        elif kind == nodes.Iir_Kind.File_Declaration:
            from pyGHDL.dom.Object import File

            obj = File.parse(item)
        else:
            if kind == nodes.Iir_Kind.Type_Declaration:
                yield GetTypeFromNode(item)

            elif kind == nodes.Iir_Kind.Anonymous_Type_Declaration:
                yield GetAnonymousTypeFromNode(item)

            elif kind == nodes.Iir_Kind.Subtype_Declaration:
                yield GetSubtypeFromNode(item)

            elif kind == nodes.Iir_Kind.Function_Declaration:
                if nodes.Get_Has_Body(item):
                    yield Function.parse(item)
                else:
                    print(
                        "[NOT IMPLEMENTED] function declaration without body")

                lastKind = kind
                item = nodes.Get_Chain(item)
                continue
            elif kind == nodes.Iir_Kind.Function_Body:
                if lastKind is nodes.Iir_Kind.Function_Declaration:
                    pass
                else:
                    position = Position.parse(item)
                    raise DOMException(
                        "Found unexpected function body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}."
                        .format(
                            functionName=GetNameOfNode(item),
                            entity=entity,
                            name=name,
                            file=position.Filename,
                            line=position.Line,
                            column=position.Column,
                        ))
            elif kind == nodes.Iir_Kind.Procedure_Declaration:
                if nodes.Get_Has_Body(item):
                    yield Procedure.parse(item)
                else:
                    print(
                        "[NOT IMPLEMENTED] procedure declaration without body")

                lastKind = kind
                item = nodes.Get_Chain(item)
                continue
            elif kind == nodes.Iir_Kind.Procedure_Body:
                if lastKind is nodes.Iir_Kind.Procedure_Declaration:
                    pass
                else:
                    position = Position.parse(item)
                    raise DOMException(
                        "Found unexpected procedure body '{functionName}' in {entity} '{name}' at {file}:{line}:{column}."
                        .format(
                            functionName=GetNameOfNode(item),
                            entity=entity,
                            name=name,
                            file=position.Filename,
                            line=position.Line,
                            column=position.Column,
                        ))
            elif kind == nodes.Iir_Kind.Protected_Type_Body:
                yield ProtectedTypeBody.parse(item)
            elif kind == nodes.Iir_Kind.Object_Alias_Declaration:
                yield GetAliasFromNode(item)
            elif kind == nodes.Iir_Kind.Component_Declaration:
                from pyGHDL.dom.DesignUnit import Component

                yield Component.parse(item)
            elif kind == nodes.Iir_Kind.Attribute_Declaration:
                from pyGHDL.dom.Attribute import Attribute

                yield Attribute.parse(item)
            elif kind == nodes.Iir_Kind.Attribute_Specification:
                from pyGHDL.dom.Attribute import AttributeSpecification

                yield AttributeSpecification.parse(item)
            elif kind == nodes.Iir_Kind.Use_Clause:
                from pyGHDL.dom.DesignUnit import UseClause

                yield UseClause.parse(item)
            elif kind == nodes.Iir_Kind.Package_Declaration:
                from pyGHDL.dom.DesignUnit import Package

                yield Package.parse(item, None)  # TODO: Can it have a context?
            elif kind == nodes.Iir_Kind.Package_Instantiation_Declaration:
                from pyGHDL.dom.DesignUnit import PackageInstantiation

                yield PackageInstantiation.parse(item)
            elif kind == nodes.Iir_Kind.Configuration_Specification:
                print(
                    "[NOT IMPLEMENTED] Configuration specification in {name}".
                    format(name=name))
            elif kind == nodes.Iir_Kind.Psl_Default_Clock:
                yield DefaultClock.parse(item)
            elif kind == nodes.Iir_Kind.Group_Declaration:
                print("[NOT IMPLEMENTED] Group declaration in {name}".format(
                    name=name))
            elif kind == nodes.Iir_Kind.Group_Template_Declaration:
                print("[NOT IMPLEMENTED] Group template declaration in {name}".
                      format(name=name))
            elif kind == nodes.Iir_Kind.Disconnection_Specification:
                print("[NOT IMPLEMENTED] Disconnect specification in {name}".
                      format(name=name))
            else:
                position = Position.parse(item)
                raise DOMException(
                    "Unknown declared item kind '{kind}' in {entity} '{name}' at {file}:{line}:{column}."
                    .format(
                        kind=kind.name,
                        entity=entity,
                        name=name,
                        file=position.Filename,
                        line=position.Line,
                        column=position.Column,
                    ))

            lastKind = None
            item = nodes.Get_Chain(item)
            continue

        # Lookahead for objects with multiple identifiers at once
        if nodes.Get_Has_Identifier_List(item):
            nextNode = nodes.Get_Chain(item)
            for nextItem in utils.chain_iter(nextNode):
                # Consecutive identifiers are found, if the subtype indication is Null
                if nodes.Get_Subtype_Indication(nextItem) == nodes.Null_Iir:
                    obj.Identifiers.append(GetNameOfNode(nextItem))
                else:
                    item = nextItem
                    break

                # The last consecutive identifiers has no Identifier_List flag
                if not nodes.Get_Has_Identifier_List(nextItem):
                    item = nodes.Get_Chain(nextItem)
                    break
            else:
                item = nodes.Null_Iir
        else:
            item = nodes.Get_Chain(item)

        yield obj
Beispiel #14
0
def GetGenericsFromChainedNodes(
    nodeChain: Iir, ) -> Generator[GenericInterfaceItem, None, None]:
    from pyGHDL.dom.InterfaceItem import (
        GenericTypeInterfaceItem,
        GenericPackageInterfaceItem,
        GenericProcedureInterfaceItem,
        GenericFunctionInterfaceItem,
    )

    generic = nodeChain
    while generic != nodes.Null_Iir:
        kind = GetIirKindOfNode(generic)
        if kind == nodes.Iir_Kind.Interface_Constant_Declaration:
            from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem

            genericConstant = GenericConstantInterfaceItem.parse(generic)

            # Lookahead for generics with multiple identifiers at once
            if nodes.Get_Has_Identifier_List(generic):
                nextNode = nodes.Get_Chain(generic)
                for nextGeneric in utils.chain_iter(nextNode):
                    # Consecutive identifiers are found, if the subtype indication is Null
                    if nodes.Get_Subtype_Indication(
                            nextGeneric) == nodes.Null_Iir:
                        genericConstant.Identifiers.append(
                            GetNameOfNode(nextGeneric))
                    else:
                        generic = nextGeneric
                        break

                    # The last consecutive identifiers has no Identifier_List flag
                    if not nodes.Get_Has_Identifier_List(nextGeneric):
                        generic = nodes.Get_Chain(nextGeneric)
                        break
                else:
                    generic = nodes.Null_Iir
            else:
                generic = nodes.Get_Chain(generic)

            yield genericConstant
            continue
        else:
            if kind == nodes.Iir_Kind.Interface_Type_Declaration:
                yield GenericTypeInterfaceItem.parse(generic)
            elif kind == nodes.Iir_Kind.Interface_Package_Declaration:
                yield GenericPackageInterfaceItem.parse(generic)
            elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration:
                yield GenericProcedureInterfaceItem.parse(generic)
            elif kind == nodes.Iir_Kind.Interface_Function_Declaration:
                yield GenericFunctionInterfaceItem.parse(generic)
            else:
                position = Position.parse(generic)
                raise DOMException(
                    "Unknown generic kind '{kind}' in generic '{generic}' at {file}:{line}:{column}."
                    .format(
                        kind=kind.name,
                        generic=generic,
                        file=position.Filename,
                        line=position.Line,
                        column=position.Column,
                    ))

        generic = nodes.Get_Chain(generic)
Beispiel #15
0
    def translate(self):
        firstUnit = nodes.Get_First_Design_Unit(self.__ghdlFile)

        for unit in utils.chain_iter(firstUnit):
            libraryUnit = nodes.Get_Library_Unit(unit)
            nodeKind = GetIirKindOfNode(libraryUnit)

            contextItems = []
            contextNames = []
            context = nodes.Get_Context_Items(unit)
            if context is not nodes.Null_Iir:
                for item in utils.chain_iter(context):
                    itemKind = GetIirKindOfNode(item)
                    if itemKind is nodes.Iir_Kind.Library_Clause:
                        contextNames.append(
                            SimpleName(item, GetNameOfNode(item)))
                        if nodes.Get_Has_Identifier_List(item):
                            continue

                        contextItems.append(LibraryClause(item, contextNames))
                        contextNames = []
                    elif itemKind is nodes.Iir_Kind.Use_Clause:
                        contextItems.append(UseClause.parse(item))
                    elif itemKind is nodes.Iir_Kind.Context_Reference:
                        contextItems.append(ContextReference.parse(item))
                    else:
                        pos = Position.parse(item)
                        raise DOMException(
                            "Unknown context item kind '{kind}' in context at line {line}."
                            .format(kind=itemKind.name, line=pos.Line))

            if nodeKind == nodes.Iir_Kind.Entity_Declaration:
                entity = Entity.parse(libraryUnit, contextItems)
                self.Entities.append(entity)

            elif nodeKind == nodes.Iir_Kind.Architecture_Body:
                architecture = Architecture.parse(libraryUnit, contextItems)
                self.Architectures.append(architecture)

            elif nodeKind == nodes.Iir_Kind.Package_Declaration:
                package = Package.parse(libraryUnit, contextItems)
                self.Packages.append(package)

            elif nodeKind == nodes.Iir_Kind.Package_Body:
                packageBody = PackageBody.parse(libraryUnit, contextItems)
                self.PackageBodies.append(packageBody)

            elif nodeKind == nodes.Iir_Kind.Package_Instantiation_Declaration:
                package = PackageInstantiation.parse(libraryUnit)
                self.Packages.append(package)

            elif nodeKind == nodes.Iir_Kind.Context_Declaration:
                context = Context.parse(libraryUnit)
                self.Contexts.append(context)

            elif nodeKind == nodes.Iir_Kind.Configuration_Declaration:
                configuration = Configuration.parse(libraryUnit, contextItems)
                self.Configurations.append(configuration)

            elif nodeKind == nodes.Iir_Kind.Vunit_Declaration:
                vunit = VerificationUnit.parse(libraryUnit)
                self.VerificationUnits.append(vunit)

            elif nodeKind == nodes.Iir_Kind.Vprop_Declaration:
                vprop = VerificationProperty.parse(libraryUnit)
                self.VerificationProperties.append(vprop)

            elif nodeKind == nodes.Iir_Kind.Vmode_Declaration:
                vmod = VerificationMode.parse(libraryUnit)
                self.VerificationModes.append(vmod)

            else:
                raise DOMException("Unknown design unit kind '{kind}'.".format(
                    kind=nodeKind.name))