コード例 #1
0
    def IfContainer(cls, ifc: IfContainer, ctx: SerializerCtx):
        cond = cls.condAsHdl(ifc.cond, ctx)
        ifTrue = ifc.ifTrue

        if ifc.elIfs:
            # replace elifs with nested if statements
            ifFalse = []
            topIf = IfContainer(ifc.cond, ifc.ifTrue, ifFalse)
            topIf._inputs = ifc._inputs
            topIf._outputs = ifc._outputs
            topIf._sensitivity = ifc._sensitivity

            for c, stms in ifc.elIfs:
                _ifFalse = []

                lastIf = IfContainer(c, stms, _ifFalse)
                lastIf._inputs = ifc._inputs
                lastIf._outputs = ifc._outputs
                lastIf._sensitivity = ifc._sensitivity

                ifFalse.append(lastIf)
                ifFalse = _ifFalse

            if ifc.ifFalse is None:
                lastIf.ifFalse = []
            else:
                lastIf.ifFalse = ifc.ifFalse

            return cls.IfContainer(topIf, ctx)
        else:
            ifFalse = ifc.ifFalse
            if ifFalse is None:
                ifFalse = []

            childCtx = ctx.withIndent()
            outputInvalidateStms = []
            for o in ifc._outputs:
                # [TODO] look up indexes
                indexes = None
                oa = Assignment(o._dtype.from_py(None),
                                o,
                                indexes,
                                virtual_only=True,
                                parentStm=ifc,
                                is_completly_event_dependent=ifc.
                                _is_completly_event_dependent)
                outputInvalidateStms.append(cls.stmAsHdl(oa, childCtx))

            return ifTmpl.render(
                indent=getIndent(ctx.indent),
                indentNum=ctx.indent,
                cond=cond,
                outputInvalidateStms=outputInvalidateStms,
                ifTrue=tuple(
                    map(lambda obj: cls.stmAsHdl(obj, childCtx), ifTrue)),
                ifFalse=tuple(
                    map(lambda obj: cls.stmAsHdl(obj, childCtx), ifFalse)))
コード例 #2
0
    def HWProcess(cls, proc: HWProcess, ctx: SerializerCtx):
        body = proc.statements
        assert body
        proc.name = ctx.scope.checkedName(proc.name, proc)
        sensitivityList = sorted(
            map(cls.sensitivityListItem, proc.sensitivityList))

        childCtx = ctx.withIndent(2)
        _body = "\n".join([cls.stmAsHdl(stm, childCtx) for stm in body])

        return processTmpl.render(hasConditions=arr_any(
            body, lambda stm: not isinstance(stm, Assignment)),
                                  name=proc.name,
                                  sensitivityList=sensitivityList,
                                  stmLines=[_body])
コード例 #3
0
ファイル: serializer.py プロジェクト: Ben-401/hwt
    def IfContainer(cls, ifc: IfContainer, ctx: SerializerCtx):
        """
        Srialize IfContainer instance
        """
        childCtx = ctx.withIndent()

        def asHdl(statements):
            return [cls.asHdl(s, childCtx) for s in statements]

        try:
            cond = cls.condAsHdl(ifc.cond, True, ctx)
        except UnsupportedEventOpErr as e:
            cond = None

        if cond is None:
            assert not ifc.elIfs
            assert not ifc.ifFalse
            stmBuff = [cls.asHdl(s, ctx) for s in ifc.ifTrue]
            return "\n".join(stmBuff)

        elIfs = []
        ifTrue = ifc.ifTrue
        ifFalse = ifc.ifFalse
        if ifFalse is None:
            ifFalse = []

        for c, statements in ifc.elIfs:
            try:
                elIfs.append((cls.condAsHdl(c, True, ctx), asHdl(statements)))
            except UnsupportedEventOpErr as e:
                if len(ifc.elIfs) == 1 and not ifFalse:
                    # register expression is in valid format and this
                    # is just register with asynchronous reset or etc...
                    ifFalse = statements
                else:
                    raise e

        return cls.ifTmpl.render(indent=getIndent(ctx.indent),
                                 cond=cond,
                                 ifTrue=asHdl(ifTrue),
                                 elIfs=elIfs,
                                 ifFalse=asHdl(ifFalse))
コード例 #4
0
ファイル: serializer.py プロジェクト: Ben-401/hwt
    def SwitchContainer(cls, sw: SwitchContainer, ctx: SerializerCtx):
        childCtx = ctx.withIndent(1)

        def asHdl(statements):
            return [cls.asHdl(s, childCtx) for s in statements]

        switchOn = cls.condAsHdl(sw.switchOn, False, ctx)

        cases = []
        for key, statements in sw.cases:
            key = cls.asHdl(key, ctx)

            cases.append((key, asHdl(statements)))

        if sw.default:
            cases.append((None, asHdl(sw.default)))

        return cls.switchTmpl.render(indent=getIndent(ctx.indent),
                                     switchOn=switchOn,
                                     cases=cases)