[pypy-svn] r46693 - in pypy/dist/pypy/translator: cli js jvm oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Mon Sep 17 14:44:21 CEST 2007
Author: antocuni
Date: Mon Sep 17 14:44:19 2007
New Revision: 46693
Modified:
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/gencli.py
pypy/dist/pypy/translator/js/function.py
pypy/dist/pypy/translator/js/js.py
pypy/dist/pypy/translator/jvm/generator.py
pypy/dist/pypy/translator/jvm/genjvm.py
pypy/dist/pypy/translator/oosupport/function.py
pypy/dist/pypy/translator/oosupport/genoo.py
Log:
prepare genjvm to use stack_optimizations, though it's disabled right now.
Move the smart version of render_bool_switch from cli to oosupport, so
genjvm uses it. Move the old non-smart version to js.
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Mon Sep 17 14:44:19 2007
@@ -1,13 +1,8 @@
-try:
- set
-except NameError:
- from sets import Set as set
-
from pypy.objspace.flow import model as flowmodel
from pypy.rpython.lltypesystem.lltype import Void
from pypy.rpython.ootypesystem import ootype
from pypy.translator.oosupport.treebuilder import SubOperation
-from pypy.translator.oosupport.function import Function as OOFunction
+from pypy.translator.oosupport.function import Function as OOFunction, render_sub_op
from pypy.translator.oosupport.constant import push_constant
from pypy.translator.cli.option import getoption
from pypy.translator.cli.cts import CTS
@@ -142,23 +137,6 @@
self.store(link.last_exc_value)
self._setup_link(link)
- # XXX: this method should be moved into oosupport, but other
- # backends are not ready :-(
- def render_bool_switch(self, block):
- assert len(block.exits) == 2
- for link in block.exits:
- if link.exitcase:
- link_true = link
- else:
- link_false = link
-
- true_label = self.next_label('link_true')
- self.generator.load(block.exitswitch)
- self.generator.branch_conditionally(True, true_label)
- self._follow_link(link_false) # if here, the exitswitch is false
- self.set_label(true_label)
- self._follow_link(link_true) # if here, the exitswitch is true
-
def render_numeric_switch(self, block):
if block.exitswitch.concretetype in (ootype.SignedLongLong, ootype.UnsignedLongLong):
# TODO: it could be faster to check is the values fit in
@@ -200,7 +178,7 @@
else:
self.ilasm.load_local(v)
elif isinstance(v, SubOperation):
- self._render_sub_op(v)
+ render_sub_op(v, self.db, self.generator)
else:
super(Function, self).load(v)
Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py (original)
+++ pypy/dist/pypy/translator/cli/gencli.py Mon Sep 17 14:44:19 2007
@@ -5,8 +5,6 @@
from py.compat import subprocess
from pypy.config.config import Config
from pypy.translator.oosupport.genoo import GenOO
-from pypy.translator.oosupport.treebuilder import build_trees
-from pypy.translator.backendopt.ssa import SSI_to_SSA
from pypy.translator.cli import conftest
from pypy.translator.cli.ilgenerator import IlasmGenerator
from pypy.translator.cli.function import Function, log
@@ -22,11 +20,6 @@
from pypy.translator.cli import query
from pypy.translator.cli import constant
-try:
- set
-except NameError:
- from sets import Set as set
-
class GenCli(GenOO):
TypeSystem = CTS
Function = Function
@@ -45,26 +38,14 @@
WeakRefConst = constant.CLIWeakRefConst
def __init__(self, tmpdir, translator, entrypoint, config=None, exctrans=False):
- GenOO.__init__(self, tmpdir, translator, entrypoint, config)
- exctrans = exctrans or translator.config.translation.cli.exception_transformer
- if exctrans:
- self.db.exceptiontransformer = translator.getexceptiontransformer()
-
- for node in get_prebuilt_nodes(translator, self.db):
- self.db.pending_node(node)
+ GenOO.__init__(self, tmpdir, translator, entrypoint, config, exctrans)
self.assembly_name = entrypoint.get_name()
self.tmpfile = tmpdir.join(self.assembly_name + '.il')
self.const_stat = str(tmpdir.join('const_stat'))
- if exctrans:
- etrafo = self.db.exceptiontransformer
- for graph in translator.graphs:
- etrafo.create_exception_handling(graph)
-
- if translator.config.translation.backendopt.stack_optimization:
- for graph in translator.graphs:
- SSI_to_SSA(graph)
- build_trees(graph)
+ def append_prebuilt_nodes(self):
+ for node in get_prebuilt_nodes(self.translator, self.db):
+ self.db.pending_node(node)
def generate_source(self):
GenOO.generate_source(self)
Modified: pypy/dist/pypy/translator/js/function.py
==============================================================================
--- pypy/dist/pypy/translator/js/function.py (original)
+++ pypy/dist/pypy/translator/js/function.py Mon Sep 17 14:44:19 2007
@@ -201,6 +201,19 @@
self.ilasm.catch()
#self.ilasm.close_branch()
+ # XXX: soon or later we should use the smarter version in oosupport
+ def render_bool_switch(self, block):
+ for link in block.exits:
+ self._setup_link(link)
+ target_label = self._get_block_name(link.target)
+ if link is block.exits[-1]:
+ self.generator.branch_unconditionally(target_label)
+ else:
+ assert type(link.exitcase) is bool
+ assert block.exitswitch is not None
+ self.generator.load(block.exitswitch)
+ self.generator.branch_conditionally(link.exitcase, target_label)
+
def record_ll_meta_exc(self, ll_meta_exc):
pass
Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py (original)
+++ pypy/dist/pypy/translator/js/js.py Mon Sep 17 14:44:19 2007
@@ -66,7 +66,10 @@
self.use_debug = use_debug
self.assembly_name = self.translator.graphs[0].name
self.tmpfile = udir.join(self.assembly_name + '.js')
-
+
+ def stack_optimization(self):
+ pass # genjs does not support treebuilder
+
def gen_pendings(self):
while self.db._pending_nodes:
node = self.db._pending_nodes.pop()
Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py (original)
+++ pypy/dist/pypy/translator/jvm/generator.py Mon Sep 17 14:44:19 2007
@@ -1,5 +1,7 @@
from pypy.objspace.flow import model as flowmodel
from pypy.translator.oosupport.metavm import Generator
+from pypy.translator.oosupport.treebuilder import SubOperation
+from pypy.translator.oosupport.function import render_sub_op
from pypy.rpython.ootypesystem import ootype
from pypy.rlib.objectmodel import CDefinedIntSymbolic
from pypy.translator.oosupport.constant import push_constant
@@ -941,6 +943,9 @@
jty, idx = self._var_data(value)
return self.load_jvm_var(jty, idx)
+ if isinstance(value, SubOperation):
+ return render_sub_op(value, self.db, self)
+
if isinstance(value, flowmodel.Constant):
return push_constant(self.db, value.concretetype, value.value, self)
@@ -1365,7 +1370,7 @@
return str(arg)
strargs = [jasmin_syntax(arg) for arg in args]
instr_text = '%s %s' % (jvmstr, " ".join(strargs))
- #self.curclass.out(' .line %d\n' % self.curfunc.instr_counter)
+ self.curclass.out(' .line %d\n' % self.curfunc.instr_counter)
self.curclass.out(' %-60s\n' % (instr_text,))
self.curfunc.instr_counter+=1
Modified: pypy/dist/pypy/translator/jvm/genjvm.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/genjvm.py (original)
+++ pypy/dist/pypy/translator/jvm/genjvm.py Mon Sep 17 14:44:19 2007
@@ -262,9 +262,14 @@
'entrypoint' --- if supplied, an object with a render method
"""
GenOO.__init__(self, tmpdir, translator, entrypoint)
- create_interlink_node(self.db)
self.jvmsrc = JvmGeneratedSource(tmpdir, getoption('package'))
+ def append_prebuilt_nodes(self):
+ create_interlink_node(self.db)
+
+ def stack_optimization(self):
+ pass # TODO: enable stack_optimization
+
def generate_source(self):
""" Creates the sources, and returns a JvmGeneratedSource object
for manipulating them """
Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py (original)
+++ pypy/dist/pypy/translator/oosupport/function.py Mon Sep 17 14:44:19 2007
@@ -8,7 +8,21 @@
from pypy.translator.oosupport.treebuilder import SubOperation
from pypy.translator.oosupport.metavm import InstructionList, StoreResult
-
+def render_sub_op(sub_op, db, generator):
+ op = sub_op.op
+ instr_list = db.genoo.opcodes.get(op.opname, None)
+ assert instr_list is not None, 'Unknown opcode: %s ' % op
+ assert isinstance(instr_list, InstructionList)
+ assert instr_list[-1] is StoreResult, "Cannot inline an operation that doesn't store the result"
+
+ # record that we know about the type of result and args
+ db.cts.lltype_to_cts(op.result.concretetype)
+ for v in op.args:
+ db.cts.lltype_to_cts(v.concretetype)
+
+ instr_list = InstructionList(instr_list[:-1]) # leave the value on the stack if this is a sub-op
+ instr_list.render(generator, op)
+ # now the value is on the stack
class Function(object):
@@ -209,19 +223,20 @@
else:
assert False, 'Unknonw exitswitch type: %s' % block.exitswitch.concretetype
- # XXX: soon or later we should use the implementation in
- # cli/function.py, but at the moment jvm and js fail with it.
def render_bool_switch(self, block):
+ assert len(block.exits) == 2
for link in block.exits:
- self._setup_link(link)
- target_label = self._get_block_name(link.target)
- if link is block.exits[-1]:
- self.generator.branch_unconditionally(target_label)
+ if link.exitcase:
+ link_true = link
else:
- assert type(link.exitcase) is bool
- assert block.exitswitch is not None
- self.generator.load(block.exitswitch)
- self.generator.branch_conditionally(link.exitcase, target_label)
+ link_false = link
+
+ true_label = self.next_label('link_true')
+ self.generator.load(block.exitswitch)
+ self.generator.branch_conditionally(True, true_label)
+ self._follow_link(link_false) # if here, the exitswitch is false
+ self.set_label(true_label)
+ self._follow_link(link_true) # if here, the exitswitch is true
def render_numeric_switch(self, block):
log.WARNING("The default version of render_numeric_switch is *slow*: please override it in the backend")
@@ -329,22 +344,6 @@
if self._trace_enabled():
self._trace_value('Result', op.result)
- def _render_sub_op(self, sub_op):
- op = sub_op.op
- instr_list = self.db.genoo.opcodes.get(op.opname, None)
- assert instr_list is not None, 'Unknown opcode: %s ' % op
- assert isinstance(instr_list, InstructionList)
- assert instr_list[-1] is StoreResult, "Cannot inline an operation that doesn't store the result"
-
- # record that we know about the type of result and args
- self.cts.lltype_to_cts(op.result.concretetype)
- for v in op.args:
- self.cts.lltype_to_cts(v.concretetype)
-
- instr_list = InstructionList(instr_list[:-1]) # leave the value on the stack if this is a sub-op
- instr_list.render(self.generator, op)
- # now the value is on the stack
-
# ---------------------------------------------------------#
# These methods are quite backend independent, but not #
# used in all backends. Invoke them from your __init__ if #
Modified: pypy/dist/pypy/translator/oosupport/genoo.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/genoo.py (original)
+++ pypy/dist/pypy/translator/oosupport/genoo.py Mon Sep 17 14:44:19 2007
@@ -1,6 +1,10 @@
""" basic oogenerator
"""
+
+from py.builtin import set
from pypy.translator.oosupport import constant as ooconst
+from pypy.translator.oosupport.treebuilder import build_trees
+from pypy.translator.backendopt.ssa import SSI_to_SSA
class GenOO(object):
TypeSystem = None
@@ -23,7 +27,7 @@
DictConst = ooconst.DictConst
WeakRefConst = ooconst.WeakRefConst
- def __init__(self, tmpdir, translator, entrypoint, config=None):
+ def __init__(self, tmpdir, translator, entrypoint, config=None, exctrans=False):
self.tmpdir = tmpdir
self.translator = translator
self.entrypoint = entrypoint
@@ -33,6 +37,29 @@
config = get_pypy_config(translating=True)
self.config = config
+ # XXX: move this option out of the 'cli' section
+ exctrans = exctrans or translator.config.translation.cli.exception_transformer
+ if exctrans:
+ self.db.exceptiontransformer = translator.getexceptiontransformer()
+
+ self.append_prebuilt_nodes()
+
+ if exctrans:
+ etrafo = self.db.exceptiontransformer
+ for graph in translator.graphs:
+ etrafo.create_exception_handling(graph)
+
+ if translator.config.translation.backendopt.stack_optimization:
+ self.stack_optimization()
+
+ def stack_optimization(self):
+ for graph in self.translator.graphs:
+ SSI_to_SSA(graph)
+ build_trees(graph)
+
+ def append_prebuilt_nodes(self):
+ pass
+
def generate_source(self):
self.ilasm = self.create_assembler()
self.fix_names()
More information about the Pypy-commit
mailing list