1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-26 03:32:23 +00:00

Added test with pointers on ZP - missing .z in ASM.

This commit is contained in:
jespergravgaard 2021-12-15 22:31:45 +01:00
parent 144bdd45f4
commit 98fcf713d9
8 changed files with 228 additions and 0 deletions

View File

@ -0,0 +1,5 @@
sec
sbc #1
sta {m1}
lda #0
sta {m1}+1

View File

@ -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) {

View File

@ -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

View File

@ -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;
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
__constant char * const _s1 = (char *) 238
__constant unsigned int * const _s2 = (unsigned int *) 239
void main()