Author: Maciej Fijalkowski <[email protected]>
Branch: jitframe-on-heap
Changeset: r60373:68a674e72126
Date: 2013-01-23 15:47 +0200
http://bitbucket.org/pypy/pypy/changeset/68a674e72126/

Log:    work some on test_random

diff --git a/rpython/jit/backend/test/test_random.py 
b/rpython/jit/backend/test/test_random.py
--- a/rpython/jit/backend/test/test_random.py
+++ b/rpython/jit/backend/test/test_random.py
@@ -2,7 +2,7 @@
 import pytest
 from rpython.rlib.rarithmetic import intmask, LONG_BIT
 from rpython.jit.metainterp.history import BasicFailDescr, TreeLoop, 
BasicFinalDescr
-from rpython.jit.metainterp.history import BoxInt, ConstInt, JitCellToken
+from rpython.jit.metainterp.history import BoxInt, ConstInt, JitCellToken, Box
 from rpython.jit.metainterp.history import BoxPtr, ConstPtr, TargetToken
 from rpython.jit.metainterp.history import BoxFloat, ConstFloat, Const
 from rpython.jit.metainterp.history import INT, FLOAT
@@ -41,10 +41,12 @@
         self.should_fail_by = None
         self.counter = 0
         assert len(self.intvars) == len(dict.fromkeys(self.intvars))
+        self.descr_counters = {}
 
     def fork(self, cpu, loop, vars):
         fork = self.__class__(cpu, loop, vars)
         fork.prebuilt_ptr_consts = self.prebuilt_ptr_consts
+        fork.descr_counters = self.descr_counters
         return fork
 
     def do(self, opnum, argboxes, descr=None):
@@ -87,21 +89,13 @@
                 seen[v] = True
         return subset
 
-    def process_operation(self, s, op, names, subops):
+    def process_operation(self, s, op, names, namespace):
         args = []
         for v in op.getarglist():
             if v in names:
                 args.append(names[v])
-##            elif isinstance(v, ConstAddr):
-##                try:
-##                    name = ''.join([v.value.ptr.name[i]
-##                                    for i in range(len(v.value.ptr.name)-1)])
-##                except AttributeError:
-##                    args.append('ConstAddr(...)')
-##                else:
-##                    args.append(
-##                        'ConstAddr(llmemory.cast_ptr_to_adr(%s_vtable), cpu)'
-##                        % name)
+            elif isinstance(v, ConstPtr):
+                args.append('ConstPtr(...')
             elif isinstance(v, ConstFloat):
                 args.append('ConstFloat(longlong.getfloatstorage(%r))'
                             % v.getfloat())
@@ -115,21 +109,27 @@
             try:
                 descrstr = ', ' + op.getdescr()._random_info
             except AttributeError:
-                descrstr = ', descr=...'
+                descrstr = ', descr=' + self.descr_counters.get(op.getdescr(), 
'...')
         print >>s, '        ResOperation(rop.%s, [%s], %s%s),' % (
             opname[op.getopnum()], ', '.join(args), names[op.result], descrstr)
-        #if getattr(op, 'suboperations', None) is not None:
-        #    subops.append(op)
 
-    def print_loop(self):
-        #raise PleaseRewriteMe()
+    def print_loop(self, output, fail_descr=None):
         def update_names(ops):
             for op in ops:
                 v = op.result
                 if v not in names:
                     writevar(v, 'tmp')
-                #if getattr(op, 'suboperations', None) is not None:
-                #    update_names(op.suboperations)
+                if op.is_guard() or op.opnum == rop.FINISH:
+                    descr = op.getdescr()
+                    no = len(self.descr_counters)
+                    if op.is_guard():
+                        name = 'faildescr%d' % no
+                        clsname = 'BasicFailDescr'
+                    else:
+                        name = 'finishdescr%d' % no
+                        clsname = 'BasicFinalDescr'
+                    self.descr_counters[descr] = name
+                    print >>s, "    %s = %s()" % (name, clsname)
 
         def print_loop_prebuilt(ops):
             for op in ops:
@@ -137,13 +137,8 @@
                     if isinstance(arg, ConstPtr):
                         if arg not in names:
                             writevar(arg, 'const_ptr')
-                #if getattr(op, 'suboperations', None) is not None:
-                #    print_loop_prebuilt(op.suboperations)
 
-        if pytest.config.option.output:
-            s = open(pytest.config.option.output, "w")
-        else:
-            s = sys.stdout
+        s = output
         names = {None: 'None'}
         subops = []
         #
@@ -161,7 +156,8 @@
         update_names(self.loop.operations)
         print_loop_prebuilt(self.loop.operations)
         #
-        print >>s, '    cpu = CPU(None, None)'
+        if fail_descr is None:
+            print >>s, '    cpu = CPU(None, None)'
         if hasattr(self.loop, 'inputargs'):
             print >>s, '    inputargs = [%s]' % (
                 ', '.join([names[v] for v in self.loop.inputargs]))
@@ -169,29 +165,21 @@
         for op in self.loop.operations:
             self.process_operation(s, op, names, subops)
         print >>s, '        ]'
-        while subops:
-            next = subops.pop(0)
-            #for op in next.suboperations:
-            #    self.process_operation(s, op, names, subops)
-        # XXX think what to do about the one below
-                #if len(op.suboperations) > 1:
-                #    continue # XXX
-                #[op] = op.suboperations
-                #assert op.opnum == rop.FAIL
-                #print >>s, '    operations[%d].suboperations = [' % i
-                #print >>s, '        ResOperation(rop.FAIL, [%s], None)]' % (
-                #    ', '.join([names[v] for v in op.args]))
-        print >>s, '    looptoken = JitCellToken()'
-        print >>s, '    cpu.compile_loop(inputargs, operations, looptoken)'
+        if fail_descr is None:
+            print >>s, '    looptoken = JitCellToken()'
+            print >>s, '    cpu.compile_loop(inputargs, operations, looptoken)'
+        else:
+            print >>s, '    cpu.compile_bridge(%s, inputargs, operations, 
looptoken)' % self.descr_counters[fail_descr]
         if hasattr(self.loop, 'inputargs'):
+            vals = []
             for i, v in enumerate(self.loop.inputargs):
-                if isinstance(v, (BoxFloat, ConstFloat)):
-                    print >>s, ('    cpu.set_future_value_float(%d,'
-                        'longlong.getfloatstorage(%r))' % (i, v.getfloat()))
+                assert isinstance(v, Box)
+                if isinstance(v, BoxFloat):
+                    vals.append("longlong.getfloatstorage(%r)" % v.getfloat())
                 else:
-                    print >>s, '    cpu.set_future_value_int(%d, %d)' % (i,
-                                                                       v.value)
-        print >>s, '    op = cpu.execute_token(looptoken)'
+                    vals.append("%r" % v.getint())
+            print >>s, '    loop_args = [%s]' % ", ".join(vals)
+        print >>s, '    op = cpu.execute_token(looptoken, *loop_args)'
         if self.should_fail_by is None:
             fail_args = self.loop.operations[-1].getarglist()
         else:
@@ -204,8 +192,7 @@
                 print >>s, ('    assert cpu.get_int_value(%d) == %d'
                             % (i, v.value))
         self.names = names
-        if pytest.config.option.output:
-            s.close()
+        s.flush()
 
     def getfaildescr(self, is_finish=False):
         if is_finish:
@@ -537,8 +524,9 @@
 class RandomLoop(object):
     dont_generate_more = False
 
-    def __init__(self, cpu, builder_factory, r, startvars=None):
+    def __init__(self, cpu, builder_factory, r, startvars=None, output=None):
         self.cpu = cpu
+        self.output = output
         if startvars is None:
             startvars = []
             if cpu.supports_floats:
@@ -566,7 +554,8 @@
         self.subloops = []
         self.build_random_loop(cpu, builder_factory, r, startvars, allow_delay)
 
-    def build_random_loop(self, cpu, builder_factory, r, startvars, 
allow_delay):
+    def build_random_loop(self, cpu, builder_factory, r, startvars,
+                          allow_delay):
 
         loop = TreeLoop('test_random_function')
         loop.inputargs = startvars[:]
@@ -583,6 +572,8 @@
         self.loop = loop
         dump(loop)
         cpu.compile_loop(loop.inputargs, loop.operations, loop._jitcelltoken)
+        if self.output:
+            builder.print_loop(self.output)
 
     def insert_label(self, loop, position, r):
         assert not hasattr(loop, '_targettoken')
@@ -641,8 +632,6 @@
         self.expected = {}
         for v in endvars:
             self.expected[v] = v.value
-        if pytest.config.option.output:
-            builder.print_loop()
 
     def runjitcelltoken(self):
         if self.startvars == self.loop.inputargs:
@@ -793,6 +782,9 @@
         self.builder.cpu.compile_bridge(fail_descr, fail_args,
                                         subloop.operations,
                                         self.loop._jitcelltoken)
+
+        if self.output:
+            bridge_builder.print_loop(self.output, fail_descr)
         return True
 
 def dump(loop):
@@ -800,21 +792,31 @@
     if hasattr(loop, 'inputargs'):
         print >> sys.stderr, '\t', loop.inputargs
     for op in loop.operations:
-        print >> sys.stderr, '\t', op
+        if op.is_guard():
+            print >> sys.stderr, '\t', op, op.getfailargs()
+        else:
+            print >> sys.stderr, '\t', op
 
 def check_random_function(cpu, BuilderClass, r, num=None, max=None):
-    loop = RandomLoop(cpu, BuilderClass, r)
+    if pytest.config.option.output:
+        output = open(pytest.config.option.output, "w")
+    else:
+        output = None
+    loop = RandomLoop(cpu, BuilderClass, r, output=output)
     while True:
         loop.run_loop()
         if loop.guard_op is not None:
             if not loop.build_bridge():
                 break
+            import pdb
+            pdb.set_trace()
         else:
             break
     if num is not None:
         print '    # passed (%d/%d).' % (num + 1, max)
     else:
         print '    # passed.'
+    output.close()
     print
 
 def test_random_function(BuilderClass=OperationBuilder):
diff --git a/rpython/jit/backend/x86/test/test_regalloc2.py 
b/rpython/jit/backend/x86/test/test_regalloc2.py
--- a/rpython/jit/backend/x86/test/test_regalloc2.py
+++ b/rpython/jit/backend/x86/test/test_regalloc2.py
@@ -1,8 +1,13 @@
 from rpython.jit.metainterp.history import ResOperation, BoxInt, ConstInt,\
-     BasicFailDescr, JitCellToken, BasicFinalDescr
+     BasicFailDescr, JitCellToken, BasicFinalDescr, TargetToken
 from rpython.jit.metainterp.resoperation import rop
 from rpython.jit.backend.detect_cpu import getcpuclass
 from rpython.jit.backend.x86.arch import WORD
+from rpython.jit.tool.oparser import parse
+from rpython.rtyper.lltypesystem import lltype, rffi, rclass, llmemory
+from rpython.rtyper.llinterp import LLException
+from rpython.rtyper.annlowlevel import llhelper
+from rpython.jit.codewriter.effectinfo import EffectInfo
 
 CPU = getcpuclass()
 
@@ -291,3 +296,19 @@
     elif WORD == 8:
         assert cpu.get_int_value(deadframe, 19) == 19327352832
     assert cpu.get_int_value(deadframe, 20) == -49
+
+def getllhelper(cpu, f, ARGS, RES):
+    FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Void))
+    fptr = llhelper(FPTR, f)
+    calldescr = cpu.calldescrof(FPTR.TO, FPTR.TO.ARGS, FPTR.TO.RESULT,
+                                EffectInfo.MOST_GENERAL)
+    return fptr, calldescr
+
+def getexception():
+    xtp = lltype.malloc(rclass.OBJECT_VTABLE, immortal=True)
+    xtp.subclassrange_min = 1
+    xtp.subclassrange_max = 3
+    X = lltype.GcStruct('X', ('parent', rclass.OBJECT),
+                        hints={'vtable':  xtp._obj})
+    xptr = lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(X))
+    return xptr, xtp
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to