[pypy-svn] r62875 - pypy/branch/pyjitpl5/pypy/jit/tl

arigo at codespeak.net arigo at codespeak.net
Thu Mar 12 11:27:42 CET 2009


Author: arigo
Date: Thu Mar 12 11:27:40 2009
New Revision: 62875

Added:
   pypy/branch/pyjitpl5/pypy/jit/tl/targetpypyjit.py   (contents, props changed)
Modified:
   pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py
Log:
A translation target, for trying to translate the JIT with PyPy.


Modified: pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/pypyjit.py	Thu Mar 12 11:27:40 2009
@@ -25,10 +25,10 @@
 config.translation.rweakref = False # XXX
 set_pypy_opt_level(config, level='0')
 config.objspace.std.multimethods = 'mrd'
+multimethod.Installer = multimethod.InstallerVersion2
 config.objspace.std.builtinshortcut = True
 config.objspace.opcodes.CALL_LIKELY_BUILTIN = True
 config.objspace.std.withrangelist = True
-multimethod.Installer = multimethod.InstallerVersion2
 print config
 
 import sys, pdb

Added: pypy/branch/pyjitpl5/pypy/jit/tl/targetpypyjit.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/tl/targetpypyjit.py	Thu Mar 12 11:27:40 2009
@@ -0,0 +1,72 @@
+from pypy.config.config import to_optparse, SUPPRESS_USAGE
+
+take_options = True
+
+
+def readfile(filename):
+    import os
+    fd = os.open(filename, os.O_RDONLY, 0)
+    blocks = []
+    while True:
+        data = os.read(fd, 4096)
+        if not data:
+            break
+        blocks.append(data)
+    os.close(fd)
+    return ''.join(blocks)
+
+def entry_point(args):
+    from pypy.interpreter.pycode import PyCode
+    source = readfile('pypyjit_demo.py')
+    ec = space.getexecutioncontext()
+    code = ec.compiler.compile(source, '?', 'exec', 0)
+    assert isinstance(code, PyCode)
+    code.exec_code(space, w_dict, w_dict)
+    return 0
+
+def opt_parser(config):
+    parser = to_optparse(config, useoptions=["objspace.*"],
+                         parserkwargs={'usage': SUPPRESS_USAGE})
+    return parser
+
+def handle_config(config, translateconfig):
+    # set up the objspace optimizations based on the --opt argument
+    from pypy.config.pypyoption import set_pypy_opt_level
+    set_pypy_opt_level(config, translateconfig.opt)
+
+def get_additional_config_options():
+    from pypy.config.pypyoption import pypy_optiondescription
+    return pypy_optiondescription
+
+def target(driver, args):
+    from pypy.tool.option import make_objspace
+    from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
+    from pypy.objspace.std import multimethod
+    global space, w_dict
+    #
+    config = driver.config
+    parser = opt_parser(config)
+    parser.parse_args(args)
+    #
+    config.objspace.compiler = 'ast'
+    config.objspace.nofaking = True
+    config.objspace.allworkingmodules = False
+    config.objspace.usemodules.pypyjit = True
+    config.objspace.usemodules._weakref = False
+    config.objspace.usemodules._sre = False
+    config.translation.rweakref = False # XXX
+    config.objspace.std.multimethods = 'mrd'
+    multimethod.Installer = multimethod.InstallerVersion2
+    config.objspace.std.builtinshortcut = True
+    config.objspace.opcodes.CALL_LIKELY_BUILTIN = True
+    config.objspace.std.withrangelist = True
+    #
+    print config
+    space = make_objspace(config)
+    w_dict = space.newdict()
+    return entry_point, None, PyPyAnnotatorPolicy(single_space = space)
+
+def jitpolicy(driver):
+    """Returns the JIT policy to use when translating."""
+    from pypy.module.pypyjit.portal import PyPyJitPolicy
+    return PyPyJitPolicy(driver.translator)



More information about the Pypy-commit mailing list