[pypy-svn] r10238 - pypy/dist/goal
pedronis at codespeak.net
pedronis at codespeak.net
Fri Apr 1 20:01:31 CEST 2005
Author: pedronis
Date: Fri Apr 1 20:01:31 2005
New Revision: 10238
Added:
pypy/dist/goal/targetpypy.py
- copied, changed from r10225, pypy/dist/goal/translate_pypy.py
pypy/dist/goal/targetpypy0.py
- copied, changed from r10225, pypy/dist/goal/translate_pypy0.py
pypy/dist/goal/targetpypy1.py
- copied, changed from r10225, pypy/dist/goal/translate_pypy1.py
Modified:
pypy/dist/goal/buildcache2.py
pypy/dist/goal/translate_pypy.py
Log:
refactored the various translate_pypy* so that the bulk of the functionality lives and is changeable in a
unified translate_pypy.py, the name of an other python file can be passed as argument (defaults to targetpypy),
this file should define a target and run functions to define and setup the entry_point and have code to run
the translated result.
What is now translate_pypy1.py can be achieved as translate_pypy.py targetpypy1
Modified: pypy/dist/goal/buildcache2.py
==============================================================================
--- pypy/dist/goal/buildcache2.py (original)
+++ pypy/dist/goal/buildcache2.py Fri Apr 1 20:01:31 2005
@@ -1,8 +1,7 @@
-import autopath
-
-from pypy.interpreter.typedef import interptypes
def buildcache(space):
+ from pypy.interpreter.typedef import interptypes
+
space.builtin.getdict()
print "*builtin*"
w_dic = space.builtin.w_dict
@@ -41,6 +40,7 @@
print "cache build finished"
if __name__ == '__main__':
+ import autopath
from pypy.objspace.std.objspace import StdObjSpace
space = StdObjSpace()
Copied: pypy/dist/goal/targetpypy.py (from r10225, pypy/dist/goal/translate_pypy.py)
==============================================================================
--- pypy/dist/goal/translate_pypy.py (original)
+++ pypy/dist/goal/targetpypy.py Fri Apr 1 20:01:31 2005
@@ -1,35 +1,6 @@
-#
-#
-#
-"""
-Command-line options for translate_pypy:
-
- port Listen on the given port number for connexions
- (see pypy/translator/tool/pygame/graphclient.py)
- -text Don't start the Pygame viewer
- -no-a Don't infer annotations, just translate everything
- -no-c Don't generate the C code
- -c Generate the C code, but don't compile it
- -o Generate and compile the C code, but don't run it
- -no-mark-some-objects
- Do not mark functions that have SomeObject in their signature.
- -tcc Equivalent to the envvar PYPY_CC='tcc -shared -o "%s.so" "%s.c"'
- -- http://fabrice.bellard.free.fr/tcc/
- -no-d Disable recording of debugging information
-"""
-import autopath, sys, threading, pdb, os
import buildcache2
from pypy.objspace.std.objspace import StdObjSpace, W_Object
from pypy.objspace.std.intobject import W_IntObject
-from pypy.translator.translator import Translator
-from pypy.annotation import model as annmodel
-from pypy.tool.cache import Cache
-from pypy.annotation.model import SomeObject
-from pypy.tool.udir import udir
-
-# XXX this tries to make compiling faster
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
# __________ Entry point __________
@@ -38,10 +9,10 @@
w_b = W_IntObject(space, -7)
return space.mul(w_a, w_b)
-# __________ Main __________
+# _____ Define and setup target ___
-def analyse(entry_point=entry_point):
- global t, space
+def target():
+ global space
# disable translation of the whole of classobjinterp.py
StdObjSpace.setup_old_style_classes = lambda self: None
space = StdObjSpace()
@@ -50,225 +21,12 @@
# further call the entry_point once to trigger building remaining
# caches (as far as analyzing the entry_point is concerned)
entry_point()
- t = Translator(entry_point, verbose=True, simplifying=True)
- if listen_port:
- run_async_server()
- if not options['-no-a']:
- a = t.annotate([])
- a.simplify()
- t.frozen = True # cannot freeze if we don't have annotations
- if not options['-no-mark-some-objects']:
- options['-no-mark-some-objects'] = True # Do not do this again
- find_someobjects(t)
-
-
-def find_someobjects(translator, quiet=False):
- """Find all functions in that have SomeObject in their signature."""
- annotator = translator.annotator
- if not annotator:
- return # no annotations available
-
- translator.highlight_functions = {}
-
- def is_someobject(var):
- try:
- return annotator.binding(var).__class__ == SomeObject
- except KeyError:
- return False
-
- def short_binding(var):
- try:
- binding = annotator.binding(var)
- except KeyError:
- return "?"
- if binding.is_constant():
- return 'const %s' % binding.__class__.__name__
- else:
- return binding.__class__.__name__
-
- header = True
- items = [(graph.name, func, graph)
- for func, graph in translator.flowgraphs.items()]
- items.sort()
- num = someobjnum = 0
- for graphname, func, graph in items:
- unknown_input_args = len(filter(is_someobject, graph.getargs()))
- unknown_return_value = is_someobject(graph.getreturnvar())
- if unknown_input_args or unknown_return_value:
- someobjnum += 1
- translator.highlight_functions[func] = True
- if not quiet:
- if header:
- header = False
- print "=" * 70
- print "Functions that have SomeObject in their signature"
- print "=" * 70
- print ("%(name)s(%(args)s) -> %(result)s\n"
- "%(filename)s:%(lineno)s\n"
- % {'name': graph.name,
- 'filename': func.func_globals.get('__name__', '?'),
- 'lineno': func.func_code.co_firstlineno,
- 'args': ', '.join(map(short_binding,
- graph.getargs())),
- 'result': short_binding(graph.getreturnvar())})
- num += 1
- if not quiet:
- print "=" * 70
- percent = int(num and (100.0*someobjnum / num) or 0)
- print "somobjectness: %2d percent" % (percent)
- print "(%d out of %d functions get or return SomeObjects" % (
- someobjnum, num)
- print "=" * 70
-
-
-def update_usession_dir(stabledir = udir.dirpath('usession')):
- from py import path
- try:
- if stabledir.check(dir=1):
- for x in udir.visit(path.checker(file=1)):
- target = stabledir.join(x.relto(udir))
- if target.check():
- target.remove()
- else:
- target.dirpath().ensure(dir=1)
- try:
- target.mklinkto(x)
- except path.Invalid:
- x.copy(target)
- except path.Invalid:
- print "ignored: couldn't link or copy to %s" % stabledir
-
-def run_in_thread(fn, args, cleanup=None, cleanup_args=()):
- def _run_in_thread():
- fn(*args)
- if cleanup is not None:
- cleanup(*cleanup_args)
- return threading.Thread(target=_run_in_thread, args=())
-
-def run_async_server():
- from pypy.translator.tool import graphpage, graphserver
- homepage = graphpage.TranslatorPage(t)
- graphserver.run_server(homepage, port=listen_port, background=True)
- options['-text'] = True
-
-
-if __name__ == '__main__':
-
- options = {'-text': False,
- '-no-c': False,
- '-c': False,
- '-o': False,
- '-no-mark-some-objects': False,
- '-no-a': False,
- '-tcc': False,
- '-no-d': False,
- }
- listen_port = None
- for arg in sys.argv[1:]:
- if arg in ('-h', '--help'):
- print __doc__.strip()
- sys.exit()
- try:
- listen_port = int(arg)
- except ValueError:
- assert arg in options, "unknown option %r" % (arg,)
- options[arg] = True
- if options['-tcc']:
- os.environ['PYPY_CC'] = 'tcc -shared -o "%s.so" "%s.c"'
- if options['-no-d']:
- annmodel.DEBUG = False
-
- def about(x):
- """ interactive debugging helper """
- from pypy.objspace.flow.model import Block, flatten
- if isinstance(x, Block):
- for func, graph in t.flowgraphs.items():
- if x in flatten(graph):
- funcname = func.func_name
- cls = getattr(func, 'class_', None)
- if cls:
- funcname = '%s.%s' % (cls.__name__, funcname)
- print '%s is a %s in the graph of %s' % (x,
- x.__class__.__name__, funcname)
- print 'at %s:%d' % (func.func_globals.get('__name__', '?'),
- func.func_code.co_firstlineno)
- break
- else:
- print '%s is a %s at some unknown location' % (x,
- x.__class__.__name__)
- print 'containing the following operations:'
- for op in x.operations:
- print op
- print '--end--'
- return
- print "don't know about", x
-
- def run_server():
- from pypy.translator.tool.graphpage import TranslatorPage
- from pypy.translator.tool.pygame.graphclient import get_layout
- from pypy.translator.tool.pygame.graphdisplay import GraphDisplay
- import pygame
-
- if not options['-no-mark-some-objects']:
- find_someobjects(t, quiet=True)
-
- display = GraphDisplay(get_layout(TranslatorPage(t)))
- async_quit = display.async_quit
- return display.run, async_quit, pygame.quit
-
- def debug(got_error):
- if got_error:
- import traceback
- exc, val, tb = sys.exc_info()
- print >> sys.stderr
- traceback.print_exception(exc, val, tb)
- print >> sys.stderr
-
- block = getattr(val, '__annotator_block', None)
- if block:
- print '-'*60
- about(block)
- print '-'*60
- print >> sys.stderr
- func, args = pdb.post_mortem, (tb,)
- else:
- print '-'*60
- print 'Done.'
- print
- func, args = pdb.set_trace, ()
- if options['-text']:
- func(*args)
- else:
- start, stop, cleanup = run_server()
- debugger = run_in_thread(func, args, stop)
- debugger.start()
- start()
- debugger.join()
- cleanup()
+ return entry_point, []
- try:
- analyse()
- print '-'*60
- if options['-no-c']:
- print 'Not generating C code.'
- elif options['-c']:
- print 'Generating C code without compiling it...'
- filename = t.ccompile(really_compile=False)
- update_usession_dir()
- print 'Written %s.' % (filename,)
- else:
- print 'Generating and compiling C code...'
- c_entry_point = t.ccompile()
- update_usession_dir()
- if not options['-o']:
- print 'Running!'
- w_result = c_entry_point()
- print w_result
- print w_result.intval
- assert w_result.intval == 42
- except:
- debug(True)
- else:
- debug(False)
-
+# _____ Run translated _____
+def run(c_entry_point):
+ w_result = c_entry_point()
+ print w_result
+ print w_result.intval
+ assert w_result.intval == 42
Copied: pypy/dist/goal/targetpypy0.py (from r10225, pypy/dist/goal/translate_pypy0.py)
==============================================================================
--- pypy/dist/goal/translate_pypy0.py (original)
+++ pypy/dist/goal/targetpypy0.py Fri Apr 1 20:01:31 2005
@@ -1,39 +1,6 @@
-#
-#
-#
-"""
-Command-line options for translate_pypy:
-
- port Listen on the given port number for connexions
- (see pypy/translator/tool/pygame/graphclient.py)
- -text Don't start the Pygame viewer
- -no-a Don't infer annotations, just translate everything
- -no-c Don't generate the C code
- -c Generate the C code, but don't compile it
- -o Generate and compile the C code, but don't run it
- -no-mark-some-objects
- Do not mark functions that have SomeObject in their signature.
- -tcc Equivalent to the envvar PYPY_CC='tcc -shared -o "%s.so" "%s.c"'
- -- http://fabrice.bellard.free.fr/tcc/
- -no-d Disable recording of debugging information
-"""
-import autopath, sys, threading, pdb, os
-import buildcache2
-from pypy.objspace.std.objspace import StdObjSpace, W_Object
-from pypy.objspace.std.intobject import W_IntObject
-from pypy.translator.translator import Translator
-from pypy.annotation import model as annmodel
-from pypy.tool.cache import Cache
-from pypy.annotation.model import SomeObject
-from pypy.tool.udir import udir
-
from pypy.objspace import dummy
from pypy.interpreter.pycode import PyCode
-# XXX this tries to make compiling faster
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
-
# __________ Entry point __________
def entry_point(code, w_loc):
@@ -41,15 +8,11 @@
code2 = code2._from_code(code)
code2.exec_code(space, space.wrap({}), w_loc)
-# __________ Main __________
+# _____ Define and setup target _____
-def analyse(entry_point=entry_point):
- global t, space
+def target():
+ global space
space = dummy.DummyObjSpace()
- # call cache filling code
- #buildcache2.buildcache(space)
- # further call the entry_point once to trigger building remaining
- # caches (as far as analyzing the entry_point is concerned)
from pypy.interpreter import pycode
@@ -60,223 +23,11 @@
# cheat
space._gatewaycache.content[pyopcode.app] = space.newdict([])
- t = Translator(entry_point, verbose=True, simplifying=True)
- if listen_port:
- run_async_server()
- if not options['-no-a']:
- a = t.annotate([object, dummy.W_Obj])
- a.simplify()
- t.frozen = True # cannot freeze if we don't have annotations
- if not options['-no-mark-some-objects']:
- options['-no-mark-some-objects'] = True # Do not do this again
- find_someobjects(t)
-
-
-def find_someobjects(translator, quiet=False):
- """Find all functions in that have SomeObject in their signature."""
- annotator = translator.annotator
- if not annotator:
- return # no annotations available
-
- translator.highlight_functions = {}
-
- def is_someobject(var):
- try:
- return annotator.binding(var).__class__ == SomeObject
- except KeyError:
- return False
-
- def short_binding(var):
- try:
- binding = annotator.binding(var)
- except KeyError:
- return "?"
- if binding.is_constant():
- return 'const %s' % binding.__class__.__name__
- else:
- return binding.__class__.__name__
-
- header = True
- items = [(graph.name, func, graph)
- for func, graph in translator.flowgraphs.items()]
- items.sort()
- num = someobjnum = 0
- for graphname, func, graph in items:
- unknown_input_args = len(filter(is_someobject, graph.getargs()))
- unknown_return_value = is_someobject(graph.getreturnvar())
- if unknown_input_args or unknown_return_value:
- someobjnum += 1
- translator.highlight_functions[func] = True
- if not quiet:
- if header:
- header = False
- print "=" * 70
- print "Functions that have SomeObject in their signature"
- print "=" * 70
- print ("%(name)s(%(args)s) -> %(result)s\n"
- "%(filename)s:%(lineno)s\n"
- % {'name': graph.name,
- 'filename': func.func_globals.get('__name__', '?'),
- 'lineno': func.func_code.co_firstlineno,
- 'args': ', '.join(map(short_binding,
- graph.getargs())),
- 'result': short_binding(graph.getreturnvar())})
- num += 1
- if not quiet:
- print "=" * 70
- percent = int(num and (100.0*someobjnum / num) or 0)
- print "somobjectness: %2d percent" % (percent)
- print "(%d out of %d functions get or return SomeObjects" % (
- someobjnum, num)
- print "=" * 70
-
-
-def update_usession_dir(stabledir = udir.dirpath('usession')):
- from py import path
- try:
- if stabledir.check(dir=1):
- for x in udir.visit(path.checker(file=1)):
- target = stabledir.join(x.relto(udir))
- if target.check():
- target.remove()
- else:
- target.dirpath().ensure(dir=1)
- try:
- target.mklinkto(x)
- except path.Invalid:
- x.copy(target)
- except path.Invalid:
- print "ignored: couldn't link or copy to %s" % stabledir
-
-def run_in_thread(fn, args, cleanup=None, cleanup_args=()):
- def _run_in_thread():
- fn(*args)
- if cleanup is not None:
- cleanup(*cleanup_args)
- return threading.Thread(target=_run_in_thread, args=())
-
-def run_async_server():
- from pypy.translator.tool import graphpage, graphserver
- homepage = graphpage.TranslatorPage(t)
- graphserver.run_server(homepage, port=listen_port, background=True)
- options['-text'] = True
-
-
-if __name__ == '__main__':
-
- options = {'-text': False,
- '-no-c': False,
- '-c': False,
- '-o': False,
- '-no-mark-some-objects': False,
- '-no-a': False,
- '-tcc': False,
- '-no-d': False,
- }
- listen_port = None
- for arg in sys.argv[1:]:
- if arg in ('-h', '--help'):
- print __doc__.strip()
- sys.exit()
- try:
- listen_port = int(arg)
- except ValueError:
- assert arg in options, "unknown option %r" % (arg,)
- options[arg] = True
- if options['-tcc']:
- os.environ['PYPY_CC'] = 'tcc -shared -o "%s.so" "%s.c"'
- if options['-no-d']:
- annmodel.DEBUG = False
-
- def about(x):
- """ interactive debugging helper """
- from pypy.objspace.flow.model import Block, flatten
- if isinstance(x, Block):
- for func, graph in t.flowgraphs.items():
- if x in flatten(graph):
- funcname = func.func_name
- cls = getattr(func, 'class_', None)
- if cls:
- funcname = '%s.%s' % (cls.__name__, funcname)
- print '%s is a %s in the graph of %s' % (x,
- x.__class__.__name__, funcname)
- print 'at %s:%d' % (func.func_globals.get('__name__', '?'),
- func.func_code.co_firstlineno)
- break
- else:
- print '%s is a %s at some unknown location' % (x,
- x.__class__.__name__)
- print 'containing the following operations:'
- for op in x.operations:
- print op
- print '--end--'
- return
- print "don't know about", x
-
- def run_server():
- from pypy.translator.tool.graphpage import TranslatorPage
- from pypy.translator.tool.pygame.graphclient import get_layout
- from pypy.translator.tool.pygame.graphdisplay import GraphDisplay
- import pygame
-
- if not options['-no-mark-some-objects']:
- find_someobjects(t, quiet=True)
-
- display = GraphDisplay(get_layout(TranslatorPage(t)))
- async_quit = display.async_quit
- return display.run, async_quit, pygame.quit
-
- def debug(got_error):
- if got_error:
- import traceback
- exc, val, tb = sys.exc_info()
- print >> sys.stderr
- traceback.print_exception(exc, val, tb)
- print >> sys.stderr
-
- block = getattr(val, '__annotator_block', None)
- if block:
- print '-'*60
- about(block)
- print '-'*60
-
- print >> sys.stderr
- func, args = pdb.post_mortem, (tb,)
- else:
- print '-'*60
- print 'Done.'
- print
- func, args = pdb.set_trace, ()
- if options['-text']:
- func(*args)
- else:
- start, stop, cleanup = run_server()
- debugger = run_in_thread(func, args, stop)
- debugger.start()
- start()
- debugger.join()
- cleanup()
-
- try:
- analyse()
- print '-'*60
- if options['-no-c']:
- print 'Not generating C code.'
- elif options['-c']:
- print 'Generating C code without compiling it...'
- filename = t.ccompile(really_compile=False)
- update_usession_dir()
- print 'Written %s.' % (filename,)
- else:
- print 'Generating and compiling C code...'
- c_entry_point = t.ccompile()
- update_usession_dir()
- if not options['-o']:
- print 'Running!'
- w_result = c_entry_point(compile("a+b","<stuff>","eval"),dummy.W_Obj())
- print w_result
- except:
- debug(True)
- else:
- debug(False)
-
+ return entry_point,[object, dummy.W_Obj]
+
+# _____ Run translated _____
+
+def run(c_entry_point):
+ w_result = c_entry_point(compile("a+b","<stuff>","eval"),dummy.W_Obj())
+ print w_result
+
Copied: pypy/dist/goal/targetpypy1.py (from r10225, pypy/dist/goal/translate_pypy1.py)
==============================================================================
--- pypy/dist/goal/translate_pypy1.py (original)
+++ pypy/dist/goal/targetpypy1.py Fri Apr 1 20:01:31 2005
@@ -1,36 +1,7 @@
-#
-#
-#
-"""
-Command-line options for translate_pypy:
-
- port Listen on the given port number for connexions
- (see pypy/translator/tool/pygame/graphclient.py)
- -text Don't start the Pygame viewer
- -no-a Don't infer annotations, just translate everything
- -no-c Don't generate the C code
- -c Generate the C code, but don't compile it
- -o Generate and compile the C code, but don't run it
- -no-mark-some-objects
- Do not mark functions that have SomeObject in their signature.
- -tcc Equivalent to the envvar PYPY_CC='tcc -shared -o "%s.so" "%s.c"'
- -- http://fabrice.bellard.free.fr/tcc/
- -no-d Disable recording of debugging information
-"""
-import autopath, sys, threading, pdb, os
import buildcache2
from pypy.objspace.std.objspace import StdObjSpace, W_Object
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std import stdtypedef
-from pypy.translator.translator import Translator
-from pypy.annotation import model as annmodel
-from pypy.tool.cache import Cache
-from pypy.annotation.model import SomeObject
-from pypy.tool.udir import udir
-
-# XXX this tries to make compiling faster
-from pypy.translator.tool import buildpyxmodule
-buildpyxmodule.enable_fast_compilation()
# __________ Entry point __________
@@ -39,10 +10,9 @@
w_b = W_IntObject(space, -7)
return mmentrypoint(space, w_a, w_b)
-# __________ Main __________
-
-def analyse(entry_point=entry_point):
- global t, space, mmentrypoint
+# _____ Define and setup target _____
+def target():
+ global space, mmentrypoint
# disable translation of the whole of classobjinterp.py
StdObjSpace.setup_old_style_classes = lambda self: None
space = StdObjSpace()
@@ -63,225 +33,13 @@
# further call the entry_point once to trigger building remaining
# caches (as far as analyzing the entry_point is concerned)
entry_point()
- t = Translator(entry_point, verbose=True, simplifying=True)
- if listen_port:
- run_async_server()
- if not options['-no-a']:
- a = t.annotate([])
- a.simplify()
- t.frozen = True # cannot freeze if we don't have annotations
- if not options['-no-mark-some-objects']:
- options['-no-mark-some-objects'] = True # Do not do this again
- find_someobjects(t)
-
-
-def find_someobjects(translator, quiet=False):
- """Find all functions in that have SomeObject in their signature."""
- annotator = translator.annotator
- if not annotator:
- return # no annotations available
-
- translator.highlight_functions = {}
-
- def is_someobject(var):
- try:
- return annotator.binding(var).__class__ == SomeObject
- except KeyError:
- return False
-
- def short_binding(var):
- try:
- binding = annotator.binding(var)
- except KeyError:
- return "?"
- if binding.is_constant():
- return 'const %s' % binding.__class__.__name__
- else:
- return binding.__class__.__name__
-
- header = True
- items = [(graph.name, func, graph)
- for func, graph in translator.flowgraphs.items()]
- items.sort()
- num = someobjnum = 0
- for graphname, func, graph in items:
- unknown_input_args = len(filter(is_someobject, graph.getargs()))
- unknown_return_value = is_someobject(graph.getreturnvar())
- if unknown_input_args or unknown_return_value:
- someobjnum += 1
- translator.highlight_functions[func] = True
- if not quiet:
- if header:
- header = False
- print "=" * 70
- print "Functions that have SomeObject in their signature"
- print "=" * 70
- print ("%(name)s(%(args)s) -> %(result)s\n"
- "%(filename)s:%(lineno)s\n"
- % {'name': graph.name,
- 'filename': func.func_globals.get('__name__', '?'),
- 'lineno': func.func_code.co_firstlineno,
- 'args': ', '.join(map(short_binding,
- graph.getargs())),
- 'result': short_binding(graph.getreturnvar())})
- num += 1
- if not quiet:
- print "=" * 70
- percent = int(num and (100.0*someobjnum / num) or 0)
- print "somobjectness: %2d percent" % (percent)
- print "(%d out of %d functions get or return SomeObjects" % (
- someobjnum, num)
- print "=" * 70
-
-
-def update_usession_dir(stabledir = udir.dirpath('usession')):
- from py import path
- try:
- if stabledir.check(dir=1):
- for x in udir.visit(path.checker(file=1)):
- target = stabledir.join(x.relto(udir))
- if target.check():
- target.remove()
- else:
- target.dirpath().ensure(dir=1)
- try:
- target.mklinkto(x)
- except path.Invalid:
- x.copy(target)
- except path.Invalid:
- print "ignored: couldn't link or copy to %s" % stabledir
-
-def run_in_thread(fn, args, cleanup=None, cleanup_args=()):
- def _run_in_thread():
- fn(*args)
- if cleanup is not None:
- cleanup(*cleanup_args)
- return threading.Thread(target=_run_in_thread, args=())
-
-def run_async_server():
- from pypy.translator.tool import graphpage, graphserver
- homepage = graphpage.TranslatorPage(t)
- graphserver.run_server(homepage, port=listen_port, background=True)
- options['-text'] = True
-
-
-if __name__ == '__main__':
-
- options = {'-text': False,
- '-no-c': False,
- '-c': False,
- '-o': False,
- '-no-mark-some-objects': False,
- '-no-a': False,
- '-tcc': False,
- '-no-d': False,
- }
- listen_port = None
- for arg in sys.argv[1:]:
- if arg in ('-h', '--help'):
- print __doc__.strip()
- sys.exit()
- try:
- listen_port = int(arg)
- except ValueError:
- assert arg in options, "unknown option %r" % (arg,)
- options[arg] = True
- if options['-tcc']:
- os.environ['PYPY_CC'] = 'tcc -shared -o "%s.so" "%s.c"'
- if options['-no-d']:
- annmodel.DEBUG = False
-
- def about(x):
- """ interactive debugging helper """
- from pypy.objspace.flow.model import Block, flatten
- if isinstance(x, Block):
- for func, graph in t.flowgraphs.items():
- if x in flatten(graph):
- funcname = func.func_name
- cls = getattr(func, 'class_', None)
- if cls:
- funcname = '%s.%s' % (cls.__name__, funcname)
- print '%s is a %s in the graph of %s' % (x,
- x.__class__.__name__, funcname)
- print 'at %s:%d' % (func.func_globals.get('__name__', '?'),
- func.func_code.co_firstlineno)
- break
- else:
- print '%s is a %s at some unknown location' % (x,
- x.__class__.__name__)
- print 'containing the following operations:'
- for op in x.operations:
- print op
- print '--end--'
- return
- print "don't know about", x
-
- def run_server():
- from pypy.translator.tool.graphpage import TranslatorPage
- from pypy.translator.tool.pygame.graphclient import get_layout
- from pypy.translator.tool.pygame.graphdisplay import GraphDisplay
- import pygame
-
- if not options['-no-mark-some-objects']:
- find_someobjects(t, quiet=True)
-
- display = GraphDisplay(get_layout(TranslatorPage(t)))
- async_quit = display.async_quit
- return display.run, async_quit, pygame.quit
-
- def debug(got_error):
- if got_error:
- import traceback
- exc, val, tb = sys.exc_info()
- print >> sys.stderr
- traceback.print_exception(exc, val, tb)
- print >> sys.stderr
- block = getattr(val, '__annotator_block', None)
- if block:
- print '-'*60
- about(block)
- print '-'*60
+ return entry_point, []
- print >> sys.stderr
- func, args = pdb.post_mortem, (tb,)
- else:
- print '-'*60
- print 'Done.'
- print
- func, args = pdb.set_trace, ()
- if options['-text']:
- func(*args)
- else:
- start, stop, cleanup = run_server()
- debugger = run_in_thread(func, args, stop)
- debugger.start()
- start()
- debugger.join()
- cleanup()
+# _____ Run translated _____
- try:
- analyse()
- print '-'*60
- if options['-no-c']:
- print 'Not generating C code.'
- elif options['-c']:
- print 'Generating C code without compiling it...'
- filename = t.ccompile(really_compile=False)
- update_usession_dir()
- print 'Written %s.' % (filename,)
- else:
- print 'Generating and compiling C code...'
- c_entry_point = t.ccompile()
- update_usession_dir()
- if not options['-o']:
- print 'Running!'
- w_result = c_entry_point()
- print w_result
- print w_result.intval
- assert w_result.intval == 42
- except:
- debug(True)
- else:
- debug(False)
-
+def run(c_entry_point):
+ w_result = c_entry_point()
+ print w_result
+ print w_result.intval
+ assert w_result.intval == 42
Modified: pypy/dist/goal/translate_pypy.py
==============================================================================
--- pypy/dist/goal/translate_pypy.py (original)
+++ pypy/dist/goal/translate_pypy.py Fri Apr 1 20:01:31 2005
@@ -4,57 +4,54 @@
"""
Command-line options for translate_pypy:
- port Listen on the given port number for connexions
- (see pypy/translator/tool/pygame/graphclient.py)
- -text Don't start the Pygame viewer
- -no-a Don't infer annotations, just translate everything
- -no-c Don't generate the C code
- -c Generate the C code, but don't compile it
- -o Generate and compile the C code, but don't run it
+ port Listen on the given port number for connexions
+ (see pypy/translator/tool/pygame/graphclient.py)
+ targetspec
+ targetspec.py is a python file defining
+ what is the translation target and setting things up for it,
+ it should have a target function returning an entry_point ...;
+ defaults to targetpypy
+ -text Don't start the Pygame viewer
+ -no-a Don't infer annotations, just translate everything
+ -no-c Don't generate the C code
+ -c Generate the C code, but don't compile it
+ -o Generate and compile the C code, but don't run it
-no-mark-some-objects
- Do not mark functions that have SomeObject in their signature.
- -tcc Equivalent to the envvar PYPY_CC='tcc -shared -o "%s.so" "%s.c"'
- -- http://fabrice.bellard.free.fr/tcc/
- -no-d Disable recording of debugging information
+ Do not mark functions that have SomeObject in their signature.
+ -tcc Equivalent to the envvar PYPY_CC='tcc -shared -o "%s.so" "%s.c"'
+ -- http://fabrice.bellard.free.fr/tcc/
+ -no-d Disable recording of debugging information
"""
import autopath, sys, threading, pdb, os
-import buildcache2
-from pypy.objspace.std.objspace import StdObjSpace, W_Object
-from pypy.objspace.std.intobject import W_IntObject
+
from pypy.translator.translator import Translator
from pypy.annotation import model as annmodel
from pypy.tool.cache import Cache
from pypy.annotation.model import SomeObject
from pypy.tool.udir import udir
+
+
+
# XXX this tries to make compiling faster
from pypy.translator.tool import buildpyxmodule
buildpyxmodule.enable_fast_compilation()
-# __________ Entry point __________
-def entry_point():
- w_a = W_IntObject(space, -6)
- w_b = W_IntObject(space, -7)
- return space.mul(w_a, w_b)
+
# __________ Main __________
-def analyse(entry_point=entry_point):
- global t, space
- # disable translation of the whole of classobjinterp.py
- StdObjSpace.setup_old_style_classes = lambda self: None
- space = StdObjSpace()
- # call cache filling code
- buildcache2.buildcache(space)
- # further call the entry_point once to trigger building remaining
- # caches (as far as analyzing the entry_point is concerned)
- entry_point()
+def analyse(target):
+ global t
+
+ entry_point, inputtypes = target()
+
t = Translator(entry_point, verbose=True, simplifying=True)
if listen_port:
run_async_server()
if not options['-no-a']:
- a = t.annotate([])
+ a = t.annotate(inputtypes)
a.simplify()
t.frozen = True # cannot freeze if we don't have annotations
if not options['-no-mark-some-objects']:
@@ -154,6 +151,8 @@
if __name__ == '__main__':
+ targetspec = 'targetpypy'
+
options = {'-text': False,
'-no-c': False,
'-c': False,
@@ -171,8 +170,11 @@
try:
listen_port = int(arg)
except ValueError:
- assert arg in options, "unknown option %r" % (arg,)
- options[arg] = True
+ if os.path.isfile(arg+'.py'):
+ targetspec = arg
+ else:
+ assert arg in options, "unknown option %r" % (arg,)
+ options[arg] = True
if options['-tcc']:
os.environ['PYPY_CC'] = 'tcc -shared -o "%s.so" "%s.c"'
if options['-no-d']:
@@ -248,7 +250,11 @@
cleanup()
try:
- analyse()
+ targetspec_dic = {}
+ sys.path.insert(0, os.path.dirname(targetspec))
+ execfile(targetspec+'.py',targetspec_dic)
+ print "Analysing target as defined by %s" % targetspec
+ analyse(targetspec_dic['target'])
print '-'*60
if options['-no-c']:
print 'Not generating C code.'
@@ -263,10 +269,7 @@
update_usession_dir()
if not options['-o']:
print 'Running!'
- w_result = c_entry_point()
- print w_result
- print w_result.intval
- assert w_result.intval == 42
+ targetspec_dic['run'](c_entry_point)
except:
debug(True)
else:
More information about the pypy-svn
mailing list