| 1 |
import py |
| 2 |
import sys |
| 3 |
from rpython.rlib.debug import debug_print |
| 4 |
from rpython.translator.translator import TranslationContext, graphof |
| 5 |
from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES |
| 6 |
from rpython.rlib.rarithmetic import is_valid_int |
| 7 |
|
| 8 |
class BaseCompiledMixin(object): |
| 9 |
|
| 10 |
CPUClass = None |
| 11 |
basic = False |
| 12 |
|
| 13 |
def _get_TranslationContext(self): |
| 14 |
return TranslationContext() |
| 15 |
|
| 16 |
def _compile_and_run(self, t, entry_point, entry_point_graph, args): |
| 17 |
raise NotImplementedError |
| 18 |
|
| 19 |
|
| 20 |
def meta_interp(self, function, args, repeat=1, inline=False, trace_limit=2**14, |
| 21 |
backendopt=None, listcomp=False, **kwds): |
| 22 |
from rpython.jit.metainterp.warmspot import WarmRunnerDesc |
| 23 |
from rpython.annotator.listdef import s_list_of_strings |
| 24 |
from rpython.annotator import model as annmodel |
| 25 |
|
| 26 |
for arg in args: |
| 27 |
assert is_valid_int(arg) |
| 28 |
|
| 29 |
self.pre_translation_hook() |
| 30 |
t = self._get_TranslationContext() |
| 31 |
if listcomp: |
| 32 |
t.config.translation.list_comprehension_operations = True |
| 33 |
|
| 34 |
arglist = ", ".join(['int(argv[%d])' % (i + 1) for i in range(len(args))]) |
| 35 |
if len(args) == 1: |
| 36 |
arglist += ',' |
| 37 |
arglist = '(%s)' % arglist |
| 38 |
if repeat != 1: |
| 39 |
src = py.code.Source(""" |
| 40 |
def entry_point(argv): |
| 41 |
args = %s |
| 42 |
res = function(*args) |
| 43 |
for k in range(%d - 1): |
| 44 |
res = function(*args) |
| 45 |
print(res) |
| 46 |
return 0 |
| 47 |
""" % (arglist, repeat)) |
| 48 |
else: |
| 49 |
src = py.code.Source(""" |
| 50 |
def entry_point(argv): |
| 51 |
args = %s |
| 52 |
res = function(*args) |
| 53 |
print(res) |
| 54 |
return 0 |
| 55 |
""" % (arglist,)) |
| 56 |
exec(src.compile(), locals()) |
| 57 |
|
| 58 |
t.buildannotator().build_types(function, [int] * len(args), |
| 59 |
main_entry_point=True) |
| 60 |
t.buildrtyper().specialize() |
| 61 |
warmrunnerdesc = WarmRunnerDesc(t, translate_support_code=True, |
| 62 |
CPUClass=self.CPUClass, |
| 63 |
**kwds) |
| 64 |
for jd in warmrunnerdesc.jitdrivers_sd: |
| 65 |
jd.warmstate.set_param_threshold(3) |
| 66 |
jd.warmstate.set_param_trace_eagerness(2) |
| 67 |
jd.warmstate.set_param_trace_limit(trace_limit) |
| 68 |
jd.warmstate.set_param_inlining(inline) |
| 69 |
jd.warmstate.set_param_enable_opts(ALL_OPTS_NAMES) |
| 70 |
mixlevelann = warmrunnerdesc.annhelper |
| 71 |
entry_point_graph = mixlevelann.getgraph(entry_point, [s_list_of_strings], |
| 72 |
annmodel.SomeInteger()) |
| 73 |
warmrunnerdesc.finish() |
| 74 |
self.post_translation_hook() |
| 75 |
return self._compile_and_run(t, entry_point, entry_point_graph, args) |
| 76 |
|
| 77 |
def pre_translation_hook(self): |
| 78 |
pass |
| 79 |
|
| 80 |
def post_translation_hook(self): |
| 81 |
pass |
| 82 |
|
| 83 |
def check_loops(self, *args, **kwds): |
| 84 |
pass |
| 85 |
|
| 86 |
def check_loop_count(self, *args, **kwds): |
| 87 |
pass |
| 88 |
|
| 89 |
def check_tree_loop_count(self, *args, **kwds): |
| 90 |
pass |
| 91 |
|
| 92 |
def check_enter_count(self, *args, **kwds): |
| 93 |
pass |
| 94 |
|
| 95 |
def check_enter_count_at_most(self, *args, **kwds): |
| 96 |
pass |
| 97 |
|
| 98 |
def check_max_trace_length(self, *args, **kwds): |
| 99 |
pass |
| 100 |
|
| 101 |
def check_aborted_count(self, *args, **kwds): |
| 102 |
pass |
| 103 |
|
| 104 |
def check_aborted_count_at_least(self, *args, **kwds): |
| 105 |
pass |
| 106 |
|
| 107 |
def interp_operations(self, *args, **kwds): |
| 108 |
py.test.skip("interp_operations test skipped") |
| 109 |
|
| 110 |
|
| 111 |
class CCompiledMixin(BaseCompiledMixin): |
| 112 |
slow = False |
| 113 |
|
| 114 |
def setup_class(cls): |
| 115 |
if cls.slow: |
| 116 |
from rpython.jit.conftest import option |
| 117 |
if not option.run_slow_tests: |
| 118 |
py.test.skip("use --slow to execute this long-running test") |
| 119 |
|
| 120 |
def _get_TranslationContext(self): |
| 121 |
t = TranslationContext() |
| 122 |
t.config.translation.gc = 'boehm' |
| 123 |
t.config.translation.list_comprehension_operations = True |
| 124 |
return t |
| 125 |
|
| 126 |
def _compile_and_run(self, t, entry_point, entry_point_graph, args): |
| 127 |
from rpython.translator.c.genc import CStandaloneBuilder as CBuilder |
| 128 |
|
| 129 |
cbuilder = CBuilder(t, entry_point, config=t.config) |
| 130 |
cbuilder.generate_source() |
| 131 |
self._check_cbuilder(cbuilder) |
| 132 |
exe_name = cbuilder.compile() |
| 133 |
debug_print('---------- Test starting ----------') |
| 134 |
stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args])) |
| 135 |
res = int(stdout) |
| 136 |
debug_print('---------- Test done (%d) ----------' % (res,)) |
| 137 |
return res |
| 138 |
|
| 139 |
def _check_cbuilder(self, cbuilder): |
| 140 |
pass |