Author: Antonio Cuni <anto.c...@gmail.com> Branch: oparser-mock-model Changeset: r44855:da29984ae88b Date: 2011-06-09 11:37 +0200 http://bitbucket.org/pypy/pypy/changeset/da29984ae88b/
Log: make it possible to use either the "real model", which uses the real BoxInt&co. or the "mock model", which uses mock objects; by default the real one is used, but the jitlogparser (used by the jitviewer) uses the latter diff --git a/pypy/jit/tool/oparser.py b/pypy/jit/tool/oparser.py --- a/pypy/jit/tool/oparser.py +++ b/pypy/jit/tool/oparser.py @@ -3,24 +3,24 @@ in a nicer fashion """ -from pypy.jit.metainterp.history import TreeLoop, BoxInt, ConstInt,\ - ConstObj, ConstPtr, Box, BasicFailDescr, BoxFloat, ConstFloat,\ +from pypy.jit.tool.oparser_model import get_model + +from pypy.jit.metainterp.history import BasicFailDescr, \ LoopToken, get_const_ptr_for_string, get_const_ptr_for_unicode +from pypy.jit.metainterp.history import ConstInt, ConstObj, ConstPtr, ConstFloat from pypy.jit.metainterp.resoperation import rop, ResOperation, \ ResOpWithDescr, N_aryOp, \ UnaryOp, PlainResOp -from pypy.jit.metainterp.typesystem import llhelper + from pypy.jit.codewriter.heaptracker import adr2int from pypy.jit.codewriter import longlong from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython.ootypesystem import ootype + class ParseError(Exception): pass -class Boxes(object): - pass - class ESCAPE_OP(N_aryOp, ResOpWithDescr): OPNUM = -123 @@ -54,37 +54,15 @@ def clone(self): return FORCE_SPILL(self.OPNUM, self.getarglist()[:]) -class ExtendedTreeLoop(TreeLoop): - - def getboxes(self): - def opboxes(operations): - for op in operations: - yield op.result - for box in op.getarglist(): - yield box - def allboxes(): - for box in self.inputargs: - yield box - for box in opboxes(self.operations): - yield box - - boxes = Boxes() - for box in allboxes(): - if isinstance(box, Box): - name = str(box) - setattr(boxes, name, box) - return boxes - - def setvalues(self, **kwds): - boxes = self.getboxes() - for name, value in kwds.iteritems(): - getattr(boxes, name).value = value def default_fail_descr(fail_args=None): return BasicFailDescr() class OpParser(object): + + use_mock_model = False + def __init__(self, input, cpu, namespace, type_system, boxkinds, invent_fail_descr=default_fail_descr, nonstrict=False): @@ -101,6 +79,7 @@ self.invent_fail_descr = invent_fail_descr self.nonstrict = nonstrict self.looptoken = LoopToken() + self.model = get_model(self.use_mock_model) def get_const(self, name, typ): if self._consts is None: @@ -132,16 +111,16 @@ pass if elem.startswith('i'): # integer - box = BoxInt() - _box_counter_more_than(elem[1:]) + box = self.model.BoxInt() + _box_counter_more_than(self.model, elem[1:]) elif elem.startswith('f'): - box = BoxFloat() - _box_counter_more_than(elem[1:]) + box = self.model.BoxFloat() + _box_counter_more_than(self.model, elem[1:]) elif elem.startswith('p'): # pointer - ts = getattr(self.cpu, 'ts', llhelper) + ts = getattr(self.cpu, 'ts', self.model.llhelper) box = ts.BoxRef() - _box_counter_more_than(elem[1:]) + _box_counter_more_than(self.model, elem[1:]) else: for prefix, boxclass in self.boxkinds.iteritems(): if elem.startswith(prefix): @@ -338,7 +317,7 @@ num, ops, last_offset = self.parse_ops(base_indent, newlines, 0) if num < len(newlines): raise ParseError("unexpected dedent at line: %s" % newlines[num]) - loop = ExtendedTreeLoop("loop") + loop = self.model.ExtendedTreeLoop("loop") loop.comment = first_comment loop.token = self.looptoken loop.operations = ops @@ -405,6 +384,6 @@ return parse(*args, **kwds) -def _box_counter_more_than(s): +def _box_counter_more_than(model, s): if s.isdigit(): - Box._counter = max(Box._counter, int(s)+1) + model.Box._counter = max(model.Box._counter, int(s)+1) diff --git a/pypy/jit/tool/oparser_model.py b/pypy/jit/tool/oparser_model.py new file mode 100644 --- /dev/null +++ b/pypy/jit/tool/oparser_model.py @@ -0,0 +1,87 @@ +class Boxes(object): + pass + +def get_real_model(): + class LoopModel(object): + from pypy.jit.metainterp.history import TreeLoop + from pypy.jit.metainterp.history import Box, BoxInt, BoxFloat + from pypy.jit.metainterp.typesystem import llhelper + + return LoopModel + +def get_mock_model(): + class LoopModel(object): + + class TreeLoop(object): + def __init__(self, name): + self.name = name + + class Box(object): + _counter = 0 + type = 'b' + + def __init__(self, value=0): + self.value = value + + def __repr__(self): + result = str(self) + result += '(%s)' % self.value + return result + + def __str__(self): + if not hasattr(self, '_str'): + self._str = '%s%d' % (self.type, Box._counter) + Box._counter += 1 + return self._str + + class BoxInt(Box): + type = 'i' + + class BoxFloat(Box): + type = 'f' + + class BoxRef(Box): + type = 'p' + + class llhelper(object): + pass + + LoopModel.llhelper.BoxRef = LoopModel.BoxRef + + return LoopModel + + +def get_model(use_mock): + if use_mock: + model = get_mock_model() + else: + model = get_real_model() + + class ExtendedTreeLoop(model.TreeLoop): + + def getboxes(self): + def opboxes(operations): + for op in operations: + yield op.result + for box in op.getarglist(): + yield box + def allboxes(): + for box in self.inputargs: + yield box + for box in opboxes(self.operations): + yield box + + boxes = Boxes() + for box in allboxes(): + if isinstance(box, model.Box): + name = str(box) + setattr(boxes, name, box) + return boxes + + def setvalues(self, **kwds): + boxes = self.getboxes() + for name, value in kwds.iteritems(): + getattr(boxes, name).value = value + + model.ExtendedTreeLoop = ExtendedTreeLoop + return model diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py --- a/pypy/tool/jitlogparser/parser.py +++ b/pypy/tool/jitlogparser/parser.py @@ -1,4 +1,5 @@ import re, sys + from pypy.jit.metainterp.resoperation import rop, opname from pypy.jit.tool.oparser import OpParser @@ -51,6 +52,7 @@ # factory method Op = Op + use_mock_model = True @classmethod def parse_from_input(cls, input): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit