예제 #1
0
파일: base.py 프로젝트: mfkiwl/hwtLib
 def isCrossingWordBoundary(self, addr, rem):
     offset_t = Bits(self.getSizeAlignBits() + 1, signed=False)
     word_B = offset_t.from_py(self.DATA_WIDTH // 8)
     bytesInLastWord = rem._eq(0)._ternary(word_B, fitTo_t(rem, offset_t))
     bytesAvaliableInLastWord = (
         word_B - fitTo_t(addr[self.getSizeAlignBits():], offset_t))
     crossesWordBoundary = rename_signal(
         self, bytesInLastWord > bytesAvaliableInLastWord,
         "crossesWordBoundary")
     return crossesWordBoundary
예제 #2
0
파일: bitsCast.py 프로젝트: klopstock/hwt
def reinterpretBits__val(self: Bits, val, toType: HdlType):
    if isinstance(toType, Bits):
        if self.signed != toType.signed:
            val = val._convSign__val(toType.signed)
        return fitTo_t(val, toType)
    elif isinstance(toType, HStruct):
        return reinterpret_bits_to_hstruct(val, toType)
    elif isinstance(toType, HUnion):
        raise NotImplementedError()
    elif isinstance(toType, HArray):
        return reinterpret_bits_to_harray(val, toType)

    return default_auto_cast_fn(self, val, toType)
예제 #3
0
파일: bitsCast.py 프로젝트: Ben-401/hwt
def reinterpretBits(self, sigOrVal, toType):
    """
    Cast object of same bit size between to other type
    (f.e. bits to struct, union or array)
    """
    if isinstance(sigOrVal, Value):
        return reinterpretBits__val(self, sigOrVal, toType)
    elif isinstance(toType, Bits):
        return fitTo_t(sigOrVal, toType)
    elif sigOrVal._dtype.bit_length() == toType.bit_length():
        if isinstance(toType, HStruct):
            raise reinterpret_bits_to_hstruct(sigOrVal, toType)
        elif isinstance(toType, HUnion):
            raise NotImplementedError()
        elif isinstance(toType, HArray):
            reinterpret_bits_to_harray(sigOrVal, toType)

    return default_auto_cast_fn(self, sigOrVal, toType)
예제 #4
0
파일: ops.py 프로젝트: pradeepchawda/hwt
    def __call__(self,
                 source,
                 dst_resolve_fn=lambda x: x.
                 _getDestinationSignalForAssignmentToThis(),
                 exclude=None,
                 fit=False) -> Assignment:
        """
        Create assignment to this signal

        :attention: it is not call of function it is operator of assignment
        :return: list of assignments
        """
        assert not self._const, self
        if exclude is not None and (self in exclude or source in exclude):
            return []

        if self.hidden:
            try:
                d = self.singleDriver()
            except:
                d = None
            operator = getattr(d, "operator", None)
            if operator is not None:
                assert operator.allowsAssignTo, (
                    "Assignment to", self,
                    "is not allowed by operator definition")

        if isinstance(source, InterfaceBase):
            assert source._isAccessible, (
                source,
                "must be a Signal Interface which is accessible in current scope"
            )
            source = source._sig

        try:
            if source is None:
                requires_type_check = False
                source = self._dtype.from_py(None)
            else:
                requires_type_check = True
                source = toHVal(source, suggestedType=self._dtype)
        except Exception as e:
            # simplification of previous exception traceback
            e_simplified = copy(e)
            raise e_simplified

        if requires_type_check:
            err = False
            try:
                if fit:
                    source = fitTo_t(source, self._dtype)
                source = source._auto_cast(self._dtype)
            except TypeConversionErr:
                err = True
            if err:
                raise TypeConversionErr(
                    ("Can not connect %r (of type %r) to %r "
                     "(of type %r) due type incompatibility") %
                    (source, source._dtype, self, self._dtype))
        try:
            mainSig, indexCascade = self._getIndexCascade()
            mainSig = dst_resolve_fn(mainSig)
            return Assignment(source, mainSig, indexCascade)
        except Exception as e:
            # simplification of previous exception traceback
            e_simplified = copy(e)
            raise e_simplified