mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-07 22:25:13 +00:00
586 lines
18 KiB
Plaintext
586 lines
18 KiB
Plaintext
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
to:@1
|
|
|
|
(word()) strlen((byte*) strlen::str)
|
|
strlen: scope:[strlen] from main
|
|
(byte*) strlen::str#4 ← phi( main/(byte*) strlen::str#1 )
|
|
(word) strlen::len#0 ← (word) 0
|
|
to:strlen::@1
|
|
strlen::@1: scope:[strlen] from strlen strlen::@2
|
|
(word) strlen::len#4 ← phi( strlen/(word) strlen::len#0 strlen::@2/(word) strlen::len#1 )
|
|
(byte*) strlen::str#2 ← phi( strlen/(byte*) strlen::str#4 strlen::@2/(byte*) strlen::str#0 )
|
|
(bool~) strlen::$0 ← (number) 0 != *((byte*) strlen::str#2)
|
|
if((bool~) strlen::$0) goto strlen::@2
|
|
to:strlen::@3
|
|
strlen::@2: scope:[strlen] from strlen::@1
|
|
(byte*) strlen::str#3 ← phi( strlen::@1/(byte*) strlen::str#2 )
|
|
(word) strlen::len#2 ← phi( strlen::@1/(word) strlen::len#4 )
|
|
(word) strlen::len#1 ← ++ (word) strlen::len#2
|
|
(byte*) strlen::str#0 ← ++ (byte*) strlen::str#3
|
|
to:strlen::@1
|
|
strlen::@3: scope:[strlen] from strlen::@1
|
|
(word) strlen::len#3 ← phi( strlen::@1/(word) strlen::len#4 )
|
|
(word) strlen::return#0 ← (word) strlen::len#3
|
|
to:strlen::@return
|
|
strlen::@return: scope:[strlen] from strlen::@3
|
|
(word) strlen::return#3 ← phi( strlen::@3/(word) strlen::return#0 )
|
|
(word) strlen::return#1 ← (word) strlen::return#3
|
|
return
|
|
to:@return
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
(byte*) strlen::str#1 ← (const byte*) STR
|
|
call strlen
|
|
(word) strlen::return#2 ← (word) strlen::return#1
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
(word) strlen::return#4 ← phi( main/(word) strlen::return#2 )
|
|
(word~) main::$0 ← (word) strlen::return#4
|
|
*((const nomodify byte*) SCREEN + (number) 0) ← (byte)(word~) main::$0
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
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
|
|
(const nomodify byte*) SCREEN = (byte*)(number) $400
|
|
(const byte*) STR = (byte*) "camelot!"
|
|
(void()) main()
|
|
(word~) main::$0
|
|
(label) main::@1
|
|
(label) main::@return
|
|
(word()) strlen((byte*) strlen::str)
|
|
(bool~) strlen::$0
|
|
(label) strlen::@1
|
|
(label) strlen::@2
|
|
(label) strlen::@3
|
|
(label) strlen::@return
|
|
(word) strlen::len
|
|
(word) strlen::len#0
|
|
(word) strlen::len#1
|
|
(word) strlen::len#2
|
|
(word) strlen::len#3
|
|
(word) strlen::len#4
|
|
(word) strlen::return
|
|
(word) strlen::return#0
|
|
(word) strlen::return#1
|
|
(word) strlen::return#2
|
|
(word) strlen::return#3
|
|
(word) strlen::return#4
|
|
(byte*) strlen::str
|
|
(byte*) strlen::str#0
|
|
(byte*) strlen::str#1
|
|
(byte*) strlen::str#2
|
|
(byte*) strlen::str#3
|
|
(byte*) strlen::str#4
|
|
|
|
Adding number conversion cast (unumber) 0 in (bool~) strlen::$0 ← (number) 0 != *((byte*) strlen::str#2)
|
|
Adding number conversion cast (unumber) 0 in *((const nomodify byte*) SCREEN + (number) 0) ← (byte)(word~) 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 strlen::len#2 = strlen::len#4 strlen::len#3 strlen::return#0 strlen::return#3 strlen::return#1
|
|
Alias strlen::str#2 = strlen::str#3
|
|
Alias strlen::return#2 = strlen::return#4
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values (byte*) strlen::str#4 (byte*) strlen::str#1
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Simple Condition (bool~) strlen::$0 [4] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant (const word) strlen::len#0 = 0
|
|
Constant (const byte*) strlen::str#1 = STR
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Simplifying expression containing zero SCREEN in [12] *((const nomodify byte*) SCREEN + (byte) 0) ← (byte)(word~) main::$0
|
|
Successful SSA optimization PassNSimplifyExpressionWithZero
|
|
Inlining constant with var siblings (const word) strlen::len#0
|
|
Inlining constant with var siblings (const byte*) strlen::str#1
|
|
Constant inlined strlen::len#0 = (word) 0
|
|
Constant inlined strlen::str#1 = (const byte*) STR
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
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 strlen
|
|
Adding NOP phi() at start of strlen::@3
|
|
CALL GRAPH
|
|
Calls in [] to main:2
|
|
Calls in [main] to strlen:6
|
|
|
|
Created 2 initial phi equivalence classes
|
|
Coalesced [18] strlen::str#5 ← strlen::str#0
|
|
Coalesced [19] strlen::len#5 ← strlen::len#1
|
|
Coalesced down to 2 phi equivalence classes
|
|
Culled Empty Block (label) @2
|
|
Culled Empty Block (label) strlen::@3
|
|
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
|
|
Adding NOP phi() at start of strlen
|
|
|
|
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()
|
|
[5] call strlen
|
|
[6] (word) strlen::return#2 ← (word) strlen::len#2
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
[7] (word~) main::$0 ← (word) strlen::return#2
|
|
[8] *((const nomodify byte*) SCREEN) ← (byte)(word~) main::$0
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@1
|
|
[9] return
|
|
to:@return
|
|
|
|
(word()) strlen((byte*) strlen::str)
|
|
strlen: scope:[strlen] from main
|
|
[10] phi()
|
|
to:strlen::@1
|
|
strlen::@1: scope:[strlen] from strlen strlen::@2
|
|
[11] (word) strlen::len#2 ← phi( strlen/(word) 0 strlen::@2/(word) strlen::len#1 )
|
|
[11] (byte*) strlen::str#2 ← phi( strlen/(const byte*) STR strlen::@2/(byte*) strlen::str#0 )
|
|
[12] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2
|
|
to:strlen::@return
|
|
strlen::@return: scope:[strlen] from strlen::@1
|
|
[13] return
|
|
to:@return
|
|
strlen::@2: scope:[strlen] from strlen::@1
|
|
[14] (word) strlen::len#1 ← ++ (word) strlen::len#2
|
|
[15] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2
|
|
to:strlen::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(void()) main()
|
|
(word~) main::$0 11.0
|
|
(word()) strlen((byte*) strlen::str)
|
|
(word) strlen::len
|
|
(word) strlen::len#1 1001.0
|
|
(word) strlen::len#2 503.25
|
|
(word) strlen::return
|
|
(word) strlen::return#2 22.0
|
|
(byte*) strlen::str
|
|
(byte*) strlen::str#0 2002.0
|
|
(byte*) strlen::str#2 1001.0
|
|
|
|
Initial phi equivalence classes
|
|
[ strlen::str#2 strlen::str#0 ]
|
|
[ strlen::len#2 strlen::len#1 ]
|
|
Added variable strlen::return#2 to live range equivalence class [ strlen::return#2 ]
|
|
Added variable main::$0 to live range equivalence class [ main::$0 ]
|
|
Complete equivalence classes
|
|
[ strlen::str#2 strlen::str#0 ]
|
|
[ strlen::len#2 strlen::len#1 ]
|
|
[ strlen::return#2 ]
|
|
[ main::$0 ]
|
|
Allocated zp[2]:2 [ strlen::str#2 strlen::str#0 ]
|
|
Allocated zp[2]:4 [ strlen::len#2 strlen::len#1 ]
|
|
Allocated zp[2]:6 [ strlen::return#2 ]
|
|
Allocated zp[2]:8 [ main::$0 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Includes a system library - ignores the local file with the same name
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label SCREEN = $400
|
|
// @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 __0 = 8
|
|
// [5] call strlen
|
|
// [10] phi from main to strlen [phi:main->strlen]
|
|
strlen_from_main:
|
|
jsr strlen
|
|
// [6] (word) strlen::return#2 ← (word) strlen::len#2 -- vwuz1=vwuz2
|
|
lda.z strlen.len
|
|
sta.z strlen.return
|
|
lda.z strlen.len+1
|
|
sta.z strlen.return+1
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] (word~) main::$0 ← (word) strlen::return#2 -- vwuz1=vwuz2
|
|
lda.z strlen.return
|
|
sta.z __0
|
|
lda.z strlen.return+1
|
|
sta.z __0+1
|
|
// [8] *((const nomodify byte*) SCREEN) ← (byte)(word~) main::$0 -- _deref_pbuc1=_byte_vwuz1
|
|
lda.z __0
|
|
sta SCREEN
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [9] return
|
|
rts
|
|
}
|
|
// strlen
|
|
// Computes the length of the string str up to but not including the terminating null character.
|
|
// strlen(byte* zp(2) str)
|
|
strlen: {
|
|
.label len = 4
|
|
.label str = 2
|
|
.label return = 6
|
|
// [11] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
|
__b1_from_strlen:
|
|
// [11] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
|
lda #<0
|
|
sta.z len
|
|
lda #>0
|
|
sta.z len+1
|
|
// [11] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
|
lda #<STR
|
|
sta.z str
|
|
lda #>STR
|
|
sta.z str+1
|
|
jmp __b1
|
|
// strlen::@1
|
|
__b1:
|
|
// [12] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (str),y
|
|
cmp #0
|
|
bne __b2
|
|
jmp __breturn
|
|
// strlen::@return
|
|
__breturn:
|
|
// [13] return
|
|
rts
|
|
// strlen::@2
|
|
__b2:
|
|
// [14] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
|
inc.z len
|
|
bne !+
|
|
inc.z len+1
|
|
!:
|
|
// [15] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
|
inc.z str
|
|
bne !+
|
|
inc.z str+1
|
|
!:
|
|
// [11] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
|
__b1_from___b2:
|
|
// [11] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
|
// [11] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
STR: .text "camelot!"
|
|
.byte 0
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [6] (word) strlen::return#2 ← (word) strlen::len#2 [ strlen::return#2 ] ( main:2 [ strlen::return#2 ] { { strlen::return#2 = strlen::len#2 } } ) always clobbers reg byte a
|
|
Statement [7] (word~) main::$0 ← (word) strlen::return#2 [ main::$0 ] ( main:2 [ main::$0 ] { } ) always clobbers reg byte a
|
|
Statement [8] *((const nomodify byte*) SCREEN) ← (byte)(word~) main::$0 [ ] ( main:2 [ ] { } ) always clobbers reg byte a
|
|
Statement [12] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 [ strlen::len#2 strlen::str#2 ] ( main:2::strlen:5 [ strlen::len#2 strlen::str#2 ] { { strlen::return#2 = strlen::len#2 } } ) always clobbers reg byte a reg byte y
|
|
Potential registers zp[2]:2 [ strlen::str#2 strlen::str#0 ] : zp[2]:2 ,
|
|
Potential registers zp[2]:4 [ strlen::len#2 strlen::len#1 ] : zp[2]:4 ,
|
|
Potential registers zp[2]:6 [ strlen::return#2 ] : zp[2]:6 ,
|
|
Potential registers zp[2]:8 [ main::$0 ] : zp[2]:8 ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [strlen] 3,003: zp[2]:2 [ strlen::str#2 strlen::str#0 ] 1,504.25: zp[2]:4 [ strlen::len#2 strlen::len#1 ] 22: zp[2]:6 [ strlen::return#2 ]
|
|
Uplift Scope [main] 11: zp[2]:8 [ main::$0 ]
|
|
Uplift Scope []
|
|
|
|
Uplifting [strlen] best 727 combination zp[2]:2 [ strlen::str#2 strlen::str#0 ] zp[2]:4 [ strlen::len#2 strlen::len#1 ] zp[2]:6 [ strlen::return#2 ]
|
|
Uplifting [main] best 727 combination zp[2]:8 [ main::$0 ]
|
|
Uplifting [] best 727 combination
|
|
Coalescing zero page register [ zp[2]:4 [ strlen::len#2 strlen::len#1 ] ] with [ zp[2]:6 [ strlen::return#2 ] ] - score: 1
|
|
Coalescing zero page register [ zp[2]:4 [ strlen::len#2 strlen::len#1 strlen::return#2 ] ] with [ zp[2]:8 [ main::$0 ] ] - score: 1
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Includes a system library - ignores the local file with the same name
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label SCREEN = $400
|
|
// @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 __0 = 4
|
|
// [5] call strlen
|
|
// [10] phi from main to strlen [phi:main->strlen]
|
|
strlen_from_main:
|
|
jsr strlen
|
|
// [6] (word) strlen::return#2 ← (word) strlen::len#2
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] (word~) main::$0 ← (word) strlen::return#2
|
|
// [8] *((const nomodify byte*) SCREEN) ← (byte)(word~) main::$0 -- _deref_pbuc1=_byte_vwuz1
|
|
lda.z __0
|
|
sta SCREEN
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [9] return
|
|
rts
|
|
}
|
|
// strlen
|
|
// Computes the length of the string str up to but not including the terminating null character.
|
|
// strlen(byte* zp(2) str)
|
|
strlen: {
|
|
.label len = 4
|
|
.label str = 2
|
|
.label return = 4
|
|
// [11] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
|
__b1_from_strlen:
|
|
// [11] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
|
lda #<0
|
|
sta.z len
|
|
lda #>0
|
|
sta.z len+1
|
|
// [11] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
|
lda #<STR
|
|
sta.z str
|
|
lda #>STR
|
|
sta.z str+1
|
|
jmp __b1
|
|
// strlen::@1
|
|
__b1:
|
|
// [12] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (str),y
|
|
cmp #0
|
|
bne __b2
|
|
jmp __breturn
|
|
// strlen::@return
|
|
__breturn:
|
|
// [13] return
|
|
rts
|
|
// strlen::@2
|
|
__b2:
|
|
// [14] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
|
inc.z len
|
|
bne !+
|
|
inc.z len+1
|
|
!:
|
|
// [15] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
|
inc.z str
|
|
bne !+
|
|
inc.z str+1
|
|
!:
|
|
// [11] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
|
__b1_from___b2:
|
|
// [11] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
|
// [11] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
STR: .text "camelot!"
|
|
.byte 0
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __breturn
|
|
Succesful ASM optimization Pass5NextJumpElimination
|
|
Removing instruction lda #>0
|
|
Succesful ASM optimization Pass5UnnecesaryLoadElimination
|
|
Removing instruction __b1_from___bbegin:
|
|
Removing instruction __b1:
|
|
Removing instruction main_from___b1:
|
|
Removing instruction __bend_from___b1:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bbegin:
|
|
Removing instruction __bend:
|
|
Removing instruction strlen_from_main:
|
|
Removing instruction __b1:
|
|
Removing instruction __breturn:
|
|
Removing instruction __b1_from_strlen:
|
|
Removing instruction __breturn:
|
|
Removing instruction __b1_from___b2:
|
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
|
Removing instruction jsr main
|
|
Succesful ASM optimization Pass5SkipBegin
|
|
|
|
FINAL SYMBOL TABLE
|
|
(label) @1
|
|
(label) @begin
|
|
(label) @end
|
|
(const nomodify byte*) SCREEN = (byte*) 1024
|
|
(const byte*) STR = (byte*) "camelot!"
|
|
(void()) main()
|
|
(word~) main::$0 zp[2]:4 11.0
|
|
(label) main::@1
|
|
(label) main::@return
|
|
(word()) strlen((byte*) strlen::str)
|
|
(label) strlen::@1
|
|
(label) strlen::@2
|
|
(label) strlen::@return
|
|
(word) strlen::len
|
|
(word) strlen::len#1 len zp[2]:4 1001.0
|
|
(word) strlen::len#2 len zp[2]:4 503.25
|
|
(word) strlen::return
|
|
(word) strlen::return#2 return zp[2]:4 22.0
|
|
(byte*) strlen::str
|
|
(byte*) strlen::str#0 str zp[2]:2 2002.0
|
|
(byte*) strlen::str#2 str zp[2]:2 1001.0
|
|
|
|
zp[2]:2 [ strlen::str#2 strlen::str#0 ]
|
|
zp[2]:4 [ strlen::len#2 strlen::len#1 strlen::return#2 main::$0 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 605
|
|
|
|
// File Comments
|
|
// Includes a system library - ignores the local file with the same name
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label SCREEN = $400
|
|
// @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 __0 = 4
|
|
// strlen(STR)
|
|
// [5] call strlen
|
|
// [10] phi from main to strlen [phi:main->strlen]
|
|
jsr strlen
|
|
// strlen(STR)
|
|
// [6] (word) strlen::return#2 ← (word) strlen::len#2
|
|
// main::@1
|
|
// [7] (word~) main::$0 ← (word) strlen::return#2
|
|
// SCREEN [0] = (char) strlen(STR)
|
|
// [8] *((const nomodify byte*) SCREEN) ← (byte)(word~) main::$0 -- _deref_pbuc1=_byte_vwuz1
|
|
lda.z __0
|
|
sta SCREEN
|
|
// main::@return
|
|
// }
|
|
// [9] return
|
|
rts
|
|
}
|
|
// strlen
|
|
// Computes the length of the string str up to but not including the terminating null character.
|
|
// strlen(byte* zp(2) str)
|
|
strlen: {
|
|
.label len = 4
|
|
.label str = 2
|
|
.label return = 4
|
|
// [11] phi from strlen to strlen::@1 [phi:strlen->strlen::@1]
|
|
// [11] phi (word) strlen::len#2 = (word) 0 [phi:strlen->strlen::@1#0] -- vwuz1=vwuc1
|
|
lda #<0
|
|
sta.z len
|
|
sta.z len+1
|
|
// [11] phi (byte*) strlen::str#2 = (const byte*) STR [phi:strlen->strlen::@1#1] -- pbuz1=pbuc1
|
|
lda #<STR
|
|
sta.z str
|
|
lda #>STR
|
|
sta.z str+1
|
|
// strlen::@1
|
|
__b1:
|
|
// while(*str)
|
|
// [12] if((byte) 0!=*((byte*) strlen::str#2)) goto strlen::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (str),y
|
|
cmp #0
|
|
bne __b2
|
|
// strlen::@return
|
|
// }
|
|
// [13] return
|
|
rts
|
|
// strlen::@2
|
|
__b2:
|
|
// len++;
|
|
// [14] (word) strlen::len#1 ← ++ (word) strlen::len#2 -- vwuz1=_inc_vwuz1
|
|
inc.z len
|
|
bne !+
|
|
inc.z len+1
|
|
!:
|
|
// str++;
|
|
// [15] (byte*) strlen::str#0 ← ++ (byte*) strlen::str#2 -- pbuz1=_inc_pbuz1
|
|
inc.z str
|
|
bne !+
|
|
inc.z str+1
|
|
!:
|
|
// [11] phi from strlen::@2 to strlen::@1 [phi:strlen::@2->strlen::@1]
|
|
// [11] phi (word) strlen::len#2 = (word) strlen::len#1 [phi:strlen::@2->strlen::@1#0] -- register_copy
|
|
// [11] phi (byte*) strlen::str#2 = (byte*) strlen::str#0 [phi:strlen::@2->strlen::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
STR: .text "camelot!"
|
|
.byte 0
|
|
|