Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74791:1d97ee1c1edd
Date: 2014-12-02 16:33 +0100
http://bitbucket.org/pypy/pypy/changeset/1d97ee1c1edd/
Log: extract a bc_reader.new_instr() method
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -127,11 +127,17 @@
oparg += next_offset
elif opnum in opcode.hasname:
oparg = code.names[oparg]
+ instr = self.new_instr(opnum, oparg, offset)
+ return next_offset, instr
+
+ def new_instr(self, opnum, arg, offset=-1):
+ if not isinstance(opnum, int):
+ opnum = opcode.opmap[opnum]
try:
- op = self.num2cls[opnum](oparg, offset)
+ return self.num2cls[opnum](arg, offset)
except KeyError:
- op = GenericOpcode(self.opnames[opnum], opnum, oparg, offset)
- return next_offset, op
+ return GenericOpcode(self.opnames[opnum], opnum, arg, offset)
+
def _iter_instr(self, code):
self.offset = 0
@@ -344,6 +350,10 @@
def __repr__(self):
return "%s(%s)" % (self.name, self.arg)
+ def __eq__(self, other):
+ # NB: offsets are ignored, for testing convenience
+ return other.num == self.num and other.arg == self.arg
+
class GenericOpcode(BCInstruction):
def __init__(self, name, opcode, arg, offset=-1):
self.name = name
diff --git a/rpython/flowspace/test/test_bytecode.py
b/rpython/flowspace/test/test_bytecode.py
--- a/rpython/flowspace/test/test_bytecode.py
+++ b/rpython/flowspace/test/test_bytecode.py
@@ -9,5 +9,5 @@
else:
return 0
bc_graph = bc_reader.build_flow(bc_reader.build_code(f.__code__))
- print bc_graph.dump()
assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10]
+ assert bc_graph.dump()[0][0] == bc_reader.new_instr('LOAD_FAST', 0)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit