Debian Codegraph @

rpython/jit/metainterp/test/strategies.py

raw symbols SCIP
1
2 import sys
3 from hypothesis import strategies
4 from rpython.jit.metainterp.resoperation import InputArgInt, ResOperation, rop
5 from rpython.jit.metainterp.history import ConstInt
6
7 machine_ints = strategies.integers(min_value=-sys.maxint - 1,
8 max_value=sys.maxint)
9 intboxes = strategies.builds(InputArgInt)
10 intconsts = strategies.builds(ConstInt, machine_ints)
11 boxes = intboxes | intconsts
12 boxlists = strategies.lists(boxes, min_size=1).flatmap(
13 lambda cis: strategies.lists(strategies.sampled_from(cis)))
14
15 const_or_box = strategies.sampled_from(['const', 'box'])
16
17 class JitCode(object):
18 def __init__(self, index):
19 self.index = index
20
21 class Frame(object):
22 parent_snapshot = None
23
24 def __init__(self, jitcode, pc, boxes):
25 self.jitcode = jitcode
26 self.pc = pc
27 self.boxes = boxes
28
29 def get_list_of_active_boxes(self, flag):
30 return self.boxes
31
32 def get_arg(draw, all_ops, allow_const=True):
33 if allow_const:
34 tp = draw(const_or_box)
35 if tp == 'const':
36 return draw(intconsts)
37 return draw(strategies.sampled_from(all_ops))
38
39 def gen_int_add(draw, all_ops, framestack):
40 arg0 = get_arg(draw, all_ops)
41 arg1 = get_arg(draw, all_ops)
42 res = ResOperation(rop.INT_ADD, [arg0, arg1])
43 all_ops.add(res)
44 return res
45
46 def gen_guard_true(draw, all_ops, framestack):
47 arg = get_arg(draw, all_ops, allow_const=False)
48 res = ResOperation(rop.GUARD_TRUE, [arg])
49 if draw(strategies.booleans()):
50 s = []
51 for i in range(10):
52 s.append(get_arg(draw, all_ops, allow_const=False))
53 boxes = list(set(s))
54 framestack.append(Frame(JitCode(1), 2, boxes))
55 res.framestack = framestack[:]
56 return res
57
58 resops = strategies.sampled_from([gen_int_add, gen_guard_true])
59
60 @strategies.composite
61 def lists_of_operations(draw, inputboxes=intboxes):
62 size = draw(strategies.integers(min_value=1, max_value=100))
63 inputargs = []
64 for i in range(size):
65 inputargs.append(draw(inputboxes))
66 size = draw(strategies.integers(min_value=1, max_value=100))
67 ops = []
68 all_ops = set(inputargs)
69 framestack = [Frame(JitCode(1), 2, [])]
70 for i in range(size):
71 opgen = draw(resops)
72 ops.append(opgen(draw, all_ops, framestack))
73 return inputargs, ops
74
75 if __name__ == '__main__':
76 import pprint
77 pprint.pprint(lists_of_operations(intboxes).example())