git @ Cat's Eye Technologies SixtyPical / 2ca843e
Begin hooking the fallthru analysis up to the compilation phase. Chris Pressey 3 years ago
3 changed file(s) with 45 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
5757 analyzer = Analyzer(debug=options.debug)
5858 analyzer.analyze_program(program)
5959
60 compilation_roster = None
6061 if options.optimize_fallthru:
6162 from sixtypical.fallthru import FallthruAnalyzer
6263
7172
7273 fa = FallthruAnalyzer(debug=options.debug)
7374 fa.analyze_program(program)
74 routines_list = fa.serialize()
75 dump(routines_list)
75 compilation_roster = fa.serialize()
76 dump(compilation_roster)
7677
7778 if options.analyze_only:
7879 return
115116 for byte in prelude:
116117 emitter.emit(Byte(byte))
117118 compiler = Compiler(emitter)
118 compiler.compile_program(program)
119 compiler.compile_program(program, compilation_roster=compilation_roster)
119120
120121 # If we are outputting a cartridge with boot and BRK address
121122 # at the end, pad to ROM size minus 4 bytes, and emit addresses.
7474
7575 # visitor methods
7676
77 def compile_program(self, program):
77 def compile_program(self, program, compilation_roster=None):
7878 assert isinstance(program, Program)
7979
8080 defn_labels = []
101101 defn_labels.append((defn, label))
102102 self.routine_statics[routine.name] = static_labels
103103
104 self.compile_routine(self.routines['main'])
105 for routine in program.routines:
106 if routine.name != 'main':
107 self.compile_routine(routine)
104 if compilation_roster is None:
105 compilation_roster = [['main']] + [[routine.name] for routine in program.routines if routine.name != 'main']
106
107 for roster_row in compilation_roster:
108 for routine_name in roster_row[0:-1]:
109 self.compile_routine(self.routines[routine_name])
110 routine_name = roster_row[-1]
111 self.compile_routine(self.routines[routine_name])
108112
109113 for location, label in self.trampolines.iteritems():
110114 self.emitter.resolve_label(label)
6363 -> Functionality "Dump fallthru info for SixtyPical program" is implemented by
6464 -> shell command "bin/sixtypical --optimize-fallthru --dump-fallthru-info --analyze-only --traceback %(test-body-file)"
6565
66 -> Functionality "Compile SixtyPical program with fallthru optimization" is implemented by
67 -> shell command "bin/sixtypical --prelude=c64 --optimize-fallthru --traceback %(test-body-file) >/tmp/foo && tests/appliances/bin/dcc6502-adapter </tmp/foo"
68
6669 -> Tests for functionality "Dump fallthru info for SixtyPical program"
6770
6871 A single routine, obviously, falls through to nothing and has nothing fall
221224 = "foo"
222225 = ]
223226 = ]
227
228 -> Tests for functionality "Compile SixtyPical program with fallthru optimization"
229
230 Basic test for actually applying this optimization when compiling SixtyPical programs.
231
232 Note this currently reflects the re-ordering, but does not remove the jmp/rts.
233
234 | define foo routine trashes a, z, n
235 | {
236 | ld a, 0
237 | }
238 |
239 | define bar routine trashes a, z, n
240 | {
241 | ld a, 255
242 | goto foo
243 | }
244 |
245 | define main routine trashes a, z, n
246 | {
247 | goto foo
248 | }
249 = $080D JMP $0811
250 = $0810 RTS
251 = $0811 LDA #$00
252 = $0813 RTS
253 = $0814 LDA #$FF
254 = $0816 JMP $0811
255 = $0819 RTS