[pypy-svn] r73902 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 20 13:44:01 CEST 2010
Author: arigo
Date: Tue Apr 20 13:43:59 2010
New Revision: 73902
Added:
pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py (contents, props changed)
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py (contents, props changed)
Log:
Integration code and test.
Added: pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py
==============================================================================
--- (empty file)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/codewriter.py Tue Apr 20 13:43:59 2010
@@ -0,0 +1,22 @@
+from pypy.jit.codewriter import support
+from pypy.jit.codewriter.regalloc import perform_register_allocation
+from pypy.jit.codewriter.flatten import flatten_graph
+from pypy.jit.codewriter.assembler import Assembler
+
+
+class CodeWriter(object):
+
+ def __init__(self):
+ self.assembler = Assembler()
+
+ def transform_func_to_jitcode(self, func, values, type_system='lltype'):
+ """For testing."""
+ rtyper = support.annotate(func, values, type_system=type_system)
+ graph = rtyper.annotator.translator.graphs[0]
+ return self.transform_graph_to_jitcode(graph)
+
+ def transform_graph_to_jitcode(self, graph):
+ regalloc = perform_register_allocation(graph)
+ ssarepr = flatten_graph(graph, regalloc)
+ jitcode = self.assembler.assemble(ssarepr)
+ return jitcode
Added: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py
==============================================================================
--- (empty file)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_codewriter.py Tue Apr 20 13:43:59 2010
@@ -0,0 +1,23 @@
+from pypy.jit.codewriter.codewriter import CodeWriter
+
+
+def test_loop():
+ def f(a, b):
+ while a > 0:
+ b += a
+ a -= 1
+ return b
+ cw = CodeWriter()
+ jitcode = cw.transform_func_to_jitcode(f, [5, 6])
+ assert jitcode.code == ("\x00\x00\x00\x02"
+ "\x01\x13\x00\x02"
+ "\x02\x01\x00\x01"
+ "\x03\x00\x01\x00"
+ "\x04\x00\x00"
+ "\x05\x01")
+ assert cw.assembler.insns == {'int_gt/ici': 0,
+ 'goto_if_not/Li': 1,
+ 'int_add/iii': 2,
+ 'int_sub/ici': 3,
+ 'goto/L': 4,
+ 'int_return/i': 5}
More information about the Pypy-commit
mailing list