1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-29 03:56:15 +00:00
kickc/src/test/ref/bool-function.log

725 lines
24 KiB
Plaintext

CONTROL FLOW GRAPH SSA
@begin: scope:[] from
to:@1
(void()) main()
main: scope:[main] from @1
(byte) main::i#0 ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@3
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@3/(byte) main::i#1 )
(number~) main::$0 ← (byte) main::i#2 & (number) 1
(bool~) main::$1 ← (number~) main::$0 == (number) 0
(byte) isSet::i#0 ← (byte) main::i#2
(bool) isSet::b#0 ← (bool~) main::$1
call isSet
(bool) isSet::return#0 ← (bool) isSet::return#2
to:main::@5
main::@5: scope:[main] from main::@1
(byte) main::i#6 ← phi( main::@1/(byte) main::i#2 )
(bool) isSet::return#3 ← phi( main::@1/(bool) isSet::return#0 )
(bool~) main::$2 ← (bool) isSet::return#3
if((bool~) main::$2) goto main::@2
to:main::@4
main::@2: scope:[main] from main::@5
(byte) main::i#3 ← phi( main::@5/(byte) main::i#6 )
*((const byte*) main::screen + (byte) main::i#3) ← (byte) '*'
to:main::@3
main::@4: scope:[main] from main::@5
(byte) main::i#4 ← phi( main::@5/(byte) main::i#6 )
*((const byte*) main::screen + (byte) main::i#4) ← (byte) ' '
to:main::@3
main::@3: scope:[main] from main::@2 main::@4
(byte) main::i#5 ← phi( main::@2/(byte) main::i#3 main::@4/(byte) main::i#4 )
(byte) main::i#1 ← (byte) main::i#5 + rangenext(0,$64)
(bool~) main::$3 ← (byte) main::i#1 != rangelast(0,$64)
if((bool~) main::$3) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@3
return
to:@return
(bool()) isSet((byte) isSet::i , (bool) isSet::b)
isSet: scope:[isSet] from main::@1
(bool) isSet::b#1 ← phi( main::@1/(bool) isSet::b#0 )
(byte) isSet::i#1 ← phi( main::@1/(byte) isSet::i#0 )
(number~) isSet::$0 ← (byte) isSet::i#1 & (number) 8
(bool~) isSet::$1 ← (number~) isSet::$0 != (number) 0
(bool~) isSet::$2 ← (bool) isSet::b#1 || (bool~) isSet::$1
(bool) isSet::return#1 ← (bool~) isSet::$2
to:isSet::@return
isSet::@return: scope:[isSet] from isSet
(bool) isSet::return#4 ← phi( isSet/(bool) isSet::return#1 )
(bool) isSet::return#2 ← (bool) isSet::return#4
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
(bool()) isSet((byte) isSet::i , (bool) isSet::b)
(number~) isSet::$0
(bool~) isSet::$1
(bool~) isSet::$2
(label) isSet::@return
(bool) isSet::b
(bool) isSet::b#0
(bool) isSet::b#1
(byte) isSet::i
(byte) isSet::i#0
(byte) isSet::i#1
(bool) isSet::return
(bool) isSet::return#0
(bool) isSet::return#1
(bool) isSet::return#2
(bool) isSet::return#3
(bool) isSet::return#4
(void()) main()
(number~) main::$0
(bool~) main::$1
(bool~) main::$2
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@return
(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
(byte) main::i#6
(const byte*) main::screen = (byte*)(number) $400
Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (byte) main::i#2 & (number) 1
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::i#2 & (unumber)(number) 1
Adding number conversion cast (unumber) 0 in (bool~) main::$1 ← (unumber~) main::$0 == (number) 0
Adding number conversion cast (unumber) 8 in (number~) isSet::$0 ← (byte) isSet::i#1 & (number) 8
Adding number conversion cast (unumber) isSet::$0 in (number~) isSet::$0 ← (byte) isSet::i#1 & (unumber)(number) 8
Adding number conversion cast (unumber) 0 in (bool~) isSet::$1 ← (unumber~) isSet::$0 != (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 8
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 8
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::i#2 & (byte) 1
Inferred type updated to byte in (unumber~) isSet::$0 ← (byte) isSet::i#1 & (byte) 8
Alias isSet::b#0 = main::$1
Alias isSet::return#0 = isSet::return#3
Alias main::i#2 = main::i#6 main::i#3 main::i#4
Alias isSet::return#1 = isSet::$2 isSet::return#4 isSet::return#2
Successful SSA optimization Pass2AliasElimination
Alias main::i#2 = main::i#5
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) isSet::i#1 (byte) isSet::i#0
Identical Phi Values (bool) isSet::b#1 (bool) isSet::b#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$3 [13] if((byte) main::i#1!=rangelast(0,$64)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [11] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [13] if(main::i#1!=rangelast(0,$64)) goto main::@1 to (number) $65
Adding number conversion cast (unumber) $65 in if((byte) main::i#1!=(number) $65) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $65
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $65
Successful SSA optimization PassNFinalizeNumberTypeConversions
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::@6(between main::@3 and main::@1)
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
CALL GRAPH
Calls in [] to main:2
Calls in [main] to isSet:10
Created 1 initial phi equivalence classes
Coalesced [18] main::i#7 ← main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@6
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()
(void()) main()
main: scope:[main] from @1
[4] phi()
to:main::@1
main::@1: scope:[main] from main main::@3
[5] (byte) main::i#2 ← phi( main/(byte) 0 main::@3/(byte) main::i#1 )
[6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1
[7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0
[8] (byte) isSet::i#0 ← (byte) main::i#2
[9] call isSet
[10] (bool) isSet::return#0 ← (bool) isSet::return#1
to:main::@5
main::@5: scope:[main] from main::@1
[11] (bool~) main::$2 ← (bool) isSet::return#0
[12] if((bool~) main::$2) goto main::@2
to:main::@4
main::@4: scope:[main] from main::@5
[13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' '
to:main::@3
main::@3: scope:[main] from main::@2 main::@4
[14] (byte) main::i#1 ← ++ (byte) main::i#2
[15] if((byte) main::i#1!=(byte) $65) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@3
[16] return
to:@return
main::@2: scope:[main] from main::@5
[17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*'
to:main::@3
(bool()) isSet((byte) isSet::i , (bool) isSet::b)
isSet: scope:[isSet] from main::@1
[18] (byte~) isSet::$0 ← (byte) isSet::i#0 & (byte) 8
[19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0
[20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1
to:isSet::@return
isSet::@return: scope:[isSet] from isSet
[21] return
to:@return
VARIABLE REGISTER WEIGHTS
(bool()) isSet((byte) isSet::i , (bool) isSet::b)
(byte~) isSet::$0 2002.0
(bool~) isSet::$1 2002.0
(bool) isSet::b
(bool) isSet::b#0 275.5
(byte) isSet::i
(byte) isSet::i#0 1102.0
(bool) isSet::return
(bool) isSet::return#0 202.0
(bool) isSet::return#1 367.33333333333337
(void()) main()
(byte~) main::$0 202.0
(bool~) main::$2 202.0
(byte) main::i
(byte) main::i#1 151.5
(byte) main::i#2 60.6
Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable isSet::b#0 to live range equivalence class [ isSet::b#0 ]
Added variable isSet::i#0 to live range equivalence class [ isSet::i#0 ]
Added variable isSet::return#0 to live range equivalence class [ isSet::return#0 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable isSet::$0 to live range equivalence class [ isSet::$0 ]
Added variable isSet::$1 to live range equivalence class [ isSet::$1 ]
Added variable isSet::return#1 to live range equivalence class [ isSet::return#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$0 ]
[ isSet::b#0 ]
[ isSet::i#0 ]
[ isSet::return#0 ]
[ main::$2 ]
[ isSet::$0 ]
[ isSet::$1 ]
[ isSet::return#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::$0 ]
Allocated zp[1]:4 [ isSet::b#0 ]
Allocated zp[1]:5 [ isSet::i#0 ]
Allocated zp[1]:6 [ isSet::return#0 ]
Allocated zp[1]:7 [ main::$2 ]
Allocated zp[1]:8 [ isSet::$0 ]
Allocated zp[1]:9 [ isSet::$1 ]
Allocated zp[1]:10 [ isSet::return#1 ]
INITIAL ASM
Target platform is c64basic / MOS6502X
// File Comments
// Test a function taking boolean parameter and returning boolean result
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.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 __2 = 7
.label i = 2
// [5] phi from main to main::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta.z i
jmp __b1
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
__b1_from___b3:
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
jmp __b1
// main::@1
__b1:
// [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuz1=vbuz2_band_vbuc1
lda #1
and.z i
sta.z __0
// [7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0 -- vboz1=vbuz2_eq_vbuc1
lda.z __0
eor #0
beq !+
lda #1
!:
eor #1
sta.z isSet.b
// [8] (byte) isSet::i#0 ← (byte) main::i#2 -- vbuz1=vbuz2
lda.z i
sta.z isSet.i
// [9] call isSet
jsr isSet
// [10] (bool) isSet::return#0 ← (bool) isSet::return#1 -- vboz1=vboz2
lda.z isSet.return_1
sta.z isSet.return
jmp __b5
// main::@5
__b5:
// [11] (bool~) main::$2 ← (bool) isSet::return#0 -- vboz1=vboz2
lda.z isSet.return
sta.z __2
// [12] if((bool~) main::$2) goto main::@2 -- vboz1_then_la1
lda.z __2
cmp #0
bne __b2
jmp __b4
// main::@4
__b4:
// [13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' ' -- pbuc1_derefidx_vbuz1=vbuc2
lda #' '
ldy.z i
sta screen,y
jmp __b3
// main::@3
__b3:
// [14] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
inc.z i
// [15] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda #$65
cmp.z i
bne __b1_from___b3
jmp __breturn
// main::@return
__breturn:
// [16] return
rts
// main::@2
__b2:
// [17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*' -- pbuc1_derefidx_vbuz1=vbuc2
lda #'*'
ldy.z i
sta screen,y
jmp __b3
}
// isSet
// Determine whether to set a char to '*.
// Returns true if i&8!=0 or b=true
// isSet(byte zp(5) i, bool zp(4) b)
isSet: {
.label __0 = 8
.label __1 = 9
.label i = 5
.label b = 4
.label return = 6
.label return_1 = $a
// [18] (byte~) isSet::$0 ← (byte) isSet::i#0 & (byte) 8 -- vbuz1=vbuz2_band_vbuc1
lda #8
and.z i
sta.z __0
// [19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0 -- vboz1=vbuz2_neq_vbuc1
lda.z __0
eor #0
beq !+
lda #1
!:
sta.z __1
// [20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1 -- vboz1=vboz2_or_vboz3
lda.z b
ora.z __1
sta.z return_1
jmp __breturn
// isSet::@return
__breturn:
// [21] return
rts
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0 [ main::i#2 isSet::b#0 ] ( main:2 [ main::i#2 isSet::b#0 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' ' [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a
Statement [17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*' [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a
Statement [19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0 [ isSet::b#0 isSet::$1 ] ( main:2::isSet:9 [ main::i#2 isSet::b#0 isSet::$1 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp[1]:4 [ isSet::b#0 ]
Statement [20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1 [ isSet::return#1 ] ( main:2::isSet:9 [ main::i#2 isSet::return#1 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Statement [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 [ main::i#2 main::$0 ] ( main:2 [ main::i#2 main::$0 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Statement [7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0 [ main::i#2 isSet::b#0 ] ( main:2 [ main::i#2 isSet::b#0 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Statement [13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' ' [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a
Statement [17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*' [ main::i#2 ] ( main:2 [ main::i#2 ] { } ) always clobbers reg byte a
Statement [19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0 [ isSet::b#0 isSet::$1 ] ( main:2::isSet:9 [ main::i#2 isSet::b#0 isSet::$1 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Statement [20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1 [ isSet::return#1 ] ( main:2::isSet:9 [ main::i#2 isSet::return#1 ] { { isSet::i#0 = main::i#2 } { isSet::return#0 = isSet::return#1 } } ) always clobbers reg byte a
Potential registers zp[1]:2 [ main::i#2 main::i#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 ,
Potential registers zp[1]:4 [ isSet::b#0 ] : zp[1]:4 , reg byte x , reg byte y ,
Potential registers zp[1]:5 [ isSet::i#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:6 [ isSet::return#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:7 [ main::$2 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:8 [ isSet::$0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:9 [ isSet::$1 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:10 [ isSet::return#1 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [isSet] 2,002: zp[1]:8 [ isSet::$0 ] 2,002: zp[1]:9 [ isSet::$1 ] 1,102: zp[1]:5 [ isSet::i#0 ] 367.33: zp[1]:10 [ isSet::return#1 ] 275.5: zp[1]:4 [ isSet::b#0 ] 202: zp[1]:6 [ isSet::return#0 ]
Uplift Scope [main] 212.1: zp[1]:2 [ main::i#2 main::i#1 ] 202: zp[1]:3 [ main::$0 ] 202: zp[1]:7 [ main::$2 ]
Uplift Scope []
Uplifting [isSet] best 1103 combination reg byte a [ isSet::$0 ] reg byte a [ isSet::$1 ] reg byte a [ isSet::i#0 ] reg byte a [ isSet::return#1 ] zp[1]:4 [ isSet::b#0 ] zp[1]:6 [ isSet::return#0 ]
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [main] best 813 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$0 ] reg byte a [ main::$2 ]
Uplifting [] best 813 combination
Attempting to uplift remaining variables inzp[1]:4 [ isSet::b#0 ]
Uplifting [isSet] best 806 combination reg byte y [ isSet::b#0 ]
Attempting to uplift remaining variables inzp[1]:6 [ isSet::return#0 ]
Uplifting [isSet] best 746 combination reg byte a [ isSet::return#0 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Test a function taking boolean parameter and returning boolean result
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.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::@1 [phi:main->main::@1]
__b1_from_main:
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
jmp __b1
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
__b1_from___b3:
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
jmp __b1
// main::@1
__b1:
// [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1
txa
and #1
// [7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0 -- vboyy=vbuaa_eq_vbuc1
eor #0
beq !+
lda #1
!:
eor #1
tay
// [8] (byte) isSet::i#0 ← (byte) main::i#2 -- vbuaa=vbuxx
txa
// [9] call isSet
jsr isSet
// [10] (bool) isSet::return#0 ← (bool) isSet::return#1
jmp __b5
// main::@5
__b5:
// [11] (bool~) main::$2 ← (bool) isSet::return#0
// [12] if((bool~) main::$2) goto main::@2 -- vboaa_then_la1
cmp #0
bne __b2
jmp __b4
// main::@4
__b4:
// [13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
lda #' '
sta screen,x
jmp __b3
// main::@3
__b3:
// [14] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
// [15] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #$65
bne __b1_from___b3
jmp __breturn
// main::@return
__breturn:
// [16] return
rts
// main::@2
__b2:
// [17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*' -- pbuc1_derefidx_vbuxx=vbuc2
lda #'*'
sta screen,x
jmp __b3
}
// isSet
// Determine whether to set a char to '*.
// Returns true if i&8!=0 or b=true
// isSet(byte register(A) i, bool register(Y) b)
isSet: {
// [18] (byte~) isSet::$0 ← (byte) isSet::i#0 & (byte) 8 -- vbuaa=vbuaa_band_vbuc1
and #8
// [19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0 -- vboaa=vbuaa_neq_vbuc1
eor #0
beq !+
lda #1
!:
// [20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1 -- vboaa=vboyy_or_vboaa
sty.z $ff
ora.z $ff
jmp __breturn
// isSet::@return
__breturn:
// [21] return
rts
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b5
Removing instruction jmp __b4
Removing instruction jmp __b3
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b1_from___b3 with __b1
Removing instruction __b1_from___bbegin:
Removing instruction __b1:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bbegin:
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b5:
Removing instruction __b4:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(bool()) isSet((byte) isSet::i , (bool) isSet::b)
(byte~) isSet::$0 reg byte a 2002.0
(bool~) isSet::$1 reg byte a 2002.0
(label) isSet::@return
(bool) isSet::b
(bool) isSet::b#0 reg byte y 275.5
(byte) isSet::i
(byte) isSet::i#0 reg byte a 1102.0
(bool) isSet::return
(bool) isSet::return#0 reg byte a 202.0
(bool) isSet::return#1 reg byte a 367.33333333333337
(void()) main()
(byte~) main::$0 reg byte a 202.0
(bool~) main::$2 reg byte a 202.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 151.5
(byte) main::i#2 reg byte x 60.6
(const byte*) main::screen = (byte*) 1024
reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::$0 ]
reg byte y [ isSet::b#0 ]
reg byte a [ isSet::i#0 ]
reg byte a [ isSet::return#0 ]
reg byte a [ main::$2 ]
reg byte a [ isSet::$0 ]
reg byte a [ isSet::$1 ]
reg byte a [ isSet::return#1 ]
FINAL ASSEMBLER
Score: 551
// File Comments
// Test a function taking boolean parameter and returning boolean result
// 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::@1 [phi:main->main::@1]
// [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
// [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy
// main::@1
__b1:
// i&1
// [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1
txa
and #1
// isSet(i, (i&1)==0)
// [7] (bool) isSet::b#0 ← (byte~) main::$0 == (byte) 0 -- vboyy=vbuaa_eq_vbuc1
eor #0
beq !+
lda #1
!:
eor #1
tay
// [8] (byte) isSet::i#0 ← (byte) main::i#2 -- vbuaa=vbuxx
txa
// [9] call isSet
jsr isSet
// [10] (bool) isSet::return#0 ← (bool) isSet::return#1
// main::@5
// [11] (bool~) main::$2 ← (bool) isSet::return#0
// if( isSet(i, (i&1)==0))
// [12] if((bool~) main::$2) goto main::@2 -- vboaa_then_la1
cmp #0
bne __b2
// main::@4
// screen[i] = ' '
// [13] *((const byte*) main::screen + (byte) main::i#2) ← (byte) ' ' -- pbuc1_derefidx_vbuxx=vbuc2
lda #' '
sta screen,x
// main::@3
__b3:
// for(byte i: 0..100)
// [14] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
// [15] if((byte) main::i#1!=(byte) $65) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #$65
bne __b1
// main::@return
// }
// [16] return
rts
// main::@2
__b2:
// screen[i] = '*'
// [17] *((const byte*) main::screen + (byte) main::i#2) ← (byte) '*' -- pbuc1_derefidx_vbuxx=vbuc2
lda #'*'
sta screen,x
jmp __b3
}
// isSet
// Determine whether to set a char to '*.
// Returns true if i&8!=0 or b=true
// isSet(byte register(A) i, bool register(Y) b)
isSet: {
// i&8
// [18] (byte~) isSet::$0 ← (byte) isSet::i#0 & (byte) 8 -- vbuaa=vbuaa_band_vbuc1
and #8
// (i&8)!=0
// [19] (bool~) isSet::$1 ← (byte~) isSet::$0 != (byte) 0 -- vboaa=vbuaa_neq_vbuc1
eor #0
beq !+
lda #1
!:
// b || ((i&8)!=0)
// [20] (bool) isSet::return#1 ← (bool) isSet::b#0 || (bool~) isSet::$1 -- vboaa=vboyy_or_vboaa
sty.z $ff
ora.z $ff
// isSet::@return
// }
// [21] return
rts
}
// File Data