コード例 #1
0
def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False,
               annotatorpolicy=None, nowrap=False):
    try: 
        func = func.im_func
    except AttributeError: 
        pass
    t = TranslationContext()
    if graph is not None:
        graph.func = func
        ann = t.buildannotator(policy=annotatorpolicy)
        inputcells = [ann.typeannotation(a) for a in annotation]
        ann.build_graph_types(graph, inputcells)
        t.graphs.insert(0, graph)
    else:
        ann = t.buildannotator(policy=annotatorpolicy)
        ann.build_types(func, annotation)

    if getoption('view'):
       t.view()

    t.buildrtyper(type_system="ootype").specialize()
    if backendopt:
        check_virtual_methods(ootype.ROOT)
        backend_optimizations(t)
    
    main_graph = t.graphs[0]

    if getoption('view'):
       t.view()
       
    return _build_gen_from_graph(main_graph, t, exctrans, nowrap)
コード例 #2
0
 def create_assembler(self):
     out = self.tmpfile.open('w')
     if getoption('stdout'):
         out = Tee(sys.stdout, out)
     isnetmodule = self.entrypoint.isnetmodule
     return IlasmGenerator(out, self.assembly_name, self.config,
                           isnetmodule)
コード例 #3
0
ファイル: cts.py プロジェクト: sota/pypy
def _get_from_dict(d, key, error):
    try:
        return d[key]
    except KeyError:
        if getoption('nostop'):
            log.WARNING(error)
            return key
        else:
            assert False, error
コード例 #4
0
def _get_from_dict(d, key, error):
    try:
        return d[key]
    except KeyError:
        if getoption('nostop'):
            log.WARNING(error)
            return key
        else:
            assert False, error
コード例 #5
0
ファイル: gencli.py プロジェクト: sota/pypy
    def build_exe(self):        
        if getoption('source'):
            return None

        pypy_dll = get_pypy_dll() # get or recompile pypy.dll
        shutil.copy(pypy_dll, self.tmpdir.strpath)

        ilasm = SDK.ilasm()
        tmpfile = self.tmpfile.strpath
        self.outfile = self.entrypoint.output_filename(tmpfile)
        argv = [tmpfile,'/output:' + self.outfile] + self.entrypoint.ilasm_flags()
        self._exec_helper(ilasm, argv,
                          'ilasm failed to assemble (%s):\n%s\n%s',
                          timeout = 900)
        # Mono's ilasm occasionally deadlocks.  We set a timer to avoid
        # blocking automated test runs forever.


        if getoption('verify'):
            peverify = SDK.peverify()
            self._exec_helper(peverify, [outfile], 'peverify failed to verify (%s):\n%s\n%s')
        return self.outfile
コード例 #6
0
def _build_gen_from_graph(graph, t, exctrans=False, nowrap=False, standalone=False):
    from rpython.translator.cli.entrypoint import get_entrypoint
    
    if getoption('wd'):
        tmpdir = py.path.local('.')
    else:
        tmpdir = udir

    if standalone:
        ep = get_entrypoint(graph)
    else:
        ep = TestEntryPoint(graph, not nowrap)
        
    return GenCli(tmpdir, t, ep, exctrans=exctrans)
コード例 #7
0
    def build_exe(self):
        if getoption('source'):
            return None

        pypy_dll = get_pypy_dll()  # get or recompile pypy.dll
        shutil.copy(pypy_dll, self.tmpdir.strpath)

        ilasm = SDK.ilasm()
        tmpfile = self.tmpfile.strpath
        self.outfile = self.entrypoint.output_filename(tmpfile)
        argv = [tmpfile, '/output:' + self.outfile
                ] + self.entrypoint.ilasm_flags()
        self._exec_helper(ilasm,
                          argv,
                          'ilasm failed to assemble (%s):\n%s\n%s',
                          timeout=900)
        # Mono's ilasm occasionally deadlocks.  We set a timer to avoid
        # blocking automated test runs forever.

        if getoption('verify'):
            peverify = SDK.peverify()
            self._exec_helper(peverify, [outfile],
                              'peverify failed to verify (%s):\n%s\n%s')
        return self.outfile
コード例 #8
0
    def run(self, *args):
        if self._exe is None:
            py.test.skip("Compilation disabled")

        if getoption('norun'):
            py.test.skip("Execution disabled")

        arglist = SDK.runtime() + [self._exe] + map(str, args)
        env = os.environ.copy()
        env['LANG'] = 'C'
        mono = subprocess.Popen(arglist, stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE, env=env)
        stdout, stderr = mono.communicate()
        retval = mono.wait()
        return stdout, stderr, retval
コード例 #9
0
ファイル: function.py プロジェクト: sota/pypy-old
 def _trace_enabled(self):
     return getoption('trace')
コード例 #10
0
ファイル: function.py プロジェクト: sota/pypy
 def _trace_enabled(self):
     return getoption('trace')
コード例 #11
0
    def render(self, ilasm):
        ilasm.begin_function('main', [('string[]', 'argv')], 'void', True, 'static')

        RETURN_TYPE = self.graph.getreturnvar().concretetype
        return_type = self.cts.lltype_to_cts(RETURN_TYPE)
        if return_type != CTS.types.void:
            ilasm.locals([(return_type, 'res')])

        if self.wrap_exceptions:
            ilasm.begin_try()

        # convert string arguments to their true type
        for i, arg in enumerate(self.graph.getargs()):
            ilasm.opcode('ldarg.0')
            ilasm.opcode('ldc.i4 %d' % i)
            ilasm.opcode('ldelem.ref')
            arg_type, arg_var = self.cts.llvar_to_cts(arg)
            self.__call_convert_method(ilasm, arg_type)

        # call the function and convert the result to a string containing a valid python expression
        ilasm.call(self.cts.graph_to_signature(self.graph))
        if return_type != CTS.types.void:
            ilasm.opcode('stloc', 'res')
        if self.wrap_exceptions:
            ilasm.leave('check_etrafo_exception')
        else:
            ilasm.leave('print_result')

        if self.wrap_exceptions:
            ilasm.end_try()

            for exc in ('[mscorlib]System.Exception', 'exceptions.Exception'):
                ilasm.begin_catch(exc)
                if getoption('nowrap'):
                    ilasm.opcode('throw')
                else:
                    ilasm.call('string class [pypylib]pypy.test.Result::FormatException(object)')
                    ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')        
                    ilasm.leave('return')
                ilasm.end_catch()

            # check for exception tranformer exceptions
            ilasm.label('check_etrafo_exception')
            if hasattr(self.db, 'exceptiontransformer'):
                ilasm.opcode('call', 'bool rpyexc_occured()')
                ilasm.opcode('brfalse', 'print_result') # no exceptions
                ilasm.opcode('call', '[mscorlib]System.Object rpyexc_fetch_value()')
                ilasm.call('string class [pypylib]pypy.test.Result::FormatException(object)')
                ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')
                ilasm.opcode('br', 'return')
            else:
                ilasm.opcode('br', 'print_result')

        ilasm.label('print_result')
        if return_type != CTS.types.void:
            ilasm.opcode('ldloc', 'res')
        format_object(RETURN_TYPE, self.cts, ilasm)
        ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')

        ilasm.label('return')
        ilasm.opcode('ret')
        ilasm.end_function()
        self.db.pending_function(self.graph)
コード例 #12
0
ファイル: gencli.py プロジェクト: sota/pypy
 def create_assembler(self):
     out = self.tmpfile.open('w')
     if getoption('stdout'):
         out = Tee(sys.stdout, out)
     isnetmodule = self.entrypoint.isnetmodule
     return IlasmGenerator(out, self.assembly_name, self.config, isnetmodule)