Merge in COME_FROM disambiguation ...

from controlflowbranch. Should probably expand to Python2
parsers as well
This commit is contained in:
rocky
2016-10-06 03:27:37 -04:00
parent 4411ecceba
commit 346d8678d2
2 changed files with 0 additions and 40 deletions

View File

@@ -1,38 +0,0 @@
"""
Detect control flow as much as possible.
The basic idea here is to put in explicit end instructions that make
grammar parsing simpler and more precise.
"""
from collections import namedtuple
from xdis.bytecode import Bytecode
control_flow_start = namedtuple('control_flow_start', ['name', 'type', 'offset'])
control_flow_end = namedtuple('control_flow_end', ['name', 'type', 'offset'])
class ControlFlow():
def __init__(self, scanner):
self.scanner = scanner
self.opc = self.scanner.opc
self.setup_ops = self.scanner.setup_ops
self.op_range = self.scanner.op_range
# Control-flow nesting
self.offset_action = {}
self.cf_end = []
def detect_control_flow(self, co):
self.bytecode = Bytecode(co, self.opc)
for inst in self.bytecode:
if inst.opcode in self.setup_ops:
# Use part after SETUP_
name = inst.opname[len('SETUP_'):]
self.offset_action[inst.offset] = control_flow_start(name, 'start', inst.offset)
self.offset_action[inst.argval] = control_flow_end(name, 'end', inst.offset)
pass
pass
# import pprint
# pp = pprint.PrettyPrinter(indent=4)
# pp.pprint(self.offset_action)
return self.offset_action

View File

@@ -29,7 +29,6 @@ from uncompyle6.scanner import Scanner, op_has_argument
from xdis.code import iscode from xdis.code import iscode
from xdis.bytecode import Bytecode from xdis.bytecode import Bytecode
from uncompyle6.scanner import Token, parse_fn_counts from uncompyle6.scanner import Token, parse_fn_counts
from uncompyle6.scanners.controlflow import ControlFlow
# Get all the opcodes into globals # Get all the opcodes into globals
import xdis.opcodes.opcode_33 as op3 import xdis.opcodes.opcode_33 as op3
@@ -192,7 +191,6 @@ class Scanner3(Scanner):
# Format: {target offset: [jump offsets]} # Format: {target offset: [jump offsets]}
jump_targets = self.find_jump_targets() jump_targets = self.find_jump_targets()
offset_action = ControlFlow(self).detect_control_flow(co)
for inst in bytecode: for inst in bytecode:
argval = inst.argval argval = inst.argval