Esempio n. 1
0
    def parse(cls, caseNode: Iir, choices: Iterable[SequentialChoice], label: str) -> "Case":
        from pyGHDL.dom._Translate import GetSequentialStatementsFromChainedNodes

        statementChain = nodes.Get_Associated_Chain(caseNode)
        statements = GetSequentialStatementsFromChainedNodes(statementChain, "case", label)

        return cls(caseNode, choices, statements)
Esempio n. 2
0
def sequential_iter(n) -> Generator[Any, None, None]:
    """
    Iterate sequential statements. The first node must be either
    a process or a subprogram body.
    """
    if n == nodes.Null_Iir:
        return
    k = nodes.Get_Kind(n)
    if k in (
            nodes.Iir_Kind.Process_Statement,
            nodes.Iir_Kind.Sensitized_Process_Statement,
            nodes.Iir_Kind.Function_Body,
            nodes.Iir_Kind.Procedure_Body,
    ):
        for n1 in chain_iter(nodes.Get_Sequential_Statement_Chain(n)):
            yield n1
            for n2 in sequential_iter(n1):
                yield n2
    elif k == nodes.Iir_Kind.If_Statement:
        while True:
            n = nodes.Get_Chain(n)
            if n == nodes.Null_Iir:
                break
            yield n
            for n1 in sequential_iter(n):
                yield n1
    elif k == nodes.Iir_Kind.Case_Statement:
        for ch in chain_iter(nodes.Get_Case_Statement_Alternative_Chain(n)):
            stmt = nodes.Get_Associated_Chain(ch)
            if stmt != nodes.Null_Iir:
                for n1 in chain_iter(stmt):
                    yield n1
                    for n2 in sequential_iter(n1):
                        yield n2
    elif k in [
            nodes.Iir_Kind.For_Loop_Statement,
            nodes.Iir_Kind.While_Loop_Statement
    ]:
        for n1 in chain_iter(nodes.Get_Sequential_Statement_Chain(n)):
            yield n1
            for n2 in sequential_iter(n1):
                yield n2
    elif k in (
            nodes.Iir_Kind.Assertion_Statement,
            nodes.Iir_Kind.Wait_Statement,
            nodes.Iir_Kind.Null_Statement,
            nodes.Iir_Kind.Exit_Statement,
            nodes.Iir_Kind.Next_Statement,
            nodes.Iir_Kind.Return_Statement,
            nodes.Iir_Kind.Variable_Assignment_Statement,
            nodes.Iir_Kind.Simple_Signal_Assignment_Statement,
            nodes.Iir_Kind.Procedure_Call_Statement,
    ):
        return
    else:
        raise Exception("Unknown node of kind {}".format(kind_image(k)))