1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-11 16:30:56 +00:00

Added missing test files and fixed a test. #121

This commit is contained in:
jespergravgaard 2021-05-11 23:19:29 +02:00
parent d1b7d45372
commit 35fdd06abf
5 changed files with 589 additions and 2 deletions

View File

@ -11,7 +11,7 @@ public class TestProgramsFast extends TestPrograms {
@Test
public void testProcedureDeclare10() throws IOException {
compileAndCompare("procedure-declare-10.c", log());
compileAndCompare("procedure-declare-10.c");
}
@Test
@ -1413,7 +1413,7 @@ public class TestProgramsFast extends TestPrograms {
@Test
public void testFunctionAsArray() throws IOException {
assertError("function-as-array.c", "Dereferencing a non-pointer type void(byte) ");
assertError("function-as-array.c", "Dereferencing a non-pointer type void(byte)");
}
//@Test

View File

@ -0,0 +1,64 @@
// Complex procedure declaration and definition.
// Commodore 64 PRG executable file
.file [name="procedure-declare-10.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)
.const SIZEOF_BYTE = 1
.label SCREEN = $400
.segment Code
main: {
// memcpy(SCREEN, STRING, sizeof(STRING))
jsr memcpy
// }
rts
}
// Copy block of memory (forwards)
// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.
memcpy: {
.const num = $c*SIZEOF_BYTE
.label destination = SCREEN
.label source = STRING
.label src_end = source+num
.label dst = 4
.label src = 2
lda #<destination
sta.z dst
lda #>destination
sta.z dst+1
lda #<source
sta.z src
lda #>source
sta.z src+1
__b1:
// while(src!=src_end)
lda.z src+1
cmp #>src_end
bne __b2
lda.z src
cmp #<src_end
bne __b2
// }
rts
__b2:
// *dst++ = *src++
ldy #0
lda (src),y
sta (dst),y
// *dst++ = *src++;
inc.z dst
bne !+
inc.z dst+1
!:
inc.z src
bne !+
inc.z src+1
!:
jmp __b1
}
.segment Data
STRING: .text "hello world"
.byte 0

View File

@ -0,0 +1,27 @@
void main()
main: scope:[main] from
[0] phi()
[1] call memcpy
to:main::@return
main::@return: scope:[main] from main
[2] return
to:@return
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
memcpy: scope:[memcpy] from main
[3] phi()
to:memcpy::@1
memcpy::@1: scope:[memcpy] from memcpy memcpy::@2
[4] memcpy::dst#2 = phi( memcpy/(byte*)memcpy::destination#0, memcpy::@2/memcpy::dst#1 )
[4] memcpy::src#2 = phi( memcpy/(byte*)memcpy::source#0, memcpy::@2/memcpy::src#1 )
[5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2
to:memcpy::@return
memcpy::@return: scope:[memcpy] from memcpy::@1
[6] return
to:@return
memcpy::@2: scope:[memcpy] from memcpy::@1
[7] *memcpy::dst#2 = *memcpy::src#2
[8] memcpy::dst#1 = ++ memcpy::dst#2
[9] memcpy::src#1 = ++ memcpy::src#2
to:memcpy::@1

View File

@ -0,0 +1,473 @@
CONTROL FLOW GRAPH SSA
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
memcpy: scope:[memcpy] from main
memcpy::num#1 = phi( main/memcpy::num#0 )
memcpy::destination#1 = phi( main/memcpy::destination#0 )
memcpy::source#1 = phi( main/memcpy::source#0 )
memcpy::src#0 = ((byte*)) memcpy::source#1
memcpy::dst#0 = ((byte*)) memcpy::destination#1
memcpy::$2 = (byte*)memcpy::source#1
memcpy::$0 = memcpy::$2 + memcpy::num#1
memcpy::src_end#0 = memcpy::$0
to:memcpy::@1
memcpy::@1: scope:[memcpy] from memcpy memcpy::@2
memcpy::destination#3 = phi( memcpy/memcpy::destination#1, memcpy::@2/memcpy::destination#4 )
memcpy::dst#3 = phi( memcpy/memcpy::dst#0, memcpy::@2/memcpy::dst#1 )
memcpy::src_end#1 = phi( memcpy/memcpy::src_end#0, memcpy::@2/memcpy::src_end#2 )
memcpy::src#2 = phi( memcpy/memcpy::src#0, memcpy::@2/memcpy::src#1 )
memcpy::$1 = memcpy::src#2 != memcpy::src_end#1
if(memcpy::$1) goto memcpy::@2
to:memcpy::@3
memcpy::@2: scope:[memcpy] from memcpy::@1
memcpy::destination#4 = phi( memcpy::@1/memcpy::destination#3 )
memcpy::src_end#2 = phi( memcpy::@1/memcpy::src_end#1 )
memcpy::dst#2 = phi( memcpy::@1/memcpy::dst#3 )
memcpy::src#3 = phi( memcpy::@1/memcpy::src#2 )
*memcpy::dst#2 = *memcpy::src#3
memcpy::dst#1 = ++ memcpy::dst#2
memcpy::src#1 = ++ memcpy::src#3
to:memcpy::@1
memcpy::@3: scope:[memcpy] from memcpy::@1
memcpy::destination#2 = phi( memcpy::@1/memcpy::destination#3 )
memcpy::return#0 = memcpy::destination#2
to:memcpy::@return
memcpy::@return: scope:[memcpy] from memcpy::@3
memcpy::return#3 = phi( memcpy::@3/memcpy::return#0 )
memcpy::return#1 = memcpy::return#3
return
to:@return
void main()
main: scope:[main] from __start
main::$0 = sizeof STRING
memcpy::destination#0 = (void*)SCREEN
memcpy::source#0 = (void*)STRING
memcpy::num#0 = main::$0
call memcpy
memcpy::return#2 = memcpy::return#1
to:main::@1
main::@1: scope:[main] from main
to:main::@return
main::@return: scope:[main] from main::@1
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
constant byte* const SCREEN = (byte*)$400
constant byte* STRING[] = "hello world"
void __start()
void main()
word~ main::$0
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
byte*~ memcpy::$0
bool~ memcpy::$1
byte*~ memcpy::$2
void* memcpy::destination
void* memcpy::destination#0
void* memcpy::destination#1
void* memcpy::destination#2
void* memcpy::destination#3
void* memcpy::destination#4
byte* memcpy::dst
byte* memcpy::dst#0
byte* memcpy::dst#1
byte* memcpy::dst#2
byte* memcpy::dst#3
word memcpy::num
word memcpy::num#0
word memcpy::num#1
void* memcpy::return
void* memcpy::return#0
void* memcpy::return#1
void* memcpy::return#2
void* memcpy::return#3
void* memcpy::source
void* memcpy::source#0
void* memcpy::source#1
byte* memcpy::src
byte* memcpy::src#0
byte* memcpy::src#1
byte* memcpy::src#2
byte* memcpy::src#3
byte* memcpy::src_end
byte* memcpy::src_end#0
byte* memcpy::src_end#1
byte* memcpy::src_end#2
Inlining cast memcpy::src#0 = (byte*)memcpy::source#1
Inlining cast memcpy::dst#0 = (byte*)memcpy::destination#1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias memcpy::src_end#0 = memcpy::$0
Alias memcpy::src#2 = memcpy::src#3
Alias memcpy::dst#2 = memcpy::dst#3
Alias memcpy::src_end#1 = memcpy::src_end#2
Alias memcpy::destination#2 = memcpy::destination#4 memcpy::destination#3 memcpy::return#0 memcpy::return#3 memcpy::return#1
Alias memcpy::num#0 = main::$0
Successful SSA optimization Pass2AliasElimination
Identical Phi Values memcpy::source#1 memcpy::source#0
Identical Phi Values memcpy::destination#1 memcpy::destination#0
Identical Phi Values memcpy::num#1 memcpy::num#0
Identical Phi Values memcpy::src_end#1 memcpy::src_end#0
Identical Phi Values memcpy::destination#2 memcpy::destination#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition memcpy::$1 [7] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [12] memcpy::num#0 = sizeof STRING
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memcpy::num#0 = sizeof STRING
Constant memcpy::destination#0 = (void*)SCREEN
Constant memcpy::source#0 = (void*)STRING
Successful SSA optimization Pass2ConstantIdentification
Constant memcpy::src#0 = (byte*)memcpy::source#0
Constant memcpy::dst#0 = (byte*)memcpy::destination#0
Constant memcpy::$2 = (byte*)memcpy::source#0
Constant memcpy::return#2 = memcpy::destination#0
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant memcpy::return#2
Successful SSA optimization PassNEliminateUnusedVars
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
Resolving string sizeof() sizeof STRING
Successful SSA optimization PassNSizeOfSimplification
Constant right-side identified [0] memcpy::src_end#0 = memcpy::$2 + memcpy::num#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant memcpy::src_end#0 = memcpy::$2+memcpy::num#0
Successful SSA optimization Pass2ConstantIdentification
Adding number conversion cast (unumber) $c in
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $c
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $c
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings memcpy::src#0
Inlining constant with var siblings memcpy::dst#0
Constant inlined memcpy::$2 = (byte*)memcpy::source#0
Constant inlined memcpy::dst#0 = (byte*)memcpy::destination#0
Constant inlined memcpy::src#0 = (byte*)memcpy::source#0
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of memcpy
Adding NOP phi() at start of memcpy::@3
CALL GRAPH
Calls in [main] to memcpy:1
Created 2 initial phi equivalence classes
Coalesced [12] memcpy::src#4 = memcpy::src#1
Coalesced [13] memcpy::dst#4 = memcpy::dst#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@1
Culled Empty Block label memcpy::@3
Adding NOP phi() at start of main
Adding NOP phi() at start of memcpy
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call memcpy
to:main::@return
main::@return: scope:[main] from main
[2] return
to:@return
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
memcpy: scope:[memcpy] from main
[3] phi()
to:memcpy::@1
memcpy::@1: scope:[memcpy] from memcpy memcpy::@2
[4] memcpy::dst#2 = phi( memcpy/(byte*)memcpy::destination#0, memcpy::@2/memcpy::dst#1 )
[4] memcpy::src#2 = phi( memcpy/(byte*)memcpy::source#0, memcpy::@2/memcpy::src#1 )
[5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2
to:memcpy::@return
memcpy::@return: scope:[memcpy] from memcpy::@1
[6] return
to:@return
memcpy::@2: scope:[memcpy] from memcpy::@1
[7] *memcpy::dst#2 = *memcpy::src#2
[8] memcpy::dst#1 = ++ memcpy::dst#2
[9] memcpy::src#1 = ++ memcpy::src#2
to:memcpy::@1
VARIABLE REGISTER WEIGHTS
void main()
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
void* memcpy::destination
byte* memcpy::dst
byte* memcpy::dst#1 101.0
byte* memcpy::dst#2 101.0
word memcpy::num
void* memcpy::return
void* memcpy::source
byte* memcpy::src
byte* memcpy::src#1 202.0
byte* memcpy::src#2 101.0
byte* memcpy::src_end
Initial phi equivalence classes
[ memcpy::src#2 memcpy::src#1 ]
[ memcpy::dst#2 memcpy::dst#1 ]
Complete equivalence classes
[ memcpy::src#2 memcpy::src#1 ]
[ memcpy::dst#2 memcpy::dst#1 ]
Allocated zp[2]:2 [ memcpy::src#2 memcpy::src#1 ]
Allocated zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 [ memcpy::src#2 memcpy::dst#2 ] ( memcpy:1 [ memcpy::src#2 memcpy::dst#2 ] { } ) always clobbers reg byte a
Statement [7] *memcpy::dst#2 = *memcpy::src#2 [ memcpy::src#2 memcpy::dst#2 ] ( memcpy:1 [ memcpy::src#2 memcpy::dst#2 ] { } ) always clobbers reg byte a reg byte y
Potential registers zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] : zp[2]:2 ,
Potential registers zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ] : zp[2]:4 ,
REGISTER UPLIFT SCOPES
Uplift Scope [memcpy] 303: zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] 202: zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]
Uplift Scope [main]
Uplift Scope []
Uplifting [memcpy] best 866 combination zp[2]:2 [ memcpy::src#2 memcpy::src#1 ] zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]
Uplifting [main] best 866 combination
Uplifting [] best 866 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Complex procedure declaration and definition.
// Upstart
// Commodore 64 PRG executable file
.file [name="procedure-declare-10.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
.const SIZEOF_BYTE = 1
.label SCREEN = $400
.segment Code
// main
main: {
// [1] call memcpy
// [3] phi from main to memcpy [phi:main->memcpy]
memcpy_from_main:
jsr memcpy
jmp __breturn
// main::@return
__breturn:
// [2] return
rts
}
// memcpy
// Copy block of memory (forwards)
// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.
memcpy: {
.const num = $c*SIZEOF_BYTE
.label destination = SCREEN
.label source = STRING
.label src_end = source+num
.label dst = 4
.label src = 2
// [4] phi from memcpy to memcpy::@1 [phi:memcpy->memcpy::@1]
__b1_from_memcpy:
// [4] phi memcpy::dst#2 = (byte*)memcpy::destination#0 [phi:memcpy->memcpy::@1#0] -- pbuz1=pbuc1
lda #<destination
sta.z dst
lda #>destination
sta.z dst+1
// [4] phi memcpy::src#2 = (byte*)memcpy::source#0 [phi:memcpy->memcpy::@1#1] -- pbuz1=pbuc1
lda #<source
sta.z src
lda #>source
sta.z src+1
jmp __b1
// memcpy::@1
__b1:
// [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuc1_then_la1
lda.z src+1
cmp #>src_end
bne __b2
lda.z src
cmp #<src_end
bne __b2
jmp __breturn
// memcpy::@return
__breturn:
// [6] return
rts
// memcpy::@2
__b2:
// [7] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (src),y
ldy #0
sta (dst),y
// [8] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1
inc.z dst
bne !+
inc.z dst+1
!:
// [9] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1
inc.z src
bne !+
inc.z src+1
!:
// [4] phi from memcpy::@2 to memcpy::@1 [phi:memcpy::@2->memcpy::@1]
__b1_from___b2:
// [4] phi memcpy::dst#2 = memcpy::dst#1 [phi:memcpy::@2->memcpy::@1#0] -- register_copy
// [4] phi memcpy::src#2 = memcpy::src#1 [phi:memcpy::@2->memcpy::@1#1] -- register_copy
jmp __b1
}
// File Data
.segment Data
STRING: .text "hello world"
.byte 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction memcpy_from_main:
Removing instruction __breturn:
Removing instruction __b1_from_memcpy:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
constant byte* const SCREEN = (byte*) 1024
constant byte SIZEOF_BYTE = 1
constant byte* STRING[] = "hello world"
void main()
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
void* memcpy::destination
constant void* memcpy::destination#0 destination = (void*)SCREEN
byte* memcpy::dst
byte* memcpy::dst#1 dst zp[2]:4 101.0
byte* memcpy::dst#2 dst zp[2]:4 101.0
word memcpy::num
constant word memcpy::num#0 num = $c*SIZEOF_BYTE
void* memcpy::return
void* memcpy::source
constant void* memcpy::source#0 source = (void*)STRING
byte* memcpy::src
byte* memcpy::src#1 src zp[2]:2 202.0
byte* memcpy::src#2 src zp[2]:2 101.0
byte* memcpy::src_end
constant byte* memcpy::src_end#0 src_end = (byte*)memcpy::source#0+memcpy::num#0
zp[2]:2 [ memcpy::src#2 memcpy::src#1 ]
zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]
FINAL ASSEMBLER
Score: 783
// File Comments
// Complex procedure declaration and definition.
// Upstart
// Commodore 64 PRG executable file
.file [name="procedure-declare-10.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
.const SIZEOF_BYTE = 1
.label SCREEN = $400
.segment Code
// main
main: {
// memcpy(SCREEN, STRING, sizeof(STRING))
// [1] call memcpy
// [3] phi from main to memcpy [phi:main->memcpy]
jsr memcpy
// main::@return
// }
// [2] return
rts
}
// memcpy
// Copy block of memory (forwards)
// Copies the values of num bytes from the location pointed to by source directly to the memory block pointed to by destination.
memcpy: {
.const num = $c*SIZEOF_BYTE
.label destination = SCREEN
.label source = STRING
.label src_end = source+num
.label dst = 4
.label src = 2
// [4] phi from memcpy to memcpy::@1 [phi:memcpy->memcpy::@1]
// [4] phi memcpy::dst#2 = (byte*)memcpy::destination#0 [phi:memcpy->memcpy::@1#0] -- pbuz1=pbuc1
lda #<destination
sta.z dst
lda #>destination
sta.z dst+1
// [4] phi memcpy::src#2 = (byte*)memcpy::source#0 [phi:memcpy->memcpy::@1#1] -- pbuz1=pbuc1
lda #<source
sta.z src
lda #>source
sta.z src+1
// memcpy::@1
__b1:
// while(src!=src_end)
// [5] if(memcpy::src#2!=memcpy::src_end#0) goto memcpy::@2 -- pbuz1_neq_pbuc1_then_la1
lda.z src+1
cmp #>src_end
bne __b2
lda.z src
cmp #<src_end
bne __b2
// memcpy::@return
// }
// [6] return
rts
// memcpy::@2
__b2:
// *dst++ = *src++
// [7] *memcpy::dst#2 = *memcpy::src#2 -- _deref_pbuz1=_deref_pbuz2
ldy #0
lda (src),y
sta (dst),y
// *dst++ = *src++;
// [8] memcpy::dst#1 = ++ memcpy::dst#2 -- pbuz1=_inc_pbuz1
inc.z dst
bne !+
inc.z dst+1
!:
// [9] memcpy::src#1 = ++ memcpy::src#2 -- pbuz1=_inc_pbuz1
inc.z src
bne !+
inc.z src+1
!:
// [4] phi from memcpy::@2 to memcpy::@1 [phi:memcpy::@2->memcpy::@1]
// [4] phi memcpy::dst#2 = memcpy::dst#1 [phi:memcpy::@2->memcpy::@1#0] -- register_copy
// [4] phi memcpy::src#2 = memcpy::src#1 [phi:memcpy::@2->memcpy::@1#1] -- register_copy
jmp __b1
}
// File Data
.segment Data
STRING: .text "hello world"
.byte 0

View File

@ -0,0 +1,23 @@
constant byte* const SCREEN = (byte*) 1024
constant byte SIZEOF_BYTE = 1
constant byte* STRING[] = "hello world"
void main()
void* memcpy(void* memcpy::destination , void* memcpy::source , word memcpy::num)
void* memcpy::destination
constant void* memcpy::destination#0 destination = (void*)SCREEN
byte* memcpy::dst
byte* memcpy::dst#1 dst zp[2]:4 101.0
byte* memcpy::dst#2 dst zp[2]:4 101.0
word memcpy::num
constant word memcpy::num#0 num = $c*SIZEOF_BYTE
void* memcpy::return
void* memcpy::source
constant void* memcpy::source#0 source = (void*)STRING
byte* memcpy::src
byte* memcpy::src#1 src zp[2]:2 202.0
byte* memcpy::src#2 src zp[2]:2 101.0
byte* memcpy::src_end
constant byte* memcpy::src_end#0 src_end = (byte*)memcpy::source#0+memcpy::num#0
zp[2]:2 [ memcpy::src#2 memcpy::src#1 ]
zp[2]:4 [ memcpy::dst#2 memcpy::dst#1 ]