Ejemplo n.º 1
0
    def ensure_operations(self, opstrlist, trace, inthatorder=True):
        oparse = OpParser('', self.cpu, self.namespace, None,
                          None, True, None)
        oplist = []
        for op_str in opstrlist:
            op = oparse.parse_next_op(op_str)
            if not op.returns_void():
                var = op_str.split('=')[0].strip()
                if '[' in var:
                    var = var[:var.find('[')]
                elem = op_str[:len(var)]
                oparse._cache['lltype', elem] = op
            oplist.append(op)
        oplist_i = 0
        match = False
        remap = {}
        last_match = 0
        for i, op in enumerate(trace.operations):
            if oplist_i >= len(oplist):
                break
            curtomatch = oplist[oplist_i]
            if self.match_op(curtomatch, op, remap):
                if not op.returns_void():
                    remap[curtomatch] = op
                oplist_i += 1
                last_match = i

        msg =  "could not find all ops in the trace sequence\n\n"
        if oplist_i != len(oplist):
            l = [str(o) for o in oplist[oplist_i:]]
            msg += "sequence\n  " + '\n  '.join(l)
            msg += "\n\ndoes not match\n  "
            l = [str(o) for o in trace.operations[last_match+1:]]
            msg += '\n  '.join(l)
        assert oplist_i == len(oplist), msg
Ejemplo n.º 2
0
    def ensure_operations(self, opstrlist, trace):
        oparse = OpParser('', self.cpu, self.namespace, None, None, True, None)
        oplist = []
        for op_str in opstrlist:
            op = oparse.parse_next_op(op_str)
            if not op.returns_void():
                var = op_str.split('=')[0].strip()
                if '[' in var:
                    var = var[:var.find('[')]
                elem = op_str[:len(var)]
                oparse._cache['lltype', elem] = op
            oplist.append(op)
        oplist_i = 0
        remap = {}
        last_match = 0
        for i, op in enumerate(trace.operations):
            if oplist_i >= len(oplist):
                break
            curtomatch = oplist[oplist_i]
            if self.match_op(curtomatch, op, remap):
                if not op.returns_void():
                    remap[curtomatch] = op
                oplist_i += 1
                last_match = i

        msg = "could not find all ops in the trace sequence\n\n"
        if oplist_i != len(oplist):
            l = [str(o) for o in oplist[oplist_i:]]
            msg += "sequence\n  " + '\n  '.join(l)
            msg += "\n\ndoes not match\n  "
            l = [str(o) for o in trace.operations[last_match + 1:]]
            msg += '\n  '.join(l)
        assert oplist_i == len(oplist), msg
Ejemplo n.º 3
0
    def assert_contains_sequence(self, loop, instr):
        class Glob(object):
            next = None
            prev = None
            def __repr__(self):
                return '*'
        from rpython.jit.tool.oparser import OpParser, default_fail_descr
        parser = OpParser(instr, self.cpu, self.namespace, None, default_fail_descr, True, None)
        parser.vars = { arg.repr_short(arg._repr_memo) : arg for arg in loop.inputargs}
        operations = []
        last_glob = None
        prev_op = None
        for line in instr.splitlines():
            line = line.strip()
            if line.startswith("#") or \
               line == "":
                continue
            if line.startswith("..."):
                last_glob = Glob()
                last_glob.prev = prev_op
                operations.append(last_glob)
                continue
            op = parser.parse_next_op(line)
            if last_glob is not None:
                last_glob.next = op
                last_glob = None
            operations.append(op)
        def check(op, candidate, rename):
            m = 0
            if isinstance(candidate, Glob):
                if candidate.next is None:
                    return 0 # consumes the rest
                if op.getopnum() != candidate.next.getopnum():
                    return 0
                m = 1
                candidate = candidate.next
            if op.getopnum() == candidate.getopnum():
                for i,arg in enumerate(op.getarglist()):
                    oarg = candidate.getarg(i)
                    if arg in rename:
                        assert rename[arg].same_box(oarg)
                    else:
                        rename[arg] = oarg

                if not op.returns_void():
                    rename[op] = candidate
                m += 1
                return m
            return 0
        j = 0
        rename = {}
        ops = loop.finaloplist()
        for i, op in enumerate(ops):
            candidate = operations[j]
            j += check(op, candidate, rename)
        if isinstance(operations[-1], Glob):
            assert j == len(operations)-1, self.debug_print_operations(loop)
        else:
            assert j == len(operations), self.debug_print_operations(loop)