def main(): sys.setrecursionlimit(2000) # PyPy can't translate within cpython's 1k limit targetspec_dic, translateconfig, config, args = parse_options_and_load_target() from rpython.translator import translator from rpython.translator import driver from rpython.translator.tool.pdbplus import PdbPlusShow if translateconfig.view: translateconfig.pdb = True if translateconfig.profile: from cProfile import Profile prof = Profile() prof.enable() else: prof = None t = translator.TranslationContext(config=config) pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands def finish_profiling(): if prof: prof.disable() statfilename = 'prof.dump' log.info('Dumping profiler stats to: %s' % statfilename) prof.dump_stats(statfilename) def debug(got_error): tb = None if got_error: import traceback stacktrace_errmsg = ["Error:\n"] exc, val, tb = sys.exc_info() stacktrace_errmsg.extend([" %s" % line for line in traceback.format_tb(tb)]) summary_errmsg = traceback.format_exception_only(exc, val) block = getattr(val, '__annotator_block', None) if block: class FileLike: def write(self, s): summary_errmsg.append(" %s" % s) summary_errmsg.append("Processing block:\n") t.about(block, FileLike()) log.info(''.join(stacktrace_errmsg)) log.ERROR(''.join(summary_errmsg)) else: log.event('Done.') if translateconfig.batch: log.event("batch mode, not calling interactive helpers") return log.event("start debugger...") if translateconfig.view: try: t1 = drv.hint_translator except (NameError, AttributeError): t1 = t from rpython.translator.tool import graphpage page = graphpage.TranslatorPage(t1, translateconfig.huge) page.display_background() pdb_plus_show.start(tb) try: drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args, empty_translator=t, disable=translateconfig.skipped_goals, default_goal='compile') log_config(translateconfig, "translate.py configuration") if config.translation.jit: if (translateconfig.goals != ['annotate'] and translateconfig.goals != ['rtype']): drv.set_extra_goals(['pyjitpl']) # early check: from rpython.jit.backend.detect_cpu import getcpuclassname getcpuclassname(config.translation.jit_backend) log_config(config.translation, "translation configuration") pdb_plus_show.expose({'drv': drv, 'prof': prof}) if config.translation.output: drv.exe_name = config.translation.output elif drv.exe_name is None and '__name__' in targetspec_dic: drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s' # Double check to ensure we are not overwriting the current interpreter goals = translateconfig.goals if not goals or 'compile' in goals: try: this_exe = py.path.local(sys.executable).new(ext='') exe_name = drv.compute_exe_name() samefile = this_exe.samefile(exe_name) assert not samefile, ( 'Output file %s is the currently running ' 'interpreter (please move the executable, and ' 'possibly its associated libpypy-c, somewhere else ' 'before you execute it)' % exe_name) except EnvironmentError: pass try: drv.proceed(goals) finally: drv.timer.pprint() except SystemExit: raise except: finish_profiling() debug(True) raise SystemExit(1) else: finish_profiling() if translateconfig.pdb: debug(False)
def main(): sys.setrecursionlimit( 2000) # PyPy can't translate within cpython's 1k limit targetspec_dic, translateconfig, config, args = parse_options_and_load_target( ) from rpython.translator import translator from rpython.translator import driver from rpython.translator.tool.pdbplus import PdbPlusShow if translateconfig.view: translateconfig.pdb = True if translateconfig.profile: from cProfile import Profile prof = Profile() prof.enable() else: prof = None t = translator.TranslationContext(config=config) pdb_plus_show = PdbPlusShow( t) # need a translator to support extended commands def finish_profiling(): if prof: prof.disable() statfilename = 'prof.dump' log.info('Dumping profiler stats to: %s' % statfilename) prof.dump_stats(statfilename) def debug(got_error): tb = None if got_error: import traceback stacktrace_errmsg = ["Error:\n"] exc, val, tb = sys.exc_info() stacktrace_errmsg.extend( [" %s" % line for line in traceback.format_tb(tb)]) summary_errmsg = traceback.format_exception_only(exc, val) block = getattr(val, '__annotator_block', None) if block: class FileLike: def write(self, s): summary_errmsg.append(" %s" % s) summary_errmsg.append("Processing block:\n") t.about(block, FileLike()) log.info(''.join(stacktrace_errmsg)) log.ERROR(''.join(summary_errmsg)) else: log.event('Done.') if translateconfig.batch: log.event("batch mode, not calling interactive helpers") return log.event("start debugger...") if translateconfig.view: try: t1 = drv.hint_translator except (NameError, AttributeError): t1 = t from rpython.translator.tool import graphpage page = graphpage.TranslatorPage(t1, translateconfig.huge) page.display_background() pdb_plus_show.start(tb) try: drv = driver.TranslationDriver.from_targetspec( targetspec_dic, config, args, empty_translator=t, disable=translateconfig.skipped_goals, default_goal='compile') log_config(translateconfig, "translate.py configuration") if config.translation.jit: if (translateconfig.goals != ['annotate'] and translateconfig.goals != ['rtype']): drv.set_extra_goals(['pyjitpl']) # early check: from rpython.jit.backend.detect_cpu import getcpuclassname getcpuclassname(config.translation.jit_backend) log_config(config.translation, "translation configuration") pdb_plus_show.expose({'drv': drv, 'prof': prof}) if config.translation.output: drv.exe_name = config.translation.output elif drv.exe_name is None and '__name__' in targetspec_dic: drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s' # Double check to ensure we are not overwriting the current interpreter goals = translateconfig.goals if not goals or 'compile' in goals: try: this_exe = py.path.local(sys.executable).new(ext='') exe_name = drv.compute_exe_name() samefile = this_exe.samefile(exe_name) assert not samefile, ( 'Output file %s is the currently running ' 'interpreter (please move the executable, and ' 'possibly its associated libpypy-c, somewhere else ' 'before you execute it)' % exe_name) except EnvironmentError: pass try: drv.proceed(goals) finally: drv.timer.pprint() except SystemExit: raise except: finish_profiling() debug(True) raise SystemExit(1) else: finish_profiling() if translateconfig.pdb: debug(False)