~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/jit/codegen/i386/test/test_genc_portal.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import py, os
 
2
from pypy.annotation import model as annmodel
 
3
from pypy.annotation.listdef import s_list_of_strings
 
4
from pypy.rlib.unroll import unrolling_iterable
 
5
from pypy.translator.c.genc import CStandaloneBuilder
 
6
from pypy.jit.timeshifter.test import test_portal
 
7
from pypy.jit.codegen.i386.rgenop import RI386GenOp
 
8
from pypy.rpython.annlowlevel import PseudoHighLevelCallable
 
9
 
 
10
class I386PortalTestMixin(object):
 
11
    RGenOp = RI386GenOp
 
12
 
 
13
    def postprocess_timeshifting(self):
 
14
        annhelper = self.hrtyper.annhelper
 
15
        convert_result = getattr(self.main, 'convert_result', str)
 
16
        annotator = self.rtyper.annotator
 
17
        args_s = [annmodel.lltype_to_annotation(v.concretetype)
 
18
                  for v in self.maingraph.getargs()]
 
19
        retvar = self.maingraph.getreturnvar()
 
20
        s_result = annmodel.lltype_to_annotation(retvar.concretetype)
 
21
        main_fnptr = self.rtyper.type_system.getcallable(self.maingraph)
 
22
        main = PseudoHighLevelCallable(main_fnptr, args_s, s_result)
 
23
        
 
24
        if hasattr(self.main, 'convert_arguments'):
 
25
            decoders = self.main.convert_arguments
 
26
            assert len(decoders) == len(args_s)
 
27
        else:
 
28
            decoders = [int] * len(args_s)
 
29
        decoders = unrolling_iterable(decoders)
 
30
        def ll_main(argv):
 
31
            args = ()
 
32
            i = 1
 
33
            for decoder in decoders:
 
34
                args += (decoder(argv[i]),)
 
35
                i = i + 1
 
36
            try:
 
37
                res = main(*args)
 
38
            except Exception, e:
 
39
                os.write(1, 'EXCEPTION: %s\n' % (e,))
 
40
                return 0
 
41
            os.write(1, convert_result(res) + '\n')
 
42
            return 0
 
43
 
 
44
        annhelper.getgraph(ll_main, [s_list_of_strings],
 
45
                           annmodel.SomeInteger())
 
46
        annhelper.finish()
 
47
        t = self.rtyper.annotator.translator
 
48
        t.config.translation.gc = 'boehm'
 
49
        self.cbuilder = CStandaloneBuilder(t, ll_main, config=t.config)
 
50
        self.cbuilder.generate_source()
 
51
        self.cbuilder.compile()
 
52
        
 
53
    def timeshift_from_portal(self, main, portal, main_args,
 
54
                              inline=None, policy=None,
 
55
                              backendoptimize=False):
 
56
        self.main = main
 
57
        self._timeshift_from_portal(main, portal, main_args,
 
58
                                    inline=inline, policy=policy,
 
59
                                    backendoptimize=backendoptimize)
 
60
        cmdargs = ' '.join([str(arg) for arg in main_args])
 
61
        output = self.cbuilder.cmdexec(cmdargs)
 
62
        lines = output.split()
 
63
        lastline = lines[-1]
 
64
        assert not lastline.startswith('EXCEPTION:')
 
65
        if hasattr(main, 'convert_result'):
 
66
            return lastline
 
67
        else:
 
68
            return int(lastline)    # assume an int
 
69
        
 
70
    def check_insns(self, expected=None, **counts):
 
71
        "Cannot check instructions in the generated assembler."
 
72
    
 
73
class TestPortal(I386PortalTestMixin,
 
74
                 test_portal.TestPortal):
 
75
 
 
76
    # for the individual tests see
 
77
    # ====> ../../../timeshifter/test/test_portal.py
 
78
    pass