예제 #1
0
 def _mapToIR(_, __=None):
     # If caller is SInt Type, it would call `mapToIR(ctx)`
     # Or caller is SInt Literal, it would call `mapToIR(literal, ctx)`
     if __ is not None:
         return low_ir.SIntLiteral(_.v, S._lowWidth(width))
     else:
         return low_ir.SIntType(S._lowWidth(width))
예제 #2
0
 def _tf(ref):
     if isinstance(ref.typ, low_ir.UIntType):
         return [ref], low_ir.SIntType(ref.typ.width)
     elif isinstance(ref.typ, low_ir.SIntType):
         return [ref], ref.typ
     else:
         Exception("need uint type")
예제 #3
0
 def _tf(lref, rref):
     if isinstance(lref.typ, low_ir.UIntType) and isinstance(
             rref.typ, low_ir.UIntType):
         return [lref, rref], low_ir.UIntType(low_ir.IntWidth(1))
     elif isinstance(lref.typ, low_ir.SIntType) and isinstance(
             rref.typ, low_ir.SIntType):
         return [lref, rref], low_ir.SIntType(low_ir.IntWidth(1))
     else:
         raise Exception("need uint types or sint types")
예제 #4
0
 def _shrtf(lref, n):
     if isinstance(lref.typ, low_ir.UIntType):
         return [lref], low_ir.UIntType(
             _pickWidth(lref.typ.width, low_ir.IntWidth(n),
                        lambda x, y: x - y))
     elif isinstance(lref.typ, low_ir.SIntType):
         return [lref], low_ir.SIntType(
             _pickWidth(lref.typ.width, low_ir.IntWidth(n),
                        lambda x, y: x - y))
     else:
         raise Exception("need uint type or sint type")
예제 #5
0
 def _dshltf(lref, rref):
     if isinstance(lref.typ, low_ir.UIntType) and isinstance(
             rref.typ, low_ir.UIntType):
         return [lref, rref], low_ir.UIntType(
             _pickWidth(lref.typ.width, rref.typ.width, lambda x, y: x +
                        (1 << y) - 1))
     elif isinstance(lref.typ, low_ir.SIntType) and isinstance(
             rref.typ, low_ir.UIntType):
         return [lref, rref], low_ir.SIntType(
             _pickWidth(lref.typ.width, rref.typ.width, lambda x, y: x +
                        (1 << y) - 1))
     else:
         raise Exception(
             "lhs needs uint type or sint type, rhs needs uint type")