示例#1
0
    async def test(stop: Integer) -> b'stop + stop':
        cnt1 = stop.dtype(0)

        async with stop as s:
            last1 = False
            while not last1:
                cnt2 = stop.dtype(0)
                last2 = False
                while not last2:
                    yield cnt1 + cnt2
                    last2 = cnt2 == s
                    cnt2 += 1

                last1 = cnt1 == s
                cnt1 += 1
示例#2
0
    def visit_ResExpr(self, node):
        if isinstance(node.val, tuple):
            res = []
            for op in reversed(node.val):
                res_op = ir.ResExpr(op)
                if res_op != ir.ResExpr(Unit()) and res_op.dtype != Uint[0]:
                    svexpr = self.visit(res_op)
                    res.append(self.cast_svexpr(svexpr, res_op.dtype,
                                                type(op)))

            if not res:
                return None

            return '{' + ', '.join(res) + '}'

        if getattr(node.val, 'unknown', False):
            return f"{node.dtype.width}'bx"

        val = node.val
        if isinstance(node.val, ir.EmptyType):
            if node.dtype is None:
                return f"'x"
            else:
                return f"{node.dtype.width}'bx"

        elif not isinstance(node.val, Integer):
            val = Integer(code(node.val, int))

        sign = '-' if val < 0 else ''
        return f"{sign}{val.width}'d{abs(int(val))}"
示例#3
0
async def qrange_stop_inclusive(stop: Integer, *, inclusive) -> Queue[b'stop']:
    cnt = stop.dtype(0)
    last: Bool

    async with stop as s:
        last = False
        while not last:
            last = cnt == s
            yield cnt, last
            cnt = code(cnt + 1, stop.dtype)
示例#4
0
    async def test(stop: Integer) -> b'stop':
        cnt = stop.dtype(0)
        last: Bool

        async with stop as s:
            last = False
            while not last:
                last = cnt == s
                yield cnt
                cnt += 1
示例#5
0
    def dtype(self):
        # if is_type(type(self.val)):
        #     return type(self.val)

        if not is_type(type(self.val)) and isinstance(self.val, int):
            return type(Integer(self.val))

        if isinstance(self.val, Intf):
            return IntfType[self.val.dtype]

        return type(self.val)
示例#6
0
    def dtype(self):
        # if is_type(type(self.val)):
        #     return type(self.val)

        if not is_type(type(self.val)) and isinstance(self.val, int):
            return type(Integer(self.val))

        # TODO: Remove this if unecessary
        if isinstance(self.val, Intf):
            return IntfType[self.val.dtype]

        return type(self.val)
示例#7
0
async def qrange_stop(stop: Integer, *, inclusive=False) -> Queue[b'stop']:
    cnt = stop.dtype(0)
    cur_cnt: stop.dtype
    last: Bool

    async with stop as s:
        last = False
        while not last:
            # while (cnt != s):
            cur_cnt = cnt
            cnt += 1

            last = cnt == s
            yield cur_cnt, last
示例#8
0
    def dtype(self):
        if isinstance(self.val, EmptyType):
            if type(self.val).dtype is None:
                return EmptyType
            else:
                return type(self.val).dtype

        # if is_type(type(self.val)):
        #     return type(self.val)

        if not is_type(type(self.val)) and isinstance(self.val, int):
            return type(Integer(self.val))

        # TODO: Remove this if unecessary
        if isinstance(self.val, Intf):
            return IntfType[self.val.dtype]

        return type(self.val)
示例#9
0
def integral_saturate_resolver(t, data: Integral, limits=None):
    if not is_type(type(data)) and isinstance(data, int):
        conv_data = Integer(data)
    else:
        conv_data = data

    idin = code(data)

    if type(conv_data).signed == t.signed and type(conv_data).width <= t.width:
        if type(conv_data).signed:
            sign = code(data, int) >> (type(conv_data).width - 1)
            sign_exten = Uint[t.width -
                              type(conv_data).width].max if sign else 0
            return t.decode((sign_exten << type(conv_data).width)
                            | code(data, int))
        else:
            return code(conv_data, t)
    elif type(conv_data).signed and not t.signed:
        if idin[t.width:] == 0:
            return code(conv_data, t)
        elif conv_data < 0:
            return 0
        else:
            return t.max
    elif type(conv_data).signed and t.signed:
        # TODO: This 0 is not typecast, check why that happens
        if ((idin[t.width - 1:] == 0)
                or (idin[t.width - 1:]
                    == Uint[type(conv_data).width - t.width + 1].max)):
            return code(conv_data, t)
        elif idin[-1]:
            return t.min
        else:
            return t.max
    else:
        if type(conv_data).width <= t.width or idin[t.width:] == 0:
            return code(conv_data, t)
        else:
            return t.max