def test_guard_descr(self): namespace = {'fdescr': BasicFailDescr()} inp = ''' [i0] guard_true(i0, descr=fdescr) [i0] ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd(), guard_number=True) output = logger.log_loop(loop) assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard0>) [i0]" pure_parse(output) logger = Logger(self.make_metainterp_sd(), guard_number=False) output = logger.log_loop(loop) lastline = output.splitlines()[-1] assert lastline.startswith("guard_true(i0, descr=<") assert not lastline.startswith("guard_true(i0, descr=<Guard")
def test_guard(self): namespace = {'fdescr': BasicFailDescr(4)} inp = ''' [i0] guard_true(i0, descr=fdescr) [i0] ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.ts, guard_number=True) output = logger.log_loop(loop) assert output.splitlines()[-1] == "guard_true(i0, descr=<Guard4>) [i0]" pure_parse(output) def boom(): raise Exception namespace['fdescr'].get_index = boom logger = Logger(self.ts, guard_number=False) output = logger.log_loop(loop) assert output.splitlines()[-1].startswith("guard_true(i0, descr=<")
def test_jump(self): namespace = {'target': LoopToken(3)} inp = ''' [i0] jump(i0, descr=target) ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop) assert output.splitlines()[-1] == "jump(i0, descr=<Loop3>)" pure_parse(output)
def test_jump(self): namespace = {'target': LoopToken(3)} inp = ''' [i0] jump(i0, descr=target) ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.ts) output = logger.log_loop(loop) assert output.splitlines()[-1] == "jump(i0, descr=<Loop3>)" pure_parse(output)
def test_jump(self): namespace = {'target': JitCellToken()} namespace['target'].number = 3 inp = ''' [i0] jump(i0, descr=target) ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop) assert output.splitlines()[-1] == "jump(i0, descr=<Loop3>)" pure_parse(output)
def reparse(self, inp, namespace=None, check_equal=True): """ parse loop once, then log it and parse again. Checks that we get the same thing. """ if namespace is None: namespace = {} loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop, namespace) oloop = pure_parse(output, namespace=namespace) if check_equal: equaloplists(loop.operations, oloop.operations) assert oloop.inputargs == loop.inputargs return logger, loop, oloop
def reparse(self, inp, namespace=None, check_equal=True): """ parse loop once, then log it and parse again. Checks that we get the same thing. """ if namespace is None: namespace = {} loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop, namespace) oloop = pure_parse(output, namespace=namespace) if check_equal: equaloplists(loop.operations, oloop.operations) assert oloop.inputargs == loop.inputargs return loop, oloop
def test_class_name(self): from pypy.rpython.lltypesystem import lltype AbcVTable = lltype.Struct('AbcVTable') abcvtable = lltype.malloc(AbcVTable, immortal=True) namespace = {'Name': abcvtable} inp = ''' [i0] p = new_with_vtable(ConstClass(Name)) ''' loop = pure_parse(inp, namespace=namespace) logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop) assert output.splitlines()[-1].endswith( " = new_with_vtable(ConstClass(Name))") pure_parse(output, namespace=namespace)
def test_ops_offset(self): inp = ''' [i0] i1 = int_add(i0, 1) i2 = int_mul(i1, 2) jump(i2) ''' loop = pure_parse(inp) ops = loop.operations ops_offset = {ops[0]: 10, ops[2]: 30, None: 40} logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop, ops_offset=ops_offset) assert output.strip() == """ [i0] +10: i2 = int_add(i0, 1) i4 = int_mul(i2, 2) +30: jump(i4) +40: --end of the loop-- """.strip()
def test_ops_offset(self): inp = ''' [i0] i1 = int_add(i0, 1) i2 = int_mul(i1, 2) jump(i2) ''' loop = pure_parse(inp) ops = loop.operations ops_offset = { ops[0]: 10, ops[2]: 30, None: 40 } logger = Logger(self.make_metainterp_sd()) output = logger.log_loop(loop, ops_offset=ops_offset) assert output.strip() == """ [i0] +10: i2 = int_add(i0, 1) i4 = int_mul(i2, 2) +30: jump(i4) +40: --end of the loop-- """.strip()