git @ Cat's Eye Technologies SixtyPical / 4755847
Add more test cases. Chris Pressey 3 years ago
2 changed file(s) with 102 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
443443 self.scanner.scan()
444444 dest = self.locexpr()
445445 return SingleOp(self.scanner.line_number, opcode=opcode, dest=dest, src=None)
446 elif self.scanner.token in ("nop"):
446 elif self.scanner.token in ("nop",):
447447 opcode = self.scanner.token
448448 self.scanner.scan()
449449 return SingleOp(self.scanner.line_number, opcode=opcode, dest=None, src=None)
212212 = ]
213213 = ]
214214
215 If, however, they are the same goto, one can be optimized away.
216
217 | define foo routine trashes a, z, n
218 | {
219 | ld a, 0
220 | if z {
221 | ld a, 1
222 | goto bar
223 | } else {
224 | ld a, 2
225 | goto bar
226 | }
227 | }
228 |
229 | define bar routine trashes a, z, n
230 | {
231 | ld a, 255
232 | }
233 |
234 | define main routine trashes a, z, n
235 | {
236 | }
237 = [
238 = [
239 = "main"
240 = ],
241 = [
242 = "foo",
243 = "bar"
244 = ]
245 = ]
246
215247 Similarly, a tail call to a vector can't be turned into a fallthru,
216248 because we don't necessarily know what actual routine the vector contains.
217249
304336
305337 Basic test for actually applying this optimization when compiling SixtyPical programs.
306338
307 Note this currently reflects the re-ordering, but does not remove the jmp/rts.
308
309339 | define foo routine trashes a, z, n
310340 | {
311341 | ld a, 0
325355 = $080F RTS
326356 = $0810 LDA #$FF
327357 = $0812 JMP $080D
358
359 It can optimize out one of the `goto`s if they are the same.
360
361 | define foo routine trashes a, z, n
362 | {
363 | ld a, 0
364 | if z {
365 | ld a, 1
366 | goto bar
367 | } else {
368 | ld a, 2
369 | goto bar
370 | }
371 | }
372 |
373 | define bar routine trashes a, z, n
374 | {
375 | ld a, 255
376 | }
377 |
378 | define main routine trashes a, z, n
379 | {
380 | }
381 = $080D RTS
382 = $080E LDA #$00
383 = $0810 BNE $0817
384 = $0812 LDA #$01
385 = $0814 JMP $0819
386 = $0817 LDA #$02
387 = $0819 LDA #$FF
388 = $081B RTS
389
390 It cannot optimize out the `goto`s if they are different.
391
392 Note, this currently produces unfortunately unoptimized code,
393 because generating code for the "true" branch of an `if` always
394 generates a jump out of the `if`, even if the last instruction
395 in the "true" branch is a `goto`.
396
397 | define foo routine trashes a, z, n
398 | {
399 | ld a, 0
400 | if z {
401 | ld a, 1
402 | goto bar
403 | } else {
404 | ld a, 2
405 | goto main
406 | }
407 | }
408 |
409 | define bar routine trashes a, z, n
410 | {
411 | ld a, 255
412 | }
413 |
414 | define main routine trashes a, z, n
415 | {
416 | }
417 = $080D RTS
418 = $080E LDA #$FF
419 = $0810 RTS
420 = $0811 LDA #$00
421 = $0813 BNE $081D
422 = $0815 LDA #$01
423 = $0817 JMP $080E
424 = $081A JMP $0822
425 = $081D LDA #$02
426 = $081F JMP $080D