[pypy-commit] pypy stm: A graph transformer, so far just renaming '{get, set}field'

arigo noreply at buildbot.pypy.org
Thu Oct 27 19:36:44 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48526:3de5c2a4796d
Date: 2011-10-27 16:34 +0200
http://bitbucket.org/pypy/pypy/changeset/3de5c2a4796d/

Log:	A graph transformer, so far just renaming '{get,set}field' into
	'stm_{get,set}field'.

diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py
--- a/pypy/translator/stm/llstminterp.py
+++ b/pypy/translator/stm/llstminterp.py
@@ -27,9 +27,8 @@
         'stm_getfield', 'stm_setfield',
         'stm_commit_transaction',
         ])
-    ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union(
-        set([
-        ]))
+    ALLOW_WHEN_INEVITABLE_TRANSACTION = ALLOW_WHEN_REGULAR_TRANSACTION.union([
+        ])
 
     def getoperationhandler(self, opname):
         stm_mode = self.llinterpreter.stm_mode
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/stm/test/test_transform.py
@@ -0,0 +1,16 @@
+from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.test.test_llinterp import get_interpreter
+from pypy.translator.stm.llstminterp import eval_stm_graph
+from pypy.translator.stm.transform import transform_graph
+
+
+def test_simple():
+    S = lltype.GcStruct('S', ('x', lltype.Signed))
+    p = lltype.malloc(S, immortal=True)
+    p.x = 42
+    def func(p):
+        return p.x
+    interp, graph = get_interpreter(func, [p])
+    transform_graph(graph)
+    res = eval_stm_graph(interp, graph, [p], stm_mode="regular_transaction")
+    assert res == 42
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
new file mode 100644
--- /dev/null
+++ b/pypy/translator/stm/transform.py
@@ -0,0 +1,29 @@
+from pypy.objspace.flow.model import SpaceOperation
+
+
+class STMTransformer(object):
+
+    def transform_block(self, block):
+        if block.operations == ():
+            return
+        newoperations = []
+        for op in block.operations:
+            meth = getattr(self, 'stt_' + op.opname, list.append)
+            meth(newoperations, op)
+        block.operations = newoperations
+
+    def transform_graph(self, graph):
+        for block in graph.iterblocks():
+            self.transform_block(block)
+
+    def stt_getfield(self, newoperations, op):
+        op1 = SpaceOperation('stm_getfield', op.args, op.result)
+        newoperations.append(op1)
+
+    def stt_setfield(self, newoperations, op):
+        op1 = SpaceOperation('stm_setfield', op.args, op.result)
+        newoperations.append(op1)
+
+
+def transform_graph(graph):
+    STMTransformer().transform_graph(graph)


More information about the pypy-commit mailing list