[pypy-svn] r65531 - in pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Mon Jun 1 19:11:53 CEST 2009


Author: antocuni
Date: Mon Jun  1 19:11:53 2009
New Revision: 65531

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_runner.py
Log:
add the possibility to change the 'option' and 'tailcall' options at runtime, by setting an environment variable


Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/method.py	Mon Jun  1 19:11:53 2009
@@ -1,4 +1,5 @@
 import py
+import os
 from pypy.tool.pairtype import extendabletype
 from pypy.rlib.objectmodel import compute_unique_id
 from pypy.rpython.ootypesystem import ootype
@@ -132,6 +133,7 @@
     debug = False
 
     def __init__(self, cpu, name, loop):
+        self.setoptions()
         self.cpu = cpu
         self.name = name
         self.loop = loop
@@ -165,6 +167,29 @@
         # ----
         self.finish_code()
 
+    def _parseopt(self, text):
+        text = text.lower()
+        if text[0] == '-':
+            return text[1:], False
+        elif text[0] == '+':
+            return text[1:], True
+        else:
+            return text, True
+
+    def setoptions(self):
+        opts = os.environ.get('PYPYJITOPT')
+        if opts is None:
+            pass
+        parts = opts.split()
+        for part in parts:
+            name, value = self._parseopt(part)
+            if name == 'debug':
+                self.debug = value
+            elif name == 'tailcall':
+                self.tailcall = value
+            else:
+                os.write(2, 'Warning: invalid option name: %s\n' % name)
+
     def finish_code(self):
         delegatetype = dotnet.typeof(LoopDelegate)
         # initialize the array of genconsts

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_runner.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/backend/cli/test/test_runner.py	Mon Jun  1 19:11:53 2009
@@ -29,3 +29,31 @@
     def test_ovf_operations(self, reversed=False):
         if reversed:
             py.test.skip('fixme')
+
+
+def test_pypycliopt():
+    import os
+    from pypy.jit.backend.cli.method import Method
+    
+    def getmeth(value):
+        oldenv = os.environ.get('PYPYJITOPT')
+        os.environ['PYPYJITOPT'] = value
+        meth = Method.__new__(Method) # evil hack not to call __init__
+        meth.setoptions()
+        if oldenv:
+            os.environ['PYPYJITOPT'] = oldenv
+        else:
+            del os.environ['PYPYJITOPT']
+        return meth
+
+    meth = getmeth('')
+    assert meth.debug == Method.debug
+    assert meth.tailcall == Method.tailcall
+
+    meth = getmeth('debug -tailcall')
+    assert meth.debug
+    assert not meth.tailcall
+
+    meth = getmeth('+debug +tailcall')
+    assert meth.debug
+    assert meth.tailcall



More information about the Pypy-commit mailing list