Beispiel #1
0
 def translate(self, targetname):
     config = get_combined_translation_config(translating=True)
     config.translation.backend = 'c'
     config.translation.gc = 'boehm'
     targetspec = 'pypy.translator.goal.' + targetname
     mod = __import__(targetspec)
     targetspec_dic = sys.modules[targetspec].__dict__
     t = translator.TranslationContext()
     drv = driver.TranslationDriver.from_targetspec(targetspec_dic,
                                                    config, [],
                                                    empty_translator=t)
     drv.exe_name = None
     drv.proceed('compile')
Beispiel #2
0
def main():
    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 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
            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([
                " %s" % line
                for line in traceback.format_exception(exc, val, tb)
            ])
            block = getattr(val, '__annotator_block', None)
            if block:

                class FileLike:
                    def write(self, s):
                        errmsg.append(" %s" % s)

                errmsg.append("Processing block:\n")
                t.about(block, FileLike())
            log.ERROR(''.join(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 pypy.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 'jitpolicy' not in targetspec_dic:
                raise Exception('target has no jitpolicy defined.')
            if (translateconfig.goals != ['annotate']
                    and translateconfig.goals != ['rtype']):
                drv.set_extra_goals(['pyjitpl'])
            # early check:
            from pypy.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
        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 (use --output=...)' % exe_name)
        except EnvironmentError:
            pass

        goals = translateconfig.goals
        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)
Beispiel #3
0
def main():
    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 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 debug(got_error):
        if prof:
            prof.disable()
            statfilename = 'prof.dump'
            log.info('Dumping profiler stats to: %s' % statfilename)
            prof.dump_stats(statfilename)
        tb = None
        if got_error:
            import traceback
            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, tb)])
            block = getattr(val, '__annotator_block', None)
            if block:
                class FileLike:
                    def write(self, s):
                        errmsg.append(" %s" % s)
                errmsg.append("Processing block:\n")
                t.about(block, FileLike())
            log.ERROR(''.join(errmsg))
        else:
            log.event('Done.')

        if translateconfig.batch:
            log.event("batch mode, not calling interactive helpers")
            return
        
        log.event("start debugger...")

        if not translateconfig.text:
            try:
                t1 = drv.hint_translator
            except (NameError, AttributeError):
                t1 = t
            from pypy.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 translateconfig.goal_options.jit:
            if 'portal' not in targetspec_dic:
               raise Exception('target has no portal defined.') 
            drv.set_extra_goals(['timeshift'])
        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'

        goals = translateconfig.goals
        try:
            drv.proceed(goals)
        finally:
            drv.timer.pprint()
    except SystemExit:
        raise
    except:
        debug(True)
        raise SystemExit(1)
    else:
        debug(False)