Example #1
0
 def visit_Slice(self, node):
     val = self.visit(node.var)
     if val is None:
         return None
     if isinstance(val.right, vtypes._Variable):
         right = vtypes.Slice(val.right, node.msb, node.lsb)
     else:
         right = vtypes.And(vtypes.Srl(val.right, node.lsb),
                            vtypes.Repeat(vtypes.Int(1, width=1), node.msb - node.lsb + 1))
     return vtypes.Subst(vtypes.Slice(val.left, node.msb, node.lsb), right)
Example #2
0
def shift_right(value, size, signed=True):
    if isinstance(value, vtypes.Int):
        value = value.value

    if isinstance(value, int) and isinstance(size, int):
        return value >> size

    if isinstance(value, bool) and isinstance(size, int):
        return value >> size

    return vtypes.Mux(signed, vtypes.Sra(value, size), vtypes.Srl(value, size))
Example #3
0
 def __init__(self, left, right):
     lpoint = left.point if isinstance(left, _FixedBase) else 0
     rpoint = right.point if isinstance(right, _FixedBase) else 0
     lsigned = vtypes.get_signed(left)
     rsigned = vtypes.get_signed(right)
     point = _min_mux(_max_mux(lpoint, rpoint), lpoint + rpoint)
     signed = lsigned and rsigned if not self.overwrite_signed else False
     ldata = to_signed(left) if signed else left
     rdata = to_signed(right) if signed else right
     shift_size = lpoint + rpoint - point
     data = vtypes.Times(ldata, rdata)
     if signed:
         data = vtypes.Sra(data, shift_size)
     else:
         data = vtypes.Srl(data, shift_size)
     _FixedSkipUnaryOperator.__init__(self, data, point, signed)
Example #4
0
 def visit_Pointer(self, node):
     val = self.visit(node.var)
     if val is None:
         return None
     left = vtypes.Pointer(val.left, node.pos)
     if not isinstance(val.right, (vtypes._Variable, vtypes.Scope)):
         if isinstance(val.right, (int, bool)):
             val_right = vtypes.Int(val.right)
         elif isinstance(val.right, float):
             val_right = vtypes.Float(val.right)
         else:
             raise TypeError("unsupported value type: %s" % str(val.right))
         right = vtypes.And(vtypes.Srl(
             val_right, node.pos), vtypes.Int(1, width=1))
     else:
         right = vtypes.Pointer(val.right, node.pos)
     return vtypes.Subst(left, right)
Example #5
0
def shift_right(value, size, signed=True):
    if isinstance(value, vtypes.Int):
        value = value.value

    if isinstance(value, vtypes.Float):
        value = value.value

    if isinstance(value, int) and isinstance(size, int):
        return value >> size

    if isinstance(value, bool) and isinstance(size, int):
        return value >> size

    if isinstance(value, float) and isinstance(size, int):
        return value / (2 ** size)

    if signed:
        return vtypes.Sra(value, size)

    return vtypes.Srl(value, size)
Example #6
0
 def visit_Srl(self, node):
     left = self.visit(node.left)
     right = self.visit(node.right)
     return vtypes.Srl(left, right)