From 9a707c250e618c070c9c74ffbaba45a5041148d9 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 9 Apr 2019 21:30:21 +0200 Subject: [PATCH] Added pointer cast test --- src/main/fragment/_deref_pwsc1=vwsc2.asm | 4 + .../dk/camelot64/kickc/test/TestPrograms.java | 5 + src/test/ref/pointer-cast.asm | 63 ++ src/test/ref/pointer-cast.cfg | 30 + src/test/ref/pointer-cast.log | 642 ++++++++++++++++++ src/test/ref/pointer-cast.sym | 22 + 6 files changed, 766 insertions(+) create mode 100644 src/main/fragment/_deref_pwsc1=vwsc2.asm create mode 100644 src/test/ref/pointer-cast.asm create mode 100644 src/test/ref/pointer-cast.cfg create mode 100644 src/test/ref/pointer-cast.log create mode 100644 src/test/ref/pointer-cast.sym diff --git a/src/main/fragment/_deref_pwsc1=vwsc2.asm b/src/main/fragment/_deref_pwsc1=vwsc2.asm new file mode 100644 index 000000000..e8b915e3e --- /dev/null +++ b/src/main/fragment/_deref_pwsc1=vwsc2.asm @@ -0,0 +1,4 @@ +lda #<{c2} +sta {c1} +lda #>{c2} +sta {c1}+1 \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 9cb4d73bd..c3d4cfe81 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -32,6 +32,11 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testPointerCast() throws IOException, URISyntaxException { + compileAndCompare("pointer-cast"); + } + @Test public void testLiteralStrings() throws IOException, URISyntaxException { compileAndCompare("literal-strings"); diff --git a/src/test/ref/pointer-cast.asm b/src/test/ref/pointer-cast.asm new file mode 100644 index 000000000..282ae1b8b --- /dev/null +++ b/src/test/ref/pointer-cast.asm @@ -0,0 +1,63 @@ +// Tests casting pointer types to other pointer types +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .label ub_screen = $400 + .label sb_screen = $428 + .label uw_screen = $450 + .label sw_screen = $478 + .const ub = $29 + .const sb = -$29 + .const uw = $3000 + .const sw = -$3000 +main: { + lda #ub + sta ub_screen + lda #sb + sta ub_screen+1 + lda #uw + sta ub_screen+2+1 + lda #sw + sta ub_screen+4+1 + lda #ub + sta sb_screen + lda #sb + sta sb_screen+1 + lda #uw + sta sb_screen+2+1 + lda #sw + sta sb_screen+4+1 + lda #ub + sta uw_screen + lda #sb + sta uw_screen+1 + lda #uw + sta uw_screen+2+1 + lda #sw + sta uw_screen+4+1 + lda #ub + sta sw_screen + lda #sb + sta sw_screen+1 + lda #uw + sta sw_screen+2+1 + lda #sw + sta sw_screen+4+1 + rts +} diff --git a/src/test/ref/pointer-cast.cfg b/src/test/ref/pointer-cast.cfg new file mode 100644 index 000000000..66602d008 --- /dev/null +++ b/src/test/ref/pointer-cast.cfg @@ -0,0 +1,30 @@ +@begin: scope:[] from + [0] phi() + to:@1 +@1: scope:[] from @begin + [1] phi() + [2] call main + to:@end +@end: scope:[] from @1 + [3] phi() +main: scope:[main] from @1 + [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 + [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 + [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 + [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 + [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + to:main::@return +main::@return: scope:[main] from main + [20] return + to:@return diff --git a/src/test/ref/pointer-cast.log b/src/test/ref/pointer-cast.log new file mode 100644 index 000000000..7a4c4d411 --- /dev/null +++ b/src/test/ref/pointer-cast.log @@ -0,0 +1,642 @@ +Identified constant variable (byte*) ub_screen +Identified constant variable (signed byte*) sb_screen +Identified constant variable (word*) uw_screen +Identified constant variable (signed word*) sw_screen +Identified constant variable (byte) ub +Identified constant variable (word) uw + +CONTROL FLOW GRAPH SSA +@begin: scope:[] from + (byte*) ub_screen#0 ← ((byte*)) (word/signed word/dword/signed dword) $400 + (signed byte*) sb_screen#0 ← ((signed byte*)) (word/signed word/dword/signed dword) $428 + (word*) uw_screen#0 ← ((word*)) (word/signed word/dword/signed dword) $450 + (signed word*) sw_screen#0 ← ((signed word*)) (word/signed word/dword/signed dword) $478 + (byte) ub#0 ← (byte/signed byte/word/signed word/dword/signed dword) $29 + (signed byte/signed word/signed dword~) $0 ← - (byte/signed byte/word/signed word/dword/signed dword) $29 + (signed byte) sb#0 ← (signed byte/signed word/signed dword~) $0 + (word) uw#0 ← (word/signed word/dword/signed dword) $3000 + (signed word/signed dword~) $1 ← - (word/signed word/dword/signed dword) $3000 + (signed word) sw#0 ← (signed word/signed dword~) $1 + to:@1 +main: scope:[main] from @1 + (signed word) sw#1 ← phi( @1/(signed word) sw#2 ) + (signed byte) sb#1 ← phi( @1/(signed byte) sb#2 ) + (byte*~) main::$0 ← ((byte*)) (byte*) ub_screen#0 + *((byte*~) main::$0) ← (byte) ub#0 + (signed byte*~) main::$1 ← ((signed byte*)) (byte*) ub_screen#0 + (signed byte*~) main::$2 ← (signed byte*~) main::$1 + (byte/signed byte/word/signed word/dword/signed dword) 1 + *((signed byte*~) main::$2) ← (signed byte) sb#1 + (word*~) main::$3 ← ((word*)) (byte*) ub_screen#0 + (word*~) main::$4 ← (word*~) main::$3 + (byte/signed byte/word/signed word/dword/signed dword) 2 + *((word*~) main::$4) ← (word) uw#0 + (signed word*~) main::$5 ← ((signed word*)) (byte*) ub_screen#0 + (signed word*~) main::$6 ← (signed word*~) main::$5 + (byte/signed byte/word/signed word/dword/signed dword) 4 + *((signed word*~) main::$6) ← (signed word) sw#1 + (byte*~) main::$7 ← ((byte*)) (signed byte*) sb_screen#0 + *((byte*~) main::$7) ← (byte) ub#0 + (signed byte*~) main::$8 ← ((signed byte*)) (signed byte*) sb_screen#0 + (signed byte*~) main::$9 ← (signed byte*~) main::$8 + (byte/signed byte/word/signed word/dword/signed dword) 1 + *((signed byte*~) main::$9) ← (signed byte) sb#1 + (word*~) main::$10 ← ((word*)) (signed byte*) sb_screen#0 + (word*~) main::$11 ← (word*~) main::$10 + (byte/signed byte/word/signed word/dword/signed dword) 2 + *((word*~) main::$11) ← (word) uw#0 + (signed word*~) main::$12 ← ((signed word*)) (signed byte*) sb_screen#0 + (signed word*~) main::$13 ← (signed word*~) main::$12 + (byte/signed byte/word/signed word/dword/signed dword) 4 + *((signed word*~) main::$13) ← (signed word) sw#1 + (byte*~) main::$14 ← ((byte*)) (word*) uw_screen#0 + *((byte*~) main::$14) ← (byte) ub#0 + (signed byte*~) main::$15 ← ((signed byte*)) (word*) uw_screen#0 + (signed byte*~) main::$16 ← (signed byte*~) main::$15 + (byte/signed byte/word/signed word/dword/signed dword) 1 + *((signed byte*~) main::$16) ← (signed byte) sb#1 + (word*~) main::$17 ← ((word*)) (word*) uw_screen#0 + (word*~) main::$18 ← (word*~) main::$17 + (byte/signed byte/word/signed word/dword/signed dword) 2 + *((word*~) main::$18) ← (word) uw#0 + (signed word*~) main::$19 ← ((signed word*)) (word*) uw_screen#0 + (signed word*~) main::$20 ← (signed word*~) main::$19 + (byte/signed byte/word/signed word/dword/signed dword) 4 + *((signed word*~) main::$20) ← (signed word) sw#1 + (byte*~) main::$21 ← ((byte*)) (signed word*) sw_screen#0 + *((byte*~) main::$21) ← (byte) ub#0 + (signed byte*~) main::$22 ← ((signed byte*)) (signed word*) sw_screen#0 + (signed byte*~) main::$23 ← (signed byte*~) main::$22 + (byte/signed byte/word/signed word/dword/signed dword) 1 + *((signed byte*~) main::$23) ← (signed byte) sb#1 + (word*~) main::$24 ← ((word*)) (signed word*) sw_screen#0 + (word*~) main::$25 ← (word*~) main::$24 + (byte/signed byte/word/signed word/dword/signed dword) 2 + *((word*~) main::$25) ← (word) uw#0 + (signed word*~) main::$26 ← ((signed word*)) (signed word*) sw_screen#0 + (signed word*~) main::$27 ← (signed word*~) main::$26 + (byte/signed byte/word/signed word/dword/signed dword) 4 + *((signed word*~) main::$27) ← (signed word) sw#1 + to:main::@return +main::@return: scope:[main] from main + return + to:@return +@1: scope:[] from @begin + (signed word) sw#2 ← phi( @begin/(signed word) sw#0 ) + (signed byte) sb#2 ← phi( @begin/(signed byte) sb#0 ) + call main + to:@2 +@2: scope:[] from @1 + to:@end +@end: scope:[] from @2 + +SYMBOL TABLE SSA +(signed byte/signed word/signed dword~) $0 +(signed word/signed dword~) $1 +(label) @1 +(label) @2 +(label) @begin +(label) @end +(void()) main() +(byte*~) main::$0 +(signed byte*~) main::$1 +(word*~) main::$10 +(word*~) main::$11 +(signed word*~) main::$12 +(signed word*~) main::$13 +(byte*~) main::$14 +(signed byte*~) main::$15 +(signed byte*~) main::$16 +(word*~) main::$17 +(word*~) main::$18 +(signed word*~) main::$19 +(signed byte*~) main::$2 +(signed word*~) main::$20 +(byte*~) main::$21 +(signed byte*~) main::$22 +(signed byte*~) main::$23 +(word*~) main::$24 +(word*~) main::$25 +(signed word*~) main::$26 +(signed word*~) main::$27 +(word*~) main::$3 +(word*~) main::$4 +(signed word*~) main::$5 +(signed word*~) main::$6 +(byte*~) main::$7 +(signed byte*~) main::$8 +(signed byte*~) main::$9 +(label) main::@return +(signed byte) sb +(signed byte) sb#0 +(signed byte) sb#1 +(signed byte) sb#2 +(signed byte*) sb_screen +(signed byte*) sb_screen#0 +(signed word) sw +(signed word) sw#0 +(signed word) sw#1 +(signed word) sw#2 +(signed word*) sw_screen +(signed word*) sw_screen#0 +(byte) ub +(byte) ub#0 +(byte*) ub_screen +(byte*) ub_screen#0 +(word) uw +(word) uw#0 +(word*) uw_screen +(word*) uw_screen#0 + +Culled Empty Block (label) @2 +Successful SSA optimization Pass2CullEmptyBlocks +Alias (signed byte) sb#0 = (signed byte/signed word/signed dword~) $0 (signed byte) sb#2 +Alias (signed word) sw#0 = (signed word/signed dword~) $1 (signed word) sw#2 +Successful SSA optimization Pass2AliasElimination +Redundant Phi (signed byte) sb#1 (signed byte) sb#0 +Redundant Phi (signed word) sw#1 (signed word) sw#0 +Successful SSA optimization Pass2RedundantPhiElimination +Constant (const byte*) ub_screen#0 = ((byte*))$400 +Constant (const signed byte*) sb_screen#0 = ((signed byte*))$428 +Constant (const word*) uw_screen#0 = ((word*))$450 +Constant (const signed word*) sw_screen#0 = ((signed word*))$478 +Constant (const byte) ub#0 = $29 +Constant (const signed byte) sb#0 = -$29 +Constant (const word) uw#0 = $3000 +Constant (const signed word) sw#0 = -$3000 +Successful SSA optimization Pass2ConstantIdentification +Constant (const byte*) main::$0 = ((byte*))ub_screen#0 +Constant (const signed byte*) main::$1 = ((signed byte*))ub_screen#0 +Constant (const word*) main::$3 = ((word*))ub_screen#0 +Constant (const signed word*) main::$5 = ((signed word*))ub_screen#0 +Constant (const byte*) main::$7 = ((byte*))sb_screen#0 +Constant (const signed byte*) main::$8 = ((signed byte*))sb_screen#0 +Constant (const word*) main::$10 = ((word*))sb_screen#0 +Constant (const signed word*) main::$12 = ((signed word*))sb_screen#0 +Constant (const byte*) main::$14 = ((byte*))uw_screen#0 +Constant (const signed byte*) main::$15 = ((signed byte*))uw_screen#0 +Constant (const word*) main::$17 = ((word*))uw_screen#0 +Constant (const signed word*) main::$19 = ((signed word*))uw_screen#0 +Constant (const byte*) main::$21 = ((byte*))sw_screen#0 +Constant (const signed byte*) main::$22 = ((signed byte*))sw_screen#0 +Constant (const word*) main::$24 = ((word*))sw_screen#0 +Constant (const signed word*) main::$26 = ((signed word*))sw_screen#0 +Successful SSA optimization Pass2ConstantIdentification +Constant (const signed byte*) main::$2 = main::$1+1 +Constant (const word*) main::$4 = main::$3+2 +Constant (const signed word*) main::$6 = main::$5+4 +Constant (const signed byte*) main::$9 = main::$8+1 +Constant (const word*) main::$11 = main::$10+2 +Constant (const signed word*) main::$13 = main::$12+4 +Constant (const signed byte*) main::$16 = main::$15+1 +Constant (const word*) main::$18 = main::$17+2 +Constant (const signed word*) main::$20 = main::$19+4 +Constant (const signed byte*) main::$23 = main::$22+1 +Constant (const word*) main::$25 = main::$24+2 +Constant (const signed word*) main::$27 = main::$26+4 +Successful SSA optimization Pass2ConstantIdentification +Constant inlined main::$12 = ((signed word*))(const signed byte*) sb_screen#0 +Constant inlined main::$13 = ((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined main::$14 = ((byte*))(const word*) uw_screen#0 +Constant inlined main::$15 = ((signed byte*))(const word*) uw_screen#0 +Constant inlined main::$10 = ((word*))(const signed byte*) sb_screen#0 +Constant inlined main::$11 = ((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2 +Constant inlined main::$16 = ((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1 +Constant inlined main::$17 = ((word*))(const word*) uw_screen#0 +Constant inlined main::$18 = ((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2 +Constant inlined main::$19 = ((signed word*))(const word*) uw_screen#0 +Constant inlined main::$23 = ((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1 +Constant inlined main::$24 = ((word*))(const signed word*) sw_screen#0 +Constant inlined main::$25 = ((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2 +Constant inlined main::$26 = ((signed word*))(const signed word*) sw_screen#0 +Constant inlined main::$20 = ((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined main::$21 = ((byte*))(const signed word*) sw_screen#0 +Constant inlined main::$22 = ((signed byte*))(const signed word*) sw_screen#0 +Constant inlined main::$1 = ((signed byte*))(const byte*) ub_screen#0 +Constant inlined main::$27 = ((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined main::$2 = ((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1 +Constant inlined main::$0 = ((byte*))(const byte*) ub_screen#0 +Constant inlined main::$5 = ((signed word*))(const byte*) ub_screen#0 +Constant inlined main::$6 = ((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4 +Constant inlined main::$3 = ((word*))(const byte*) ub_screen#0 +Constant inlined main::$4 = ((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2 +Constant inlined main::$9 = ((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1 +Constant inlined main::$7 = ((byte*))(const signed byte*) sb_screen#0 +Constant inlined main::$8 = ((signed byte*))(const signed byte*) sb_screen#0 +Successful SSA optimization Pass2ConstantInlining +Adding NOP phi() at start of @begin +Adding NOP phi() at start of @1 +Adding NOP phi() at start of @end +CALL GRAPH +Calls in [] to main:2 + +Created 0 initial phi equivalence classes +Coalesced down to 0 phi equivalence classes +Adding NOP phi() at start of @begin +Adding NOP phi() at start of @1 +Adding NOP phi() at start of @end + +FINAL CONTROL FLOW GRAPH +@begin: scope:[] from + [0] phi() + to:@1 +@1: scope:[] from @begin + [1] phi() + [2] call main + to:@end +@end: scope:[] from @1 + [3] phi() +main: scope:[main] from @1 + [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 + [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 + [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 + [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 + [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 + [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 + [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 + to:main::@return +main::@return: scope:[main] from main + [20] return + to:@return + + +VARIABLE REGISTER WEIGHTS +(void()) main() +(signed byte) sb +(signed byte*) sb_screen +(signed word) sw +(signed word*) sw_screen +(byte) ub +(byte*) ub_screen +(word) uw +(word*) uw_screen + +Initial phi equivalence classes +Complete equivalence classes + +INITIAL ASM +//SEG0 File Comments +// Tests casting pointer types to other pointer types +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(bbegin) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label ub_screen = $400 + .label sb_screen = $428 + .label uw_screen = $450 + .label sw_screen = $478 + .const ub = $29 + .const sb = -$29 + .const uw = $3000 + .const sw = -$3000 +//SEG3 @begin +bbegin: +//SEG4 [1] phi from @begin to @1 [phi:@begin->@1] +b1_from_bbegin: + jmp b1 +//SEG5 @1 +b1: +//SEG6 [2] call main + jsr main +//SEG7 [3] phi from @1 to @end [phi:@1->@end] +bend_from_b1: + jmp bend +//SEG8 @end +bend: +//SEG9 main +main: { + //SEG10 [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta ub_screen + //SEG11 [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta ub_screen+1 + //SEG12 [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta ub_screen+2+1 + //SEG13 [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta ub_screen+4+1 + //SEG14 [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sb_screen + //SEG15 [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sb_screen+1 + //SEG16 [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sb_screen+2+1 + //SEG17 [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sb_screen+4+1 + //SEG18 [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta uw_screen + //SEG19 [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta uw_screen+1 + //SEG20 [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta uw_screen+2+1 + //SEG21 [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta uw_screen+4+1 + //SEG22 [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sw_screen + //SEG23 [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sw_screen+1 + //SEG24 [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sw_screen+2+1 + //SEG25 [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sw_screen+4+1 + jmp breturn + //SEG26 main::@return + breturn: + //SEG27 [20] return + rts +} + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 [ ] ( main:2 [ ] ) always clobbers reg byte a + +REGISTER UPLIFT SCOPES +Uplift Scope [main] +Uplift Scope [] + +Uplifting [main] best 165 combination +Uplifting [] best 165 combination + +ASSEMBLER BEFORE OPTIMIZATION +//SEG0 File Comments +// Tests casting pointer types to other pointer types +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(bbegin) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label ub_screen = $400 + .label sb_screen = $428 + .label uw_screen = $450 + .label sw_screen = $478 + .const ub = $29 + .const sb = -$29 + .const uw = $3000 + .const sw = -$3000 +//SEG3 @begin +bbegin: +//SEG4 [1] phi from @begin to @1 [phi:@begin->@1] +b1_from_bbegin: + jmp b1 +//SEG5 @1 +b1: +//SEG6 [2] call main + jsr main +//SEG7 [3] phi from @1 to @end [phi:@1->@end] +bend_from_b1: + jmp bend +//SEG8 @end +bend: +//SEG9 main +main: { + //SEG10 [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta ub_screen + //SEG11 [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta ub_screen+1 + //SEG12 [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta ub_screen+2+1 + //SEG13 [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta ub_screen+4+1 + //SEG14 [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sb_screen + //SEG15 [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sb_screen+1 + //SEG16 [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sb_screen+2+1 + //SEG17 [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sb_screen+4+1 + //SEG18 [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta uw_screen + //SEG19 [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta uw_screen+1 + //SEG20 [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta uw_screen+2+1 + //SEG21 [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta uw_screen+4+1 + //SEG22 [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sw_screen + //SEG23 [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sw_screen+1 + //SEG24 [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sw_screen+2+1 + //SEG25 [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sw_screen+4+1 + jmp breturn + //SEG26 main::@return + breturn: + //SEG27 [20] return + rts +} + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp b1 +Removing instruction jmp bend +Removing instruction jmp breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction b1_from_bbegin: +Removing instruction b1: +Removing instruction bend_from_b1: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction bend: +Removing instruction breturn: +Succesful ASM optimization Pass5UnusedLabelElimination +Updating BasicUpstart to call main directly +Removing instruction jsr main +Succesful ASM optimization Pass5SkipBegin +Removing instruction bbegin: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +(signed byte) sb +(const signed byte) sb#0 sb = -(byte/signed byte/word/signed word/dword/signed dword) $29 +(signed byte*) sb_screen +(const signed byte*) sb_screen#0 sb_screen = ((signed byte*))(word/signed word/dword/signed dword) $428 +(signed word) sw +(const signed word) sw#0 sw = -(word/signed word/dword/signed dword) $3000 +(signed word*) sw_screen +(const signed word*) sw_screen#0 sw_screen = ((signed word*))(word/signed word/dword/signed dword) $478 +(byte) ub +(const byte) ub#0 ub = (byte/signed byte/word/signed word/dword/signed dword) $29 +(byte*) ub_screen +(const byte*) ub_screen#0 ub_screen = ((byte*))(word/signed word/dword/signed dword) $400 +(word) uw +(const word) uw#0 uw = (word/signed word/dword/signed dword) $3000 +(word*) uw_screen +(const word*) uw_screen#0 uw_screen = ((word*))(word/signed word/dword/signed dword) $450 + + + +FINAL ASSEMBLER +Score: 150 + +//SEG0 File Comments +// Tests casting pointer types to other pointer types +//SEG1 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +//SEG2 Global Constants & labels + .label ub_screen = $400 + .label sb_screen = $428 + .label uw_screen = $450 + .label sw_screen = $478 + .const ub = $29 + .const sb = -$29 + .const uw = $3000 + .const sw = -$3000 +//SEG3 @begin +//SEG4 [1] phi from @begin to @1 [phi:@begin->@1] +//SEG5 @1 +//SEG6 [2] call main +//SEG7 [3] phi from @1 to @end [phi:@1->@end] +//SEG8 @end +//SEG9 main +main: { + //SEG10 [4] *(((byte*))(const byte*) ub_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta ub_screen + //SEG11 [5] *(((signed byte*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta ub_screen+1 + //SEG12 [6] *(((word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta ub_screen+2+1 + //SEG13 [7] *(((signed word*))(const byte*) ub_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta ub_screen+4+1 + //SEG14 [8] *(((byte*))(const signed byte*) sb_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sb_screen + //SEG15 [9] *(((signed byte*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sb_screen+1 + //SEG16 [10] *(((word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sb_screen+2+1 + //SEG17 [11] *(((signed word*))(const signed byte*) sb_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sb_screen+4+1 + //SEG18 [12] *(((byte*))(const word*) uw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta uw_screen + //SEG19 [13] *(((signed byte*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta uw_screen+1 + //SEG20 [14] *(((word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta uw_screen+2+1 + //SEG21 [15] *(((signed word*))(const word*) uw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta uw_screen+4+1 + //SEG22 [16] *(((byte*))(const signed word*) sw_screen#0) ← (const byte) ub#0 -- _deref_pbuc1=vbuc2 + lda #ub + sta sw_screen + //SEG23 [17] *(((signed byte*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const signed byte) sb#0 -- _deref_pbsc1=vbsc2 + lda #sb + sta sw_screen+1 + //SEG24 [18] *(((word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← (const word) uw#0 -- _deref_pwuc1=vwuc2 + lda #uw + sta sw_screen+2+1 + //SEG25 [19] *(((signed word*))(const signed word*) sw_screen#0+(byte/signed byte/word/signed word/dword/signed dword) 4) ← (const signed word) sw#0 -- _deref_pwsc1=vwsc2 + lda #sw + sta sw_screen+4+1 + //SEG26 main::@return + //SEG27 [20] return + rts +} + diff --git a/src/test/ref/pointer-cast.sym b/src/test/ref/pointer-cast.sym new file mode 100644 index 000000000..3bf8d6fda --- /dev/null +++ b/src/test/ref/pointer-cast.sym @@ -0,0 +1,22 @@ +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +(signed byte) sb +(const signed byte) sb#0 sb = -(byte/signed byte/word/signed word/dword/signed dword) $29 +(signed byte*) sb_screen +(const signed byte*) sb_screen#0 sb_screen = ((signed byte*))(word/signed word/dword/signed dword) $428 +(signed word) sw +(const signed word) sw#0 sw = -(word/signed word/dword/signed dword) $3000 +(signed word*) sw_screen +(const signed word*) sw_screen#0 sw_screen = ((signed word*))(word/signed word/dword/signed dword) $478 +(byte) ub +(const byte) ub#0 ub = (byte/signed byte/word/signed word/dword/signed dword) $29 +(byte*) ub_screen +(const byte*) ub_screen#0 ub_screen = ((byte*))(word/signed word/dword/signed dword) $400 +(word) uw +(const word) uw#0 uw = (word/signed word/dword/signed dword) $3000 +(word*) uw_screen +(const word*) uw_screen#0 uw_screen = ((word*))(word/signed word/dword/signed dword) $450 +