1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 18:41:35 +00:00

Add a dedicated module for a dedicated FallthruAnalyzer.

This commit is contained in:
Chris Pressey 2018-04-04 11:09:39 +01:00
parent 2be4406964
commit a0d3ea8167
3 changed files with 35 additions and 7 deletions

View File

@ -60,7 +60,12 @@ def process_input_files(filenames, options):
if options.dump_fallthru_map:
import json
sys.stdout.write(json.dumps(program.fallthru_map, indent=4, sort_keys=True))
from sixtypical.fallthru import FallthruAnalyzer
fa = FallthruAnalyzer(debug=options.debug)
fa.analyze_program(program)
sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True))
sys.stdout.write("\n")
if options.analyze_only:
@ -155,6 +160,11 @@ if __name__ == '__main__':
action="store_true",
help="Dump the fallthru map to stdout after analyzing the program."
)
argparser.add_argument(
"--dump-fallthru-ordering",
action="store_true",
help="Dump the fallthru ordering to stdout after analyzing the program."
)
argparser.add_argument(
"--parse-only",
action="store_true",

View File

@ -310,14 +310,9 @@ class Analyzer(object):
def analyze_program(self, program):
assert isinstance(program, Program)
self.routines = {r.location: r for r in program.routines}
fallthru_map = {}
for routine in program.routines:
context = self.analyze_routine(routine)
if context:
encountered_gotos = list(context.encountered_gotos())
if len(encountered_gotos) == 1 and isinstance(encountered_gotos[0].type, RoutineType):
fallthru_map.setdefault(encountered_gotos[0].name, set()).add(routine.name)
program.fallthru_map = dict([(k, sorted(v)) for k, v in fallthru_map.iteritems()])
routine.encountered_gotos = list(context.encountered_gotos()) if context else []
def analyze_routine(self, routine):
assert isinstance(routine, Routine)

View File

@ -0,0 +1,23 @@
# encoding: UTF-8
from sixtypical.model import RoutineType
class FallthruAnalyzer(object):
def __init__(self, debug=False):
self.debug = debug
def analyze_program(self, program):
fallthru_map = {}
for routine in program.routines:
encountered_gotos = list(routine.encountered_gotos)
if len(encountered_gotos) == 1 and isinstance(encountered_gotos[0].type, RoutineType):
fallthru_map.setdefault(encountered_gotos[0].name, set()).add(routine.name)
self.fallthru_map = dict([(k, sorted(v)) for k, v in fallthru_map.iteritems()])
def break_cycles(self):
raise NotImplementedError
def serialize(self):
raise NotImplementedError