mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-18 22:30:05 +00:00
Fixed switch without default. Closes #285
This commit is contained in:
parent
4ec3c6b369
commit
642f196786
@ -108,7 +108,7 @@ stmt
|
||||
;
|
||||
|
||||
switchCases:
|
||||
switchCase+ ( 'default:' stmtSeq? )
|
||||
switchCase+ ( 'default:' stmtSeq? )?
|
||||
;
|
||||
|
||||
switchCase:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -95,6 +95,11 @@ public class TestPrograms {
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testSwitch4() throws IOException, URISyntaxException {
|
||||
compileAndCompare("switch-4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitch2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("switch-2");
|
||||
|
15
src/test/kc/switch-4.kc
Normal file
15
src/test/kc/switch-4.kc
Normal file
@ -0,0 +1,15 @@
|
||||
// Tests simple switch()-statement - switch without default
|
||||
// Expected output " 1 4 "
|
||||
|
||||
void main() {
|
||||
const char* SCREEN = 0x0400;
|
||||
for(char i:0..5) {
|
||||
// Test switching on a simple char
|
||||
switch(i) {
|
||||
case 1:
|
||||
case 4:
|
||||
SCREEN[i] = '0'+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
25
src/test/ref/switch-4.asm
Normal file
25
src/test/ref/switch-4.asm
Normal file
@ -0,0 +1,25 @@
|
||||
// Tests simple switch()-statement - switch without default
|
||||
// Expeced output "14"
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
ldx #0
|
||||
b3:
|
||||
inx
|
||||
cpx #6
|
||||
bne b1
|
||||
rts
|
||||
b1:
|
||||
cpx #1
|
||||
beq b2
|
||||
cpx #4
|
||||
bne b3
|
||||
b2:
|
||||
txa
|
||||
clc
|
||||
adc #'0'
|
||||
sta SCREEN,x
|
||||
jmp b3
|
||||
}
|
30
src/test/ref/switch-4.cfg
Normal file
30
src/test/ref/switch-4.cfg
Normal file
@ -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] phi()
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main main::@2 main::@4
|
||||
[5] (byte) main::i#8 ← phi( main::@2/(byte) main::i#1 main::@4/(byte) main::i#1 main/(byte) 0 )
|
||||
[6] (byte) main::i#1 ← ++ (byte) main::i#8
|
||||
[7] if((byte) main::i#1!=(byte) 6) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[8] return
|
||||
to:@return
|
||||
main::@1: scope:[main] from main::@3
|
||||
[9] if((byte) main::i#1==(byte) 1) goto main::@2
|
||||
to:main::@4
|
||||
main::@4: scope:[main] from main::@1
|
||||
[10] if((byte) main::i#1!=(byte) 4) goto main::@3
|
||||
to:main::@2
|
||||
main::@2: scope:[main] from main::@1 main::@4
|
||||
[11] (byte~) main::$0 ← (byte) '0' + (byte) main::i#1
|
||||
[12] *((const byte*) main::SCREEN#0 + (byte) main::i#1) ← (byte~) main::$0
|
||||
to:main::@3
|
482
src/test/ref/switch-4.log
Normal file
482
src/test/ref/switch-4.log
Normal file
@ -0,0 +1,482 @@
|
||||
Culled Empty Block (label) main::@2
|
||||
Culled Empty Block (label) main::@9
|
||||
Culled Empty Block (label) main::@4
|
||||
Culled Empty Block (label) main::@10
|
||||
Culled Empty Block (label) main::@5
|
||||
Culled Empty Block (label) main::@6
|
||||
Culled Empty Block (label) main::@11
|
||||
|
||||
CONTROL FLOW GRAPH SSA
|
||||
@begin: scope:[] from
|
||||
to:@1
|
||||
main: scope:[main] from @1
|
||||
(byte*) main::SCREEN#0 ← ((byte*)) (number) $400
|
||||
(byte) main::i#0 ← (byte) 0
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@7
|
||||
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@7/(byte) main::i#1 )
|
||||
if((byte) main::i#2==(number) 1) goto main::@3
|
||||
to:main::@8
|
||||
main::@8: scope:[main] from main::@1
|
||||
(byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
|
||||
if((byte) main::i#3==(number) 4) goto main::@3
|
||||
to:main::@7
|
||||
main::@3: scope:[main] from main::@1 main::@8
|
||||
(byte) main::i#4 ← phi( main::@1/(byte) main::i#2 main::@8/(byte) main::i#3 )
|
||||
(byte~) main::$0 ← (byte) '0' + (byte) main::i#4
|
||||
*((byte*) main::SCREEN#0 + (byte) main::i#4) ← (byte~) main::$0
|
||||
to:main::@7
|
||||
main::@7: scope:[main] from main::@3 main::@8
|
||||
(byte) main::i#5 ← phi( main::@3/(byte) main::i#4 main::@8/(byte) main::i#3 )
|
||||
(byte) main::i#1 ← (byte) main::i#5 + rangenext(0,5)
|
||||
(bool~) main::$1 ← (byte) main::i#1 != rangelast(0,5)
|
||||
if((bool~) main::$1) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@7
|
||||
return
|
||||
to:@return
|
||||
@1: scope:[] from @begin
|
||||
call main
|
||||
to:@2
|
||||
@2: scope:[] from @1
|
||||
to:@end
|
||||
@end: scope:[] from @2
|
||||
|
||||
SYMBOL TABLE SSA
|
||||
(label) @1
|
||||
(label) @2
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0
|
||||
(bool~) main::$1
|
||||
(label) main::@1
|
||||
(label) main::@3
|
||||
(label) main::@7
|
||||
(label) main::@8
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(byte*) main::SCREEN#0
|
||||
(byte) main::i
|
||||
(byte) main::i#0
|
||||
(byte) main::i#1
|
||||
(byte) main::i#2
|
||||
(byte) main::i#3
|
||||
(byte) main::i#4
|
||||
(byte) main::i#5
|
||||
|
||||
Adding number conversion cast (unumber) 1 in if((byte) main::i#2==(number) 1) goto main::@3
|
||||
Adding number conversion cast (unumber) 4 in if((byte) main::i#3==(number) 4) goto main::@3
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Inlining cast (byte*) main::SCREEN#0 ← (byte*)(number) $400
|
||||
Successful SSA optimization Pass2InlineCast
|
||||
Simplifying constant pointer cast (byte*) 1024
|
||||
Simplifying constant integer cast 1
|
||||
Simplifying constant integer cast 4
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 1
|
||||
Finalized unsigned number type (byte) 4
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Alias (byte) main::i#2 = (byte) main::i#3
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Alias (byte) main::i#2 = (byte) main::i#4
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Alias (byte) main::i#2 = (byte) main::i#5
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Simple Condition (bool~) main::$1 [12] if((byte) main::i#1!=rangelast(0,5)) goto main::@1
|
||||
Successful SSA optimization Pass2ConditionalJumpSimplification
|
||||
Negating conditional jump and destination [5] if((byte) main::i#2!=(byte) 4) goto main::@7
|
||||
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
|
||||
Constant (const byte*) main::SCREEN#0 = (byte*) 1024
|
||||
Constant (const byte) main::i#0 = 0
|
||||
Successful SSA optimization Pass2ConstantIdentification
|
||||
Resolved ranged next value [10] main::i#1 ← ++ main::i#2 to ++
|
||||
Resolved ranged comparison value [12] if(main::i#1!=rangelast(0,5)) goto main::@1 to (number) 6
|
||||
Successful SSA optimization Pass2LoopHeadConstantIdentification
|
||||
Adding number conversion cast (unumber) 6 in if((byte) main::i#1!=(number) 6) goto main::@1
|
||||
Successful SSA optimization PassNAddNumberTypeConversions
|
||||
Simplifying constant integer cast 6
|
||||
Successful SSA optimization PassNCastSimplification
|
||||
Finalized unsigned number type (byte) 6
|
||||
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
||||
Alias (byte) main::i#1 = (byte) main::i#2
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Identical Phi Values (byte) main::i#9 (const byte) main::i#0
|
||||
Successful SSA optimization Pass2IdenticalPhiElimination
|
||||
Removing PHI-reference to removed block (main::@1_1) in block main::@3
|
||||
if() condition always false - eliminating [13] if((const byte) main::i#0==(byte) 1) goto main::@3
|
||||
Successful SSA optimization Pass2ConstantIfs
|
||||
Successful SSA optimization Pass2LoopHeadConstantIdentification
|
||||
Alias (byte) main::i#1 = (byte) main::i#6
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Identical Phi Values (byte) main::i#10 (const byte) main::i#0
|
||||
Successful SSA optimization Pass2IdenticalPhiElimination
|
||||
Removing PHI-reference to removed block (main::@8_1) in block main::@3
|
||||
if() condition always true - replacing block destination [12] if((const byte) main::i#0!=(byte) 4) goto main::@7
|
||||
Successful SSA optimization Pass2ConstantIfs
|
||||
Alias (byte) main::i#1 = (byte) main::i#7
|
||||
Successful SSA optimization Pass2AliasElimination
|
||||
Inlining constant with var siblings (const byte) main::i#0
|
||||
Constant inlined main::i#0 = (byte) 0
|
||||
Successful SSA optimization Pass2ConstantInlining
|
||||
Added new block during phi lifting main::@12(between main::@8 and main::@7)
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @2
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
Adding NOP phi() at start of main::@1_1
|
||||
Adding NOP phi() at start of main::@8_1
|
||||
CALL GRAPH
|
||||
Calls in [] to main:2
|
||||
|
||||
Created 1 initial phi equivalence classes
|
||||
Coalesced [16] main::i#11 ← main::i#1
|
||||
Coalesced (already) [17] main::i#12 ← main::i#1
|
||||
Coalesced down to 1 phi equivalence classes
|
||||
Culled Empty Block (label) @2
|
||||
Culled Empty Block (label) main::@1_1
|
||||
Culled Empty Block (label) main::@8_1
|
||||
Culled Empty Block (label) main::@12
|
||||
Renumbering block main::@3 to main::@2
|
||||
Renumbering block main::@7 to main::@3
|
||||
Renumbering block main::@8 to main::@4
|
||||
Adding NOP phi() at start of @begin
|
||||
Adding NOP phi() at start of @1
|
||||
Adding NOP phi() at start of @end
|
||||
Adding NOP phi() at start of main
|
||||
|
||||
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] phi()
|
||||
to:main::@3
|
||||
main::@3: scope:[main] from main main::@2 main::@4
|
||||
[5] (byte) main::i#8 ← phi( main::@2/(byte) main::i#1 main::@4/(byte) main::i#1 main/(byte) 0 )
|
||||
[6] (byte) main::i#1 ← ++ (byte) main::i#8
|
||||
[7] if((byte) main::i#1!=(byte) 6) goto main::@1
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@3
|
||||
[8] return
|
||||
to:@return
|
||||
main::@1: scope:[main] from main::@3
|
||||
[9] if((byte) main::i#1==(byte) 1) goto main::@2
|
||||
to:main::@4
|
||||
main::@4: scope:[main] from main::@1
|
||||
[10] if((byte) main::i#1!=(byte) 4) goto main::@3
|
||||
to:main::@2
|
||||
main::@2: scope:[main] from main::@1 main::@4
|
||||
[11] (byte~) main::$0 ← (byte) '0' + (byte) main::i#1
|
||||
[12] *((const byte*) main::SCREEN#0 + (byte) main::i#1) ← (byte~) main::$0
|
||||
to:main::@3
|
||||
|
||||
|
||||
VARIABLE REGISTER WEIGHTS
|
||||
(void()) main()
|
||||
(byte~) main::$0 22.0
|
||||
(byte*) main::SCREEN
|
||||
(byte) main::i
|
||||
(byte) main::i#1 89.66666666666664
|
||||
(byte) main::i#8 213.0
|
||||
|
||||
Initial phi equivalence classes
|
||||
[ main::i#8 main::i#1 ]
|
||||
Added variable main::$0 to zero page equivalence class [ main::$0 ]
|
||||
Complete equivalence classes
|
||||
[ main::i#8 main::i#1 ]
|
||||
[ main::$0 ]
|
||||
Allocated zp ZP_BYTE:2 [ main::i#8 main::i#1 ]
|
||||
Allocated zp ZP_BYTE:3 [ main::$0 ]
|
||||
|
||||
INITIAL ASM
|
||||
Target platform is c64basic
|
||||
// File Comments
|
||||
// Tests simple switch()-statement - switch without default
|
||||
// Expeced output "14"
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// @begin
|
||||
bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
// @1
|
||||
b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
// @end
|
||||
bend:
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _0 = 3
|
||||
.label i = 2
|
||||
// [5] phi from main to main::@3 [phi:main->main::@3]
|
||||
b3_from_main:
|
||||
// [5] phi (byte) main::i#8 = (byte) 0 [phi:main->main::@3#0] -- vbuz1=vbuc1
|
||||
lda #0
|
||||
sta.z i
|
||||
jmp b3
|
||||
// [5] phi from main::@2 main::@4 to main::@3 [phi:main::@2/main::@4->main::@3]
|
||||
b3_from_b2:
|
||||
b3_from_b4:
|
||||
// [5] phi (byte) main::i#8 = (byte) main::i#1 [phi:main::@2/main::@4->main::@3#0] -- register_copy
|
||||
jmp b3
|
||||
// main::@3
|
||||
b3:
|
||||
// [6] (byte) main::i#1 ← ++ (byte) main::i#8 -- vbuz1=_inc_vbuz1
|
||||
inc.z i
|
||||
// [7] if((byte) main::i#1!=(byte) 6) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda #6
|
||||
cmp.z i
|
||||
bne b1
|
||||
jmp breturn
|
||||
// main::@return
|
||||
breturn:
|
||||
// [8] return
|
||||
rts
|
||||
// main::@1
|
||||
b1:
|
||||
// [9] if((byte) main::i#1==(byte) 1) goto main::@2 -- vbuz1_eq_vbuc1_then_la1
|
||||
lda #1
|
||||
cmp.z i
|
||||
beq b2
|
||||
jmp b4
|
||||
// main::@4
|
||||
b4:
|
||||
// [10] if((byte) main::i#1!=(byte) 4) goto main::@3 -- vbuz1_neq_vbuc1_then_la1
|
||||
lda #4
|
||||
cmp.z i
|
||||
bne b3_from_b4
|
||||
jmp b2
|
||||
// main::@2
|
||||
b2:
|
||||
// [11] (byte~) main::$0 ← (byte) '0' + (byte) main::i#1 -- vbuz1=vbuc1_plus_vbuz2
|
||||
lax.z i
|
||||
axs #-['0']
|
||||
stx.z _0
|
||||
// [12] *((const byte*) main::SCREEN#0 + (byte) main::i#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2
|
||||
lda.z _0
|
||||
ldy.z i
|
||||
sta SCREEN,y
|
||||
jmp b3_from_b2
|
||||
}
|
||||
// File Data
|
||||
|
||||
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||
Potential registers zp ZP_BYTE:2 [ main::i#8 main::i#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y ,
|
||||
Potential registers zp ZP_BYTE:3 [ main::$0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
|
||||
|
||||
REGISTER UPLIFT SCOPES
|
||||
Uplift Scope [main] 302.67: zp ZP_BYTE:2 [ main::i#8 main::i#1 ] 22: zp ZP_BYTE:3 [ main::$0 ]
|
||||
Uplift Scope []
|
||||
|
||||
Uplifting [main] best 3408 combination reg byte x [ main::i#8 main::i#1 ] reg byte a [ main::$0 ]
|
||||
Uplifting [] best 3408 combination
|
||||
|
||||
ASSEMBLER BEFORE OPTIMIZATION
|
||||
// File Comments
|
||||
// Tests simple switch()-statement - switch without default
|
||||
// Expeced output "14"
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(bbegin)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// @begin
|
||||
bbegin:
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
b1_from_bbegin:
|
||||
jmp b1
|
||||
// @1
|
||||
b1:
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
main_from_b1:
|
||||
jsr main
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
bend_from_b1:
|
||||
jmp bend
|
||||
// @end
|
||||
bend:
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [5] phi from main to main::@3 [phi:main->main::@3]
|
||||
b3_from_main:
|
||||
// [5] phi (byte) main::i#8 = (byte) 0 [phi:main->main::@3#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
jmp b3
|
||||
// [5] phi from main::@2 main::@4 to main::@3 [phi:main::@2/main::@4->main::@3]
|
||||
b3_from_b2:
|
||||
b3_from_b4:
|
||||
// [5] phi (byte) main::i#8 = (byte) main::i#1 [phi:main::@2/main::@4->main::@3#0] -- register_copy
|
||||
jmp b3
|
||||
// main::@3
|
||||
b3:
|
||||
// [6] (byte) main::i#1 ← ++ (byte) main::i#8 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [7] if((byte) main::i#1!=(byte) 6) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #6
|
||||
bne b1
|
||||
jmp breturn
|
||||
// main::@return
|
||||
breturn:
|
||||
// [8] return
|
||||
rts
|
||||
// main::@1
|
||||
b1:
|
||||
// [9] if((byte) main::i#1==(byte) 1) goto main::@2 -- vbuxx_eq_vbuc1_then_la1
|
||||
cpx #1
|
||||
beq b2
|
||||
jmp b4
|
||||
// main::@4
|
||||
b4:
|
||||
// [10] if((byte) main::i#1!=(byte) 4) goto main::@3 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #4
|
||||
bne b3_from_b4
|
||||
jmp b2
|
||||
// main::@2
|
||||
b2:
|
||||
// [11] (byte~) main::$0 ← (byte) '0' + (byte) main::i#1 -- vbuaa=vbuc1_plus_vbuxx
|
||||
txa
|
||||
clc
|
||||
adc #'0'
|
||||
// [12] *((const byte*) main::SCREEN#0 + (byte) main::i#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
jmp b3_from_b2
|
||||
}
|
||||
// File Data
|
||||
|
||||
ASSEMBLER OPTIMIZATIONS
|
||||
Removing instruction jmp b1
|
||||
Removing instruction jmp bend
|
||||
Removing instruction jmp b3
|
||||
Removing instruction jmp breturn
|
||||
Removing instruction jmp b4
|
||||
Removing instruction jmp b2
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Replacing label b3_from_b4 with b3
|
||||
Replacing label b3_from_b2 with b3
|
||||
Removing instruction b1_from_bbegin:
|
||||
Removing instruction b1:
|
||||
Removing instruction main_from_b1:
|
||||
Removing instruction bend_from_b1:
|
||||
Removing instruction b3_from_b2:
|
||||
Removing instruction b3_from_b4:
|
||||
Succesful ASM optimization Pass5RedundantLabelElimination
|
||||
Removing instruction bend:
|
||||
Removing instruction b3_from_main:
|
||||
Removing instruction breturn:
|
||||
Removing instruction b4:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
Updating BasicUpstart to call main directly
|
||||
Removing instruction jsr main
|
||||
Succesful ASM optimization Pass5SkipBegin
|
||||
Removing instruction jmp b3
|
||||
Succesful ASM optimization Pass5NextJumpElimination
|
||||
Removing instruction bbegin:
|
||||
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||
|
||||
FINAL SYMBOL TABLE
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@4
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 89.66666666666664
|
||||
(byte) main::i#8 reg byte x 213.0
|
||||
|
||||
reg byte x [ main::i#8 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
||||
|
||||
|
||||
FINAL ASSEMBLER
|
||||
Score: 1896
|
||||
|
||||
// File Comments
|
||||
// Tests simple switch()-statement - switch without default
|
||||
// Expeced output "14"
|
||||
// Upstart
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
// Global Constants & labels
|
||||
// @begin
|
||||
// [1] phi from @begin to @1 [phi:@begin->@1]
|
||||
// @1
|
||||
// [2] call main
|
||||
// [4] phi from @1 to main [phi:@1->main]
|
||||
// [3] phi from @1 to @end [phi:@1->@end]
|
||||
// @end
|
||||
// main
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
// [5] phi from main to main::@3 [phi:main->main::@3]
|
||||
// [5] phi (byte) main::i#8 = (byte) 0 [phi:main->main::@3#0] -- vbuxx=vbuc1
|
||||
ldx #0
|
||||
// [5] phi from main::@2 main::@4 to main::@3 [phi:main::@2/main::@4->main::@3]
|
||||
// [5] phi (byte) main::i#8 = (byte) main::i#1 [phi:main::@2/main::@4->main::@3#0] -- register_copy
|
||||
// main::@3
|
||||
b3:
|
||||
// for(char i:0..5)
|
||||
// [6] (byte) main::i#1 ← ++ (byte) main::i#8 -- vbuxx=_inc_vbuxx
|
||||
inx
|
||||
// [7] if((byte) main::i#1!=(byte) 6) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #6
|
||||
bne b1
|
||||
// main::@return
|
||||
// }
|
||||
// [8] return
|
||||
rts
|
||||
// main::@1
|
||||
b1:
|
||||
// case 1:
|
||||
// [9] if((byte) main::i#1==(byte) 1) goto main::@2 -- vbuxx_eq_vbuc1_then_la1
|
||||
cpx #1
|
||||
beq b2
|
||||
// main::@4
|
||||
// case 4:
|
||||
// SCREEN[i] = '0'+i;
|
||||
// break;
|
||||
// [10] if((byte) main::i#1!=(byte) 4) goto main::@3 -- vbuxx_neq_vbuc1_then_la1
|
||||
cpx #4
|
||||
bne b3
|
||||
// main::@2
|
||||
b2:
|
||||
// '0'+i
|
||||
// [11] (byte~) main::$0 ← (byte) '0' + (byte) main::i#1 -- vbuaa=vbuc1_plus_vbuxx
|
||||
txa
|
||||
clc
|
||||
adc #'0'
|
||||
// SCREEN[i] = '0'+i
|
||||
// [12] *((const byte*) main::SCREEN#0 + (byte) main::i#1) ← (byte~) main::$0 -- pbuc1_derefidx_vbuxx=vbuaa
|
||||
sta SCREEN,x
|
||||
jmp b3
|
||||
}
|
||||
// File Data
|
||||
|
18
src/test/ref/switch-4.sym
Normal file
18
src/test/ref/switch-4.sym
Normal file
@ -0,0 +1,18 @@
|
||||
(label) @1
|
||||
(label) @begin
|
||||
(label) @end
|
||||
(void()) main()
|
||||
(byte~) main::$0 reg byte a 22.0
|
||||
(label) main::@1
|
||||
(label) main::@2
|
||||
(label) main::@3
|
||||
(label) main::@4
|
||||
(label) main::@return
|
||||
(byte*) main::SCREEN
|
||||
(const byte*) main::SCREEN#0 SCREEN = (byte*) 1024
|
||||
(byte) main::i
|
||||
(byte) main::i#1 reg byte x 89.66666666666664
|
||||
(byte) main::i#8 reg byte x 213.0
|
||||
|
||||
reg byte x [ main::i#8 main::i#1 ]
|
||||
reg byte a [ main::$0 ]
|
Loading…
x
Reference in New Issue
Block a user