<s> from pypy . translator . c . support import USESLOTS <EOL> from pypy . translator . c . support import cdecl <EOL> from pypy . translator . c . support import llvalue_from_constant , gen_assignments <EOL> from pypy . translator . c . support import c_string_constant , barebonearray <EOL> from pypy . objspace . flow . model import Variable , Constant , Block <EOL> from pypy . objspace . flow . model import c_last_exception , copygraph <EOL> from pypy . rpython . lltypesystem . lltype import Ptr , PyObject , Void , Bool , Signed <EOL> from pypy . rpython . lltypesystem . lltype import Unsigned , SignedLongLong , Float <EOL> from pypy . rpython . lltypesystem . lltype import UnsignedLongLong , Char , UniChar <EOL> from pypy . rpython . lltypesystem . lltype import pyobjectptr , ContainerType <EOL> from pypy . rpython . lltypesystem . lltype import Struct , Array , FixedSizeArray <EOL> from pypy . rpython . lltypesystem . lltype import ForwardReference , FuncType <EOL> from pypy . rpython . lltypesystem . llmemory import Address <EOL> from pypy . translator . backendopt . ssa import SSI_to_SSA <EOL> from pypy . translator . backendopt . innerloop import find_inner_loops <EOL> PyObjPtr = Ptr ( PyObject ) <EOL> LOCALVAR = '<STR_LIT>' <EOL> KEEP_INLINED_GRAPHS = False <EOL> class FunctionCodeGenerator ( object ) : <EOL> """<STR_LIT>""" <EOL> if USESLOTS : <EOL> __slots__ = """<STR_LIT>""" . split ( ) <EOL> def __init__ ( self , graph , db , exception_policy = None , functionname = None ) : <EOL> graph . _seen_by_the_backend = True <EOL> self . graph = graph <EOL> self . db = db <EOL> self . gcpolicy = db . gcpolicy <EOL> self . exception_policy = exception_policy <EOL> self . functionname = functionname <EOL> if db . stacklesstransformer : <EOL> db . stacklesstransformer . transform_graph ( graph ) <EOL> if self . db . exctransformer : <EOL> self . db . exctransformer . create_exception_handling ( self . graph ) <EOL> if self . db . gctransformer : <EOL> self . db . gctransformer . transform_graph ( self . graph ) <EOL> self . collect_var_and_types ( ) <EOL> for v in self . vars : <EOL> T = getattr ( v , '<STR_LIT>' , PyObjPtr ) <EOL> if isinstance ( T , Ptr ) and T . TO . __class__ == ForwardReference : <EOL> continue <EOL> db . gettype ( T ) <EOL> self . lltypes = None <EOL> def collect_var_and_types ( self ) : <EOL> self . all_cached_consts = None <EOL> mix = [ self . graph . getreturnvar ( ) ] <EOL> self . more_ll_values = [ ] <EOL> for block in self . graph . iterblocks ( ) : <EOL> mix . extend ( block . inputargs ) <EOL> for op in block . operations : <EOL> mix . extend ( op . args ) <EOL> mix . append ( op . result ) <EOL> for link in block . exits : <EOL> mix . extend ( link . getextravars ( ) ) <EOL> mix . extend ( link . args ) <EOL> if hasattr ( link , '<STR_LIT>' ) : <EOL> self . more_ll_values . append ( link . llexitcase ) <EOL> elif link . exitcase is not None : <EOL> mix . append ( Constant ( link . exitcase ) ) <EOL> if self . exception_policy == "<STR_LIT>" : <EOL> v , exc_cleanup_ops = self . graph . exc_cleanup <EOL> mix . append ( v ) <EOL> for cleanupop in exc_cleanup_ops : <EOL> mix . extend ( cleanupop . args ) <EOL> mix . append ( cleanupop . result ) <EOL> uniquemix = [ ] <EOL> seen = { } <EOL> for v in mix : <EOL> if id ( v ) not in seen : <EOL> uniquemix . append ( v ) <EOL> seen [ id ( v ) ] = True <EOL> self . vars = uniquemix <EOL> def name ( self , cname ) : <EOL> return cname <EOL> def patch_graph ( self , copy_graph ) : <EOL> graph = self . graph <EOL> if self . db . gctransformer and self . db . gctransformer . inline : <EOL> if copy_graph : <EOL> graph = copygraph ( graph , shallow = True ) <EOL> self . db . gctransformer . inline_helpers ( graph ) <EOL> return graph <EOL> def implementation_begin ( self ) : <EOL> self . oldgraph = self . graph <EOL> self . graph = self . patch_graph ( copy_graph = True ) <EOL> SSI_to_SSA ( self . graph ) <EOL> self . collect_var_and_types ( ) <EOL> self . blocknum = { } <EOL> for block in self . graph . iterblocks ( ) : <EOL> self . blocknum [ block ] = len ( self . blocknum ) <EOL> db = self . db <EOL> lltypes = { } <EOL> for v in self . vars : <EOL> T = getattr ( v , '<STR_LIT>' , PyObjPtr ) <EOL> typename = db . gettype ( T ) <EOL> lltypes [ id ( v ) ] = T , typename <EOL> self . lltypes = lltypes <EOL> self . innerloops = { } <EOL> for loop in find_inner_loops ( self . graph , Bool ) : <EOL> self . innerloops [ loop . headblock ] = loop <EOL> def graphs_to_patch ( self ) : <EOL> yield self . graph <EOL> def implementation_end ( self ) : <EOL> self . all_cached_consts = list ( self . allconstantvalues ( ) ) <EOL> self . lltypes = None <EOL> self . vars = None <EOL> self . blocknum = None <EOL> self . innerloops = None <EOL> self . graph = self . oldgraph <EOL> del self . oldgraph <EOL> def argnames ( self ) : <EOL> return [ LOCALVAR % v . name for v in self . graph . getargs ( ) ] <EOL> def allvariables ( self ) : <EOL> return [ v for v in self . vars if isinstance ( v , Variable ) ] <EOL> def allconstants ( self ) : <EOL> return [ c for c in self . vars if isinstance ( c , Constant ) ] <EOL> def allconstantvalues ( self ) : <EOL> for c in self . vars : <EOL> if isinstance ( c , Constant ) : <EOL> yield llvalue_from_constant ( c ) <EOL> for llvalue in self . more_ll_values : <EOL> yield llvalue <EOL> def lltypemap ( self , v ) : <EOL> T , typename = self . lltypes [ id ( v ) ] <EOL> return T <EOL> def lltypename ( self , v ) : <EOL> T , typename = self . lltypes [ id ( v ) ] <EOL> return typename <EOL> def expr ( self , v , special_case_void = True ) : <EOL> if isinstance ( v , Variable ) : <EOL> if self . lltypemap ( v ) is Void and special_case_void : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return LOCALVAR % v . name <EOL> elif isinstance ( v , Constant ) : <EOL> value = llvalue_from_constant ( v ) <EOL> if value is None and not special_case_void : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return self . db . get ( value ) <EOL> else : <EOL> raise TypeError , "<STR_LIT>" % ( v , ) <EOL> def cfunction_declarations ( self ) : <EOL> seen = { } <EOL> for a in self . graph . getargs ( ) : <EOL> seen [ a . name ] = True <EOL> result_by_name = [ ] <EOL> for v in self . allvariables ( ) : <EOL> name = v . name <EOL> if name not in seen : <EOL> seen [ name ] = True <EOL> result = cdecl ( self . lltypename ( v ) , LOCALVAR % name ) + '<STR_LIT:;>' <EOL> if self . lltypemap ( v ) is Void : <EOL> continue <EOL> result_by_name . append ( ( v . _name , result ) ) <EOL> result_by_name . sort ( ) <EOL> return [ result for name , result in result_by_name ] <EOL> def cfunction_body ( self ) : <EOL> graph = self . graph <EOL> for block in graph . iterblocks ( ) : <EOL> myblocknum = self . blocknum [ block ] <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % myblocknum <EOL> for i , op in enumerate ( block . operations ) : <EOL> for line in self . gen_op ( op ) : <EOL> yield line <EOL> if len ( block . exits ) == <NUM_LIT:0> : <EOL> assert len ( block . inputargs ) == <NUM_LIT:1> <EOL> if self . exception_policy == "<STR_LIT>" : <EOL> assert self . lltypemap ( self . graph . getreturnvar ( ) ) == PyObjPtr <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT:}>' <EOL> retval = self . expr ( block . inputargs [ <NUM_LIT:0> ] ) <EOL> if self . exception_policy != "<STR_LIT>" : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % retval <EOL> continue <EOL> elif block . exitswitch is None : <EOL> assert len ( block . exits ) == <NUM_LIT:1> <EOL> for op in self . gen_link ( block . exits [ <NUM_LIT:0> ] ) : <EOL> yield op <EOL> elif block in self . innerloops : <EOL> for line in self . gen_while_loop_hack ( block ) : <EOL> yield line <EOL> else : <EOL> assert block . exitswitch != c_last_exception <EOL> TYPE = self . lltypemap ( block . exitswitch ) <EOL> if TYPE in ( Bool , PyObjPtr ) : <EOL> expr = self . expr ( block . exitswitch ) <EOL> for link in block . exits [ : <NUM_LIT:0> : - <NUM_LIT:1> ] : <EOL> assert link . exitcase in ( False , True ) <EOL> if TYPE == Bool : <EOL> if not link . exitcase : <EOL> expr = '<STR_LIT:!>' + expr <EOL> elif TYPE == PyObjPtr : <EOL> yield '<STR_LIT>' % ( <EOL> expr , expr ) <EOL> if link . exitcase : <EOL> expr = '<STR_LIT>' % expr <EOL> else : <EOL> expr = '<STR_LIT>' % expr <EOL> yield '<STR_LIT>' % expr <EOL> for op in self . gen_link ( link ) : <EOL> yield '<STR_LIT:\t>' + op <EOL> yield '<STR_LIT:}>' <EOL> link = block . exits [ <NUM_LIT:0> ] <EOL> assert link . exitcase in ( False , True ) <EOL> for op in self . gen_link ( link ) : <EOL> yield op <EOL> elif TYPE in ( Signed , Unsigned , SignedLongLong , <EOL> UnsignedLongLong , Char , UniChar ) : <EOL> defaultlink = None <EOL> expr = self . expr ( block . exitswitch ) <EOL> yield '<STR_LIT>' % self . expr ( block . exitswitch ) <EOL> for link in block . exits : <EOL> if link . exitcase == '<STR_LIT:default>' : <EOL> defaultlink = link <EOL> continue <EOL> yield '<STR_LIT>' % self . db . get ( link . llexitcase ) <EOL> for op in self . gen_link ( link ) : <EOL> yield '<STR_LIT:\t>' + op <EOL> yield '<STR_LIT>' <EOL> if defaultlink is None : <EOL> yield '<STR_LIT>' <EOL> else : <EOL> for op in self . gen_link ( defaultlink ) : <EOL> yield '<STR_LIT:\t>' + op <EOL> yield '<STR_LIT:}>' <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( TYPE , ) ) <EOL> def gen_link ( self , link ) : <EOL> "<STR_LIT>" <EOL> is_alive = { } <EOL> assignments = [ ] <EOL> for a1 , a2 in zip ( link . args , link . target . inputargs ) : <EOL> a2type , a2typename = self . lltypes [ id ( a2 ) ] <EOL> if a2type is Void : <EOL> continue <EOL> src = self . expr ( a1 ) <EOL> dest = LOCALVAR % a2 . name <EOL> assignments . append ( ( a2typename , dest , src ) ) <EOL> for line in gen_assignments ( assignments ) : <EOL> yield line <EOL> label = '<STR_LIT>' % self . blocknum [ link . target ] <EOL> if link . target in self . innerloops : <EOL> loop = self . innerloops [ link . target ] <EOL> if link is loop . links [ - <NUM_LIT:1> ] : <EOL> label += '<STR_LIT>' <EOL> yield '<STR_LIT>' % label <EOL> def gen_op ( self , op ) : <EOL> macro = '<STR_LIT>' % op . opname . upper ( ) <EOL> if op . opname . startswith ( '<STR_LIT>' ) : <EOL> meth = getattr ( self . gcpolicy , macro , None ) <EOL> if meth : <EOL> line = meth ( self , op ) <EOL> else : <EOL> meth = getattr ( self , macro , None ) <EOL> if meth : <EOL> line = meth ( op ) <EOL> if meth is None : <EOL> lst = [ self . expr ( v ) for v in op . args ] <EOL> lst . append ( self . expr ( op . result ) ) <EOL> line = '<STR_LIT>' % ( macro , '<STR_LIT:U+002CU+0020>' . join ( lst ) ) <EOL> if "<STR_LIT:\n>" not in line : <EOL> yield line <EOL> else : <EOL> for line in line . splitlines ( ) : <EOL> yield line <EOL> def gen_while_loop_hack ( self , headblock ) : <EOL> looplinks = self . innerloops [ headblock ] . links <EOL> enterlink = looplinks [ <NUM_LIT:0> ] <EOL> assert len ( headblock . exits ) == <NUM_LIT:2> <EOL> assert isinstance ( headblock . exits [ <NUM_LIT:0> ] . exitcase , bool ) <EOL> assert isinstance ( headblock . exits [ <NUM_LIT:1> ] . exitcase , bool ) <EOL> i = list ( headblock . exits ) . index ( enterlink ) <EOL> exitlink = headblock . exits [ <NUM_LIT:1> - i ] <EOL> expr = self . expr ( headblock . exitswitch ) <EOL> if enterlink . exitcase == False : <EOL> expr = '<STR_LIT:!>' + expr <EOL> yield '<STR_LIT>' % expr <EOL> for op in self . gen_link ( enterlink ) : <EOL> yield '<STR_LIT:\t>' + op <EOL> yield '<STR_LIT>' % self . blocknum [ headblock ] <EOL> if headblock . operations : <EOL> for i , op in enumerate ( headblock . operations ) : <EOL> for line in self . gen_op ( op ) : <EOL> yield '<STR_LIT:\t>' + line <EOL> yield '<STR_LIT:}>' <EOL> for op in self . gen_link ( exitlink ) : <EOL> yield op <EOL> def OP_NEWLIST ( self , op ) : <EOL> args = [ self . expr ( v ) for v in op . args ] <EOL> r = self . expr ( op . result ) <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' % ( r , ) <EOL> else : <EOL> args . insert ( <NUM_LIT:0> , '<STR_LIT>' % len ( args ) ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( args ) , r ) <EOL> def OP_NEWDICT ( self , op ) : <EOL> args = [ self . expr ( v ) for v in op . args ] <EOL> r = self . expr ( op . result ) <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> return '<STR_LIT>' % ( r , ) <EOL> else : <EOL> assert len ( args ) % <NUM_LIT:2> == <NUM_LIT:0> <EOL> args . insert ( <NUM_LIT:0> , '<STR_LIT>' % ( len ( args ) // <NUM_LIT:2> ) ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( args ) , r ) <EOL> def OP_NEWTUPLE ( self , op ) : <EOL> args = [ self . expr ( v ) for v in op . args ] <EOL> r = self . expr ( op . result ) <EOL> args . insert ( <NUM_LIT:0> , '<STR_LIT>' % len ( args ) ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( args ) , r ) <EOL> def OP_SIMPLE_CALL ( self , op ) : <EOL> args = [ self . expr ( v ) for v in op . args ] <EOL> r = self . expr ( op . result ) <EOL> args . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( args ) , r ) <EOL> def OP_CALL_ARGS ( self , op ) : <EOL> args = [ self . expr ( v ) for v in op . args ] <EOL> r = self . expr ( op . result ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( args ) , r ) <EOL> def generic_call ( self , FUNC , fnexpr , args_v , v_result ) : <EOL> args = [ ] <EOL> assert len ( args_v ) == len ( FUNC . TO . ARGS ) <EOL> for v , ARGTYPE in zip ( args_v , FUNC . TO . ARGS ) : <EOL> if ARGTYPE is Void : <EOL> continue <EOL> args . append ( self . expr ( v ) ) <EOL> if isinstance ( ARGTYPE , ContainerType ) : <EOL> args [ - <NUM_LIT:1> ] = '<STR_LIT>' % ( args [ - <NUM_LIT:1> ] , ) <EOL> line = '<STR_LIT>' % ( fnexpr , '<STR_LIT:U+002CU+0020>' . join ( args ) ) <EOL> if self . lltypemap ( v_result ) is not Void : <EOL> r = self . expr ( v_result ) <EOL> line = '<STR_LIT>' % ( r , line ) <EOL> return line <EOL> def OP_DIRECT_CALL ( self , op ) : <EOL> fn = op . args [ <NUM_LIT:0> ] <EOL> return self . generic_call ( fn . concretetype , self . expr ( fn ) , <EOL> op . args [ <NUM_LIT:1> : ] , op . result ) <EOL> def OP_INDIRECT_CALL ( self , op ) : <EOL> fn = op . args [ <NUM_LIT:0> ] <EOL> return self . generic_call ( fn . concretetype , self . expr ( fn ) , <EOL> op . args [ <NUM_LIT:1> : - <NUM_LIT:1> ] , op . result ) <EOL> def OP_ADR_CALL ( self , op ) : <EOL> ARGTYPES = [ v . concretetype for v in op . args [ <NUM_LIT:1> : ] ] <EOL> RESTYPE = op . result . concretetype <EOL> FUNC = Ptr ( FuncType ( ARGTYPES , RESTYPE ) ) <EOL> typename = self . db . gettype ( FUNC ) <EOL> fnaddr = op . args [ <NUM_LIT:0> ] <EOL> fnexpr = '<STR_LIT>' % ( cdecl ( typename , '<STR_LIT>' ) , self . expr ( fnaddr ) ) <EOL> return self . generic_call ( FUNC , fnexpr , op . args [ <NUM_LIT:1> : ] , op . result ) <EOL> def generic_get ( self , op , sourceexpr ) : <EOL> T = self . lltypemap ( op . result ) <EOL> newvalue = self . expr ( op . result , special_case_void = False ) <EOL> result = [ '<STR_LIT>' % ( newvalue , sourceexpr ) ] <EOL> result = '<STR_LIT:\n>' . join ( result ) <EOL> if T is Void : <EOL> result = '<STR_LIT>' % result <EOL> return result <EOL> def generic_set ( self , op , targetexpr ) : <EOL> newvalue = self . expr ( op . args [ - <NUM_LIT:1> ] , special_case_void = False ) <EOL> result = [ '<STR_LIT>' % ( targetexpr , newvalue ) ] <EOL> T = self . lltypemap ( op . args [ - <NUM_LIT:1> ] ) <EOL> result = '<STR_LIT:\n>' . join ( result ) <EOL> if T is Void : <EOL> result = '<STR_LIT>' % result <EOL> return result <EOL> def OP_GETFIELD ( self , op , ampersand = '<STR_LIT>' ) : <EOL> assert isinstance ( op . args [ <NUM_LIT:1> ] , Constant ) <EOL> STRUCT = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> structdef = self . db . gettypedefnode ( STRUCT ) <EOL> expr = ampersand + structdef . ptr_access_expr ( self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> op . args [ <NUM_LIT:1> ] . value ) <EOL> return self . generic_get ( op , expr ) <EOL> def OP_BARE_SETFIELD ( self , op ) : <EOL> assert isinstance ( op . args [ <NUM_LIT:1> ] , Constant ) <EOL> STRUCT = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> structdef = self . db . gettypedefnode ( STRUCT ) <EOL> expr = structdef . ptr_access_expr ( self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> op . args [ <NUM_LIT:1> ] . value ) <EOL> return self . generic_set ( op , expr ) <EOL> def OP_GETSUBSTRUCT ( self , op ) : <EOL> RESULT = self . lltypemap ( op . result ) . TO <EOL> if isinstance ( RESULT , FixedSizeArray ) : <EOL> return self . OP_GETFIELD ( op , ampersand = '<STR_LIT>' ) <EOL> else : <EOL> return self . OP_GETFIELD ( op , ampersand = '<STR_LIT:&>' ) <EOL> def OP_GETARRAYSIZE ( self , op ) : <EOL> ARRAY = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> if isinstance ( ARRAY , FixedSizeArray ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> ARRAY . length ) <EOL> else : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) <EOL> def OP_GETARRAYITEM ( self , op ) : <EOL> ARRAY = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> ptr = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> index = self . expr ( op . args [ <NUM_LIT:1> ] ) <EOL> arraydef = self . db . gettypedefnode ( ARRAY ) <EOL> return self . generic_get ( op , arraydef . itemindex_access_expr ( ptr , index ) ) <EOL> def OP_SETARRAYITEM ( self , op ) : <EOL> ARRAY = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> ptr = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> index = self . expr ( op . args [ <NUM_LIT:1> ] ) <EOL> arraydef = self . db . gettypedefnode ( ARRAY ) <EOL> return self . generic_set ( op , arraydef . itemindex_access_expr ( ptr , index ) ) <EOL> OP_BARE_SETARRAYITEM = OP_SETARRAYITEM <EOL> def OP_GETARRAYSUBSTRUCT ( self , op ) : <EOL> ARRAY = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> ptr = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> index = self . expr ( op . args [ <NUM_LIT:1> ] ) <EOL> arraydef = self . db . gettypedefnode ( ARRAY ) <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> arraydef . itemindex_access_expr ( ptr , index ) ) <EOL> def interior_expr ( self , args , rettype = False ) : <EOL> TYPE = args [ <NUM_LIT:0> ] . concretetype . TO <EOL> expr = self . expr ( args [ <NUM_LIT:0> ] ) <EOL> for i , arg in enumerate ( args [ <NUM_LIT:1> : ] ) : <EOL> defnode = self . db . gettypedefnode ( TYPE ) <EOL> if arg . concretetype is Void : <EOL> fieldname = arg . value <EOL> if i == <NUM_LIT:0> : <EOL> expr = defnode . ptr_access_expr ( expr , fieldname ) <EOL> else : <EOL> expr = defnode . access_expr ( expr , fieldname ) <EOL> if isinstance ( TYPE , FixedSizeArray ) : <EOL> TYPE = TYPE . OF <EOL> else : <EOL> TYPE = getattr ( TYPE , fieldname ) <EOL> else : <EOL> indexexpr = self . expr ( arg ) <EOL> if i == <NUM_LIT:0> : <EOL> expr = defnode . itemindex_access_expr ( expr , indexexpr ) <EOL> else : <EOL> expr = defnode . access_expr_varindex ( expr , indexexpr ) <EOL> TYPE = TYPE . OF <EOL> if rettype : <EOL> return expr , TYPE <EOL> else : <EOL> return expr <EOL> def OP_GETINTERIORFIELD ( self , op ) : <EOL> return self . generic_get ( op , self . interior_expr ( op . args ) ) <EOL> def OP_BARE_SETINTERIORFIELD ( self , op ) : <EOL> return self . generic_set ( op , self . interior_expr ( op . args [ : - <NUM_LIT:1> ] ) ) <EOL> def OP_GETINTERIORARRAYSIZE ( self , op ) : <EOL> expr , ARRAY = self . interior_expr ( op . args , True ) <EOL> if isinstance ( ARRAY , FixedSizeArray ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , ARRAY . length ) <EOL> else : <EOL> assert isinstance ( ARRAY , Array ) <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , expr ) <EOL> def OP_PTR_NONZERO ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) <EOL> def OP_PTR_ISZERO ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) <EOL> def OP_PTR_EQ ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:1> ] ) ) <EOL> def OP_PTR_NE ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:1> ] ) ) <EOL> def OP_BOEHM_MALLOC ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . result ) ) <EOL> def OP_BOEHM_MALLOC_ATOMIC ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . result ) ) <EOL> def OP_BOEHM_REGISTER_FINALIZER ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . args [ <NUM_LIT:0> ] ) , self . expr ( op . args [ <NUM_LIT:1> ] ) ) <EOL> def OP_RAW_MALLOC ( self , op ) : <EOL> eresult = self . expr ( op . result ) <EOL> esize = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> return "<STR_LIT>" % ( esize , eresult ) <EOL> def OP_STACK_MALLOC ( self , op ) : <EOL> eresult = self . expr ( op . result ) <EOL> esize = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> return "<STR_LIT>" % ( esize , eresult ) <EOL> def OP_DIRECT_FIELDPTR ( self , op ) : <EOL> return self . OP_GETFIELD ( op , ampersand = '<STR_LIT:&>' ) <EOL> def OP_DIRECT_ARRAYITEMS ( self , op ) : <EOL> ARRAY = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) . TO <EOL> items = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> if not isinstance ( ARRAY , FixedSizeArray ) and not barebonearray ( ARRAY ) : <EOL> items += '<STR_LIT>' <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , items ) <EOL> def OP_DIRECT_PTRADD ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:1> ] ) ) <EOL> def OP_CAST_POINTER ( self , op ) : <EOL> TYPE = self . lltypemap ( op . result ) <EOL> typename = self . db . gettype ( TYPE ) <EOL> result = [ ] <EOL> result . append ( '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> cdecl ( typename , '<STR_LIT>' ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) ) <EOL> return '<STR_LIT:\t>' . join ( result ) <EOL> OP_CAST_PTR_TO_ADR = OP_CAST_POINTER <EOL> OP_CAST_ADR_TO_PTR = OP_CAST_POINTER <EOL> OP_CAST_OPAQUE_PTR = OP_CAST_POINTER <EOL> def OP_CAST_INT_TO_PTR ( self , op ) : <EOL> TYPE = self . lltypemap ( op . result ) <EOL> typename = self . db . gettype ( TYPE ) <EOL> return "<STR_LIT>" % ( self . expr ( op . result ) , cdecl ( typename , "<STR_LIT>" ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) <EOL> def OP_SAME_AS ( self , op ) : <EOL> result = [ ] <EOL> TYPE = self . lltypemap ( op . result ) <EOL> assert self . lltypemap ( op . args [ <NUM_LIT:0> ] ) == TYPE <EOL> if TYPE is not Void : <EOL> result . append ( '<STR_LIT>' % ( self . expr ( op . result ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) ) ) <EOL> return '<STR_LIT:\t>' . join ( result ) <EOL> def OP_HINT ( self , op ) : <EOL> hints = op . args [ <NUM_LIT:1> ] . value <EOL> return '<STR_LIT>' % ( self . OP_SAME_AS ( op ) , hints ) <EOL> def OP_KEEPALIVE ( self , op ) : <EOL> v = op . args [ <NUM_LIT:0> ] <EOL> TYPE = self . lltypemap ( v ) <EOL> if TYPE is Void : <EOL> return "<STR_LIT>" <EOL> if isinstance ( TYPE , Ptr ) and TYPE . TO . _gckind == '<STR_LIT>' : <EOL> meth = getattr ( self . gcpolicy , '<STR_LIT>' , None ) <EOL> if meth : <EOL> return meth ( self , v ) <EOL> return "<STR_LIT>" % self . expr ( v ) <EOL> def OP_RAW_STORE ( self , op ) : <EOL> addr = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> TYPE = op . args [ <NUM_LIT:1> ] . value <EOL> offset = self . expr ( op . args [ <NUM_LIT:2> ] ) <EOL> value = self . expr ( op . args [ <NUM_LIT:3> ] ) <EOL> typename = cdecl ( self . db . gettype ( TYPE ) . replace ( '<STR_LIT:@>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> def OP_RAW_LOAD ( self , op ) : <EOL> addr = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> TYPE = op . args [ <NUM_LIT:1> ] . value <EOL> offset = self . expr ( op . args [ <NUM_LIT:2> ] ) <EOL> result = self . expr ( op . result ) <EOL> typename = cdecl ( self . db . gettype ( TYPE ) . replace ( '<STR_LIT:@>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> def OP_CAST_PRIMITIVE ( self , op ) : <EOL> TYPE = self . lltypemap ( op . result ) <EOL> val = self . expr ( op . args [ <NUM_LIT:0> ] ) <EOL> ORIG = self . lltypemap ( op . args [ <NUM_LIT:0> ] ) <EOL> if ORIG is Char : <EOL> val = "<STR_LIT>" % val <EOL> elif ORIG is UniChar : <EOL> val = "<STR_LIT>" % val <EOL> result = self . expr ( op . result ) <EOL> typename = cdecl ( self . db . gettype ( TYPE ) , '<STR_LIT>' ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> OP_FORCE_CAST = OP_CAST_PRIMITIVE <EOL> def OP_RESUME_POINT ( self , op ) : <EOL> return '<STR_LIT>' % ( op . args [ <NUM_LIT:0> ] , ) <EOL> def OP_DEBUG_PRINT ( self , op ) : <EOL> from pypy . rpython . lltypesystem . rstr import STR <EOL> format = [ ] <EOL> argv = [ ] <EOL> for arg in op . args : <EOL> T = arg . concretetype <EOL> if T == Ptr ( STR ) : <EOL> if isinstance ( arg , Constant ) : <EOL> format . append ( '<STR_LIT>' . join ( arg . value . chars ) . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> else : <EOL> format . append ( '<STR_LIT:%s>' ) <EOL> argv . append ( '<STR_LIT>' % self . expr ( arg ) ) <EOL> continue <EOL> elif T == Signed : <EOL> format . append ( '<STR_LIT>' ) <EOL> elif T == Float : <EOL> format . append ( '<STR_LIT>' ) <EOL> elif isinstance ( T , Ptr ) or T == Address : <EOL> format . append ( '<STR_LIT>' ) <EOL> elif T == Char : <EOL> if isinstance ( arg , Constant ) : <EOL> format . append ( arg . value . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> continue <EOL> format . append ( '<STR_LIT>' ) <EOL> elif T == Bool : <EOL> format . append ( '<STR_LIT:%s>' ) <EOL> argv . append ( '<STR_LIT>' % self . expr ( arg ) ) <EOL> continue <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % ( T , ) ) <EOL> argv . append ( self . expr ( arg ) ) <EOL> return "<STR_LIT>" % ( <EOL> c_string_constant ( '<STR_LIT:U+0020>' . join ( format ) + '<STR_LIT>' ) , <EOL> '<STR_LIT>' . join ( [ '<STR_LIT:U+002CU+0020>' + s for s in argv ] ) ) <EOL> def OP_DEBUG_ASSERT ( self , op ) : <EOL> return '<STR_LIT>' % ( self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> c_string_constant ( op . args [ <NUM_LIT:1> ] . value ) ) <EOL> def OP_DEBUG_FATALERROR ( self , op ) : <EOL> from pypy . rpython . lltypesystem . rstr import STR <EOL> msg = op . args [ <NUM_LIT:0> ] <EOL> assert msg . concretetype == Ptr ( STR ) <EOL> argv = [ ] <EOL> if isinstance ( msg , Constant ) : <EOL> msg = c_string_constant ( '<STR_LIT>' . join ( msg . value . chars ) ) <EOL> else : <EOL> msg = '<STR_LIT>' % self . expr ( msg ) <EOL> return '<STR_LIT>' % msg <EOL> def OP_DEBUG_LLINTERPCALL ( self , op ) : <EOL> return '<STR_LIT>' <EOL> def OP_INSTRUMENT_COUNT ( self , op ) : <EOL> counter_label = op . args [ <NUM_LIT:1> ] . value <EOL> self . db . instrument_ncounter = max ( self . db . instrument_ncounter , <EOL> counter_label + <NUM_LIT:1> ) <EOL> counter_label = self . expr ( op . args [ <NUM_LIT:1> ] ) <EOL> return '<STR_LIT>' % counter_label <EOL> def OP_IS_EARLY_CONSTANT ( self , op ) : <EOL> return self . expr ( op . result ) + '<STR_LIT>' <EOL> def OP_JIT_MARKER ( self , op ) : <EOL> return '<STR_LIT>' % op <EOL> def OP_PROMOTE_VIRTUALIZABLE ( self , op ) : <EOL> return '<STR_LIT>' % op <EOL> def OP_GET_GROUP_MEMBER ( self , op ) : <EOL> typename = self . db . gettype ( op . result . concretetype ) <EOL> return '<STR_LIT>' % ( <EOL> self . expr ( op . result ) , <EOL> cdecl ( typename , '<STR_LIT>' ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:1> ] ) ) <EOL> def OP_GET_NEXT_GROUP_MEMBER ( self , op ) : <EOL> typename = self . db . gettype ( op . result . concretetype ) <EOL> return '<STR_LIT>' % ( <EOL> self . expr ( op . result ) , <EOL> cdecl ( typename , '<STR_LIT>' ) , <EOL> self . expr ( op . args [ <NUM_LIT:0> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:1> ] ) , <EOL> self . expr ( op . args [ <NUM_LIT:2> ] ) ) <EOL> assert not USESLOTS or '<STR_LIT>' not in dir ( FunctionCodeGenerator ) </s>
