mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-25 11:32:07 +00:00
Added test of support for empty statements. Closes #267
This commit is contained in:
parent
75e71b5bbb
commit
dfc5905c5e
@ -43,7 +43,12 @@ public class TestPrograms {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStmtEmpty() throws IOException, URISyntaxException {
|
||||
public void testStmtEmpty1() throws IOException, URISyntaxException {
|
||||
compileAndCompare("stmt-empty-1.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStmtEmpty0() throws IOException, URISyntaxException {
|
||||
compileAndCompare("stmt-empty.c");
|
||||
}
|
||||
|
||||
|
10
src/test/kc/stmt-empty-1.c
Normal file
10
src/test/kc/stmt-empty-1.c
Normal file
@ -0,0 +1,10 @@
|
||||
// Test an empty statement ';'
|
||||
|
||||
const char str[] = "Hello!";
|
||||
const char* SCREEN = 0x0400;
|
||||
|
||||
void main() {
|
||||
char b = 0;
|
||||
for (; str[b] != 0; ++b) ; // Empty body
|
||||
SCREEN[0] = '0'+b;
|
||||
}
|
27
src/test/ref/stmt-empty-1.asm
Normal file
27
src/test/ref/stmt-empty-1.asm
Normal file
@ -0,0 +1,27 @@
|
||||
// Test an empty statement ';'
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.label SCREEN = $400
|
||||
main: {
|
||||
ldx #0
|
||||
__b1:
|
||||
// for (; str[b] != 0; ++b)
|
||||
lda str,x
|
||||
cmp #0
|
||||
bne __b2
|
||||
// '0'+b
|
||||
txa
|
||||
axs #-['0']
|
||||
// SCREEN[0] = '0'+b
|
||||
// Empty body
|
||||
stx SCREEN
|
||||
// }
|
||||
rts
|
||||
__b2:
|
||||
// for (; str[b] != 0; ++b)
|
||||
inx
|
||||
jmp __b1
|
||||
}
|
||||
str: .text "Hello!"
|
||||
.byte 0
|
19
src/test/ref/stmt-empty-1.cfg
Normal file
19
src/test/ref/stmt-empty-1.cfg
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from
|
||||
[0] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@2
|
||||
[1] (byte) main::b#2 ← phi( main/(byte) 0 main::@2/(byte) main::b#1 )
|
||||
[2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1
|
||||
[3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2
|
||||
[4] *((const to_nomodify byte*) SCREEN) ← (byte~) main::$0
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[5] return
|
||||
to:@return
|
||||
main::@2: scope:[main] from main::@1
|
||||
[6] (byte) main::b#1 ← ++ (byte) main::b#2
|
||||
to:main::@1
|
334
src/test/ref/stmt-empty-1.log
Normal file
334
src/test/ref/stmt-empty-1.log
Normal file
@ -0,0 +1,334 @@
|
||||
Inlined call call __init
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from __start::@1
|
||||
(byte) main::b#0 ← (byte) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@2
|
||||
(byte) main::b#2 ← phi( main/(byte) main::b#0 main::@2/(byte) main::b#1 )
|
||||
(bool~) main::$1 ← *((const to_nomodify byte*) str + (byte) main::b#2) != (number) 0
|
||||
if((bool~) main::$1) goto main::@2
|
||||
to:main::@3
|
||||
main::@2: scope:[main] from main::@1
|
||||
(byte) main::b#3 ← phi( main::@1/(byte) main::b#2 )
|
||||
(byte) main::b#1 ← ++ (byte) main::b#3
|
||||
to:main::@1
|
||||
main::@3: scope:[main] from main::@1
|
||||
(byte) main::b#4 ← phi( main::@1/(byte) main::b#2 )
|
||||
(byte~) main::$0 ← (byte) '0' + (byte) main::b#4
|
||||
*((const to_nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$0
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
return
|
||||
to:@return
|
||||
|
||||
(void()) __start()
|
||||
__start: scope:[__start] from
|
||||
to:__start::__init1
|
||||
__start::__init1: scope:[__start] from __start
|
||||
to:__start::@1
|
||||
__start::@1: scope:[__start] from __start::__init1
|
||||
call main
|
||||
to:__start::@2
|
||||
__start::@2: scope:[__start] from __start::@1
|
||||
to:__start::@return
|
||||
__start::@return: scope:[__start] from __start::@2
|
||||
return
|
||||
to:@return
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(const to_nomodify byte*) SCREEN = (byte*)(number) $400
|
||||
(void()) __start()
|
||||
(label) __start::@1
|
||||
(label) __start::@2
|
||||
(label) __start::@return
|
||||
(label) __start::__init1
|
||||
(void()) main()
|
||||
(byte~) main::$0
|
||||
(bool~) main::$1
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#0
|
||||
(byte) main::b#1
|
||||
(byte) main::b#2
|
||||
(byte) main::b#3
|
||||
(byte) main::b#4
|
||||
(const to_nomodify byte*) str[] = (byte*) "Hello!"
|
||||
|
||||
Adding number conversion cast (unumber) 0 in (bool~) main::$1 ← *((const to_nomodify byte*) str + (byte) main::b#2) != (number) 0
|
||||
Adding number conversion cast (unumber) 0 in *((const to_nomodify byte*) SCREEN + (number) 0) ← (byte~) main::$0
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Simplifying constant integer cast 0
|
||||
Simplifying constant integer cast 0
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 0
|
||||
Finalized unsigned number type (byte) 0
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Alias main::b#2 = main::b#3 main::b#4
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Simple Condition (bool~) main::$1 [3] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Constant (const byte) main::b#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Simplifying expression containing zero SCREEN in [6] *((const to_nomodify byte*) SCREEN + (byte) 0) ← (byte~) main::$0
|
||||
Successful SSA optimization PassNSimplifyExpressionWithZero
|
||||
Removing unused procedure __start
|
||||
Removing unused procedure block __start
|
||||
Removing unused procedure block __start::__init1
|
||||
Removing unused procedure block __start::@1
|
||||
Removing unused procedure block __start::@2
|
||||
Removing unused procedure block __start::@return
|
||||
Successful SSA optimization PassNEliminateEmptyStart
|
||||
Inlining constant with var siblings (const byte) main::b#0
|
||||
Constant inlined main::b#0 = (byte) 0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Adding NOP phi() at start of main
|
||||
CALL GRAPH
|
||||
|
||||
Created 1 initial phi equivalence classes
|
||||
Coalesced [7] main::b#5 ← main::b#1
|
||||
Coalesced down to 1 phi equivalence classes
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
FINAL CONTROL FLOW GRAPH
|
||||
|
||||
(void()) main()
|
||||
main: scope:[main] from
|
||||
[0] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@2
|
||||
[1] (byte) main::b#2 ← phi( main/(byte) 0 main::@2/(byte) main::b#1 )
|
||||
[2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main::@1
|
||||
[3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2
|
||||
[4] *((const to_nomodify byte*) SCREEN) ← (byte~) main::$0
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[5] return
|
||||
to:@return
|
||||
main::@2: scope:[main] from main::@1
|
||||
[6] (byte) main::b#1 ← ++ (byte) main::b#2
|
||||
to:main::@1
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(byte~) main::$0 4.0
|
||||
(byte) main::b
|
||||
(byte) main::b#1 22.0
|
||||
(byte) main::b#2 17.5
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::b#2 main::b#1 ]
|
||||
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
||||
Complete equivalence classes
|
||||
[ main::b#2 main::b#1 ]
|
||||
[ main::$0 ]
|
||||
Allocated zp[1]:2 [ main::b#2 main::b#1 ]
|
||||
Allocated zp[1]:3 [ main::$0 ]
|
||||
|
||||
INITIAL ASM
|
||||
Target platform is c64basic / MOS6502X
|
||||
// File Comments
|
||||
// Test an empty statement ';'
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// main
|
||||
main: {
|
||||
.label __0 = 3
|
||||
.label b = 2
|
||||
// [1] phi from main to main::@1 [phi:main->main::@1]
|
||||
__b1_from_main:
|
||||
// [1] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta.z b
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2 -- pbuc1_derefidx_vbuz1_neq_0_then_la1
|
||||
ldy.z b
|
||||
lda str,y
|
||||
cmp #0
|
||||
bne __b2
|
||||
jmp __b3
|
||||
// main::@3
|
||||
__b3:
|
||||
// [3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2 -- vbuz1=vbuc1_plus_vbuz2
|
||||
lax.z b
|
||||
axs #-['0']
|
||||
stx.z __0
|
||||
// [4] *((const to_nomodify byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuz1
|
||||
// Empty body
|
||||
lda.z __0
|
||||
sta SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [5] return
|
||||
rts
|
||||
// main::@2
|
||||
__b2:
|
||||
// [6] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1
|
||||
inc.z b
|
||||
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
||||
__b1_from___b2:
|
||||
// [1] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#0] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
str: .text "Hello!"
|
||||
.byte 0
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Statement [2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2 [ main::b#2 ] ( [ main::b#2 ] { } ) always clobbers reg byte a
|
||||
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::b#2 main::b#1 ]
|
||||
Statement [3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2 [ main::$0 ] ( [ main::$0 ] { } ) always clobbers reg byte a
|
||||
Statement [2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2 [ main::b#2 ] ( [ main::b#2 ] { } ) always clobbers reg byte a
|
||||
Statement [3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2 [ main::$0 ] ( [ main::$0 ] { } ) always clobbers reg byte a
|
||||
Potential registers zp[1]:2 [ main::b#2 main::b#1 ] : zp[1]:2 , reg byte x , reg byte y ,
|
||||
Potential registers zp[1]:3 [ main::$0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 39.5: zp[1]:2 [ main::b#2 main::b#1 ] 4: zp[1]:3 [ main::$0 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 237 combination reg byte x [ main::b#2 main::b#1 ] reg byte x [ main::$0 ]
|
||||
Uplifting [] best 237 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Test an empty statement ';'
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// main
|
||||
main: {
|
||||
// [1] phi from main to main::@1 [phi:main->main::@1]
|
||||
__b1_from_main:
|
||||
// [1] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp __b1
|
||||
// main::@1
|
||||
__b1:
|
||||
// [2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2 -- pbuc1_derefidx_vbuxx_neq_0_then_la1
|
||||
lda str,x
|
||||
cmp #0
|
||||
bne __b2
|
||||
jmp __b3
|
||||
// main::@3
|
||||
__b3:
|
||||
// [3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2 -- vbuxx=vbuc1_plus_vbuxx
|
||||
txa
|
||||
axs #-['0']
|
||||
// [4] *((const to_nomodify byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuxx
|
||||
// Empty body
|
||||
stx SCREEN
|
||||
jmp __breturn
|
||||
// main::@return
|
||||
__breturn:
|
||||
// [5] return
|
||||
rts
|
||||
// main::@2
|
||||
__b2:
|
||||
// [6] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
||||
__b1_from___b2:
|
||||
// [1] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#0] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
str: .text "Hello!"
|
||||
.byte 0
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp __b1
|
||||
Removing instruction jmp __b3
|
||||
Removing instruction jmp __breturn
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction __b1_from_main:
|
||||
Removing instruction __b3:
|
||||
Removing instruction __breturn:
|
||||
Removing instruction __b1_from___b2:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(const to_nomodify byte*) SCREEN = (byte*) 1024
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte x 4.0
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#1 reg byte x 22.0
|
||||
(byte) main::b#2 reg byte x 17.5
|
||||
(const to_nomodify byte*) str[] = (byte*) "Hello!"
|
||||
|
||||
reg byte x [ main::b#2 main::b#1 ]
|
||||
reg byte x [ main::$0 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 174
|
||||
|
||||
// File Comments
|
||||
// Test an empty statement ';'
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
.label SCREEN = $400
|
||||
// main
|
||||
main: {
|
||||
// [1] phi from main to main::@1 [phi:main->main::@1]
|
||||
// [1] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
// main::@1
|
||||
__b1:
|
||||
// for (; str[b] != 0; ++b)
|
||||
// [2] if(*((const to_nomodify byte*) str + (byte) main::b#2)!=(byte) 0) goto main::@2 -- pbuc1_derefidx_vbuxx_neq_0_then_la1
|
||||
lda str,x
|
||||
cmp #0
|
||||
bne __b2
|
||||
// main::@3
|
||||
// '0'+b
|
||||
// [3] (byte~) main::$0 ← (byte) '0' + (byte) main::b#2 -- vbuxx=vbuc1_plus_vbuxx
|
||||
txa
|
||||
axs #-['0']
|
||||
// SCREEN[0] = '0'+b
|
||||
// [4] *((const to_nomodify byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuxx
|
||||
// Empty body
|
||||
stx SCREEN
|
||||
// main::@return
|
||||
// }
|
||||
// [5] return
|
||||
rts
|
||||
// main::@2
|
||||
__b2:
|
||||
// for (; str[b] != 0; ++b)
|
||||
// [6] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
|
||||
// [1] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@2->main::@1#0] -- register_copy
|
||||
jmp __b1
|
||||
}
|
||||
// File Data
|
||||
str: .text "Hello!"
|
||||
.byte 0
|
||||
|
14
src/test/ref/stmt-empty-1.sym
Normal file
14
src/test/ref/stmt-empty-1.sym
Normal file
@ -0,0 +1,14 @@
|
||||
(const to_nomodify byte*) SCREEN = (byte*) 1024
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte x 4.0
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@return
|
||||
(byte) main::b
|
||||
(byte) main::b#1 reg byte x 22.0
|
||||
(byte) main::b#2 reg byte x 17.5
|
||||
(const to_nomodify byte*) str[] = (byte*) "Hello!"
|
||||
|
||||
reg byte x [ main::b#2 main::b#1 ]
|
||||
reg byte x [ main::$0 ]
|
Loading…
Reference in New Issue
Block a user