1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-30 09:57:11 +00:00
kickc/src/test/ref/pointer-void-3.log

643 lines
22 KiB
Plaintext
Raw Normal View History

Culled Empty Block (label) malloc::@1
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte*) SCREEN#0 ← ((byte*)) (number) $400
to:@1
main: scope:[main] from @2
(byte*) heap_head#13 ← phi( @2/(byte*) heap_head#14 )
call malloc
(void*) malloc::return#0 ← (void*) malloc::return#3
to:main::@1
main::@1: scope:[main] from main
(byte*) heap_head#7 ← phi( main/(byte*) heap_head#5 )
(void*) malloc::return#4 ← phi( main/(void*) malloc::return#0 )
(void*~) main::$0 ← (void*) malloc::return#4
(byte*) heap_head#0 ← (byte*) heap_head#7
(byte*) main::buf1#0 ← ((byte*)) (void*~) main::$0
call malloc
(void*) malloc::return#1 ← (void*) malloc::return#3
to:main::@2
main::@2: scope:[main] from main::@1
(byte*) main::buf1#1 ← phi( main::@1/(byte*) main::buf1#0 )
(byte*) heap_head#8 ← phi( main::@1/(byte*) heap_head#5 )
(void*) malloc::return#5 ← phi( main::@1/(void*) malloc::return#1 )
(void*~) main::$1 ← (void*) malloc::return#5
(byte*) heap_head#1 ← (byte*) heap_head#8
(byte*) main::buf2#0 ← ((byte*)) (void*~) main::$1
*((byte*) main::buf1#1) ← (byte) 'a'
*((byte*) main::buf2#0) ← (byte) 'b'
*((byte*) SCREEN#0 + (number) 0) ← *((byte*) main::buf1#1)
*((byte*) SCREEN#0 + (number) 1) ← *((byte*) main::buf2#0)
to:main::@return
main::@return: scope:[main] from main::@2
(byte*) heap_head#9 ← phi( main::@2/(byte*) heap_head#1 )
(byte*) heap_head#2 ← (byte*) heap_head#9
return
to:@return
@1: scope:[] from @begin
(byte*) heap_head#3 ← ((byte*)) (number) $c000
to:@2
malloc: scope:[malloc] from main main::@1
(byte*) heap_head#10 ← phi( main/(byte*) heap_head#13 main::@1/(byte*) heap_head#0 )
(byte*) heap_head#4 ← ++ (byte*) heap_head#10
(void*) malloc::return#2 ← ((void*)) (byte*) heap_head#4
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
(byte*) heap_head#11 ← phi( malloc/(byte*) heap_head#4 )
(void*) malloc::return#6 ← phi( malloc/(void*) malloc::return#2 )
(void*) malloc::return#3 ← (void*) malloc::return#6
(byte*) heap_head#5 ← (byte*) heap_head#11
return
to:@return
@2: scope:[] from @1
(byte*) heap_head#14 ← phi( @1/(byte*) heap_head#3 )
call main
to:@3
@3: scope:[] from @2
(byte*) heap_head#12 ← phi( @2/(byte*) heap_head#2 )
(byte*) heap_head#6 ← (byte*) heap_head#12
to:@end
@end: scope:[] from @3
SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) heap_head
(byte*) heap_head#0
(byte*) heap_head#1
(byte*) heap_head#10
(byte*) heap_head#11
(byte*) heap_head#12
(byte*) heap_head#13
(byte*) heap_head#14
(byte*) heap_head#2
(byte*) heap_head#3
(byte*) heap_head#4
(byte*) heap_head#5
(byte*) heap_head#6
(byte*) heap_head#7
(byte*) heap_head#8
(byte*) heap_head#9
(void()) main()
(void*~) main::$0
(void*~) main::$1
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::buf1
(byte*) main::buf1#0
(byte*) main::buf1#1
(byte*) main::buf2
(byte*) main::buf2#0
(void*()) malloc()
(label) malloc::@return
(void*) malloc::return
(void*) malloc::return#0
(void*) malloc::return#1
(void*) malloc::return#2
(void*) malloc::return#3
(void*) malloc::return#4
(void*) malloc::return#5
(void*) malloc::return#6
Adding number conversion cast (unumber) 0 in *((byte*) SCREEN#0 + (number) 0) ← *((byte*) main::buf1#1)
Adding number conversion cast (unumber) 1 in *((byte*) SCREEN#0 + (number) 1) ← *((byte*) main::buf2#0)
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte*) main::buf1#0 ← (byte*)(void*~) main::$0
Inlining cast (byte*) main::buf2#0 ← (byte*)(void*~) main::$1
Inlining cast (byte*) heap_head#3 ← (byte*)(number) $c000
Inlining cast (void*) malloc::return#2 ← (void*)(byte*) heap_head#4
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant pointer cast (byte*) 49152
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (void*) malloc::return#0 = (void*) malloc::return#4
Alias (byte*) heap_head#0 = (byte*) heap_head#7
Alias (void*) malloc::return#1 = (void*) malloc::return#5
Alias (byte*) main::buf1#0 = (byte*) main::buf1#1
Alias (byte*) heap_head#1 = (byte*) heap_head#8 (byte*) heap_head#9 (byte*) heap_head#2
Alias (void*) malloc::return#2 = (void*) malloc::return#6 (void*) malloc::return#3
Alias (byte*) heap_head#11 = (byte*) heap_head#4 (byte*) heap_head#5
Alias (byte*) heap_head#14 = (byte*) heap_head#3
Alias (byte*) heap_head#12 = (byte*) heap_head#6
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) heap_head#13 (byte*) heap_head#14
Identical Phi Values (byte*) heap_head#0 (byte*) heap_head#11
Identical Phi Values (byte*) heap_head#1 (byte*) heap_head#11
Identical Phi Values (byte*) heap_head#12 (byte*) heap_head#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte*) heap_head#14 = (byte*) 49152
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN#0 in [16] *((const byte*) SCREEN#0 + (byte) 0) ← *((byte*) main::buf1#0)
Successful SSA optimization PassNSimplifyExpressionWithZero
Inlining Noop Cast [3] (byte*) main::buf1#0 ← (byte*)(void*~) main::$0 keeping main::buf1#0
Inlining Noop Cast [7] (byte*) main::buf2#0 ← (byte*)(void*~) main::$1 keeping main::buf2#0
Successful SSA optimization Pass2NopCastInlining
Inlining constant with var siblings (const byte*) heap_head#14
Constant inlined heap_head#14 = (byte*) 49152
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
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 @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:3
2019-06-24 17:48:18 +00:00
Calls in [main] to malloc:7 malloc:11
Created 1 initial phi equivalence classes
2019-06-24 17:48:18 +00:00
Coalesced [10] heap_head#15 ← heap_head#11
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @3
Renumbering block @2 to @1
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()
[5] call malloc
[6] (void*) malloc::return#0 ← (void*) malloc::return#2
to:main::@1
main::@1: scope:[main] from main
[7] (void*) main::buf1#0 ← (void*) malloc::return#0
2019-06-24 17:48:18 +00:00
[8] call malloc
[9] (void*) malloc::return#1 ← (void*) malloc::return#2
to:main::@2
main::@2: scope:[main] from main::@1
[10] (void*) main::buf2#0 ← (void*) malloc::return#1
[11] *((byte*)(void*) main::buf1#0) ← (byte) 'a'
[12] *((byte*)(void*) main::buf2#0) ← (byte) 'b'
[13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0)
[14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0)
to:main::@return
main::@return: scope:[main] from main::@2
2019-06-24 17:48:18 +00:00
[15] return
to:@return
malloc: scope:[malloc] from main main::@1
2019-06-24 17:48:18 +00:00
[16] (byte*) heap_head#10 ← phi( main/(byte*) 49152 main::@1/(byte*) heap_head#11 )
[17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10
[18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
2019-06-24 17:48:18 +00:00
[19] return
to:@return
VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(byte*) heap_head
(byte*) heap_head#10 4.0
(byte*) heap_head#11 0.6666666666666666
(void()) main()
(byte*) main::buf1
(void*) main::buf1#0 0.3333333333333333
(byte*) main::buf2
(void*) main::buf2#0 0.5
(void*()) malloc()
(void*) malloc::return
(void*) malloc::return#0 4.0
(void*) malloc::return#1 4.0
(void*) malloc::return#2 1.5
Initial phi equivalence classes
[ heap_head#10 heap_head#11 ]
2019-06-24 17:48:18 +00:00
Added variable malloc::return#0 to zero page equivalence class [ malloc::return#0 ]
Added variable main::buf1#0 to zero page equivalence class [ main::buf1#0 ]
Added variable malloc::return#1 to zero page equivalence class [ malloc::return#1 ]
Added variable main::buf2#0 to zero page equivalence class [ main::buf2#0 ]
Added variable malloc::return#2 to zero page equivalence class [ malloc::return#2 ]
Complete equivalence classes
[ heap_head#10 heap_head#11 ]
2019-06-24 17:48:18 +00:00
[ malloc::return#0 ]
[ main::buf1#0 ]
[ malloc::return#1 ]
[ main::buf2#0 ]
[ malloc::return#2 ]
Allocated zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
2019-06-24 17:48:18 +00:00
Allocated zp ZP_WORD:4 [ malloc::return#0 ]
Allocated zp ZP_WORD:6 [ main::buf1#0 ]
Allocated zp ZP_WORD:8 [ malloc::return#1 ]
Allocated zp ZP_WORD:10 [ main::buf2#0 ]
Allocated zp ZP_WORD:12 [ malloc::return#2 ]
INITIAL ASM
2019-07-08 10:04:43 +00:00
// File Comments
// Test void pointer - issues when assigning returns from malloc()
2019-07-08 10:04:43 +00:00
// Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
2019-07-08 10:04:43 +00:00
// Global Constants & labels
.label SCREEN = $400
.label heap_head = 2
2019-07-08 10:04:43 +00:00
// @begin
bbegin:
2019-07-08 10:04:43 +00:00
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
2019-07-08 10:04:43 +00:00
// @1
b1:
2019-07-08 10:04:43 +00:00
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
2019-07-08 10:04:43 +00:00
// [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
2019-07-08 10:04:43 +00:00
// @end
bend:
2019-07-08 10:04:43 +00:00
// main
main: {
2019-06-24 17:48:18 +00:00
.label buf1 = 6
.label buf2 = $a
2019-07-08 10:04:43 +00:00
// [5] call malloc
// [16] phi from main to malloc [phi:main->malloc]
malloc_from_main:
2019-07-08 10:04:43 +00:00
// [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000
sta heap_head
lda #>$c000
sta heap_head+1
jsr malloc
2019-07-08 10:04:43 +00:00
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
jmp b1
2019-07-08 10:04:43 +00:00
// main::@1
b1:
2019-07-08 10:04:43 +00:00
// [7] (void*) main::buf1#0 ← (void*) malloc::return#0 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return
sta buf1
lda malloc.return+1
sta buf1+1
2019-07-08 10:04:43 +00:00
// [8] call malloc
// [16] phi from main::@1 to malloc [phi:main::@1->malloc]
malloc_from_b1:
2019-07-08 10:04:43 +00:00
// [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc
2019-07-08 10:04:43 +00:00
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return_2
sta malloc.return_1
lda malloc.return_2+1
sta malloc.return_1+1
jmp b2
2019-07-08 10:04:43 +00:00
// main::@2
b2:
2019-07-08 10:04:43 +00:00
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return_1
sta buf2
lda malloc.return_1+1
sta buf2+1
2019-07-08 10:04:43 +00:00
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a'
ldy #0
2019-06-24 17:48:18 +00:00
sta (buf1),y
2019-07-08 10:04:43 +00:00
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b'
ldy #0
2019-06-24 17:48:18 +00:00
sta (buf2),y
2019-07-08 10:04:43 +00:00
// [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0
2019-06-24 17:48:18 +00:00
lda (buf1),y
sta SCREEN
2019-07-08 10:04:43 +00:00
// [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0
2019-06-24 17:48:18 +00:00
lda (buf2),y
sta SCREEN+1
jmp breturn
2019-07-08 10:04:43 +00:00
// main::@return
breturn:
2019-07-08 10:04:43 +00:00
// [15] return
rts
}
2019-07-08 10:04:43 +00:00
// malloc
malloc: {
2019-06-24 17:48:18 +00:00
.label return = 4
.label return_1 = 8
.label return_2 = $c
2019-07-08 10:04:43 +00:00
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head
bne !+
inc heap_head+1
!:
2019-07-08 10:04:43 +00:00
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
jmp breturn
2019-07-08 10:04:43 +00:00
// malloc::@return
breturn:
2019-07-08 10:04:43 +00:00
// [19] return
rts
}
2019-07-08 10:04:43 +00:00
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (void*) malloc::return#0 ← (void*) malloc::return#2 [ malloc::return#0 heap_head#11 ] ( main:2 [ malloc::return#0 heap_head#11 ] ) always clobbers reg byte a
Statement [7] (void*) main::buf1#0 ← (void*) malloc::return#0 [ main::buf1#0 heap_head#11 ] ( main:2 [ main::buf1#0 heap_head#11 ] ) always clobbers reg byte a
Statement [9] (void*) malloc::return#1 ← (void*) malloc::return#2 [ main::buf1#0 malloc::return#1 ] ( main:2 [ main::buf1#0 malloc::return#1 ] ) always clobbers reg byte a
Statement [10] (void*) main::buf2#0 ← (void*) malloc::return#1 [ main::buf1#0 main::buf2#0 ] ( main:2 [ main::buf1#0 main::buf2#0 ] ) always clobbers reg byte a
Statement [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' [ main::buf1#0 main::buf2#0 ] ( main:2 [ main::buf1#0 main::buf2#0 ] ) always clobbers reg byte a reg byte y
Statement [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' [ main::buf1#0 main::buf2#0 ] ( main:2 [ main::buf1#0 main::buf2#0 ] ) always clobbers reg byte a reg byte y
Statement [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) [ main::buf2#0 ] ( main:2 [ main::buf2#0 ] ) always clobbers reg byte a reg byte y
Statement [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Statement [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 [ malloc::return#2 heap_head#11 ] ( main:2::malloc:5 [ malloc::return#2 heap_head#11 ] main:2::malloc:8 [ main::buf1#0 malloc::return#2 heap_head#11 ] ) always clobbers reg byte a
Potential registers zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] : zp ZP_WORD:2 ,
2019-06-24 17:48:18 +00:00
Potential registers zp ZP_WORD:4 [ malloc::return#0 ] : zp ZP_WORD:4 ,
Potential registers zp ZP_WORD:6 [ main::buf1#0 ] : zp ZP_WORD:6 ,
Potential registers zp ZP_WORD:8 [ malloc::return#1 ] : zp ZP_WORD:8 ,
Potential registers zp ZP_WORD:10 [ main::buf2#0 ] : zp ZP_WORD:10 ,
Potential registers zp ZP_WORD:12 [ malloc::return#2 ] : zp ZP_WORD:12 ,
REGISTER UPLIFT SCOPES
2019-06-24 17:48:18 +00:00
Uplift Scope [malloc] 4: zp ZP_WORD:4 [ malloc::return#0 ] 4: zp ZP_WORD:8 [ malloc::return#1 ] 1.5: zp ZP_WORD:12 [ malloc::return#2 ]
Uplift Scope [] 4.67: zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
Uplift Scope [main] 0.5: zp ZP_WORD:10 [ main::buf2#0 ] 0.33: zp ZP_WORD:6 [ main::buf1#0 ]
2019-06-24 17:48:18 +00:00
Uplifting [malloc] best 172 combination zp ZP_WORD:4 [ malloc::return#0 ] zp ZP_WORD:8 [ malloc::return#1 ] zp ZP_WORD:12 [ malloc::return#2 ]
Uplifting [] best 172 combination zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
Uplifting [main] best 172 combination zp ZP_WORD:10 [ main::buf2#0 ] zp ZP_WORD:6 [ main::buf1#0 ]
Coalescing zero page register with common assignment [ zp ZP_WORD:4 [ malloc::return#0 ] ] with [ zp ZP_WORD:6 [ main::buf1#0 ] ] - score: 1
Coalescing zero page register with common assignment [ zp ZP_WORD:8 [ malloc::return#1 ] ] with [ zp ZP_WORD:10 [ main::buf2#0 ] ] - score: 1
Coalescing zero page register with common assignment [ zp ZP_WORD:8 [ malloc::return#1 main::buf2#0 ] ] with [ zp ZP_WORD:12 [ malloc::return#2 ] ] - score: 1
Allocated (was zp ZP_WORD:8) zp ZP_WORD:6 [ malloc::return#1 main::buf2#0 malloc::return#2 ]
ASSEMBLER BEFORE OPTIMIZATION
2019-07-08 10:04:43 +00:00
// File Comments
// Test void pointer - issues when assigning returns from malloc()
2019-07-08 10:04:43 +00:00
// Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
2019-07-08 10:04:43 +00:00
// Global Constants & labels
.label SCREEN = $400
.label heap_head = 2
2019-07-08 10:04:43 +00:00
// @begin
bbegin:
2019-07-08 10:04:43 +00:00
// [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
jmp b1
2019-07-08 10:04:43 +00:00
// @1
b1:
2019-07-08 10:04:43 +00:00
// [2] call main
// [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
2019-07-08 10:04:43 +00:00
// [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
2019-07-08 10:04:43 +00:00
// @end
bend:
2019-07-08 10:04:43 +00:00
// main
main: {
2019-06-24 17:48:18 +00:00
.label buf1 = 4
.label buf2 = 6
2019-07-08 10:04:43 +00:00
// [5] call malloc
// [16] phi from main to malloc [phi:main->malloc]
malloc_from_main:
2019-07-08 10:04:43 +00:00
// [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000
sta heap_head
lda #>$c000
sta heap_head+1
jsr malloc
2019-07-08 10:04:43 +00:00
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
jmp b1
2019-07-08 10:04:43 +00:00
// main::@1
b1:
2019-07-08 10:04:43 +00:00
// [7] (void*) main::buf1#0 ← (void*) malloc::return#0
// [8] call malloc
// [16] phi from main::@1 to malloc [phi:main::@1->malloc]
malloc_from_b1:
2019-07-08 10:04:43 +00:00
// [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc
2019-07-08 10:04:43 +00:00
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2
jmp b2
2019-07-08 10:04:43 +00:00
// main::@2
b2:
2019-07-08 10:04:43 +00:00
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a'
ldy #0
2019-06-24 17:48:18 +00:00
sta (buf1),y
2019-07-08 10:04:43 +00:00
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b'
ldy #0
2019-06-24 17:48:18 +00:00
sta (buf2),y
2019-07-08 10:04:43 +00:00
// [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0
2019-06-24 17:48:18 +00:00
lda (buf1),y
sta SCREEN
2019-07-08 10:04:43 +00:00
// [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0
2019-06-24 17:48:18 +00:00
lda (buf2),y
sta SCREEN+1
jmp breturn
2019-07-08 10:04:43 +00:00
// main::@return
breturn:
2019-07-08 10:04:43 +00:00
// [15] return
rts
}
2019-07-08 10:04:43 +00:00
// malloc
malloc: {
2019-06-24 17:48:18 +00:00
.label return = 4
.label return_1 = 6
.label return_2 = 6
2019-07-08 10:04:43 +00:00
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head
bne !+
inc heap_head+1
!:
2019-07-08 10:04:43 +00:00
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
jmp breturn
2019-07-08 10:04:43 +00:00
// malloc::@return
breturn:
2019-07-08 10:04:43 +00:00
// [19] return
rts
}
2019-07-08 10:04:43 +00:00
// File Data
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 breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Removing instruction ldy #0
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 malloc_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction malloc_from_main:
Removing instruction b1:
Removing instruction b2:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte*) heap_head
(byte*) heap_head#10 heap_head zp ZP_WORD:2 4.0
(byte*) heap_head#11 heap_head zp ZP_WORD:2 0.6666666666666666
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::buf1
(void*) main::buf1#0 buf1 zp ZP_WORD:4 0.3333333333333333
(byte*) main::buf2
(void*) main::buf2#0 buf2 zp ZP_WORD:6 0.5
(void*()) malloc()
(label) malloc::@return
(void*) malloc::return
(void*) malloc::return#0 return zp ZP_WORD:4 4.0
(void*) malloc::return#1 return#1 zp ZP_WORD:6 4.0
(void*) malloc::return#2 return#2 zp ZP_WORD:6 1.5
zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
2019-06-24 17:48:18 +00:00
zp ZP_WORD:4 [ malloc::return#0 main::buf1#0 ]
zp ZP_WORD:6 [ malloc::return#1 main::buf2#0 malloc::return#2 ]
FINAL ASSEMBLER
2019-06-24 17:48:18 +00:00
Score: 106
2019-07-08 10:04:43 +00:00
// File Comments
// Test void pointer - issues when assigning returns from malloc()
2019-07-08 10:04:43 +00:00
// Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
2019-07-08 10:04:43 +00:00
// Global Constants & labels
.label SCREEN = $400
.label heap_head = 2
2019-07-08 10:04:43 +00:00
// @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: {
2019-06-24 17:48:18 +00:00
.label buf1 = 4
.label buf2 = 6
2019-07-08 10:04:43 +00:00
// [5] call malloc
// [16] phi from main to malloc [phi:main->malloc]
// [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000
sta heap_head
lda #>$c000
sta heap_head+1
jsr malloc
2019-07-08 10:04:43 +00:00
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
2019-07-08 10:04:43 +00:00
// main::@1
// [7] (void*) main::buf1#0 ← (void*) malloc::return#0
// [8] call malloc
// [16] phi from main::@1 to malloc [phi:main::@1->malloc]
// [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc
2019-07-08 10:04:43 +00:00
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2
// main::@2
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a'
ldy #0
2019-06-24 17:48:18 +00:00
sta (buf1),y
2019-07-08 10:04:43 +00:00
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b'
2019-06-24 17:48:18 +00:00
sta (buf2),y
2019-07-08 10:04:43 +00:00
// [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
2019-06-24 17:48:18 +00:00
lda (buf1),y
sta SCREEN
2019-07-08 10:04:43 +00:00
// [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
2019-06-24 17:48:18 +00:00
lda (buf2),y
sta SCREEN+1
2019-07-08 10:04:43 +00:00
// main::@return
// [15] return
rts
}
2019-07-08 10:04:43 +00:00
// malloc
malloc: {
2019-06-24 17:48:18 +00:00
.label return = 4
.label return_1 = 6
.label return_2 = 6
2019-07-08 10:04:43 +00:00
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head
bne !+
inc heap_head+1
!:
2019-07-08 10:04:43 +00:00
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
2019-06-24 17:48:18 +00:00
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
2019-07-08 10:04:43 +00:00
// malloc::@return
// [19] return
rts
}
2019-07-08 10:04:43 +00:00
// File Data