mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-16 21:07:56 +00:00
651 lines
20 KiB
Plaintext
651 lines
20 KiB
Plaintext
|
|
CONTROL FLOW GRAPH SSA
|
|
@begin: scope:[] from
|
|
(byte*) screen#0 ← (byte*)(number) $400
|
|
to:@1
|
|
|
|
(void()) main()
|
|
main: scope:[main] from @1
|
|
(byte*) screen#15 ← phi( @1/(byte*) screen#17 )
|
|
(byte*) print::string#0 ← (const byte*) rex1
|
|
call print
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
(byte*) screen#8 ← phi( main/(byte*) screen#6 )
|
|
(byte*) screen#1 ← (byte*) screen#8
|
|
(byte*) print::string#1 ← (const byte*) main::rex2
|
|
call print
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
(byte*) screen#9 ← phi( main::@1/(byte*) screen#6 )
|
|
(byte*) screen#2 ← (byte*) screen#9
|
|
(byte*) print::string#2 ← (const byte*) main::string
|
|
call print
|
|
to:main::@3
|
|
main::@3: scope:[main] from main::@2
|
|
(byte*) screen#10 ← phi( main::@2/(byte*) screen#6 )
|
|
(byte*) screen#3 ← (byte*) screen#10
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@3
|
|
(byte*) screen#11 ← phi( main::@3/(byte*) screen#3 )
|
|
(byte*) screen#4 ← (byte*) screen#11
|
|
return
|
|
to:@return
|
|
|
|
(void()) print((byte*) print::string)
|
|
print: scope:[print] from main main::@1 main::@2
|
|
(byte*) screen#18 ← phi( main/(byte*) screen#15 main::@1/(byte*) screen#1 main::@2/(byte*) screen#2 )
|
|
(byte*) print::string#6 ← phi( main/(byte*) print::string#0 main::@1/(byte*) print::string#1 main::@2/(byte*) print::string#2 )
|
|
to:print::@1
|
|
print::@1: scope:[print] from print print::@2
|
|
(byte*) screen#16 ← phi( print/(byte*) screen#18 print::@2/(byte*) screen#5 )
|
|
(byte*) print::string#4 ← phi( print/(byte*) print::string#6 print::@2/(byte*) print::string#3 )
|
|
(bool~) print::$0 ← (number) 0 != *((byte*) print::string#4)
|
|
if((bool~) print::$0) goto print::@2
|
|
to:print::@return
|
|
print::@2: scope:[print] from print::@1
|
|
(byte*) screen#12 ← phi( print::@1/(byte*) screen#16 )
|
|
(byte*) print::string#5 ← phi( print::@1/(byte*) print::string#4 )
|
|
*((byte*) screen#12) ← *((byte*) print::string#5)
|
|
(byte*) screen#5 ← ++ (byte*) screen#12
|
|
(byte*) print::string#3 ← ++ (byte*) print::string#5
|
|
to:print::@1
|
|
print::@return: scope:[print] from print::@1
|
|
(byte*) screen#13 ← phi( print::@1/(byte*) screen#16 )
|
|
(byte*) screen#6 ← (byte*) screen#13
|
|
return
|
|
to:@return
|
|
@1: scope:[] from @begin
|
|
(byte*) screen#17 ← phi( @begin/(byte*) screen#0 )
|
|
call main
|
|
to:@2
|
|
@2: scope:[] from @1
|
|
(byte*) screen#14 ← phi( @1/(byte*) screen#4 )
|
|
(byte*) screen#7 ← (byte*) screen#14
|
|
to:@end
|
|
@end: scope:[] from @2
|
|
|
|
SYMBOL TABLE SSA
|
|
(label) @1
|
|
(label) @2
|
|
(label) @begin
|
|
(label) @end
|
|
(void()) main()
|
|
(label) main::@1
|
|
(label) main::@2
|
|
(label) main::@3
|
|
(label) main::@return
|
|
(const byte*) main::rex2[] = (byte*) "rex"
|
|
(const byte*) main::string[(byte) 4] = (byte*) "rex"
|
|
(void()) print((byte*) print::string)
|
|
(bool~) print::$0
|
|
(label) print::@1
|
|
(label) print::@2
|
|
(label) print::@return
|
|
(byte*) print::string
|
|
(byte*) print::string#0
|
|
(byte*) print::string#1
|
|
(byte*) print::string#2
|
|
(byte*) print::string#3
|
|
(byte*) print::string#4
|
|
(byte*) print::string#5
|
|
(byte*) print::string#6
|
|
(const byte*) rex1[] = (byte*) "rex"
|
|
(byte*) screen
|
|
(byte*) screen#0
|
|
(byte*) screen#1
|
|
(byte*) screen#10
|
|
(byte*) screen#11
|
|
(byte*) screen#12
|
|
(byte*) screen#13
|
|
(byte*) screen#14
|
|
(byte*) screen#15
|
|
(byte*) screen#16
|
|
(byte*) screen#17
|
|
(byte*) screen#18
|
|
(byte*) screen#2
|
|
(byte*) screen#3
|
|
(byte*) screen#4
|
|
(byte*) screen#5
|
|
(byte*) screen#6
|
|
(byte*) screen#7
|
|
(byte*) screen#8
|
|
(byte*) screen#9
|
|
|
|
Adding number conversion cast (unumber) 0 in (bool~) print::$0 ← (number) 0 != *((byte*) print::string#4)
|
|
Successful SSA optimization PassNAddNumberTypeConversions
|
|
Simplifying constant pointer cast (byte*) 1024
|
|
Simplifying constant integer cast 0
|
|
Successful SSA optimization PassNCastSimplification
|
|
Finalized unsigned number type (byte) 0
|
|
Successful SSA optimization PassNFinalizeNumberTypeConversions
|
|
Alias screen#1 = screen#8
|
|
Alias screen#2 = screen#9
|
|
Alias screen#10 = screen#3 screen#11 screen#4
|
|
Alias print::string#4 = print::string#5
|
|
Alias screen#12 = screen#16 screen#13 screen#6
|
|
Alias screen#0 = screen#17
|
|
Alias screen#14 = screen#7
|
|
Successful SSA optimization Pass2AliasElimination
|
|
Identical Phi Values (byte*) screen#15 (byte*) screen#0
|
|
Identical Phi Values (byte*) screen#1 (byte*) screen#12
|
|
Identical Phi Values (byte*) screen#2 (byte*) screen#12
|
|
Identical Phi Values (byte*) screen#10 (byte*) screen#12
|
|
Identical Phi Values (byte*) screen#14 (byte*) screen#10
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
Simple Condition (bool~) print::$0 [15] if((byte) 0!=*((byte*) print::string#4)) goto print::@2
|
|
Successful SSA optimization Pass2ConditionalJumpSimplification
|
|
Constant (const byte*) screen#0 = (byte*) 1024
|
|
Constant (const byte*) print::string#0 = rex1
|
|
Constant (const byte*) print::string#1 = main::rex2
|
|
Constant (const byte*) print::string#2 = main::string
|
|
Successful SSA optimization Pass2ConstantIdentification
|
|
Consolidated constant strings into (const byte*) rex1
|
|
Successful SSA optimization Pass2ConstantStringConsolidation
|
|
Inlining constant with var siblings (const byte*) print::string#0
|
|
Inlining constant with var siblings (const byte*) print::string#1
|
|
Inlining constant with var siblings (const byte*) print::string#2
|
|
Inlining constant with var siblings (const byte*) screen#0
|
|
Constant inlined print::string#0 = (const byte*) rex1
|
|
Constant inlined print::string#1 = (const byte*) rex1
|
|
Constant inlined print::string#2 = (const byte*) rex1
|
|
Constant inlined main::rex2 = (const byte*) rex1
|
|
Constant inlined screen#0 = (byte*) 1024
|
|
Constant inlined main::string = (const byte*) rex1
|
|
Successful SSA optimization Pass2ConstantInlining
|
|
Identical Phi Values (byte*) print::string#6 (const byte*) rex1
|
|
Successful SSA optimization Pass2IdenticalPhiElimination
|
|
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::@3
|
|
CALL GRAPH
|
|
Calls in [] to main:2
|
|
Calls in [main] to print:6 print:8 print:10
|
|
|
|
Created 3 initial phi equivalence classes
|
|
Coalesced [7] screen#19 ← screen#12
|
|
Coalesced (already) [9] screen#20 ← screen#12
|
|
Coalesced (already) [14] screen#21 ← screen#18
|
|
Coalesced [21] print::string#7 ← print::string#3
|
|
Coalesced [22] screen#22 ← screen#5
|
|
Coalesced down to 2 phi equivalence classes
|
|
Culled Empty Block (label) @2
|
|
Culled Empty Block (label) main::@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 main::@1
|
|
Adding NOP phi() at start of main::@2
|
|
|
|
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 print
|
|
to:main::@1
|
|
main::@1: scope:[main] from main
|
|
[6] phi()
|
|
[7] call print
|
|
to:main::@2
|
|
main::@2: scope:[main] from main::@1
|
|
[8] phi()
|
|
[9] call print
|
|
to:main::@return
|
|
main::@return: scope:[main] from main::@2
|
|
[10] return
|
|
to:@return
|
|
|
|
(void()) print((byte*) print::string)
|
|
print: scope:[print] from main main::@1 main::@2
|
|
[11] (byte*) screen#18 ← phi( main/(byte*) 1024 main::@1/(byte*) screen#12 main::@2/(byte*) screen#12 )
|
|
to:print::@1
|
|
print::@1: scope:[print] from print print::@2
|
|
[12] (byte*) screen#12 ← phi( print/(byte*) screen#18 print::@2/(byte*) screen#5 )
|
|
[12] (byte*) print::string#4 ← phi( print/(const byte*) rex1 print::@2/(byte*) print::string#3 )
|
|
[13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2
|
|
to:print::@return
|
|
print::@return: scope:[print] from print::@1
|
|
[14] return
|
|
to:@return
|
|
print::@2: scope:[print] from print::@1
|
|
[15] *((byte*) screen#12) ← *((byte*) print::string#4)
|
|
[16] (byte*) screen#5 ← ++ (byte*) screen#12
|
|
[17] (byte*) print::string#3 ← ++ (byte*) print::string#4
|
|
to:print::@1
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
(void()) main()
|
|
(void()) print((byte*) print::string)
|
|
(byte*) print::string
|
|
(byte*) print::string#3 2002.0
|
|
(byte*) print::string#4 1001.0
|
|
(byte*) screen
|
|
(byte*) screen#12 390.75
|
|
(byte*) screen#18 123.0
|
|
(byte*) screen#5 1001.0
|
|
|
|
Initial phi equivalence classes
|
|
[ screen#18 screen#12 screen#5 ]
|
|
[ print::string#4 print::string#3 ]
|
|
Complete equivalence classes
|
|
[ screen#18 screen#12 screen#5 ]
|
|
[ print::string#4 print::string#3 ]
|
|
Allocated zp[2]:2 [ screen#18 screen#12 screen#5 ]
|
|
Allocated zp[2]:4 [ print::string#4 print::string#3 ]
|
|
|
|
INITIAL ASM
|
|
Target platform is c64basic / MOS6502X
|
|
// File Comments
|
|
// Tests that identical strings are consolidated
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label screen = 2
|
|
// @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: {
|
|
// [5] call print
|
|
// [11] phi from main to print [phi:main->print]
|
|
print_from_main:
|
|
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
|
|
lda #<$400
|
|
sta.z screen
|
|
lda #>$400
|
|
sta.z screen+1
|
|
jsr print
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call print
|
|
// [11] phi from main::@1 to print [phi:main::@1->print]
|
|
print_from___b1:
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
|
|
jsr print
|
|
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
__b2_from___b1:
|
|
jmp __b2
|
|
// main::@2
|
|
__b2:
|
|
// [9] call print
|
|
// [11] phi from main::@2 to print [phi:main::@2->print]
|
|
print_from___b2:
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
|
|
jsr print
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [10] return
|
|
rts
|
|
}
|
|
// print
|
|
// print(byte* zp(4) string)
|
|
print: {
|
|
.label string = 4
|
|
// [12] phi from print to print::@1 [phi:print->print::@1]
|
|
__b1_from_print:
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (const byte*) rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
|
|
lda #<rex1
|
|
sta.z string
|
|
lda #>rex1
|
|
sta.z string+1
|
|
jmp __b1
|
|
// print::@1
|
|
__b1:
|
|
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (string),y
|
|
cmp #0
|
|
bne __b2
|
|
jmp __breturn
|
|
// print::@return
|
|
__breturn:
|
|
// [14] return
|
|
rts
|
|
// print::@2
|
|
__b2:
|
|
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
|
|
ldy #0
|
|
lda (string),y
|
|
ldy #0
|
|
sta (screen),y
|
|
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
|
|
inc.z screen
|
|
bne !+
|
|
inc.z screen+1
|
|
!:
|
|
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
|
|
inc.z string
|
|
bne !+
|
|
inc.z string+1
|
|
!:
|
|
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
|
|
__b1_from___b2:
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
rex1: .text "rex"
|
|
.byte 0
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
|
Statement [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 [ screen#12 print::string#4 ] ( main:2::print:5 [ screen#12 print::string#4 ] { } main:2::print:7 [ screen#12 print::string#4 ] { { screen#12 = screen#18 } } main:2::print:9 [ screen#12 print::string#4 ] { { screen#12 = screen#18 } } ) always clobbers reg byte a reg byte y
|
|
Statement [15] *((byte*) screen#12) ← *((byte*) print::string#4) [ screen#12 print::string#4 ] ( main:2::print:5 [ screen#12 print::string#4 ] { } main:2::print:7 [ screen#12 print::string#4 ] { { screen#12 = screen#18 } } main:2::print:9 [ screen#12 print::string#4 ] { { screen#12 = screen#18 } } ) always clobbers reg byte a reg byte y
|
|
Potential registers zp[2]:2 [ screen#18 screen#12 screen#5 ] : zp[2]:2 ,
|
|
Potential registers zp[2]:4 [ print::string#4 print::string#3 ] : zp[2]:4 ,
|
|
|
|
REGISTER UPLIFT SCOPES
|
|
Uplift Scope [print] 3,003: zp[2]:4 [ print::string#4 print::string#3 ]
|
|
Uplift Scope [] 1,514.75: zp[2]:2 [ screen#18 screen#12 screen#5 ]
|
|
Uplift Scope [main]
|
|
|
|
Uplifting [print] best 776 combination zp[2]:4 [ print::string#4 print::string#3 ]
|
|
Uplifting [] best 776 combination zp[2]:2 [ screen#18 screen#12 screen#5 ]
|
|
Uplifting [main] best 776 combination
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
|
// File Comments
|
|
// Tests that identical strings are consolidated
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label screen = 2
|
|
// @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: {
|
|
// [5] call print
|
|
// [11] phi from main to print [phi:main->print]
|
|
print_from_main:
|
|
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
|
|
lda #<$400
|
|
sta.z screen
|
|
lda #>$400
|
|
sta.z screen+1
|
|
jsr print
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
__b1_from_main:
|
|
jmp __b1
|
|
// main::@1
|
|
__b1:
|
|
// [7] call print
|
|
// [11] phi from main::@1 to print [phi:main::@1->print]
|
|
print_from___b1:
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
|
|
jsr print
|
|
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
__b2_from___b1:
|
|
jmp __b2
|
|
// main::@2
|
|
__b2:
|
|
// [9] call print
|
|
// [11] phi from main::@2 to print [phi:main::@2->print]
|
|
print_from___b2:
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
|
|
jsr print
|
|
jmp __breturn
|
|
// main::@return
|
|
__breturn:
|
|
// [10] return
|
|
rts
|
|
}
|
|
// print
|
|
// print(byte* zp(4) string)
|
|
print: {
|
|
.label string = 4
|
|
// [12] phi from print to print::@1 [phi:print->print::@1]
|
|
__b1_from_print:
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (const byte*) rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
|
|
lda #<rex1
|
|
sta.z string
|
|
lda #>rex1
|
|
sta.z string+1
|
|
jmp __b1
|
|
// print::@1
|
|
__b1:
|
|
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (string),y
|
|
cmp #0
|
|
bne __b2
|
|
jmp __breturn
|
|
// print::@return
|
|
__breturn:
|
|
// [14] return
|
|
rts
|
|
// print::@2
|
|
__b2:
|
|
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
|
|
ldy #0
|
|
lda (string),y
|
|
ldy #0
|
|
sta (screen),y
|
|
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
|
|
inc.z screen
|
|
bne !+
|
|
inc.z screen+1
|
|
!:
|
|
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
|
|
inc.z string
|
|
bne !+
|
|
inc.z string+1
|
|
!:
|
|
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
|
|
__b1_from___b2:
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
rex1: .text "rex"
|
|
.byte 0
|
|
|
|
ASSEMBLER OPTIMIZATIONS
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __bend
|
|
Removing instruction jmp __b1
|
|
Removing instruction jmp __b2
|
|
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 __b1_from___bbegin:
|
|
Removing instruction __b1:
|
|
Removing instruction main_from___b1:
|
|
Removing instruction __bend_from___b1:
|
|
Removing instruction __b1_from_main:
|
|
Removing instruction print_from___b1:
|
|
Removing instruction __b2_from___b1:
|
|
Removing instruction print_from___b2:
|
|
Succesful ASM optimization Pass5RedundantLabelElimination
|
|
Removing instruction __bbegin:
|
|
Removing instruction __bend:
|
|
Removing instruction print_from_main:
|
|
Removing instruction __b1:
|
|
Removing instruction __b2:
|
|
Removing instruction __breturn:
|
|
Removing instruction __b1_from_print:
|
|
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
|
|
(void()) main()
|
|
(label) main::@1
|
|
(label) main::@2
|
|
(label) main::@return
|
|
(void()) print((byte*) print::string)
|
|
(label) print::@1
|
|
(label) print::@2
|
|
(label) print::@return
|
|
(byte*) print::string
|
|
(byte*) print::string#3 string zp[2]:4 2002.0
|
|
(byte*) print::string#4 string zp[2]:4 1001.0
|
|
(const byte*) rex1[] = (byte*) "rex"
|
|
(byte*) screen
|
|
(byte*) screen#12 screen zp[2]:2 390.75
|
|
(byte*) screen#18 screen zp[2]:2 123.0
|
|
(byte*) screen#5 screen zp[2]:2 1001.0
|
|
|
|
zp[2]:2 [ screen#18 screen#12 screen#5 ]
|
|
zp[2]:4 [ print::string#4 print::string#3 ]
|
|
|
|
|
|
FINAL ASSEMBLER
|
|
Score: 675
|
|
|
|
// File Comments
|
|
// Tests that identical strings are consolidated
|
|
// Upstart
|
|
.pc = $801 "Basic"
|
|
:BasicUpstart(main)
|
|
.pc = $80d "Program"
|
|
// Global Constants & labels
|
|
.label screen = 2
|
|
// @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: {
|
|
// print(rex1)
|
|
// [5] call print
|
|
// [11] phi from main to print [phi:main->print]
|
|
// [11] phi (byte*) screen#18 = (byte*) 1024 [phi:main->print#0] -- pbuz1=pbuc1
|
|
lda #<$400
|
|
sta.z screen
|
|
lda #>$400
|
|
sta.z screen+1
|
|
jsr print
|
|
// [6] phi from main to main::@1 [phi:main->main::@1]
|
|
// main::@1
|
|
// print(rex2)
|
|
// [7] call print
|
|
// [11] phi from main::@1 to print [phi:main::@1->print]
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@1->print#0] -- register_copy
|
|
jsr print
|
|
// [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
|
|
// main::@2
|
|
// print("rex")
|
|
// [9] call print
|
|
// [11] phi from main::@2 to print [phi:main::@2->print]
|
|
// [11] phi (byte*) screen#18 = (byte*) screen#12 [phi:main::@2->print#0] -- register_copy
|
|
jsr print
|
|
// main::@return
|
|
// }
|
|
// [10] return
|
|
rts
|
|
}
|
|
// print
|
|
// print(byte* zp(4) string)
|
|
print: {
|
|
.label string = 4
|
|
// [12] phi from print to print::@1 [phi:print->print::@1]
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#18 [phi:print->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (const byte*) rex1 [phi:print->print::@1#1] -- pbuz1=pbuc1
|
|
lda #<rex1
|
|
sta.z string
|
|
lda #>rex1
|
|
sta.z string+1
|
|
// print::@1
|
|
__b1:
|
|
// while(*string)
|
|
// [13] if((byte) 0!=*((byte*) print::string#4)) goto print::@2 -- vbuc1_neq__deref_pbuz1_then_la1
|
|
ldy #0
|
|
lda (string),y
|
|
cmp #0
|
|
bne __b2
|
|
// print::@return
|
|
// }
|
|
// [14] return
|
|
rts
|
|
// print::@2
|
|
__b2:
|
|
// *screen++ = *string++
|
|
// [15] *((byte*) screen#12) ← *((byte*) print::string#4) -- _deref_pbuz1=_deref_pbuz2
|
|
ldy #0
|
|
lda (string),y
|
|
sta (screen),y
|
|
// *screen++ = *string++;
|
|
// [16] (byte*) screen#5 ← ++ (byte*) screen#12 -- pbuz1=_inc_pbuz1
|
|
inc.z screen
|
|
bne !+
|
|
inc.z screen+1
|
|
!:
|
|
// [17] (byte*) print::string#3 ← ++ (byte*) print::string#4 -- pbuz1=_inc_pbuz1
|
|
inc.z string
|
|
bne !+
|
|
inc.z string+1
|
|
!:
|
|
// [12] phi from print::@2 to print::@1 [phi:print::@2->print::@1]
|
|
// [12] phi (byte*) screen#12 = (byte*) screen#5 [phi:print::@2->print::@1#0] -- register_copy
|
|
// [12] phi (byte*) print::string#4 = (byte*) print::string#3 [phi:print::@2->print::@1#1] -- register_copy
|
|
jmp __b1
|
|
}
|
|
// File Data
|
|
rex1: .text "rex"
|
|
.byte 0
|
|
|