[pypy-svn] r23068 - pypy/dist/pypy/bin
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Feb 6 13:16:19 CET 2006
Author: cfbolz
Date: Mon Feb 6 13:16:17 2006
New Revision: 23068
Modified:
pypy/dist/pypy/bin/translator.py
Log:
remove the unmaintained and probably unused translation cmdline tool
Modified: pypy/dist/pypy/bin/translator.py
==============================================================================
--- pypy/dist/pypy/bin/translator.py (original)
+++ pypy/dist/pypy/bin/translator.py Mon Feb 6 13:16:17 2006
@@ -21,26 +21,8 @@
Some functions are provided for the benefit of interactive testing.
Try dir(snippet) for list of current snippets.
-
-For extra features start this script with a -h option.
-"""
-
-
-extra_help = """Extra options enable features for testing the various backend
-translators. As a sideeffect the entry function of the compiled
-code will be run.
-
-options:
- -h(elp)
- -v(iew flow graph)
- -b<org/c/cl/llvm> (set backend) [default=c]
- -s(show source)
- -C(ompilation disable)
- -t(est compiled)
- [python script] <entry function (default=main())>
"""
-
import autopath, os, sys
from pypy.translator.interactive import Translation
from pypy.rpython.rtyper import *
@@ -48,157 +30,6 @@
import py
-class Options(object):
- available_backends = {'org':'Original source', 'c':'C translation (default)', 'cl':'common lisp translation', 'llvm':'LLVM translation', 'pyrex':'pyrex translation'}
- backend = 'c' #ugly !?!
- python_script = ''
- entry_function = 'main()'
- view_flow_graph = False
- show_source = False
- compile = True
- test_compiled = False
-
- def __init__(self,argv=[]):
- if not argv:
- print extra_help
- sys.exit(0)
-
- for arg in argv:
- if arg[0] == '-':
- option = arg[:2]
-
- if option == '-b':
- new_backend = arg[2:]
- if new_backend in self.available_backends:
- self.backend = new_backend
- else:
- print 'error: unknown backend', new_backend, '. Avaialable backends are:', self.available_backends
- sys.exit(0)
-
- elif option == '-v':
- self.view_flow_graph = True
-
- elif option == '-s':
- self.show_source = True
-
- elif option == '-C':
- self.compile = False
-
- elif option == '-t':
- self.test_compiled = True
-
- else:
- print extra_help
- sys.exit(0)
-
- else:
- if not self.python_script:
- self.python_script = arg
- else:
- self.entry_function = arg
-
-
-def main(argv=[]):
- options = Options(argv)
-
- modname = options.python_script.replace('/', '.')
- if modname[-3:] == '.py':
- modname = modname[:-3]
-
- if modname[0] == '.': #absolute path #ah
- path = py.path.local(options.python_script)
- print path, path.get("basename"), path.get("dirname")
- sys.path.append(path.get("dirname")[0])
- absmodname = path.get("purebasename")[0]
- exec "import %(absmodname)s as testmodule" % locals()
- sys.path.pop()
- else: #relative path
- exec "import %(modname)s as testmodule" % locals()
-
- if '(' in options.entry_function:
- entry_function, arguments = options.entry_function.split('(',1)
- else:
- entry_function, arguments = options.entry_function, ')'
-
- #print 'entry_functionText=',entry_function
- entry_function = getattr(testmodule, entry_function)
- #print 'entry_function=',entry_function
-
- if arguments != ')' and arguments.find(',') == -1:
- arguments = arguments[:-1] + ',)'
- arguments = [argument for argument in eval('('+arguments)]
- #print 'arguments=',arguments
-
- argumentTypes = [type(arg) for arg in arguments]
- #print 'argumentTypes=',argumentTypes
-
- t = Translator(entry_function)
- t.simplify()
- a = t.annotate(argumentTypes)
- a.simplify()
-
- if options.view_flow_graph:
- rtyper = RPythonTyper(t.annotator)
- rtyper.specialize()
- t.view()
- t = Translator(entry_function)
- t.simplify()
- a = t.annotate(argumentTypes)
- a.simplify()
-
- if options.show_source:
- if options.backend == 'org':
- print t.source()
-
- elif options.backend == 'c':
- print t.c()
- #note: this is a workaround until GenC can generate identical code multiple times
- t = Translator(entry_function)
- t.simplify()
- a = t.annotate(argumentTypes)
- a.simplify()
-
- elif options.backend == 'cl':
- print t.cl()
-
- elif options.backend == 'llvm':
- print t.llvm()
- #note: this is a workaround because genllvm calls the RPythonTyper which is not smart enough right now to leave already lltyped blocks alone
- t = Translator(entry_function)
- t.simplify()
- a = t.annotate(argumentTypes)
- a.simplify()
-
- elif options.backend == 'pyrex':
- print t.pyrex()
-
- if options.compile:
- if options.backend == 'c':
- #a.specialize() # use low level operations (for C only)
- f = t.ccompile()
-
- elif options.backend == 'llvm':
- f = t.llvmcompile()
-
- elif options.backend == 'pyrex':
- f = t.pyrexcompile()
-
- else:
- print 'warning: backend', options.backend, 'has no compile phase'
- sys.exit(0)
-
- assert f
- print 'Backend', options.backend, 'compilation successful!'
- backendReturn = t.call(*arguments)
-
- if options.test_compiled:
- pythonReturn = f(*arguments)
- assert backendReturn == pythonReturn
- print 'Backend', options.backend, 'compiled code returns same as python script (%s)' % backendReturn
- else:
- print 'Backend', options.backend, 'compiled code returns (%s)' % backendReturn, '[use -t to perform a sanity check]'
-
-
def setup_readline():
import readline
try:
@@ -228,12 +59,8 @@
os.path.curdir not in sys.path):
sys.path.insert(0, os.getcwd())
- if len(sys.argv) > 1:
- sys.exit(main(sys.argv[1:]))
-
print __doc__
- # 2.3 specific -- sanxiyn
import os
os.putenv("PYTHONINSPECT", "1")
More information about the Pypy-commit
mailing list