From 98fcf713d977c62559b83acb230a67224082eee1 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 15 Dec 2021 22:31:45 +0100 Subject: [PATCH] Added test with pointers on ZP - missing .z in ASM. --- .../mos6502-common/vwum1=vbuaa_minus_1.asm | 5 + .../parsing/macros/TestPreprocessor.java | 3 + .../kickc/test/TestProgramsFast.java | 6 + src/test/kc/pcea-pointer-1.c | 10 ++ src/test/ref/pcea-pointer-1.asm | 24 +++ src/test/ref/pcea-pointer-1.cfg | 9 + src/test/ref/pcea-pointer-1.log | 167 ++++++++++++++++++ src/test/ref/pcea-pointer-1.sym | 4 + 8 files changed, 228 insertions(+) create mode 100644 src/main/fragment/mos6502-common/vwum1=vbuaa_minus_1.asm create mode 100644 src/test/kc/pcea-pointer-1.c create mode 100644 src/test/ref/pcea-pointer-1.asm create mode 100644 src/test/ref/pcea-pointer-1.cfg create mode 100644 src/test/ref/pcea-pointer-1.log create mode 100644 src/test/ref/pcea-pointer-1.sym diff --git a/src/main/fragment/mos6502-common/vwum1=vbuaa_minus_1.asm b/src/main/fragment/mos6502-common/vwum1=vbuaa_minus_1.asm new file mode 100644 index 000000000..a31eb5999 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=vbuaa_minus_1.asm @@ -0,0 +1,5 @@ +sec +sbc #1 +sta {m1} +lda #0 +sta {m1}+1 \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/parsing/macros/TestPreprocessor.java b/src/test/java/dk/camelot64/kickc/parsing/macros/TestPreprocessor.java index 662d50d2b..6e38e3093 100644 --- a/src/test/java/dk/camelot64/kickc/parsing/macros/TestPreprocessor.java +++ b/src/test/java/dk/camelot64/kickc/parsing/macros/TestPreprocessor.java @@ -233,6 +233,9 @@ public class TestPreprocessor { assertEquals("str:\"/usr/tmp\"\"%s\";", parse("#define tempfile(dir) #dir \"%s\" \n tempfile(/usr/tmp);")); // Complex stringize example - from https://gcc.gnu.org/onlinedocs/gcc-3.4.6/cpp/Stringification.html assertEquals("str:\"4\";", parse("#define str(s) #s \n #define foo 4 \n str (foo);")); + // Complex stringize example using the two-macro trick - from @everslick + assertEquals("str:\"qwe\";", parse("#define _mkstr_(_s_) #_s_ \n #define mkstr(_s_) _mkstr_(_s_) \n mkstr(qwe);")); + } private void assertError(String program, String expectError, boolean expectLineNumber) { diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index 40d1b201f..1868bcc90 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -9,6 +9,12 @@ import java.io.IOException; */ public class TestProgramsFast extends TestPrograms { + + @Test + public void testPceaPointer1() throws IOException { + compileAndCompare("pcea-pointer-1.c", log()); + } + /* Fix problem where removing empty method can cause NPE (because a local variable in the method is still used) https://gitlab.com/camelot/kickc/-/issues/724 @Test diff --git a/src/test/kc/pcea-pointer-1.c b/src/test/kc/pcea-pointer-1.c new file mode 100644 index 000000000..09755766a --- /dev/null +++ b/src/test/kc/pcea-pointer-1.c @@ -0,0 +1,10 @@ +// These pointers lives on zeropage +// KickAss should be able to add .z to the STAs + +char * const _s1 = (char*)0xee; +unsigned int * const _s2 = (unsigned int*)0xef; + +void main() { + *_s1 = 7; + *_s2 = 7; +} \ No newline at end of file diff --git a/src/test/ref/pcea-pointer-1.asm b/src/test/ref/pcea-pointer-1.asm new file mode 100644 index 000000000..dbc7dc5ce --- /dev/null +++ b/src/test/ref/pcea-pointer-1.asm @@ -0,0 +1,24 @@ +// These pointers lives on zeropage +// KickAss should be able to add .z to the + // Commodore 64 PRG executable file +.file [name="pcea-pointer-1.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + .label _s1 = $ee + .label _s2 = $ef +.segment Code +main: { + // *_s1 = 7 + lda #7 + sta _s1 + // *_s2 = 7 + sta _s2 + lda #>7 + sta _s2+1 + // } + rts +} diff --git a/src/test/ref/pcea-pointer-1.cfg b/src/test/ref/pcea-pointer-1.cfg new file mode 100644 index 000000000..1fe9079f8 --- /dev/null +++ b/src/test/ref/pcea-pointer-1.cfg @@ -0,0 +1,9 @@ + +void main() +main: scope:[main] from + [0] *_s1 = 7 + [1] *_s2 = 7 + to:main::@return +main::@return: scope:[main] from main + [2] return + to:@return diff --git a/src/test/ref/pcea-pointer-1.log b/src/test/ref/pcea-pointer-1.log new file mode 100644 index 000000000..bdebe4697 --- /dev/null +++ b/src/test/ref/pcea-pointer-1.log @@ -0,0 +1,167 @@ + +CONTROL FLOW GRAPH SSA + +void main() +main: scope:[main] from __start + *_s1 = 7 + *_s2 = 7 + to:main::@return +main::@return: scope:[main] from main + return + to:@return + +void __start() +__start: scope:[__start] from + call main + to:__start::@1 +__start::@1: scope:[__start] from __start + to:__start::@return +__start::@return: scope:[__start] from __start::@1 + return + to:@return + +SYMBOL TABLE SSA +void __start() +__constant char * const _s1 = (char *)$ee +__constant unsigned int * const _s2 = (unsigned int *)$ef +void main() + +Adding number conversion cast (unumber) 7 in *_s1 = 7 +Adding number conversion cast (unumber) 7 in *_s2 = 7 +Successful SSA optimization PassNAddNumberTypeConversions +Inlining cast *_s1 = (unumber)7 +Inlining cast *_s2 = (unumber)7 +Successful SSA optimization Pass2InlineCast +Simplifying constant pointer cast (char *) 238 +Simplifying constant pointer cast (unsigned int *) 239 +Simplifying constant integer cast 7 +Simplifying constant integer cast 7 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (char) 7 +Finalized unsigned number type (char) 7 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Removing unused procedure __start +Removing unused procedure block __start +Removing unused procedure block __start::@1 +Removing unused procedure block __start::@return +Successful SSA optimization PassNEliminateEmptyStart +CALL GRAPH + +Created 0 initial phi equivalence classes +Coalesced down to 0 phi equivalence classes + +FINAL CONTROL FLOW GRAPH + +void main() +main: scope:[main] from + [0] *_s1 = 7 + [1] *_s2 = 7 + to:main::@return +main::@return: scope:[main] from main + [2] return + to:@return + + +VARIABLE REGISTER WEIGHTS +void main() + +Initial phi equivalence classes +Complete equivalence classes +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [0] *_s1 = 7 [ ] ( [ ] { } ) always clobbers reg byte a +Statement [1] *_s2 = 7 [ ] ( [ ] { } ) always clobbers reg byte a + +REGISTER UPLIFT SCOPES +Uplift Scope [main] +Uplift Scope [] + +Uplifting [main] best 27 combination +Uplifting [] best 27 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// These pointers lives on zeropage +// KickAss should be able to add .z to the + // Upstart + // Commodore 64 PRG executable file +.file [name="pcea-pointer-1.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label _s1 = $ee + .label _s2 = $ef +.segment Code + // main +main: { + // [0] *_s1 = 7 -- _deref_pbuc1=vbuc2 + lda #7 + sta _s1 + // [1] *_s2 = 7 -- _deref_pwuc1=vbuc2 + lda #<7 + sta _s2 + lda #>7 + sta _s2+1 + jmp __breturn + // main::@return + __breturn: + // [2] return + rts +} + // File Data + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction lda #<7 +Succesful ASM optimization Pass5UnnecesaryLoadElimination +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +__constant char * const _s1 = (char *) 238 +__constant unsigned int * const _s2 = (unsigned int *) 239 +void main() + + + +FINAL ASSEMBLER +Score: 22 + + // File Comments +// These pointers lives on zeropage +// KickAss should be able to add .z to the + // Upstart + // Commodore 64 PRG executable file +.file [name="pcea-pointer-1.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label _s1 = $ee + .label _s2 = $ef +.segment Code + // main +main: { + // *_s1 = 7 + // [0] *_s1 = 7 -- _deref_pbuc1=vbuc2 + lda #7 + sta _s1 + // *_s2 = 7 + // [1] *_s2 = 7 -- _deref_pwuc1=vbuc2 + sta _s2 + lda #>7 + sta _s2+1 + // main::@return + // } + // [2] return + rts +} + // File Data + diff --git a/src/test/ref/pcea-pointer-1.sym b/src/test/ref/pcea-pointer-1.sym new file mode 100644 index 000000000..cfc026317 --- /dev/null +++ b/src/test/ref/pcea-pointer-1.sym @@ -0,0 +1,4 @@ +__constant char * const _s1 = (char *) 238 +__constant unsigned int * const _s2 = (unsigned int *) 239 +void main() +