Make test as intended. It fails atm. Simplify driver code.
Chris Pressey
2 years ago
60 | 60 |
if options.optimize_fallthru:
|
61 | 61 |
from sixtypical.fallthru import FallthruAnalyzer
|
62 | 62 |
|
63 | |
def dump(data, label=None):
|
64 | |
if not options.dump_fallthru_info:
|
65 | |
return
|
66 | |
if label:
|
67 | |
sys.stdout.write("*** {}:\n".format(label))
|
68 | |
sys.stdout.write(json.dumps(data, indent=4, sort_keys=True, separators=(',', ': ')))
|
69 | |
sys.stdout.write("\n")
|
70 | |
|
71 | 63 |
fa = FallthruAnalyzer(symtab, debug=options.debug)
|
72 | 64 |
fa.analyze_program(program)
|
73 | 65 |
compilation_roster = fa.serialize()
|
74 | |
dump(compilation_roster)
|
|
66 |
if options.dump_fallthru_info:
|
|
67 |
sys.stdout.write(json.dumps(compilation_roster, indent=4, sort_keys=True, separators=(',', ': ')))
|
75 | 68 |
|
76 | 69 |
if options.analyze_only or (options.output is None and not options.run_on):
|
77 | 70 |
return
|
383 | 383 |
|
384 | 384 |
It cannot optimize out the `goto`s if they are different.
|
385 | 385 |
|
386 | |
Note, this currently produces unfortunately unoptimized code,
|
387 | |
because generating code for the "true" branch of an `if` always
|
388 | |
generates a jump out of the `if`, even if the last instruction
|
389 | |
in the "true" branch is a `goto`.
|
390 | |
|
391 | 386 |
| define foo routine trashes a, z, n
|
392 | 387 |
| {
|
393 | 388 |
| ld a, 0
|
|
410 | 405 |
| }
|
411 | 406 |
= $080D RTS
|
412 | 407 |
= $080E LDA #$00
|
413 | |
= $0810 BNE $081A
|
|
408 |
= $0810 BNE $0817
|
414 | 409 |
= $0812 LDA #$01
|
415 | |
= $0814 JMP $081F
|
416 | |
= $0817 JMP $081F
|
417 | |
= $081A LDA #$02
|
418 | |
= $081C JMP $080D
|
419 | |
= $081F LDA #$FF
|
420 | |
= $0821 RTS
|
|
410 |
= $0814 JMP $081C
|
|
411 |
= $0817 LDA #$02
|
|
412 |
= $0819 JMP $080D
|
|
413 |
= $081C LDA #$FF
|
|
414 |
= $081E RTS
|