Begin hooking the fallthru analysis up to the compilation phase.
Chris Pressey
4 years ago
57 | 57 |
analyzer = Analyzer(debug=options.debug)
|
58 | 58 |
analyzer.analyze_program(program)
|
59 | 59 |
|
|
60 |
compilation_roster = None
|
60 | 61 |
if options.optimize_fallthru:
|
61 | 62 |
from sixtypical.fallthru import FallthruAnalyzer
|
62 | 63 |
|
|
71 | 72 |
|
72 | 73 |
fa = FallthruAnalyzer(debug=options.debug)
|
73 | 74 |
fa.analyze_program(program)
|
74 | |
routines_list = fa.serialize()
|
75 | |
dump(routines_list)
|
|
75 |
compilation_roster = fa.serialize()
|
|
76 |
dump(compilation_roster)
|
76 | 77 |
|
77 | 78 |
if options.analyze_only:
|
78 | 79 |
return
|
|
115 | 116 |
for byte in prelude:
|
116 | 117 |
emitter.emit(Byte(byte))
|
117 | 118 |
compiler = Compiler(emitter)
|
118 | |
compiler.compile_program(program)
|
|
119 |
compiler.compile_program(program, compilation_roster=compilation_roster)
|
119 | 120 |
|
120 | 121 |
# If we are outputting a cartridge with boot and BRK address
|
121 | 122 |
# at the end, pad to ROM size minus 4 bytes, and emit addresses.
|
74 | 74 |
|
75 | 75 |
# visitor methods
|
76 | 76 |
|
77 | |
def compile_program(self, program):
|
|
77 |
def compile_program(self, program, compilation_roster=None):
|
78 | 78 |
assert isinstance(program, Program)
|
79 | 79 |
|
80 | 80 |
defn_labels = []
|
|
101 | 101 |
defn_labels.append((defn, label))
|
102 | 102 |
self.routine_statics[routine.name] = static_labels
|
103 | 103 |
|
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])
|
108 | 112 |
|
109 | 113 |
for location, label in self.trampolines.iteritems():
|
110 | 114 |
self.emitter.resolve_label(label)
|
63 | 63 |
-> Functionality "Dump fallthru info for SixtyPical program" is implemented by
|
64 | 64 |
-> shell command "bin/sixtypical --optimize-fallthru --dump-fallthru-info --analyze-only --traceback %(test-body-file)"
|
65 | 65 |
|
|
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 |
|
66 | 69 |
-> Tests for functionality "Dump fallthru info for SixtyPical program"
|
67 | 70 |
|
68 | 71 |
A single routine, obviously, falls through to nothing and has nothing fall
|
|
221 | 224 |
= "foo"
|
222 | 225 |
= ]
|
223 | 226 |
= ]
|
|
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
|