Author: Richard Plangger <planri...@gmail.com>
Branch: s390x-backend
Changeset: r82638:ae5c221a741c
Date: 2016-03-01 17:25 +0100
http://bitbucket.org/pypy/pypy/changeset/ae5c221a741c/

Log:    translating the interpreter and feeding it with hypothesis, it
        compiles but does not correctly enter the dispatch loop

diff --git a/rpython/jit/backend/llsupport/tl/interp.py 
b/rpython/jit/backend/llsupport/tl/interp.py
--- a/rpython/jit/backend/llsupport/tl/interp.py
+++ b/rpython/jit/backend/llsupport/tl/interp.py
@@ -2,6 +2,7 @@
 from rpython.rlib.objectmodel import specialize, always_inline
 from rpython.jit.backend.llsupport.tl import code
 from rpython.jit.backend.llsupport.tl.stack import Stack
+from rpython.rlib import rstring
 
 class W_Root(object):
     pass
@@ -48,14 +49,28 @@
             return W_ListObject(val)
         raise NotImplementedError("cannot handle: " + str(val))
 
+def _read_all_from_file(file):
+    with open(file, 'rb') as fd:
+        return fd.read()
+
+_read_bytecode_from_file = _read_all_from_file
+
+def _read_consts_from_file(file):
+    consts = []
+    bytestring = _read_all_from_file(file)
+    for line in bytestring.splitlines():
+        consts.append(rstring.replace(line, "\\n", "\n"))
+    return consts
+
 def entry_point(argv):
-    bytecode = argv[0]
+    bytecode = _read_bytecode_from_file(argv[0])
+    consts = _read_consts_from_file(argv[1])
+    print(bytecode)
+    print(consts)
     pc = 0
     end = len(bytecode)
     stack = Stack(16)
     space = Space()
-    consts = ["hello"] * 100
-    consts[0] = "world"
     while pc < end:
         pc = dispatch_once(space, pc, bytecode, consts, stack)
     return 0
@@ -106,5 +121,6 @@
         del w_lst.items[w_idx.value]
         # index error, just crash the machine!!
     else:
+        print("opcode %d is not implemented" % opcode)
         raise NotImplementedError
     return i + 1
diff --git a/rpython/jit/backend/llsupport/tl/test/zrpy_gc_hypo_test.py 
b/rpython/jit/backend/llsupport/tl/test/zrpy_gc_hypo_test.py
--- a/rpython/jit/backend/llsupport/tl/test/zrpy_gc_hypo_test.py
+++ b/rpython/jit/backend/llsupport/tl/test/zrpy_gc_hypo_test.py
@@ -1,19 +1,35 @@
-from rpython.jit.backend.detect_cpu import getcpuclass
-from rpython.jit.tool.oparser import parse
-from rpython.jit.metainterp.history import JitCellToken, NoStats
-from rpython.jit.metainterp.history import BasicFinalDescr, BasicFailDescr
-from rpython.jit.metainterp.gc import get_description
+import py
+from hypothesis import given
+from rpython.tool.udir import udir
 from rpython.jit.metainterp.optimize import SpeculativeError
 from rpython.annotator.listdef import s_list_of_strings
-from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rtyper.rclass import getclassrepr, getinstancerepr
-from rpython.translator.unsimplify import call_initial_function
 from rpython.translator.translator import TranslationContext
 from rpython.translator.c import genc
 from rpython.jit.backend.llsupport.tl import interp
+from rpython.jit.backend.llsupport.tl.test import code_strategies as st
+
+def persist(type, contents):
+    dir = udir.ensure(type)
+    print "written", type, "to", dir
+    with open(dir.strpath, 'wb') as fd:
+        fd.write(contents)
+    return dir.strpath
+
+def persist_constants(consts):
+    contents = ""
+    for string in consts:
+        contents += string.replace("\n", "\\n") + "\n"
+    return persist('constants', contents)
+
+def persist_bytecode(bc):
+    return persist('bytecode', bc)
 
 class GCHypothesis(object):
-    def setup_class(self):
+    builder = None
+    def setup_method(self, name):
+        if self.builder:
+            return
+
         t = TranslationContext()
         t.config.translation.gc = "incminimark"
         t.config.translation.gcremovetypeptr = True
@@ -22,12 +38,23 @@
         rtyper = t.buildrtyper()
         rtyper.specialize()
 
-        cbuilder = genc.CStandaloneBuilder(t, f, t.config)
+        cbuilder = genc.CStandaloneBuilder(t, interp.entry_point, t.config)
         cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
         cbuilder.compile()
+        # prevent from rebuilding the c object!
+        self.builder = cbuilder
 
-        import pdb; pdb.set_trace()
+    def execute(self, bytecode, consts):
+        exe = self.builder.executable_name
+        bc_file = persist_bytecode(bytecode)
+        consts_file = persist_constants(consts)
+        args = [bc_file, consts_file]
+        env = {}
+        res = self.builder.translator.platform.execute(exe, args, env=env)
+        return res.returncode, res.out, res.err
 
-
-    def test_void(self):
-        pass
+    @given(st.single_bytecode())
+    def test_execute_single_bytecode(self, program):
+        clazz, bytecode, consts, stack = program
+        result, out, err = self.execute(bytecode, consts)
+        assert result == 0
diff --git a/rpython/jit/backend/x86/test/test_zrpy_gc_hypo.py 
b/rpython/jit/backend/x86/test/test_zrpy_gc_hypo.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/x86/test/test_zrpy_gc_hypo.py
@@ -0,0 +1,6 @@
+from rpython.jit.backend.llsupport.tl.test.zrpy_gc_hypo_test import 
GCHypothesis
+
+class TestGCHypothesis(GCHypothesis):
+    # runs ../../llsupport/tl/test/zrpy_gc_hypo_test.py
+    gcrootfinder = "shadowstack"
+    gc = "incminimark"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to