[pypy-svn] r77456 - pypy/trunk/pypy/jit/metainterp/test
antocuni at codespeak.net
antocuni at codespeak.net
Tue Sep 28 17:02:01 CEST 2010
Author: antocuni
Date: Tue Sep 28 17:02:00 2010
New Revision: 77456
Modified:
pypy/trunk/pypy/jit/metainterp/test/oparser.py
pypy/trunk/pypy/jit/metainterp/test/test_oparser.py
Log:
make oparser optionally less strict about what it can parse. This is needed to parse non-optimized loops from the logs
Modified: pypy/trunk/pypy/jit/metainterp/test/oparser.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/oparser.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/oparser.py Tue Sep 28 17:02:00 2010
@@ -63,7 +63,8 @@
class OpParser(object):
def __init__(self, input, cpu, namespace, type_system, boxkinds,
- invent_fail_descr=default_fail_descr):
+ invent_fail_descr=default_fail_descr,
+ nonstrict=False):
self.input = input
self.vars = {}
self.cpu = cpu
@@ -75,6 +76,7 @@
else:
self._cache = {}
self.invent_fail_descr = invent_fail_descr
+ self.nonstrict = nonstrict
self.looptoken = LoopToken()
def get_const(self, name, typ):
@@ -133,11 +135,14 @@
vars = []
for elem in elements:
elem = elem.strip()
- box = self.box_for_var(elem)
- vars.append(box)
- self.vars[elem] = box
+ vars.append(self.newvar(elem))
return vars
+ def newvar(self, elem):
+ box = self.box_for_var(elem)
+ self.vars[elem] = box
+ return box
+
def is_float(self, arg):
try:
float(arg)
@@ -170,6 +175,8 @@
elif arg.startswith('ConstPtr('):
name = arg[len('ConstPtr('):-1]
return self.get_const(name, 'ptr')
+ if arg not in self.vars and self.nonstrict:
+ self.newvar(arg)
return self.vars[arg]
def parse_op(self, line):
@@ -210,7 +217,7 @@
if rop._GUARD_FIRST <= opnum <= rop._GUARD_LAST:
i = line.find('[', endnum) + 1
j = line.find(']', i)
- if i <= 0 or j <= 0:
+ if (i <= 0 or j <= 0) and not self.nonstrict:
raise ParseError("missing fail_args for guard operation")
fail_args = []
if i < j:
@@ -276,11 +283,14 @@
lines = self.input.splitlines()
ops = []
newlines = []
+ first_comment = None
for line in lines:
# for simplicity comments are not allowed on
# debug_merge_point lines
if '#' in line and 'debug_merge_point(' not in line:
if line.lstrip()[0] == '#': # comment only
+ if first_comment is None:
+ first_comment = line
continue
comm = line.rfind('#')
rpar = line.find(')') # assume there's a op(...)
@@ -289,12 +299,12 @@
if not line.strip():
continue # a comment or empty line
newlines.append(line)
- base_indent, inpargs = self.parse_inpargs(newlines[0])
- newlines = newlines[1:]
+ base_indent, inpargs, newlines = self.parse_inpargs(newlines)
num, ops = self.parse_ops(base_indent, newlines, 0)
if num < len(newlines):
raise ParseError("unexpected dedent at line: %s" % newlines[num])
loop = ExtendedTreeLoop("loop")
+ loop.comment = first_comment
loop.token = self.looptoken
loop.operations = ops
loop.inputargs = inpargs
@@ -315,23 +325,27 @@
num += 1
return num, ops
- def parse_inpargs(self, line):
- base_indent = line.find('[')
+ def parse_inpargs(self, lines):
+ line = lines[0]
+ base_indent = len(line) - len(line.lstrip(' '))
line = line.strip()
+ if not line.startswith('[') and self.nonstrict:
+ return base_indent, [], lines
+ lines = lines[1:]
if line == '[]':
- return base_indent, []
- if base_indent == -1 or not line.endswith(']'):
+ return base_indent, [], lines
+ if not line.startswith('[') or not line.endswith(']'):
raise ParseError("Wrong header: %s" % line)
inpargs = self.parse_header_line(line[1:-1])
- return base_indent, inpargs
+ return base_indent, inpargs, lines
def parse(input, cpu=None, namespace=None, type_system='lltype',
boxkinds=None, invent_fail_descr=default_fail_descr,
- no_namespace=False):
+ no_namespace=False, nonstrict=False):
if namespace is None and not no_namespace:
namespace = {}
return OpParser(input, cpu, namespace, type_system, boxkinds,
- invent_fail_descr).parse()
+ invent_fail_descr, nonstrict).parse()
def pure_parse(*args, **kwds):
kwds['invent_fail_descr'] = None
Modified: pypy/trunk/pypy/jit/metainterp/test/test_oparser.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_oparser.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_oparser.py Tue Sep 28 17:02:00 2010
@@ -175,6 +175,10 @@
def test_parse_no_namespace():
loop = parse(example_loop_log, no_namespace=True)
+def test_attach_comment_to_loop():
+ loop = parse(example_loop_log, no_namespace=True)
+ assert loop.comment == '# bridge out of Guard12, 6 ops'
+
def test_parse_new_with_comma():
# this is generated by PYPYJITLOG, check that we can handle it
x = '''
@@ -183,3 +187,19 @@
'''
loop = parse(x)
assert loop.operations[0].getopname() == 'new'
+
+def test_no_fail_args():
+ x = '''
+ [i0]
+ guard_true(i0, descr=<Guard0>)
+ '''
+ loop = parse(x, nonstrict=True)
+ assert loop.operations[0].getfailargs() == []
+
+def test_no_inputargs():
+ x = '''
+ i2 = int_add(i0, i1)
+ '''
+ loop = parse(x, nonstrict=True)
+ assert loop.inputargs == []
+ assert loop.operations[0].getopname() == 'int_add'
More information about the Pypy-commit
mailing list