code stringlengths 17 6.64M |
|---|
class Error(Exception):
'Base class for all exceptions thrown by Alive.\n '
pass
|
class Type(object):
__slots__ = ()
def __ne__(self, other):
return (not (self == other))
|
class Comparable(object):
def __eq__(self, other):
return self._cmp(operator.eq, other)
def __ge__(self, other):
return self._cmp(operator.ge, other)
def __gt__(self, other):
return self._cmp(operator.gt, other)
def __le__(self, other):
return self._cmp(operator.le, other)
def __lt__(self, other):
return self._cmp(operator.lt, other)
def __ne__(self, other):
return self._cmp(operator.ne, other)
|
class IntType(Type, Comparable):
__slots__ = ('width',)
def __init__(self, width):
self.width = width
def __repr__(self):
return 'IntType({0!r})'.format(self.width)
def __str__(self):
return ('i' + str(self.width))
def __hash__(self):
return (hash(type(self)) ^ hash(self.width))
def _cmp(self, op, other):
if isinstance(other, int):
return op(self.width, other)
if isinstance(other, IntType):
return op(self.width, other.width)
return NotImplemented
|
class PtrType(Type):
__slots__ = ()
def __eq__(self, other):
return (type(self) is type(other))
def __ne__(self, other):
return (not (self == other))
def __hash__(self):
return (hash(PtrType) * 2)
def __repr__(self):
return 'PtrType()'
|
class FloatType(Type, Comparable):
__slots__ = ()
def __repr__(self):
return (type(self).__name__ + '()')
def __hash__(self):
return (hash(type(self)) * 2)
def _cmp(self, op, other):
if isinstance(other, int):
return op(self.frac, other)
if isinstance(other, FloatType):
return op(self.frac, other.frac)
return NotImplemented
|
class HalfType(FloatType):
__slots__ = ()
exp = 5
frac = 11
def __str__(self):
return 'half'
|
class SingleType(FloatType):
__slots__ = ()
exp = 8
frac = 24
def __str__(self):
return 'float'
|
class DoubleType(FloatType):
__slots__ = ()
exp = 11
frac = 53
def __str__(self):
return 'double'
|
class FP128Type(FloatType):
__slots__ = ()
exp = 15
frac = 113
def __str__(self):
return 'fp128'
|
class X86FP80Type(FloatType):
__slots__ = ()
exp = 15
frac = 64
def __str__(self):
return 'x86_fp80'
|
class MetaNode(type):
'Automatically generate a superclass table for Node classes'
def __new__(cls, name, bases, dict):
if ('__slots__' not in dict):
dict['__slots__'] = ()
return super(MetaNode, cls).__new__(cls, name, bases, dict)
def __init__(cls, name, bases, dict):
if hasattr(cls, 'code'):
assert (cls.code not in cls.codes)
cls.codes[cls.code] = cls
if ('__slots__' in dict):
cls._allslots = (getattr(cls, '_allslots', ()) + tuple(dict['__slots__']))
return super(MetaNode, cls).__init__(name, bases, dict)
|
class Node(pretty.PrettyRepr):
__metaclass__ = MetaNode
def pretty(self):
args = (getattr(self, s) for s in self._allslots)
return pretty.pfun(type(self).__name__, args)
def args(self):
return tuple((getattr(self, s) for s in self._allslots))
def copy(self, **kws):
args = tuple(((kws[s] if (s in kws) else getattr(self, s)) for s in self._allslots))
return type(self)(*args)
def type_constraints(self, tcs):
raise NotImplementedError((type(self).__name__ + ' should override type_constraints'))
|
class Value(Node):
pass
|
class Input(Value):
__slots__ = ('name',)
def __init__(self, name):
self.name = name
def args(self):
return ()
def type_constraints(self, tcs):
tcs.first_class(self)
|
class Instruction(Value):
pass
|
class BinaryOperator(Instruction):
__slots__ = ('x', 'y', 'ty', 'flags', 'name')
codes = {}
def __init__(self, x, y, ty=None, flags=(), name=''):
self.ty = ty
self.x = x
self.y = y
self.flags = tuple(flags)
self.name = name
def args(self):
return (self.x, self.y)
|
class IntBinaryOperator(BinaryOperator):
def type_constraints(self, tcs):
tcs.integer(self)
tcs.specific(self, self.ty)
tcs.eq_types(self, self.x, self.y)
|
class WrappingBinaryOperator(IntBinaryOperator):
pass
|
class InexactBinaryOperator(IntBinaryOperator):
pass
|
class AddInst(WrappingBinaryOperator):
code = 'add'
|
class SubInst(WrappingBinaryOperator):
code = 'sub'
|
class MulInst(WrappingBinaryOperator):
code = 'mul'
|
class SDivInst(InexactBinaryOperator):
code = 'sdiv'
|
class UDivInst(InexactBinaryOperator):
code = 'udiv'
|
class SRemInst(IntBinaryOperator):
code = 'srem'
|
class URemInst(IntBinaryOperator):
code = 'urem'
|
class ShlInst(WrappingBinaryOperator):
code = 'shl'
|
class AShrInst(InexactBinaryOperator):
code = 'ashr'
|
class LShrInst(InexactBinaryOperator):
code = 'lshr'
|
class AndInst(IntBinaryOperator):
code = 'and'
|
class OrInst(IntBinaryOperator):
code = 'or'
|
class XorInst(IntBinaryOperator):
code = 'xor'
|
class FastMathInst(Instruction):
pass
|
class FloatBinaryOperator(BinaryOperator, FastMathInst):
def type_constraints(self, tcs):
tcs.float(self)
tcs.specific(self, self.ty)
tcs.eq_types(self, self.x, self.y)
|
class FAddInst(FloatBinaryOperator):
code = 'fadd'
|
class FSubInst(FloatBinaryOperator):
code = 'fsub'
|
class FMulInst(FloatBinaryOperator):
code = 'fmul'
|
class FDivInst(FloatBinaryOperator):
code = 'fdiv'
|
class FRemInst(FloatBinaryOperator):
code = 'frem'
|
class ConversionInst(Instruction):
__slots__ = ('arg', 'src_ty', 'ty', 'name')
codes = {}
def __init__(self, arg, src_ty=None, dest_ty=None, name=''):
self.src_ty = src_ty
self.arg = arg
self.ty = dest_ty
self.name = name
def args(self):
return (self.arg,)
|
class BitcastInst(ConversionInst):
code = 'bitcast'
def type_constraints(self, tcs):
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_equal(self.arg, self)
|
class InttoptrInst(ConversionInst):
code = 'inttoptr'
def type_constraints(self, tcs):
tcs.integer(self.arg)
tcs.pointer(self)
tcs.specific(self.arg, self.src_ty)
tcs.specific(self, self.ty)
|
class PtrtointInst(ConversionInst):
code = 'ptrtoint'
def type_constraints(self, tcs):
tcs.pointer(self.arg)
tcs.integer(self)
tcs.specific(self.arg, self.src_ty)
tcs.specific(self, self.ty)
|
class SExtInst(ConversionInst):
code = 'sext'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_order(self.arg, self)
|
class ZExtInst(ConversionInst):
code = 'zext'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_order(self.arg, self)
|
class TruncInst(ConversionInst):
code = 'trunc'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_order(self, self.arg)
|
class ZExtOrTruncInst(ConversionInst):
code = 'ZExtOrTrunc'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
|
class FPtoSIInst(ConversionInst):
code = 'fptosi'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.float(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
|
class FPtoUIInst(ConversionInst):
code = 'fptoui'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.float(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
|
class SItoFPInst(ConversionInst):
code = 'sitofp'
def type_constraints(self, tcs):
tcs.float(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
|
class UItoFPInst(ConversionInst):
code = 'uitofp'
def type_constraints(self, tcs):
tcs.float(self)
tcs.integer(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
|
class FPTruncInst(ConversionInst):
code = 'fptrunc'
def type_constraints(self, tcs):
tcs.float(self)
tcs.float(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_order(self, self.arg)
|
class FPExtInst(ConversionInst):
code = 'fpext'
def type_constraints(self, tcs):
tcs.float(self)
tcs.float(self.arg)
tcs.specific(self, self.ty)
tcs.specific(self.arg, self.src_ty)
tcs.width_order(self.arg, self)
|
class IcmpInst(Instruction):
__slots__ = ('pred', 'x', 'y', 'ty', 'name')
def __init__(self, pred, arg1, arg2, ty=None, name=''):
self.pred = pred
self.ty = ty
self.x = arg1
self.y = arg2
self.name = name
def args(self):
return (self.x, self.y)
def type_constraints(self, tcs):
tcs.bool(self)
tcs.int_ptr_vec(self.x)
tcs.specific(self.x, self.ty)
tcs.eq_types(self.x, self.y)
|
class FcmpInst(FastMathInst):
__slots__ = ('pred', 'x', 'y', 'ty', 'flags', 'name')
def __init__(self, pred, arg1, arg2, ty=None, flags=(), name=''):
self.pred = pred
self.ty = ty
self.flags = flags
self.x = arg1
self.y = arg2
self.name = name
def args(self):
return (self.x, self.y)
def type_constraints(self, tcs):
tcs.bool(self)
tcs.float(self.x)
tcs.specific(self.x, self.ty)
tcs.eq_types(self.x, self.y)
|
class SelectInst(Instruction):
__slots__ = ('sel', 'arg1', 'arg2', 'ty1', 'ty2', 'name')
def __init__(self, sel, arg1, arg2, ty1=None, ty2=None, name=''):
self.sel = sel
self.ty1 = ty1
self.arg1 = arg1
self.ty2 = ty2
self.arg2 = arg2
self.name = name
def args(self):
return (self.sel, self.arg1, self.arg2)
def type_constraints(self, tcs):
tcs.bool(self.sel)
tcs.first_class(self)
tcs.specific(self.arg1, self.ty1)
tcs.specific(self.arg2, self.ty2)
tcs.eq_types(self, self.arg1, self.arg2)
|
class FreezeInst(Instruction):
__slots__ = ('x', 'ty', 'name')
def __init__(self, x, ty=None, name=''):
self.x = x
self.ty = ty
self.name = name
def args(self):
return (self.x,)
def type_constraints(self, tcs):
tcs.first_class(self)
tcs.eq_types(self, self.x)
|
class Constant(Value):
pass
|
class Symbol(Input, Constant):
'Symbolic constants.\n '
def type_constraints(self, tcs):
tcs.number(self)
|
class Literal(Constant):
__slots__ = ('val',)
def __init__(self, val):
self.val = val
def args(self):
return ()
def type_constraints(self, tcs):
tcs.number(self)
x = self.val
bl = (x.bit_length() if (x >= 0) else (((- x) - 1).bit_length() + 1))
if (bl > 0):
tcs.width_order((bl - 1), self)
|
class FLiteral(Constant):
def type_constraints(self, tcs):
tcs.float(self)
|
class FLiteralNaN(FLiteral):
val = 'nan'
|
class FLiteralPlusInf(FLiteral):
val = 'inf'
|
class FLiteralMinusInf(FLiteral):
val = '-inf'
|
class FLiteralMinusZero(FLiteral):
val = '-0.0'
|
class FLiteralVal(FLiteral):
__slots__ = ('val',)
def __init__(self, val):
self.val = val
def __repr__(self):
return (('FLiteral(' + repr(self.val)) + ')')
def args(self):
return ()
|
class UndefValue(Constant):
__slots__ = ('ty',)
def __init__(self, ty=None):
self.ty = ty
def args(self):
return ()
def type_constraints(self, tcs):
tcs.first_class(self)
tcs.specific(self, self.ty)
|
class PoisonValue(Constant):
def type_constraints(self, tcs):
tcs.first_class(self)
|
class BinaryCnxp(Constant):
__slots__ = ('x', 'y')
codes = {}
def __init__(self, x, y):
self.x = x
self.y = y
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, self.x, self.y)
|
class NumBinaryCnxp(BinaryCnxp):
def type_constraints(self, tcs):
tcs.number(self)
tcs.eq_types(self, self.x, self.y)
|
class AddCnxp(NumBinaryCnxp):
code = '+'
|
class SubCnxp(NumBinaryCnxp):
code = '-'
|
class MulCnxp(NumBinaryCnxp):
code = '*'
|
class SDivCnxp(NumBinaryCnxp):
code = '/'
|
class UDivCnxp(BinaryCnxp):
code = '/u'
|
class SRemCnxp(NumBinaryCnxp):
code = '%'
|
class URemCnxp(BinaryCnxp):
code = '%u'
|
class ShlCnxp(BinaryCnxp):
code = '<<'
|
class AShrCnxp(BinaryCnxp):
code = '>>'
|
class LShrCnxp(BinaryCnxp):
code = 'u>>'
|
class AndCnxp(BinaryCnxp):
code = '&'
|
class OrCnxp(BinaryCnxp):
code = '|'
|
class XorCnxp(BinaryCnxp):
code = '^'
|
class UnaryCnxp(Constant):
__slots__ = ('x',)
codes = {}
def __init__(self, x):
self.x = x
|
class NegCnxp(UnaryCnxp):
code = '-'
def type_constraints(self, tcs):
tcs.number(self)
tcs.eq_types(self, self.x)
|
class NotCnxp(UnaryCnxp):
code = '~'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, self.x)
|
class FunCnxp(Constant):
__slots__ = ('_args',)
codes = {}
@classmethod
def check_args(cls, args):
if (len(args) != len(cls.sig)):
raise BadArgumentCount(len(cls.sig), len(args))
for i in xrange(len(args)):
if (not isinstance(args[i], cls.sig[i])):
raise BadArgumentKind(i, cls.sig[i])
def __init__(self, *args):
self.check_args(args)
self._args = args
def pretty(self):
return pretty.pfun(type(self).__name__, self._args)
def args(self):
return self._args
|
class AbsCnxp(FunCnxp):
sig = (Constant,)
code = 'abs'
def type_constraints(self, tcs):
tcs.number(self)
tcs.eq_types(self, self._args[0])
|
class SignBitsCnxp(FunCnxp):
sig = (Value,)
code = 'ComputeNumSignBits'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self._args[0])
|
class OneBitsCnxp(FunCnxp):
sig = (Value,)
code = 'computeKnownOneBits'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, self._args[0])
|
class ZeroBitsCnxp(FunCnxp):
sig = (Value,)
code = 'computeKnownZeroBits'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, self._args[0])
|
class LeadingZerosCnxp(FunCnxp):
sig = (Constant,)
code = 'countLeadingZeros'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self._args[0])
|
class TrailingZerosCnxp(FunCnxp):
sig = (Constant,)
code = 'countTrailingZeros'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self._args[0])
|
class FPMantissaWidthCnxp(FunCnxp):
sig = (Value,)
code = 'fpMantissaWidth'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.float(self._args[0])
|
class LShrFunCnxp(FunCnxp):
sig = (Constant, Constant)
code = 'lshr'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, *self._args)
|
class Log2Cnxp(FunCnxp):
sig = (Constant,)
code = 'log2'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self._args[0])
|
class SMaxCnxp(FunCnxp):
sig = (Constant, Constant)
code = 'max'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, *self._args)
|
class SMinCnxp(FunCnxp):
sig = (Constant, Constant)
code = 'min'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.eq_types(self, *self._args)
|
class SExtCnxp(FunCnxp):
sig = (Constant,)
code = 'sext'
def type_constraints(self, tcs):
tcs.integer(self)
tcs.integer(self._args[0])
tcs.width_order(self._args[0], self)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.