[pypy-svn] r33390 - in pypy/branch/even-more-config3/pypy: config translator translator/goal
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Oct 17 21:42:30 CEST 2006
Author: cfbolz
Date: Tue Oct 17 21:42:29 2006
New Revision: 33390
Modified:
pypy/branch/even-more-config3/pypy/config/pypyoption.py
pypy/branch/even-more-config3/pypy/translator/driver.py
pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py
pypy/branch/even-more-config3/pypy/translator/goal/translate.py
Log:
(pedronis, cfbolz): intermediate check in: refactor translate.py to use
configuration handling (also to generate all the commandline options). Seems to
work so far, more refactorings needed.
Modified: pypy/branch/even-more-config3/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/config/pypyoption.py (original)
+++ pypy/branch/even-more-config3/pypy/config/pypyoption.py Tue Oct 17 21:42:29 2006
@@ -144,13 +144,6 @@
StrOption("cc", "Specify compiler", default='', cmdline="--cc"),
StrOption("profopt", "Specify profile based optimization script",
default="", cmdline="--profopt"),
- BoolOption("batch", "Don't run interactive helpers", default=False,
- cmdline="--batch", negation=False),
- IntOption("huge", "Threshold in the number of functions after which"
- "a local call graph and not a full one is displayed",
- default=100, cmdline="--huge"),
- BoolOption("text", "Don't start the pygame viewer", default=False,
- cmdline="--text", negation=False),
BoolOption("debug_transform", "Perform the debug transformation",
default=False, cmdline=None, negation=False),
@@ -162,6 +155,10 @@
cmdline=None),
BoolOption("list_comprehension_operations", "XXX", default=False,
cmdline=None),
+ ChoiceOption("fork_before",
+ "(UNIX) Create restartable checkpoint before step",
+ ["annotate", "rtype", "backendopt", "database", "source"],
+ default=None, cmdline="--fork-before"),
OptionDescription("backendopt", "Backend Optimization Options", [
BoolOption("print_statistics", "Print statistics while optimizing",
@@ -184,36 +181,6 @@
IntOption("inline_threshold", "Threshold when to inline functions",
default=1, cmdline=None),
]),
- OptionDescription("goals",
- "Goals that should be reached during translation", [
- BoolOption("annotate", "Do type inference", default=False,
- cmdline="-a --annotate", negation=False),
- BoolOption("no_annotate", "Don't do type inference", default=False,
- cmdline="--no-annotate", negation=False),
- BoolOption("rtype", "Do rtyping", default=False,
- cmdline="-t --rtype", negation=False),
- BoolOption("no_rtype", "Don't do rtyping", default=False,
- cmdline="--no-rtype", negation=False),
- BoolOption("backendopt", "Do backend optimizations", default=False,
- cmdline="--backendopt", negation=False),
- BoolOption("no_backenopt", "Don't do backend optimizations",
- default=False, cmdline="--no-backendopt", negation=False),
- BoolOption("source", "Create source", default=False,
- cmdline="-s --source", negation=False),
- BoolOption("no_source", "Don't create source", default=False,
- cmdline="--no-source", negation=False),
- BoolOption("compile", "Compile", default=False,
- cmdline="--compile", negation=False),
- BoolOption("no_compile", "Don't compile", default=False,
- cmdline="--no-compile", negation=False),
- BoolOption("llinterpret", "Interpret the rtyped flow graphs",
- default=False, cmdline="--llinterpret", negation=False),
- ChoiceOption("fork_before",
- "(UNIX) Create restartable checkpoint before step",
- ["annotate", "rtype", "backendopt", "database",
- "source"], default=None, cmdline="--fork-before"),
-
- ]),
]),
])
Modified: pypy/branch/even-more-config3/pypy/translator/driver.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/driver.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/driver.py Tue Oct 17 21:42:29 2006
@@ -533,14 +533,15 @@
goals = self.backend_select_goals(goals)
return self._execute(goals, task_skip = self._maybe_skip())
- def from_targetspec(targetspec_dic, options=None, args=None,
+ def from_targetspec(targetspec_dic, config=None, args=None,
empty_translator=None,
disable=[],
default_goal=None):
if args is None:
args = []
- driver = TranslationDriver(options, default_goal, disable)
+ driver = TranslationDriver(config=config, default_goal=default_goal,
+ disable=disable)
# patch some attributes of the os module to make sure they
# have the same value on every platform.
backend, ts = driver.get_backend_and_type_system()
@@ -575,7 +576,7 @@
# checkpointing support
def _event(self, kind, goal, func):
if kind == 'pre':
- fork_before = self.config.translation.goals.fork_before
+ fork_before = self.config.translation.fork_before
if fork_before:
fork_before, = self.backend_select_goals([fork_before])
if not fork_before in self.done and fork_before == goal:
Modified: pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/targetpypystandalone.py Tue Oct 17 21:42:29 2006
@@ -80,7 +80,7 @@
config = Config(pypy_optiondescription)
opt_parser = py.compat.optparse.OptionParser(usage="target PyPy standalone",
add_help_option=False)
- to_optparse(config, parser=parser)
+ to_optparse(config, useoption=["objspace.*"], parser=parser)
return config, parser
def print_help():
Modified: pypy/branch/even-more-config3/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/even-more-config3/pypy/translator/goal/translate.py (original)
+++ pypy/branch/even-more-config3/pypy/translator/goal/translate.py Tue Oct 17 21:42:29 2006
@@ -8,6 +8,11 @@
import autopath
+from pypy.config.config import to_optparse, OptionDescription, BoolOption, \
+ ArbitraryOption, StrOption, IntOption, Config, \
+ ChoiceOption
+from pypy.config.pypyoption import pypy_optiondescription
+
# dict are not ordered, cheat with #_xyz keys and bunchiter
def OPT(*args):
@@ -89,38 +94,69 @@
}
-defaults = {
- 'help': False,
+GOALS= [
+ ("annotate", "do type inference", "-a --annotate"),
+ ("rtype", "do rtyping", "-t --rtype"),
+ ("backendopt", "do backend optimizations", "--backendopt"),
+ ("source", "create source", "-s --source"),
+ ("compile", "compile", "-c --compile"),
+ ("run", "run the resulting binary", "--run"),
+ ("llinterpret", "interpret the rtyped flow graphs", "--llinterpret"),
+ ]
+
+def goal_options():
+ result = []
+ for name, doc, cmdline in GOALS:
+ result.append(BoolOption(name, doc.title(), default=False, cmdline=cmdline,
+ negation=False))
+ result.append(BoolOption("no_%s" % name, "Don't "+doc, default=False,
+ cmdline="--no-"+name, negation=False))
+ return result
+
+translate_optiondescr = OptionDescription("translate", "XXX", [
+ IntOption("graphserve", """Serve analysis graphs on port number
+(see pypy/translator/tool/pygame/graphclient.py)""", default=0,
+ cmdline="--graphserve"),
+ StrOption("targetspec", "XXX", default='targetpypystandalone',
+ cmdline=None),
+ BoolOption("profile",
+ "cProfile (to debug the speed of the translation process)",
+ default=False,
+ cmdline="--profile"),
+ BoolOption("batch", "Don't run interactive helpers", default=False,
+ cmdline="--batch", negation=False),
+ IntOption("huge", "Threshold in the number of functions after which"
+ "a local call graph and not a full one is displayed",
+ default=100, cmdline="--huge"),
+ BoolOption("text", "Don't start the pygame viewer", default=False,
+ cmdline="--text", negation=False),
+ BoolOption("help", "show this help message and exit", default=False,
+ cmdline="-h --help", negation=False),
+ ArbitraryOption("goals", "XXX",
+ defaultfactory=list),
+ # xxx default goals ['annotate', 'rtype', 'backendopt', 'source', 'compile']
+ ArbitraryOption("skipped_goals", "XXX",
+ defaultfactory=lambda: ['run']),
+ OptionDescription("goal_options",
+ "Goals that should be reached during translation",
+ goal_options()),
+])
- 'targetspec': 'targetpypystandalone',
- 'goals': [],
+OVERRIDES = {
+ 'translation.debug': False,
+ 'translation.insist': False,
+
+ 'translation.gc': 'boehm',
+ 'translation.backend': 'c',
+ 'translation.stackless': False,
+ 'translation.backendopt.raisingop2direct_call' : False,
+ 'translation.backendopt.merge_if_blocks': True,
- 'default_goals': ['annotate', 'rtype', 'backendopt', 'source', 'compile'],
- 'skipped_goals': ['run'],
-
- 'lowmem': False,
-
- 'debug': False,
- 'insist': False,
+ 'translation.cc': None,
+ 'translation.profopt': None,
- 'gc': 'boehm',
- 'backend': 'c',
- 'type_system': None,
- 'stackless': False,
- 'raisingop2direct_call' : False,
- 'merge_if_blocks': True,
-
- 'batch': False,
- 'text': False,
- 'graphserve': None,
- 'huge': 100,
- 'cc': None,
- 'profopt': None,
-
- 'fork_before': None,
- 'profile': False,
- 'debug_transform': False,
+ 'translation.debug_transform': False,
}
import py
@@ -176,88 +212,60 @@
def parse_options_and_load_target():
opt_parser = optparse.OptionParser(usage="%prog [options] [target] [target-specific-options]",
prog="translate",
- formatter=OptHelpFormatter(),
+ #formatter=OptHelpFormatter(),
add_help_option=False)
opt_parser.disable_interspersed_args()
- for group_name, grp_opts in bunchiter(opts):
- grp = opt_parser.add_option_group(group_name)
- for dest, dest_opts in bunchiter(grp_opts):
- for names, descr, choice in dest_opts:
- opt_setup = {'action': 'store',
- 'dest': dest,
- 'help': descr+" %defl"}
- if choice in (GOAL, SKIP_GOAL):
- del opt_setup['dest']
- opt_setup['action'] = 'callback'
- opt_setup['nargs'] = 0
- opt_setup['callback'] = goal_cb
- opt_setup['callback_args'] = (choice is GOAL, dest,)
- elif isinstance(choice, list):
- opt_setup['type'] = 'choice'
- opt_setup['choices'] = choice
- opt_setup['metavar'] = "[%s]" % '|'.join(choice)
- elif isinstance(choice, bool):
- opt_setup['action'] = ['store_false', 'store_true'][choice]
- elif choice is int:
- opt_setup['type'] = 'int'
- elif choice is str:
- opt_setup['type'] = 'string'
- else:
- opt_setup['action'] = 'store_const'
- opt_setup['const'] = choice
-
- grp.add_option(*names, **opt_setup)
-
- # add help back as a flag
- opt_parser.add_option("-h", "--help",
- action="store_true", dest="help",
- help="show this help message and exit")
+ config = Config(pypy_optiondescription,
+ **OVERRIDES)
+ to_optparse(config, parser=opt_parser, useoptions=['translation.*'])
+ translateconfig = Config(translate_optiondescr)
+ to_optparse(translateconfig, parser=opt_parser)
options, args = opt_parser.parse_args()
+ # set goals and skipped_goals
+ for name, _, _ in GOALS:
+ if getattr(translateconfig.goal_options, name):
+ if name not in translateconfig.goals:
+ translateconfig.goals.append(name)
+ if getattr(translateconfig.goal_options, 'no_'+name):
+ if name not in translateconfig.skipped_goals:
+ translateconfig.skipped_goals.append(name)
+
if args:
arg = args[0]
args = args[1:]
if os.path.isfile(arg+'.py'):
assert not os.path.isfile(arg), (
"ambiguous file naming, please rename %s" % arg)
- options.targetspec = arg
+ translateconfig.targetspec = arg
elif os.path.isfile(arg) and arg.endswith('.py'):
- options.targetspec = arg[:-3]
+ translateconfig.targetspec = arg[:-3]
else:
args = [arg] + args
- # for help, applied later
- opt_parser.set_defaults(**defaults)
-
- targetspec = options.ensure_value('targetspec', opt_parser.defaults['targetspec'])
+ targetspec = translateconfig.targetspec
targetspec_dic = load_target(targetspec)
if args and not targetspec_dic.get('take_options', False):
log.WARNING("target specific arguments supplied but will be ignored: %s" % ' '.join(args))
# target specific defaults taking over
+ # xxx change this interface
if 'opt_defaults' in targetspec_dic:
- opt_parser.set_defaults(**targetspec_dic['opt_defaults'])
+ config.translation.override(targetspec_dic['opt_defaults'])
- if options.help:
+ if translateconfig.help:
+ # xxx change interface
opt_parser.print_help()
if 'print_help' in targetspec_dic:
print
targetspec_dic['print_help']()
sys.exit(0)
-
- # apply defaults
- for name, val in opt_parser.defaults.iteritems():
- options.ensure_value(name, val)
-
- # tweak: default_goals into default_goal
- del options.default_goals
- options.default_goal = 'compile'
- return targetspec_dic, options, args
+ return targetspec_dic, translateconfig, config, args
def log_options(options, header="options in effect"):
# list options (xxx filter, filter for target)
@@ -273,20 +281,19 @@
log(str(config))
def main():
- targetspec_dic, options, args = parse_options_and_load_target()
+ targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
from pypy.translator import translator
from pypy.translator import driver
from pypy.translator.tool.pdbplus import PdbPlusShow
- if options.profile:
+ if translateconfig.profile:
from cProfile import Profile
prof = Profile()
prof.enable()
else:
prof = None
- t = translator.TranslationContext()
- t.driver_options = options
+ t = translator.TranslationContext(config=config)
class ServerSetup:
async_server = None
@@ -294,16 +301,16 @@
def __call__(self, port=None, async_only=False):
if self.async_server is not None:
return self.async_server
- elif port is not None:
+ elif port != 0:
from pypy.translator.tool.graphserver import run_async_server
- serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, options, port)
+ serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, translateconfig, port)
return serv_start, serv_show, serv_stop
elif not async_only:
from pypy.translator.tool.graphserver import run_server_for_inprocess_client
- return run_server_for_inprocess_client(t, options)
+ return run_server_for_inprocess_client(t, translateconfig)
server_setup = ServerSetup()
- server_setup(options.graphserve, async_only=True)
+ server_setup(translateconfig.graphserve, async_only=True)
pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands
@@ -330,27 +337,28 @@
else:
log.event('Done.')
- if options.batch:
+ if translateconfig.batch:
log.event("batch mode, not calling interactive helpers")
return
log.event("start debugger...")
- pdb_plus_show.start(tb, server_setup, graphic=not options.text)
+ pdb_plus_show.start(tb, server_setup, graphic=not translateconfig.text)
- log_options(options)
+ log_config(translateconfig)
+ log_config(config)
try:
- drv = driver.TranslationDriver.from_targetspec(targetspec_dic, options, args,
- empty_translator=t,
- disable=options.skipped_goals,
- default_goal='compile')
+ drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args,
+ empty_translator=t,
+ disable=translateconfig.skipped_goals,
+ default_goal='compile')
pdb_plus_show.expose({'drv': drv, 'prof': prof})
if drv.exe_name is None and '__name__' in targetspec_dic:
drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s'
- goals = options.goals
+ goals = translateconfig.goals
drv.proceed(goals)
except SystemExit:
More information about the Pypy-commit
mailing list