<s> from pypy . rpython . extregistry import ExtRegistryEntry <EOL> from pypy . rpython . lltypesystem import lltype , llmemory , rffi <EOL> from pypy . rpython . ootypesystem import ootype <EOL> from pypy . rlib . objectmodel import we_are_translated , r_dict , Symbolic <EOL> from pypy . rlib . objectmodel import compute_hash <EOL> from pypy . rlib . rarithmetic import intmask <EOL> from pypy . tool . uid import uid <EOL> from pypy . conftest import option <EOL> from pypy . jit . metainterp . resoperation import ResOperation , rop <EOL> import py <EOL> from pypy . tool . ansi_print import ansi_log <EOL> log = py . log . Producer ( '<STR_LIT>' ) <EOL> py . log . setconsumer ( '<STR_LIT>' , ansi_log ) <EOL> INT = '<STR_LIT:i>' <EOL> REF = '<STR_LIT:r>' <EOL> FLOAT = '<STR_LIT:f>' <EOL> FAILARGS_LIMIT = <NUM_LIT:1000> <EOL> def getkind ( TYPE , supports_floats = True ) : <EOL> if TYPE is lltype . Void : <EOL> return "<STR_LIT>" <EOL> elif isinstance ( TYPE , lltype . Primitive ) : <EOL> if TYPE is lltype . Float and supports_floats : <EOL> return '<STR_LIT:float>' <EOL> if TYPE in ( lltype . Float , lltype . SingleFloat ) : <EOL> raise NotImplementedError ( "<STR_LIT>" % TYPE ) <EOL> if rffi . sizeof ( TYPE ) > rffi . sizeof ( lltype . Signed ) : <EOL> raise NotImplementedError ( "<STR_LIT>" % TYPE ) <EOL> return "<STR_LIT:int>" <EOL> elif isinstance ( TYPE , lltype . Ptr ) : <EOL> if TYPE . TO . _gckind == '<STR_LIT>' : <EOL> return "<STR_LIT:int>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> elif isinstance ( TYPE , ootype . OOType ) : <EOL> return "<STR_LIT>" <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" % TYPE ) <EOL> def repr_pointer ( box ) : <EOL> from pypy . rpython . lltypesystem import rstr <EOL> try : <EOL> T = box . value . _obj . container . _normalizedcontainer ( check = False ) . _TYPE <EOL> if T is rstr . STR : <EOL> return repr ( box . _get_str ( ) ) <EOL> return '<STR_LIT>' % ( T . _name , ) <EOL> except AttributeError : <EOL> return box . value <EOL> def repr_object ( box ) : <EOL> try : <EOL> TYPE = box . value . obj . _TYPE <EOL> if TYPE is ootype . String : <EOL> return '<STR_LIT>' % box . value . obj . _str <EOL> if TYPE is ootype . Class or isinstance ( TYPE , ootype . StaticMethod ) : <EOL> return '<STR_LIT>' % box . value . obj <EOL> if isinstance ( box . value . obj , ootype . _view ) : <EOL> return repr ( box . value . obj . _inst . _TYPE ) <EOL> else : <EOL> return repr ( TYPE ) <EOL> except AttributeError : <EOL> return box . value <EOL> class ReprRPython : <EOL> def __init__ ( self ) : <EOL> self . seen = { } <EOL> def repr_rpython ( self , box , typechars ) : <EOL> n = self . seen . setdefault ( box , len ( self . seen ) ) <EOL> return '<STR_LIT>' % ( box . _get_hash_ ( ) , typechars , n ) <EOL> repr_rpython = ReprRPython ( ) . repr_rpython <EOL> class AbstractValue ( object ) : <EOL> __slots__ = ( ) <EOL> def getint ( self ) : <EOL> raise NotImplementedError <EOL> def getfloat ( self ) : <EOL> raise NotImplementedError <EOL> def getref_base ( self ) : <EOL> raise NotImplementedError <EOL> def getref ( self , TYPE ) : <EOL> raise NotImplementedError <EOL> getref . _annspecialcase_ = '<STR_LIT>' <EOL> def _get_hash_ ( self ) : <EOL> raise NotImplementedError <EOL> def clonebox ( self ) : <EOL> raise NotImplementedError <EOL> def constbox ( self ) : <EOL> raise NotImplementedError <EOL> def nonconstbox ( self ) : <EOL> raise NotImplementedError <EOL> def getaddr ( self , cpu ) : <EOL> raise NotImplementedError <EOL> def sort_key ( self ) : <EOL> raise NotImplementedError <EOL> def set_future_value ( self , cpu , j ) : <EOL> raise NotImplementedError <EOL> def repr_rpython ( self ) : <EOL> return '<STR_LIT:%s>' % self <EOL> def _get_str ( self ) : <EOL> raise NotImplementedError <EOL> class AbstractDescr ( AbstractValue ) : <EOL> __slots__ = ( ) <EOL> def repr_of_descr ( self ) : <EOL> return '<STR_LIT>' % ( self , ) <EOL> class AbstractFailDescr ( AbstractDescr ) : <EOL> def get_index ( self ) : <EOL> raise NotImplementedError <EOL> def handle_fail ( self , metainterp_sd ) : <EOL> raise NotImplementedError <EOL> def compile_and_attach ( self , metainterp , new_loop ) : <EOL> raise NotImplementedError <EOL> class BasicFailDescr ( AbstractFailDescr ) : <EOL> def __init__ ( self , index = - <NUM_LIT:1> ) : <EOL> self . index = index <EOL> def get_index ( self ) : <EOL> return self . index <EOL> class AbstractMethDescr ( AbstractDescr ) : <EOL> jitcodes = None <EOL> def setup ( self , jitcodes ) : <EOL> self . jitcodes = jitcodes <EOL> def get_jitcode_for_class ( self , oocls ) : <EOL> return self . jitcodes [ oocls ] <EOL> class Const ( AbstractValue ) : <EOL> __slots__ = ( ) <EOL> @ staticmethod <EOL> def _new ( x , cpu ) : <EOL> "<STR_LIT>" <EOL> T = lltype . typeOf ( x ) <EOL> kind = getkind ( T ) <EOL> if kind == "<STR_LIT:int>" : <EOL> if isinstance ( T , lltype . Ptr ) : <EOL> if not we_are_translated ( ) : <EOL> return ConstAddr ( x , cpu ) <EOL> intval = cpu . cast_adr_to_int ( llmemory . cast_ptr_to_adr ( x ) ) <EOL> else : <EOL> intval = lltype . cast_primitive ( lltype . Signed , x ) <EOL> return ConstInt ( intval ) <EOL> elif kind == "<STR_LIT>" : <EOL> return cpu . ts . new_ConstRef ( x ) <EOL> elif kind == "<STR_LIT:float>" : <EOL> return ConstFloat ( x ) <EOL> else : <EOL> raise NotImplementedError ( kind ) <EOL> def constbox ( self ) : <EOL> return self <EOL> def same_constant ( self , other ) : <EOL> raise NotImplementedError <EOL> def nonnull_constant ( self ) : <EOL> raise NotImplementedError <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . _getrepr_ ( ) <EOL> def __eq__ ( self , other ) : <EOL> "<STR_LIT>" <EOL> if self . __class__ is not other . __class__ : <EOL> return False <EOL> if isinstance ( self . value , Symbolic ) : <EOL> v1 = "<STR_LIT>" , id ( self . value ) <EOL> else : <EOL> v1 = self . value <EOL> if isinstance ( other . value , Symbolic ) : <EOL> v2 = "<STR_LIT>" , id ( other . value ) <EOL> else : <EOL> v2 = other . value <EOL> return v1 == v2 <EOL> def __ne__ ( self , other ) : <EOL> return not ( self == other ) <EOL> class ConstInt ( Const ) : <EOL> type = INT <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value ) : <EOL> if not we_are_translated ( ) : <EOL> if isinstance ( value , int ) : <EOL> value = int ( value ) <EOL> else : <EOL> assert isinstance ( value , Symbolic ) <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxInt ( self . value ) <EOL> nonconstbox = clonebox <EOL> def getint ( self ) : <EOL> return self . value <EOL> def getaddr ( self , cpu ) : <EOL> return cpu . cast_int_to_adr ( self . value ) <EOL> def _get_hash_ ( self ) : <EOL> return self . value <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_int ( j , self . value ) <EOL> def same_constant ( self , other ) : <EOL> assert isinstance ( other , Const ) <EOL> return self . value == other . getint ( ) <EOL> def nonnull_constant ( self ) : <EOL> return self . value != <NUM_LIT:0> <EOL> def _getrepr_ ( self ) : <EOL> return self . value <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> CONST_FALSE = ConstInt ( <NUM_LIT:0> ) <EOL> CONST_TRUE = ConstInt ( <NUM_LIT:1> ) <EOL> class ConstAddr ( Const ) : <EOL> type = INT <EOL> _attrs_ = ( '<STR_LIT:value>' , '<STR_LIT>' ) <EOL> def __init__ ( self , adrvalue , cpu ) : <EOL> "<STR_LIT>" <EOL> assert not we_are_translated ( ) <EOL> if isinstance ( lltype . typeOf ( adrvalue ) , lltype . Ptr ) : <EOL> adrvalue = llmemory . cast_ptr_to_adr ( adrvalue ) <EOL> else : <EOL> assert lltype . typeOf ( adrvalue ) == llmemory . Address <EOL> self . value = adrvalue <EOL> self . cpu = cpu <EOL> def clonebox ( self ) : <EOL> return BoxInt ( self . cpu . cast_adr_to_int ( self . value ) ) <EOL> nonconstbox = clonebox <EOL> def getint ( self ) : <EOL> return self . cpu . cast_adr_to_int ( self . value ) <EOL> def getaddr ( self , cpu ) : <EOL> return self . value <EOL> def _get_hash_ ( self ) : <EOL> return llmemory . cast_adr_to_int ( self . value ) <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_int ( j , self . getint ( ) ) <EOL> def same_constant ( self , other ) : <EOL> assert isinstance ( other , Const ) <EOL> return self . value == other . getaddr ( self . cpu ) <EOL> def nonnull_constant ( self ) : <EOL> return bool ( self . value ) <EOL> def _getrepr_ ( self ) : <EOL> return self . value <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> class ConstFloat ( Const ) : <EOL> type = FLOAT <EOL> value = <NUM_LIT:0.0> <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , floatval ) : <EOL> assert isinstance ( floatval , float ) <EOL> self . value = floatval <EOL> def clonebox ( self ) : <EOL> return BoxFloat ( self . value ) <EOL> nonconstbox = clonebox <EOL> def getfloat ( self ) : <EOL> return self . value <EOL> def _get_hash_ ( self ) : <EOL> return compute_hash ( self . value ) <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_float ( j , self . getfloat ( ) ) <EOL> def same_constant ( self , other ) : <EOL> assert isinstance ( other , ConstFloat ) <EOL> return self . value == other . value <EOL> def nonnull_constant ( self ) : <EOL> return self . value != <NUM_LIT:0.0> <EOL> def _getrepr_ ( self ) : <EOL> return self . value <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> class ConstPtr ( Const ) : <EOL> type = REF <EOL> value = lltype . nullptr ( llmemory . GCREF . TO ) <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value ) : <EOL> assert lltype . typeOf ( value ) == llmemory . GCREF <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxPtr ( self . value ) <EOL> nonconstbox = clonebox <EOL> def getref_base ( self ) : <EOL> return self . value <EOL> def getref ( self , PTR ) : <EOL> return lltype . cast_opaque_ptr ( PTR , self . getref_base ( ) ) <EOL> getref . _annspecialcase_ = '<STR_LIT>' <EOL> def _get_hash_ ( self ) : <EOL> if self . value : <EOL> return lltype . identityhash ( self . value ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def getaddr ( self , cpu ) : <EOL> return llmemory . cast_ptr_to_adr ( self . value ) <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_ref ( j , self . value ) <EOL> def same_constant ( self , other ) : <EOL> assert isinstance ( other , ConstPtr ) <EOL> return self . value == other . value <EOL> def nonnull_constant ( self ) : <EOL> return bool ( self . value ) <EOL> _getrepr_ = repr_pointer <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> def _get_str ( self ) : <EOL> from pypy . rpython . annlowlevel import hlstr <EOL> from pypy . rpython . lltypesystem import rstr <EOL> return hlstr ( lltype . cast_opaque_ptr ( lltype . Ptr ( rstr . STR ) , self . value ) ) <EOL> class ConstObj ( Const ) : <EOL> type = REF <EOL> value = ootype . NULL <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value ) : <EOL> assert ootype . typeOf ( value ) is ootype . Object <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxObj ( self . value ) <EOL> nonconstbox = clonebox <EOL> def getref_base ( self ) : <EOL> return self . value <EOL> def getref ( self , OBJ ) : <EOL> return ootype . cast_from_object ( OBJ , self . getref_base ( ) ) <EOL> getref . _annspecialcase_ = '<STR_LIT>' <EOL> def _get_hash_ ( self ) : <EOL> if self . value : <EOL> return ootype . identityhash ( self . value ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_ref ( j , self . value ) <EOL> def same_constant ( self , other ) : <EOL> assert isinstance ( other , ConstObj ) <EOL> return self . value == other . value <EOL> def nonnull_constant ( self ) : <EOL> return bool ( self . value ) <EOL> _getrepr_ = repr_object <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> def _get_str ( self ) : <EOL> from pypy . rpython . annlowlevel import hlstr <EOL> return hlstr ( ootype . cast_from_object ( ootype . String , self . value ) ) <EOL> class Box ( AbstractValue ) : <EOL> __slots__ = ( ) <EOL> _extended_display = True <EOL> _counter = <NUM_LIT:0> <EOL> is_box = True <EOL> @ staticmethod <EOL> def _new ( x , cpu ) : <EOL> "<STR_LIT>" <EOL> kind = getkind ( lltype . typeOf ( x ) ) <EOL> if kind == "<STR_LIT:int>" : <EOL> intval = lltype . cast_primitive ( lltype . Signed , x ) <EOL> return BoxInt ( intval ) <EOL> elif kind == "<STR_LIT>" : <EOL> ptrval = lltype . cast_opaque_ptr ( llmemory . GCREF , x ) <EOL> return BoxPtr ( ptrval ) <EOL> elif kind == "<STR_LIT:float>" : <EOL> return BoxFloat ( x ) <EOL> else : <EOL> raise NotImplementedError ( kind ) <EOL> def nonconstbox ( self ) : <EOL> return self <EOL> def __repr__ ( self ) : <EOL> result = str ( self ) <EOL> if self . _extended_display : <EOL> result += '<STR_LIT>' % self . _getrepr_ ( ) <EOL> return result <EOL> def __str__ ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> try : <EOL> if self . type == INT : <EOL> t = '<STR_LIT:i>' <EOL> elif self . type == FLOAT : <EOL> t = '<STR_LIT:f>' <EOL> else : <EOL> t = '<STR_LIT:p>' <EOL> except AttributeError : <EOL> t = '<STR_LIT:b>' <EOL> self . _str = '<STR_LIT>' % ( t , Box . _counter ) <EOL> Box . _counter += <NUM_LIT:1> <EOL> return self . _str <EOL> def _get_str ( self ) : <EOL> return self . constbox ( ) . _get_str ( ) <EOL> class BoxInt ( Box ) : <EOL> type = INT <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value = <NUM_LIT:0> ) : <EOL> if not we_are_translated ( ) : <EOL> if isinstance ( value , int ) : <EOL> value = int ( value ) <EOL> else : <EOL> assert isinstance ( value , Symbolic ) <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxInt ( self . value ) <EOL> def constbox ( self ) : <EOL> return ConstInt ( self . value ) <EOL> def getint ( self ) : <EOL> return self . value <EOL> def getaddr ( self , cpu ) : <EOL> return cpu . cast_int_to_adr ( self . value ) <EOL> def _get_hash_ ( self ) : <EOL> return self . value <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_int ( j , self . value ) <EOL> def _getrepr_ ( self ) : <EOL> return self . value <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> class BoxFloat ( Box ) : <EOL> type = FLOAT <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , floatval = <NUM_LIT:0.0> ) : <EOL> assert isinstance ( floatval , float ) <EOL> self . value = floatval <EOL> def clonebox ( self ) : <EOL> return BoxFloat ( self . value ) <EOL> def constbox ( self ) : <EOL> return ConstFloat ( self . value ) <EOL> def getfloat ( self ) : <EOL> return self . value <EOL> def _get_hash_ ( self ) : <EOL> return compute_hash ( self . value ) <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_float ( j , self . value ) <EOL> def _getrepr_ ( self ) : <EOL> return self . value <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> class BoxPtr ( Box ) : <EOL> type = REF <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value = lltype . nullptr ( llmemory . GCREF . TO ) ) : <EOL> assert lltype . typeOf ( value ) == llmemory . GCREF <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxPtr ( self . value ) <EOL> def constbox ( self ) : <EOL> return ConstPtr ( self . value ) <EOL> def getref_base ( self ) : <EOL> return self . value <EOL> def getref ( self , PTR ) : <EOL> return lltype . cast_opaque_ptr ( PTR , self . getref_base ( ) ) <EOL> getref . _annspecialcase_ = '<STR_LIT>' <EOL> def getaddr ( self , cpu ) : <EOL> return llmemory . cast_ptr_to_adr ( self . value ) <EOL> def _get_hash_ ( self ) : <EOL> if self . value : <EOL> return lltype . identityhash ( self . value ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_ref ( j , self . value ) <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> _getrepr_ = repr_pointer <EOL> NULLBOX = BoxPtr ( ) <EOL> class BoxObj ( Box ) : <EOL> type = REF <EOL> _attrs_ = ( '<STR_LIT:value>' , ) <EOL> def __init__ ( self , value = ootype . NULL ) : <EOL> assert ootype . typeOf ( value ) is ootype . Object <EOL> self . value = value <EOL> def clonebox ( self ) : <EOL> return BoxObj ( self . value ) <EOL> def constbox ( self ) : <EOL> return ConstObj ( self . value ) <EOL> def getref_base ( self ) : <EOL> return self . value <EOL> def getref ( self , OBJ ) : <EOL> return ootype . cast_from_object ( OBJ , self . getref_base ( ) ) <EOL> getref . _annspecialcase_ = '<STR_LIT>' <EOL> def _get_hash_ ( self ) : <EOL> if self . value : <EOL> return ootype . identityhash ( self . value ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def set_future_value ( self , cpu , j ) : <EOL> cpu . set_future_value_ref ( j , self . value ) <EOL> def repr_rpython ( self ) : <EOL> return repr_rpython ( self , '<STR_LIT>' ) <EOL> _getrepr_ = repr_object <EOL> def set_future_values ( cpu , boxes ) : <EOL> for j in range ( len ( boxes ) ) : <EOL> boxes [ j ] . set_future_value ( cpu , j ) <EOL> def dict_equal_consts ( ) : <EOL> "<STR_LIT>" <EOL> return r_dict ( dc_eq , dc_hash ) <EOL> def dc_eq ( c1 , c2 ) : <EOL> return c1 == c2 <EOL> def dc_hash ( c ) : <EOL> "<STR_LIT>" <EOL> if not isinstance ( c , Const ) : <EOL> return hash ( c ) <EOL> if isinstance ( c . value , Symbolic ) : <EOL> return id ( c . value ) <EOL> try : <EOL> if isinstance ( c , ConstPtr ) : <EOL> p = lltype . normalizeptr ( c . value ) <EOL> if p is not None : <EOL> return hash ( p . _obj ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> return c . _get_hash_ ( ) <EOL> except lltype . DelayedPointer : <EOL> return - <NUM_LIT:2> <EOL> class LoopToken ( AbstractDescr ) : <EOL> """<STR_LIT>""" <EOL> terminating = False <EOL> def __init__ ( self , number = <NUM_LIT:0> ) : <EOL> self . number = number <EOL> def repr_of_descr ( self ) : <EOL> return '<STR_LIT>' % self . number <EOL> class TreeLoop ( object ) : <EOL> inputargs = None <EOL> operations = None <EOL> token = None <EOL> specnodes = property ( lambda x : crash , lambda x , y : crash ) <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> def _all_operations ( self , omit_finish = False ) : <EOL> "<STR_LIT>" <EOL> result = [ ] <EOL> _list_all_operations ( result , self . operations , omit_finish ) <EOL> return result <EOL> def summary ( self , adding_insns = { } ) : <EOL> "<STR_LIT>" <EOL> insns = adding_insns . copy ( ) <EOL> for op in self . _all_operations ( omit_finish = True ) : <EOL> opname = op . getopname ( ) <EOL> insns [ opname ] = insns . get ( opname , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> return insns <EOL> def get_operations ( self ) : <EOL> return self . operations <EOL> def get_display_text ( self ) : <EOL> return self . name + '<STR_LIT:\n>' + repr ( self . inputargs ) <EOL> def show ( self , errmsg = None ) : <EOL> "<STR_LIT>" <EOL> from pypy . jit . metainterp . graphpage import display_loops <EOL> display_loops ( [ self ] , errmsg ) <EOL> def check_consistency ( self ) : <EOL> "<STR_LIT>" <EOL> self . check_consistency_of ( self . inputargs , self . operations ) <EOL> @ staticmethod <EOL> def check_consistency_of ( inputargs , operations ) : <EOL> for box in inputargs : <EOL> assert isinstance ( box , Box ) , "<STR_LIT>" % ( box , ) <EOL> seen = dict . fromkeys ( inputargs ) <EOL> assert len ( seen ) == len ( inputargs ) , ( <EOL> "<STR_LIT>" ) <EOL> TreeLoop . check_consistency_of_branch ( operations , seen ) <EOL> @ staticmethod <EOL> def check_consistency_of_branch ( operations , seen ) : <EOL> "<STR_LIT>" <EOL> for op in operations : <EOL> for box in op . args : <EOL> if isinstance ( box , Box ) : <EOL> assert box in seen <EOL> if op . is_guard ( ) : <EOL> assert op . descr is not None <EOL> if hasattr ( op . descr , '<STR_LIT>' ) : <EOL> ops = op . descr . _debug_suboperations <EOL> TreeLoop . check_consistency_of_branch ( ops , seen . copy ( ) ) <EOL> for box in op . fail_args or [ ] : <EOL> assert isinstance ( box , Box ) <EOL> assert box in seen <EOL> else : <EOL> assert op . fail_args is None <EOL> box = op . result <EOL> if box is not None : <EOL> assert isinstance ( box , Box ) <EOL> assert box not in seen <EOL> seen [ box ] = True <EOL> assert operations [ - <NUM_LIT:1> ] . is_final ( ) <EOL> if operations [ - <NUM_LIT:1> ] . opnum == rop . JUMP : <EOL> target = operations [ - <NUM_LIT:1> ] . descr <EOL> if target is not None : <EOL> assert isinstance ( target , LoopToken ) <EOL> def dump ( self ) : <EOL> print '<STR_LIT>' % self , self . _dump_args ( self . inputargs ) <EOL> for op in self . operations : <EOL> print '<STR_LIT:\t>' , op . getopname ( ) , self . _dump_args ( op . args ) , self . _dump_box ( op . result ) <EOL> def _dump_args ( self , boxes ) : <EOL> return '<STR_LIT:[>' + '<STR_LIT:U+002CU+0020>' . join ( [ self . _dump_box ( box ) for box in boxes ] ) + '<STR_LIT:]>' <EOL> def _dump_box ( self , box ) : <EOL> if box is None : <EOL> return '<STR_LIT:None>' <EOL> else : <EOL> return box . repr_rpython ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name , ) <EOL> def _list_all_operations ( result , operations , omit_finish = True ) : <EOL> if omit_finish and operations [ - <NUM_LIT:1> ] . opnum == rop . FINISH : <EOL> return <EOL> result . extend ( operations ) <EOL> for op in operations : <EOL> if op . is_guard ( ) and op . descr : <EOL> if hasattr ( op . descr , '<STR_LIT>' ) : <EOL> ops = op . descr . _debug_suboperations <EOL> _list_all_operations ( result , ops , omit_finish ) <EOL> class History ( object ) : <EOL> def __init__ ( self , cpu ) : <EOL> self . cpu = cpu <EOL> self . inputargs = None <EOL> self . operations = [ ] <EOL> def record ( self , opnum , argboxes , resbox , descr = None ) : <EOL> op = ResOperation ( opnum , argboxes , resbox , descr ) <EOL> self . operations . append ( op ) <EOL> return op <EOL> class NoStats ( object ) : <EOL> def set_history ( self , history ) : <EOL> pass <EOL> def aborted ( self ) : <EOL> pass <EOL> def entered ( self ) : <EOL> pass <EOL> def compiled ( self ) : <EOL> pass <EOL> def add_merge_point_location ( self , loc ) : <EOL> pass <EOL> def name_for_new_loop ( self ) : <EOL> return '<STR_LIT>' <EOL> def add_new_loop ( self , loop ) : <EOL> pass <EOL> def view ( self , ** kwds ) : <EOL> pass <EOL> class Stats ( object ) : <EOL> """<STR_LIT>""" <EOL> compiled_count = <NUM_LIT:0> <EOL> enter_count = <NUM_LIT:0> <EOL> aborted_count = <NUM_LIT:0> <EOL> def __init__ ( self ) : <EOL> self . loops = [ ] <EOL> self . locations = [ ] <EOL> def set_history ( self , history ) : <EOL> self . history = history <EOL> def aborted ( self ) : <EOL> self . aborted_count += <NUM_LIT:1> <EOL> def entered ( self ) : <EOL> self . enter_count += <NUM_LIT:1> <EOL> def compiled ( self ) : <EOL> self . compiled_count += <NUM_LIT:1> <EOL> def add_merge_point_location ( self , loc ) : <EOL> self . locations . append ( loc ) <EOL> def name_for_new_loop ( self ) : <EOL> return '<STR_LIT>' % len ( self . loops ) <EOL> def add_new_loop ( self , loop ) : <EOL> self . loops . append ( loop ) <EOL> def get_all_loops ( self ) : <EOL> return self . loops <EOL> def check_history ( self , expected = None , ** check ) : <EOL> insns = { } <EOL> for op in self . history . operations : <EOL> opname = op . getopname ( ) <EOL> insns [ opname ] = insns . get ( opname , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if expected is not None : <EOL> insns . pop ( '<STR_LIT>' , None ) <EOL> assert insns == expected <EOL> for insn , expected_count in check . items ( ) : <EOL> getattr ( rop , insn . upper ( ) ) <EOL> found = insns . get ( insn , <NUM_LIT:0> ) <EOL> assert found == expected_count , ( <EOL> "<STR_LIT>" % ( found , insn , expected_count ) ) <EOL> return insns <EOL> def check_loops ( self , expected = None , ** check ) : <EOL> insns = { } <EOL> for loop in self . loops : <EOL> if getattr ( loop , '<STR_LIT>' , False ) : <EOL> continue <EOL> insns = loop . summary ( adding_insns = insns ) <EOL> if expected is not None : <EOL> insns . pop ( '<STR_LIT>' , None ) <EOL> assert insns == expected <EOL> for insn , expected_count in check . items ( ) : <EOL> getattr ( rop , insn . upper ( ) ) <EOL> found = insns . get ( insn , <NUM_LIT:0> ) <EOL> assert found == expected_count , ( <EOL> "<STR_LIT>" % ( found , insn , expected_count ) ) <EOL> return insns <EOL> def check_consistency ( self ) : <EOL> "<STR_LIT>" <EOL> for loop in self . loops : <EOL> loop . check_consistency ( ) <EOL> def maybe_view ( self ) : <EOL> if option . view : <EOL> self . view ( ) <EOL> def view ( self , errmsg = None , extraloops = [ ] ) : <EOL> from pypy . jit . metainterp . graphpage import display_loops <EOL> loops = self . get_all_loops ( ) [ : ] <EOL> for loop in extraloops : <EOL> if loop in loops : <EOL> loops . remove ( loop ) <EOL> loops . append ( loop ) <EOL> display_loops ( loops , errmsg , extraloops ) <EOL> class CrashInJIT ( Exception ) : <EOL> pass <EOL> class Options : <EOL> def __init__ ( self , listops = False , failargs_limit = FAILARGS_LIMIT ) : <EOL> self . listops = listops <EOL> self . failargs_limit = failargs_limit <EOL> def _freeze_ ( self ) : <EOL> return True <EOL> def check_descr ( x ) : <EOL> """<STR_LIT>""" <EOL> if x is not None : <EOL> assert isinstance ( x , AbstractDescr ) <EOL> class Entry ( ExtRegistryEntry ) : <EOL> _about_ = check_descr <EOL> def compute_result_annotation ( self , s_x ) : <EOL> from pypy . annotation import model as annmodel <EOL> if not annmodel . s_None . contains ( s_x ) : <EOL> assert isinstance ( s_x , annmodel . SomeInstance ) <EOL> assert issubclass ( s_x . classdef . classdesc . pyobj , AbstractDescr ) <EOL> def specialize_call ( self , hop ) : <EOL> hop . exception_cannot_occur ( ) </s>
