Exemplo n.º 1
0
def slice_to_SLICE(sliceVals, width):
    """convert python slice to value of SLICE hdl type"""
    if sliceVals.step is not None:
        raise NotImplementedError()

    start = sliceVals.start
    stop = sliceVals.stop

    if sliceVals.start is None:
        start = INT.fromPy(width)
    else:
        start = toHVal(sliceVals.start)

    if sliceVals.stop is None:
        stop = INT.fromPy(0)
    else:
        stop = toHVal(sliceVals.stop)

    startIsVal = isinstance(start, Value)
    stopIsVal = isinstance(stop, Value)

    indexesAreValues = startIsVal and stopIsVal
    if indexesAreValues:
        updateTime = max(start.updateTime, stop.updateTime)
    else:
        updateTime = -1

    return Slice.getValueCls()((start, stop), SLICE, 1, updateTime)
Exemplo n.º 2
0
 def test_int_neg(self):
     self.assertEqual(int(INT.fromPy(-10)), -10)
     self.assertEqual(int(-INT.fromPy(10)), -10)
     self.assertEqual(int(-INT.fromPy(10)), -10)
     v = -INT.fromPy(None)
     self.assertEqual(v.val, 0)
     self.assertEqual(v.vldMask, 0)
Exemplo n.º 3
0
 def test_int_neg(self):
     self.assertEqual(int(INT.fromPy(-10)), -10)
     self.assertEqual(int(-INT.fromPy(10)), -10)
     self.assertEqual(int(-INT.fromPy(10)), -10)
     v = -INT.fromPy(None)
     self.assertEqual(v.val, 0)
     self.assertEqual(v.vldMask, 0)
Exemplo n.º 4
0
    def test_int_to_bool(self):
        self.assertFalse(bool(INT.fromPy(0)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(1)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(-11)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(500)._auto_cast(BOOL)))

        with self.assertRaises(ValueError):
            bool(INT.fromPy(None)._auto_cast(BOOL))
Exemplo n.º 5
0
    def test_int_to_bool(self):
        self.assertFalse(bool(INT.fromPy(0)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(1)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(-11)._auto_cast(BOOL)))
        self.assertTrue(bool(INT.fromPy(500)._auto_cast(BOOL)))

        with self.assertRaises(ValueError):
            bool(INT.fromPy(None)._auto_cast(BOOL))
Exemplo n.º 6
0
    def __setitem__(self, index, value):
        """
        Only syntax sugar for user, not used inside HWT

        * In HW design is not used (__getitem__ returns "reference"
            and it is used)

        * In simulator is used _setitem__val directly
        """
        if isinstance(index, int):
            index = INT.fromPy(index)
        else:
            assert isinstance(self, Value)
            assert index._dtype == INT, index._dtype

        if not isinstance(value, Value):
            value = self._dtype.elmType.fromPy(value)
        else:
            assert value._dtype == self._dtype.elmType, (value._dtype,
                                                         self._dtype.elmType)

        return self._setitem__val(index, value)
Exemplo n.º 7
0
def hInt(pyVal):
    """ create hdl integer value (for example integer value in vhdl)"""
    return INT.fromPy(pyVal)