[pypy-svn] r45533 - in pypy/dist/pypy/translator: cli jvm oosupport
antocuni at codespeak.net
antocuni at codespeak.net
Tue Aug 7 16:34:49 CEST 2007
Author: antocuni
Date: Tue Aug 7 16:34:48 2007
New Revision: 45533
Modified:
pypy/dist/pypy/translator/cli/conftest.py
pypy/dist/pypy/translator/cli/function.py
pypy/dist/pypy/translator/cli/ilgenerator.py
pypy/dist/pypy/translator/jvm/node.py
pypy/dist/pypy/translator/oosupport/function.py
Log:
move --trace from jvm to oosupport, and teach gencli how to use it.
Modified: pypy/dist/pypy/translator/cli/conftest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/conftest.py (original)
+++ pypy/dist/pypy/translator/cli/conftest.py Tue Aug 7 16:34:48 2007
@@ -28,6 +28,9 @@
Option('--nostackopt', action='store_true', dest='nostackopt', default=False,
help="don't optimize stack load/store operations"),
+
+ Option('--trace', action='store_true', dest='trace', default=False,
+ help='Trace execution of generated code'),
)
Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py (original)
+++ pypy/dist/pypy/translator/cli/function.py Tue Aug 7 16:34:48 2007
@@ -193,6 +193,21 @@
if NATIVE_INSTANCE is None:
OOFunction.record_ll_meta_exc(self, ll_meta_exc)
+ def _trace_enabled(self):
+ return getoption('trace')
+
+ def _trace(self, s, writeline=False):
+ self.ilasm.stderr(s, writeline=writeline)
+
+ def _trace_value(self, prompt, v):
+ self.ilasm.stderr(' ' + prompt + ': ', writeline=False)
+ self.ilasm.load_stderr()
+ self.load(v)
+ if v.concretetype is not ootype.String:
+ from pypy.translator.cli.test.runtest import format_object
+ format_object(v.concretetype, self.cts, self.ilasm)
+ self.ilasm.write_stderr()
+
def begin_render(self):
self._set_args()
self._set_locals()
Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py Tue Aug 7 16:34:48 2007
@@ -252,12 +252,22 @@
self.code.write(opcode + ' ')
self.code.writeline(' '.join(map(str, args)))
- def stderr(self, msg, cond=True):
+ def stderr(self, msg, cond=True, writeline=True):
from pypy.translator.cli.support import string_literal
if cond:
- self.call('class [mscorlib]System.IO.TextWriter class [mscorlib]System.Console::get_Error()')
+ self.load_stderr()
self.opcode('ldstr', string_literal(msg))
- self.call_method('void class [mscorlib]System.IO.TextWriter::WriteLine(string)', virtual=True)
+ self.write_stderr(writeline)
+
+ def load_stderr(self):
+ self.call('class [mscorlib]System.IO.TextWriter class [mscorlib]System.Console::get_Error()')
+
+ def write_stderr(self, writeline=True):
+ if writeline:
+ meth = 'WriteLine'
+ else:
+ meth = 'Write'
+ self.call_method('void class [mscorlib]System.IO.TextWriter::%s(string)' % meth, virtual=True)
def add_comment(self, text):
self.code.writeline('// %s' % text)
Modified: pypy/dist/pypy/translator/jvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/node.py (original)
+++ pypy/dist/pypy/translator/jvm/node.py Tue Aug 7 16:34:48 2007
@@ -337,7 +337,9 @@
self.ilasm.throw()
- def _trace(self, str):
+ def _trace(self, str, writeline=False):
+ if writeline:
+ str += '\n'
jvmgen.SYSTEMERR.load(self.generator)
self.generator.load_string(str)
jvmgen.PRINTSTREAMPRINTSTR.invoke(self.generator)
@@ -381,19 +383,13 @@
self.generator.emit(jvmgen.PRINTSTREAMPRINTSTR)
self._trace("\n")
+ def _trace_enabled(self):
+ return getoption('trace')
+
def _render_op(self, op):
self.generator.add_comment(str(op))
-
- if getoption('trace'):
- self._trace(str(op)+"\n")
-
- for i, arg in enumerate(op.args):
- self._trace_value('Arg %02d' % i, arg)
-
OOFunction._render_op(self, op)
- if getoption('trace'):
- self._trace_value('Result', op.result)
class StaticMethodInterface(Node, JvmClassType):
"""
Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py (original)
+++ pypy/dist/pypy/translator/oosupport/function.py Tue Aug 7 16:34:48 2007
@@ -242,11 +242,29 @@
self.generator.load(to_load)
self.generator.store(to_store)
+ def _trace_enabled(self):
+ return False
+
+ def _trace(self, s):
+ raise NotImplementedError
+
+ def _trace_value(self, prompt, v):
+ raise NotImplementedError
+
def _render_op(self, 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)
+
+ if self._trace_enabled():
+ self._trace(str(op), writeline=True)
+ for i, arg in enumerate(op.args):
+ self._trace_value('Arg %02d' % i, arg)
+
instr_list.render(self.generator, op)
+
+ if self._trace_enabled():
+ self._trace_value('Result', op.result)
def _render_sub_op(self, sub_op):
op = sub_op.op
More information about the Pypy-commit
mailing list