git @ Cat's Eye Technologies SixtyPical / b33998c
First cut at building fallthru map. Needs tests. Chris Pressey 4 years ago
2 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
5656
5757 analyzer = Analyzer(debug=options.debug)
5858 analyzer.analyze_program(program)
59
60 if options.dump_fallthru_map:
61 import json
62 sys.stdout.write(json.dumps(program.fallthru_map, indent=4, sort_keys=True))
63 sys.stdout.write("\n")
5964
6065 if options.analyze_only:
6166 return
120125 'filenames', metavar='FILENAME', type=str, nargs='+',
121126 help="The SixtyPical source files to compile."
122127 )
123 argparser.add_argument(
124 "--analyze-only",
125 action="store_true",
126 help="Only parse and analyze the program; do not compile it."
127 )
128
128129 argparser.add_argument(
129130 "--origin", type=str, default='0xc000',
130131 help="Location in memory where the `main` routine will be "
142143 "Also sets the origin and format. "
143144 "Options are: c64, vic20, atari2600."
144145 )
146
145147 argparser.add_argument(
146 "--debug",
148 "--analyze-only",
147149 action="store_true",
148 help="Display debugging information when analyzing and compiling."
150 help="Only parse and analyze the program; do not compile it."
151 )
152 argparser.add_argument(
153 "--dump-fallthru-map",
154 action="store_true",
155 help="Dump the fallthru map to stdout after analyzing the program."
149156 )
150157 argparser.add_argument(
151158 "--parse-only",
152159 action="store_true",
153160 help="Only parse the program; do not analyze or compile it."
161 )
162 argparser.add_argument(
163 "--debug",
164 action="store_true",
165 help="Display debugging information when analyzing and compiling."
154166 )
155167 argparser.add_argument(
156168 "--traceback",
309309 def analyze_program(self, program):
310310 assert isinstance(program, Program)
311311 self.routines = {r.location: r for r in program.routines}
312 fallthru_map = {}
312313 for routine in program.routines:
313 self.analyze_routine(routine)
314 context = self.analyze_routine(routine)
315 if context:
316 for encountered_goto in context.encountered_gotos():
317 fallthru_map.setdefault(encountered_goto.name, set()).add(routine.name)
318 program.fallthru_map = dict([(k, list(v)) for k, v in fallthru_map.iteritems()])
314319
315320 def analyze_routine(self, routine):
316321 assert isinstance(routine, Routine)
352357 if ref not in type_.outputs and ref not in type_.trashes and not routine_has_static(routine, ref):
353358 raise ForbiddenWriteError(routine, ref.name)
354359 self.current_routine = None
360 return context
355361
356362 def analyze_block(self, block, context):
357363 assert isinstance(block, Block)