Ejemplo n.º 1
0
    def Architecture(cls, arch: Architecture, ctx: SerializerCtx):
        cls.Entity_prepare(arch.entity, ctx, serialize=False)
        variables = []
        procs = []
        extraTypes = set()
        extraTypes_serialized = []
        arch.variables.sort(key=lambda x: (x.name, x._instId))
        arch.processes.sort(key=lambda x: (x.name, maxStmId(x)))
        arch.componentInstances.sort(key=lambda x: x._name)

        ports = list(
            map(lambda p: (p.name, cls.HdlType(p._dtype, ctx)),
                arch.entity.ports))

        for v in arch.variables:
            t = v._dtype
            # if type requires extra definition
            if isinstance(t, HEnum) and t not in extraTypes:
                extraTypes.add(v._dtype)
                extraTypes_serialized.append(
                    cls.HdlType(t, ctx, declaration=True))

            v.name = ctx.scope.checkedName(v.name, v)
            variables.append(v)

        childCtx = copy(ctx)
        childCtx.constCache = ConstCache(ctx.scope.checkedName)

        def serializeVar(v):
            dv = evalParam(v.defVal)
            if isinstance(dv, HEnumVal):
                dv = "%s.%s" % (dv._dtype.name, dv.val)
            else:
                dv = cls.Value(dv, ctx)

            return v.name, cls.HdlType(v._dtype, childCtx), dv

        for p in arch.processes:
            procs.append(cls.HWProcess(p, childCtx))

        constants = []
        for c in sorted(childCtx.constCache._cache.items(), key=lambda x: x[1],
                        reverse=True):
            constants.append((c[1], cls.Value(c[0], ctx)))

        return unitTmpl.render(
            name=arch.getEntityName(),
            constants=constants,
            ports=ports,
            signals=list(map(serializeVar, variables)),
            extraTypes=extraTypes_serialized,
            processes=procs,
            processObjects=arch.processes,
            processesNames=map(lambda p: p.name, arch.processes),
            componentInstances=arch.componentInstances,
            isOp=lambda x: isinstance(x, Operator),
            sensitivityByOp=sensitivityByOp,
            serialize_io=cls.sensitivityListItem,
        )
Ejemplo n.º 2
0
    def Architecture(cls, arch: Architecture, ctx: HwtSerializerCtx):
        variables = []
        procs = []
        extraTypes = set()
        extraTypes_serialized = []
        arch.variables.sort(key=lambda x: (x.name, x._instId))
        arch.processes.sort(key=lambda x: (x.name, maxStmId(x)))
        arch.componentInstances.sort(key=lambda x: x._name)

        for v in arch.variables:
            t = v._dtype
            # if type requires extra definition
            if isinstance(t, HEnum) and t not in extraTypes:
                extraTypes.add(v._dtype)
                extraTypes_serialized.append(
                    cls.HdlType(t, ctx, declaration=True))

            v.name = ctx.scope.checkedName(v.name, v)
            variables.append(v)

        childCtx = ctx.withIndent(2)
        childCtx.constCache = ConstCache(ctx.scope.checkedName)

        def serializeVar(v):
            dv = v.def_val
            if isinstance(dv, HEnumVal):
                dv = "%s.%s" % (dv._dtype.name, dv.val)
            else:
                dv = cls.Value(dv, childCtx)

            return v.name, cls.HdlType(v._dtype, childCtx), dv

        for p in arch.processes:
            procs.append(cls.HWProcess(p, childCtx))

        constants = []
        const_cache = childCtx.constCache
        childCtx.constCache = None
        for cVal, cName in sorted(const_cache._cache.items(),
                                  key=lambda x: x[1],
                                  reverse=True):
            constants.append((cName, cls.Value(cVal, childCtx)))

        portNames = [p.name for p in arch.entity.ports]
        portToLocalsRow = "%s = %s" % (
            ", ".join(portNames),
            ", ".join(["self." + n for n in portNames]))

        return unitBodyTmpl.render(
            DIRECTION_IN=DIRECTION.IN,
            name=arch.getEntityName(),
            portToLocalsRow=portToLocalsRow,
            constants=constants,
            signals=[serializeVar(v) for v in variables],
            extraTypes=extraTypes_serialized,
            processes=procs,
            componentInstances=arch.componentInstances,
        )
Ejemplo n.º 3
0
    def Architecture(cls, arch: Architecture, ctx):
        with CurrentUnitSwap(ctx, arch.entity.origin):
            variables = []
            procs = []
            extraTypes = set()
            extraTypes_serialized = []
            arch.variables.sort(key=lambda x: (x.name, x._instId))
            arch.processes.sort(key=lambda x: (x.name, maxStmId(x)))
            arch.components.sort(key=lambda x: x.name)
            arch.componentInstances.sort(key=lambda x: x._name)

            childCtx = ctx.withIndent()

            for v in arch.variables:
                t = v._dtype
                # if type requires extra definition
                if isinstance(t, (HEnum, HArray)) and t not in extraTypes:
                    extraTypes.add(v._dtype)
                    extraTypes_serialized.append(
                        cls.HdlType(t, childCtx, declaration=True))

                v.name = ctx.scope.checkedName(v.name, v)
                serializedVar = cls.SignalItem(v, childCtx, declaration=True)
                variables.append(serializedVar)

            for p in arch.processes:
                procs.append(cls.HWProcess(p, childCtx))

            # architecture names can be same for different entities
            # arch.name = scope.checkedName(arch.name, arch, isGlobal=True)

            uniqComponents = list(
                map(lambda x: x[1][0],
                    groupedby(arch.components, lambda c: c.name)))
            uniqComponents.sort(key=lambda c: c.name)
            components = list(
                map(lambda c: cls.Component(c, childCtx), uniqComponents))

            componentInstances = list(
                map(lambda c: cls.ComponentInstance(c, childCtx),
                    arch.componentInstances))

            return cls.architectureTmpl.render(
                indent=getIndent(ctx.indent),
                entityName=arch.getEntityName(),
                name=arch.name,
                variables=variables,
                extraTypes=extraTypes_serialized,
                processes=procs,
                components=components,
                componentInstances=componentInstances)
Ejemplo n.º 4
0
    def Architecture(cls, arch: Architecture, ctx):
        serializerVars = []
        procs = []
        extraTypes = set()
        extraTypes_serialized = []
        arch.variables.sort(key=lambda x: (x.name, x._instId))
        arch.componentInstances.sort(key=lambda x: x._name)

        childCtx = ctx.withIndent()
        extraProcesses = []
        for v in arch.variables:
            _eProc = cls.Architecture_var(v,
                                          serializerVars,
                                          extraTypes,
                                          extraTypes_serialized,
                                          ctx,
                                          childCtx)

            extraProcesses.extend(_eProc)

        arch.processes.extend(extraProcesses)
        arch.processes.sort(key=lambda x: (x.name, maxStmId(x)))
        for p in arch.processes:
            p_str = cls.HWProcess(p, childCtx)
            procs.append(p_str)

        # architecture names can be same for different entities
        # arch.name = scope.checkedName(arch.name, arch, isGlobal=True)
        componentInstances = list(
            map(lambda c: cls.ComponentInstance(c, childCtx),
                arch.componentInstances))

        return cls.moduleBodyTmpl.render(
            indent=getIndent(ctx.indent),
            entityName=arch.getEntityName(),
            name=arch.name,
            variables=serializerVars,
            extraTypes=extraTypes_serialized,
            processes=procs,
            componentInstances=componentInstances
        )