Esempio n. 1
0
 def as_hdl_SignalItem(self, si: SignalItem, declaration=False):
     if declaration:
         sigType = systemCTypeOfSig(si)
         with SignalTypeSwap(self, sigType):
             return ToHdlAst_Value.as_hdl_SignalItem(self, si, declaration=True)
     else:
         if si.hidden and si.origin is not None:
             return self.as_hdl(si.origin)
         else:
             sigType = systemCTypeOfSig(si)
             _si = HdlValueId(si.name, obj=si)
             if self._in_sensitivity_list or self._is_target or sigType is SIGNAL_TYPE.REG:
                 return _si
             else:
                 return hdl_call(hdl_getattr(_si, "read"), [])
Esempio n. 2
0
    def Assignment(cls, a, ctx):
        dst = a.dst
        assert isinstance(dst, SignalItem)
        assert not dst.virtualOnly, "should not be required"

        typeOfDst = systemCTypeOfSig(dst)
        if a.indexes is not None:
            for i in a.indexes:
                dst = dst[i]

        if dst._dtype == a.src._dtype:
            return cls._Assignment(dst, typeOfDst, a.src, ctx)
        else:
            raise SerializerException(
                "%r <= %r  is not valid assignment\n"
                " because types are different (%r; %r) " %
                (dst, a.src, dst._dtype, a.src._dtype))
Esempio n. 3
0
    def as_hdl_Assignment(self, a: Assignment):
        dst = a.dst
        assert isinstance(dst, SignalItem)
        # assert not dst.virtual_only, "should not be required"

        if a.indexes is not None:
            for i in a.indexes:
                dst = dst[i]

        typeOfDst = systemCTypeOfSig(dst)
        if dst.virtual_only and isinstance(a.src, Operator):
            assert a.src.operator == AllOps.CONCAT
            return self._as_hdl_Assignment(dst, typeOfDst, a.src.operands)

        if dst._dtype == a.src._dtype or (isinstance(dst._dtype, Bits)
                                          and a.src._dtype == BOOL):
            return self._as_hdl_Assignment(dst, typeOfDst, a.src)
        else:
            raise SerializerException(
                "%r <= %r  is not valid assignment\n"
                " because types are different (%r; %r) " %
                (dst, a.src, dst._dtype, a.src._dtype))
Esempio n. 4
0
    def SignalItem(cls, si, ctx, declaration=False):
        sigType = systemCTypeOfSig(si)
        if declaration:
            if sigType is SIGNAL_TYPE.REG:
                fmt = "%s%s %s"
            else:
                fmt = "%ssc_signal<%s> %s"

            ctx = ctx.forSignal(si)

            v = si.def_val
            if si.virtual_only:
                raise NotImplementedError()
            elif si.drivers:
                pass
            elif si.endpoints or si.simSensProcs:
                if not v.vld_mask:
                    raise SerializerException(
                        "Signal %s is constant and has undefined value" %
                        si.name)
            else:
                raise SerializerException(
                    "Signal %s should be declared but it is not used" %
                    si.name)

            t = si._dtype
            dimensions = []
            while isinstance(t, HArray):
                # collect array dimensions
                dimensions.append(t.size)
                t = t.element_t

            s = fmt % (getIndent(ctx.indent), cls.HdlType(t, ctx), si.name)
            if dimensions:
                # to make a space between name and dimensoins
                dimensions = [
                    "[%s]" % cls.asHdl(toHVal(x), ctx) for x in dimensions
                ]
                dimensions.append("")
                s += " ".join(reversed(dimensions))

            if isinstance(v, RtlSignalBase):
                if v._const:
                    return s + " = %s" % cls.asHdl(v, ctx)
                else:
                    # default value has to be set by reset
                    # because it is only signal
                    return s
            elif isinstance(v, Value):
                if si.def_val.vld_mask:
                    return s + " = %s" % cls.Value(v, ctx)
                else:
                    return s
            else:
                raise NotImplementedError(v)

        else:
            if si.hidden and hasattr(si, "origin"):
                return cls.asHdl(si.origin, ctx)
            else:
                if ctx.isTarget or sigType is SIGNAL_TYPE.REG:
                    return si.name
                else:
                    return "%s.read()" % si.name