Exemple #1
0
 def match(self, src1, src2, **kwds):
     from pypy.tool.jitlogparser.parser import SimpleParser
     loop = SimpleParser.parse_from_input(src1)
     matcher = OpMatcher(loop.operations)
     try:
         res = matcher.match(src2, **kwds)
         assert res is True
         return True
     except InvalidMatch:
         return False
Exemple #2
0
 def match(self, src1, src2, **kwds):
     from pypy.tool.jitlogparser.parser import SimpleParser
     loop = SimpleParser.parse_from_input(src1)
     matcher = OpMatcher(loop.operations)
     try:
         res = matcher.match(src2, **kwds)
         assert res is True
         return True
     except InvalidMatch:
         return False
Exemple #3
0
 def test_parse_op(self):
     res = OpMatcher.parse_op("  a =   int_add(  b,  3 ) # foo")
     assert res == ("int_add", "a", ["b", "3"], None)
     res = OpMatcher.parse_op("guard_true(a)")
     assert res == ("guard_true", None, ["a"], None)
     res = OpMatcher.parse_op("setfield_gc(p0, i0, descr=<foobar>)")
     assert res == ("setfield_gc", None, ["p0", "i0"], "<foobar>")
     res = OpMatcher.parse_op("i1 = getfield_gc(p0, descr=<foobar>)")
     assert res == ("getfield_gc", "i1", ["p0"], "<foobar>")
     res = OpMatcher.parse_op("p0 = force_token()")
     assert res == ("force_token", "p0", [], None)
Exemple #4
0
 def test_parse_op(self):
     res = OpMatcher.parse_op("  a =   int_add(  b,  3 ) # foo")
     assert res == ("int_add", "a", ["b", "3"], None, True)
     res = OpMatcher.parse_op("guard_true(a)")
     assert res == ("guard_true", None, ["a"], None, True)
     res = OpMatcher.parse_op("setfield_gc(p0, i0, descr=<foobar>)")
     assert res == ("setfield_gc", None, ["p0", "i0"], "<foobar>", True)
     res = OpMatcher.parse_op("i1 = getfield_gc(p0, descr=<foobar>)")
     assert res == ("getfield_gc", "i1", ["p0"], "<foobar>", True)
     res = OpMatcher.parse_op("p0 = force_token()")
     assert res == ("force_token", "p0", [], None, True)
     res = OpMatcher.parse_op("guard_not_invalidated?")
     assert res == ("guard_not_invalidated", None, [], '...', False)
Exemple #5
0
 def test_match_var(self):
     match_var = OpMatcher([]).match_var
     assert match_var('v0', 'V0')
     assert not match_var('v0', 'V1')
     assert match_var('v0', 'V0')
     #
     # for ConstPtr, we allow the same alpha-renaming as for variables
     assert match_var('ConstPtr(ptr0)', 'PTR0')
     assert not match_var('ConstPtr(ptr0)', 'PTR1')
     assert match_var('ConstPtr(ptr0)', 'PTR0')
     #
     # for ConstClass, we want the exact matching
     assert match_var('ConstClass(foo)', 'ConstClass(foo)')
     assert not match_var('ConstClass(bar)', 'v1')
     assert not match_var('v2', 'ConstClass(baz)')
     #
     # the var '_' matches everything (but only on the right, of course)
     assert match_var('v0', '_')
     assert match_var('v0', 'V0')
     assert match_var('ConstPtr(ptr0)', '_')
     py.test.raises(AssertionError, "match_var('_', 'v0')")
Exemple #6
0
    def test_kwargs_non_virtual(self):
        log = self.run("""
        def f(a, b, c):
            pass

        def main(stop):
            d = {'a': 2, 'b': 3, 'c': 4}
            i = 0
            while i < stop:
                f(**d) # ID: call
                i += 1
            return 13
        """, [1000])
        assert log.result == 13
        loop, = log.loops_by_id('call')
        allops = loop.allops()
        calls = [op for op in allops if op.name.startswith('call')]
        assert OpMatcher(calls).match('''
        p93 = call_r(ConstClass(view_as_kwargs), p35, p12, descr=<.*>)
        i103 = call_i(ConstClass(_match_keywords), ConstPtr(ptr52), 0, 0, p94, p98, 0, descr=<.*>)
        ''')
        assert len([op for op in allops if op.name.startswith('new')]) == 1
Exemple #7
0
 def match(self, src1, src2, **kwds):
     from pypy.tool.jitlogparser.parser import SimpleParser
     loop = SimpleParser.parse_from_input(src1)
     matcher = OpMatcher(loop.operations, src=src1)
     return matcher.match(src2, **kwds)