2019-06-24 06:21:58 +00:00
|
|
|
Culled Empty Block (label) malloc::@1
|
|
|
|
|
|
|
|
CONTROL FLOW GRAPH SSA
|
|
|
|
@begin: scope:[] from
|
|
|
|
(byte*) SCREEN#0 ← ((byte*)) (number) $400
|
|
|
|
to:@1
|
2019-09-18 21:00:30 +00:00
|
|
|
|
|
|
|
(void()) main()
|
2019-06-24 06:21:58 +00:00
|
|
|
main: scope:[main] from @2
|
|
|
|
(byte*) heap_head#13 ← phi( @2/(byte*) heap_head#14 )
|
|
|
|
call malloc
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#0 ← (void*) malloc::return#3
|
2019-06-24 06:21:58 +00:00
|
|
|
to:main::@1
|
|
|
|
main::@1: scope:[main] from main
|
|
|
|
(byte*) heap_head#7 ← phi( main/(byte*) heap_head#5 )
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#4 ← phi( main/(void*) malloc::return#0 )
|
|
|
|
(void*~) main::$0 ← (void*) malloc::return#4
|
2019-06-24 06:21:58 +00:00
|
|
|
(byte*) heap_head#0 ← (byte*) heap_head#7
|
2019-06-24 20:46:07 +00:00
|
|
|
(byte*) main::buf1#0 ← ((byte*)) (void*~) main::$0
|
2019-06-24 06:21:58 +00:00
|
|
|
call malloc
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#1 ← (void*) malloc::return#3
|
2019-06-24 06:21:58 +00:00
|
|
|
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 )
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#5 ← phi( main::@1/(void*) malloc::return#1 )
|
|
|
|
(void*~) main::$1 ← (void*) malloc::return#5
|
2019-06-24 06:21:58 +00:00
|
|
|
(byte*) heap_head#1 ← (byte*) heap_head#8
|
2019-06-24 20:46:07 +00:00
|
|
|
(byte*) main::buf2#0 ← ((byte*)) (void*~) main::$1
|
2019-06-24 06:21:58 +00:00
|
|
|
*((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
|
2019-09-18 21:00:30 +00:00
|
|
|
|
|
|
|
(void*()) malloc()
|
2019-06-24 06:21:58 +00:00
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#2 ← ((void*)) (byte*) heap_head#4
|
2019-06-24 06:21:58 +00:00
|
|
|
to:malloc::@return
|
|
|
|
malloc::@return: scope:[malloc] from malloc
|
|
|
|
(byte*) heap_head#11 ← phi( malloc/(byte*) heap_head#4 )
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) malloc::return#6 ← phi( malloc/(void*) malloc::return#2 )
|
|
|
|
(void*) malloc::return#3 ← (void*) malloc::return#6
|
2019-06-24 06:21:58 +00:00
|
|
|
(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()
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*~) main::$0
|
|
|
|
(void*~) main::$1
|
2019-06-24 06:21:58 +00:00
|
|
|
(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
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*()) malloc()
|
2019-06-24 06:21:58 +00:00
|
|
|
(label) malloc::@return
|
2019-06-24 20:46:07 +00:00
|
|
|
(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
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
Inlining cast (byte*) main::buf1#0 ← (byte*)(void*~) main::$0
|
|
|
|
Inlining cast (byte*) main::buf2#0 ← (byte*)(void*~) main::$1
|
2019-06-24 06:21:58 +00:00
|
|
|
Inlining cast (byte*) heap_head#3 ← (byte*)(number) $c000
|
2019-06-24 20:46:07 +00:00
|
|
|
Inlining cast (void*) malloc::return#2 ← (void*)(byte*) heap_head#4
|
2019-06-24 06:21:58 +00:00
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
Alias (void*) malloc::return#0 = (void*) malloc::return#4
|
2019-06-24 06:21:58 +00:00
|
|
|
Alias (byte*) heap_head#0 = (byte*) heap_head#7
|
2019-06-24 20:46:07 +00:00
|
|
|
Alias (void*) malloc::return#1 = (void*) malloc::return#5
|
|
|
|
Alias (byte*) main::buf1#0 = (byte*) main::buf1#1
|
2019-06-24 06:21:58 +00:00
|
|
|
Alias (byte*) heap_head#1 = (byte*) heap_head#8 (byte*) heap_head#9 (byte*) heap_head#2
|
2019-06-24 20:46:07 +00:00
|
|
|
Alias (void*) malloc::return#2 = (void*) malloc::return#6 (void*) malloc::return#3
|
2019-06-24 06:21:58 +00:00
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
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
|
2019-06-24 06:21:58 +00:00
|
|
|
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
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
Created 1 initial phi equivalence classes
|
2019-06-24 17:48:18 +00:00
|
|
|
Coalesced [10] heap_head#15 ← heap_head#11
|
2019-06-24 06:21:58 +00:00
|
|
|
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()
|
2019-09-18 21:00:30 +00:00
|
|
|
|
|
|
|
(void()) main()
|
2019-06-24 06:21:58 +00:00
|
|
|
main: scope:[main] from @1
|
|
|
|
[4] phi()
|
|
|
|
[5] call malloc
|
2019-06-24 20:46:07 +00:00
|
|
|
[6] (void*) malloc::return#0 ← (void*) malloc::return#2
|
2019-06-24 06:21:58 +00:00
|
|
|
to:main::@1
|
|
|
|
main::@1: scope:[main] from main
|
2019-06-24 20:46:07 +00:00
|
|
|
[7] (void*) main::buf1#0 ← (void*) malloc::return#0
|
2019-06-24 17:48:18 +00:00
|
|
|
[8] call malloc
|
2019-06-24 20:46:07 +00:00
|
|
|
[9] (void*) malloc::return#1 ← (void*) malloc::return#2
|
2019-06-24 06:21:58 +00:00
|
|
|
to:main::@2
|
|
|
|
main::@2: scope:[main] from main::@1
|
2019-06-24 20:46:07 +00:00
|
|
|
[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)
|
2019-06-24 06:21:58 +00:00
|
|
|
to:main::@return
|
|
|
|
main::@return: scope:[main] from main::@2
|
2019-06-24 17:48:18 +00:00
|
|
|
[15] return
|
2019-06-24 06:21:58 +00:00
|
|
|
to:@return
|
2019-09-18 21:00:30 +00:00
|
|
|
|
|
|
|
(void*()) malloc()
|
2019-06-24 06:21:58 +00:00
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
[18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11
|
2019-06-24 06:21:58 +00:00
|
|
|
to:malloc::@return
|
|
|
|
malloc::@return: scope:[malloc] from malloc
|
2019-06-24 17:48:18 +00:00
|
|
|
[19] return
|
2019-06-24 06:21:58 +00:00
|
|
|
to:@return
|
|
|
|
|
|
|
|
|
|
|
|
VARIABLE REGISTER WEIGHTS
|
|
|
|
(byte*) SCREEN
|
|
|
|
(byte*) heap_head
|
|
|
|
(byte*) heap_head#10 4.0
|
2019-06-24 20:46:07 +00:00
|
|
|
(byte*) heap_head#11 0.6666666666666666
|
2019-06-24 06:21:58 +00:00
|
|
|
(void()) main()
|
|
|
|
(byte*) main::buf1
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) main::buf1#0 0.3333333333333333
|
2019-06-24 06:21:58 +00:00
|
|
|
(byte*) main::buf2
|
2019-06-24 20:46:07 +00:00
|
|
|
(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
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
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 ]
|
2019-06-24 06:21:58 +00:00
|
|
|
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 ]
|
2019-06-24 06:21:58 +00:00
|
|
|
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 ]
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
INITIAL ASM
|
2019-09-08 00:29:17 +00:00
|
|
|
Target platform is c64basic / MOS6502X
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-06-24 06:21:58 +00:00
|
|
|
// Test void pointer - issues when assigning returns from malloc()
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-06-24 06:21:58 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
2019-06-24 06:21:58 +00:00
|
|
|
.label SCREEN = $400
|
|
|
|
.label heap_head = 2
|
2019-07-08 14:43:09 +00:00
|
|
|
// @begin
|
2019-06-24 06:21:58 +00:00
|
|
|
bbegin:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
2019-06-24 06:21:58 +00:00
|
|
|
b1_from_bbegin:
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// @1
|
2019-06-24 06:21:58 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [2] call main
|
|
|
|
// [4] phi from @1 to main [phi:@1->main]
|
2019-06-24 06:21:58 +00:00
|
|
|
main_from_b1:
|
|
|
|
jsr main
|
2019-07-08 14:43:09 +00:00
|
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
2019-06-24 06:21:58 +00:00
|
|
|
bend_from_b1:
|
|
|
|
jmp bend
|
2019-07-08 14:43:09 +00:00
|
|
|
// @end
|
2019-06-24 06:21:58 +00:00
|
|
|
bend:
|
2019-07-08 14:43:09 +00:00
|
|
|
// main
|
2019-06-24 06:21:58 +00:00
|
|
|
main: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label buf1 = 6
|
|
|
|
.label buf2 = $a
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] call malloc
|
|
|
|
// [16] phi from main to malloc [phi:main->malloc]
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc_from_main:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #<$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #>$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return_2
|
|
|
|
sta.z malloc.return
|
|
|
|
lda.z malloc.return_2+1
|
|
|
|
sta.z malloc.return+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@1
|
2019-06-24 06:21:58 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [7] (void*) main::buf1#0 ← (void*) malloc::return#0 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return
|
|
|
|
sta.z buf1
|
|
|
|
lda.z malloc.return+1
|
|
|
|
sta.z buf1+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// [8] call malloc
|
|
|
|
// [16] phi from main::@1 to malloc [phi:main::@1->malloc]
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc_from_b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return_2
|
|
|
|
sta.z malloc.return_1
|
|
|
|
lda.z malloc.return_2+1
|
|
|
|
sta.z malloc.return_1+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp b2
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@2
|
2019-06-24 06:21:58 +00:00
|
|
|
b2:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return_1
|
|
|
|
sta.z buf2
|
|
|
|
lda.z malloc.return_1+1
|
|
|
|
sta.z buf2+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'a'
|
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf1),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'b'
|
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf2),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
|
2019-06-24 06:21:58 +00:00
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
lda (buf1),y
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN
|
2019-07-08 14:43:09 +00:00
|
|
|
// [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
|
2019-06-24 06:21:58 +00:00
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
lda (buf2),y
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN+1
|
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
2019-06-24 06:21:58 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [15] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label return = 4
|
|
|
|
.label return_1 = 8
|
|
|
|
.label return_2 = $c
|
2019-07-08 14:43:09 +00:00
|
|
|
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z heap_head
|
|
|
|
sta.z return_2
|
|
|
|
lda.z heap_head+1
|
|
|
|
sta.z return_2+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc::@return
|
2019-06-24 06:21:58 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [19] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
2019-06-24 20:46:07 +00:00
|
|
|
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
|
2019-06-24 06:21:58 +00:00
|
|
|
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 ,
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
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 ]
|
2019-06-24 20:46:07 +00:00
|
|
|
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 06:21:58 +00:00
|
|
|
|
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 ]
|
2019-07-31 09:08:33 +00:00
|
|
|
Coalescing zero page register [ zp ZP_WORD:4 [ malloc::return#0 ] ] with [ zp ZP_WORD:6 [ main::buf1#0 ] ] - score: 1
|
|
|
|
Coalescing zero page register [ zp ZP_WORD:8 [ malloc::return#1 ] ] with [ zp ZP_WORD:10 [ main::buf2#0 ] ] - score: 1
|
|
|
|
Coalescing zero page register [ zp ZP_WORD:8 [ malloc::return#1 main::buf2#0 ] ] with [ zp ZP_WORD:12 [ malloc::return#2 ] ] - score: 1
|
2019-06-24 17:48:18 +00:00
|
|
|
Allocated (was zp ZP_WORD:8) zp ZP_WORD:6 [ malloc::return#1 main::buf2#0 malloc::return#2 ]
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
ASSEMBLER BEFORE OPTIMIZATION
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-06-24 06:21:58 +00:00
|
|
|
// Test void pointer - issues when assigning returns from malloc()
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-06-24 06:21:58 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(bbegin)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
2019-06-24 06:21:58 +00:00
|
|
|
.label SCREEN = $400
|
|
|
|
.label heap_head = 2
|
2019-07-08 14:43:09 +00:00
|
|
|
// @begin
|
2019-06-24 06:21:58 +00:00
|
|
|
bbegin:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [1] phi from @begin to @1 [phi:@begin->@1]
|
2019-06-24 06:21:58 +00:00
|
|
|
b1_from_bbegin:
|
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// @1
|
2019-06-24 06:21:58 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [2] call main
|
|
|
|
// [4] phi from @1 to main [phi:@1->main]
|
2019-06-24 06:21:58 +00:00
|
|
|
main_from_b1:
|
|
|
|
jsr main
|
2019-07-08 14:43:09 +00:00
|
|
|
// [3] phi from @1 to @end [phi:@1->@end]
|
2019-06-24 06:21:58 +00:00
|
|
|
bend_from_b1:
|
|
|
|
jmp bend
|
2019-07-08 14:43:09 +00:00
|
|
|
// @end
|
2019-06-24 06:21:58 +00:00
|
|
|
bend:
|
2019-07-08 14:43:09 +00:00
|
|
|
// main
|
2019-06-24 06:21:58 +00:00
|
|
|
main: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label buf1 = 4
|
|
|
|
.label buf2 = 6
|
2019-07-08 14:43:09 +00:00
|
|
|
// [5] call malloc
|
|
|
|
// [16] phi from main to malloc [phi:main->malloc]
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc_from_main:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #<$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #>$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return_2
|
|
|
|
sta.z malloc.return
|
|
|
|
lda.z malloc.return_2+1
|
|
|
|
sta.z malloc.return+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp b1
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@1
|
2019-06-24 06:21:58 +00:00
|
|
|
b1:
|
2019-07-08 14:43:09 +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]
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc_from_b1:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp b2
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@2
|
2019-06-24 06:21:58 +00:00
|
|
|
b2:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1
|
|
|
|
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'a'
|
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf1),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'b'
|
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf2),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// [13] *((const byte*) SCREEN#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
|
2019-06-24 06:21:58 +00:00
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
lda (buf1),y
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN
|
2019-07-08 14:43:09 +00:00
|
|
|
// [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
|
2019-06-24 06:21:58 +00:00
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
lda (buf2),y
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN+1
|
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
2019-06-24 06:21:58 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [15] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label return = 4
|
|
|
|
.label return_1 = 6
|
|
|
|
.label return_2 = 6
|
2019-07-08 14:43:09 +00:00
|
|
|
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z heap_head
|
|
|
|
sta.z return_2
|
|
|
|
lda.z heap_head+1
|
|
|
|
sta.z return_2+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jmp breturn
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc::@return
|
2019-06-24 06:21:58 +00:00
|
|
|
breturn:
|
2019-07-08 14:43:09 +00:00
|
|
|
// [19] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
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
|
2019-06-24 20:46:07 +00:00
|
|
|
(byte*) heap_head#11 heap_head zp ZP_WORD:2 0.6666666666666666
|
2019-06-24 06:21:58 +00:00
|
|
|
(void()) main()
|
|
|
|
(label) main::@1
|
|
|
|
(label) main::@2
|
|
|
|
(label) main::@return
|
|
|
|
(byte*) main::buf1
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) main::buf1#0 buf1 zp ZP_WORD:4 0.3333333333333333
|
2019-06-24 06:21:58 +00:00
|
|
|
(byte*) main::buf2
|
2019-06-24 20:46:07 +00:00
|
|
|
(void*) main::buf2#0 buf2 zp ZP_WORD:6 0.5
|
|
|
|
(void*()) malloc()
|
2019-06-24 06:21:58 +00:00
|
|
|
(label) malloc::@return
|
2019-06-24 20:46:07 +00:00
|
|
|
(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
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
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 ]
|
2019-06-24 06:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
FINAL ASSEMBLER
|
2019-06-24 17:48:18 +00:00
|
|
|
Score: 106
|
2019-06-24 06:21:58 +00:00
|
|
|
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Comments
|
2019-06-24 06:21:58 +00:00
|
|
|
// Test void pointer - issues when assigning returns from malloc()
|
2019-07-25 15:06:17 +00:00
|
|
|
// Upstart
|
2019-06-24 06:21:58 +00:00
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
2019-07-08 14:43:09 +00:00
|
|
|
// Global Constants & labels
|
2019-06-24 06:21:58 +00:00
|
|
|
.label SCREEN = $400
|
|
|
|
.label heap_head = 2
|
2019-07-08 14:43:09 +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
|
2019-06-24 06:21:58 +00:00
|
|
|
main: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label buf1 = 4
|
|
|
|
.label buf2 = 6
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc()
|
|
|
|
// [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
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #<$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #>$c000
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc()
|
|
|
|
// [6] (void*) malloc::return#0 ← (void*) malloc::return#2 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z malloc.return_2
|
|
|
|
sta.z malloc.return
|
|
|
|
lda.z malloc.return_2+1
|
|
|
|
sta.z malloc.return+1
|
2019-07-08 14:43:09 +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
|
2019-06-24 06:21:58 +00:00
|
|
|
jsr malloc
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc()
|
|
|
|
// [9] (void*) malloc::return#1 ← (void*) malloc::return#2
|
|
|
|
// main::@2
|
|
|
|
// [10] (void*) main::buf2#0 ← (void*) malloc::return#1
|
|
|
|
// *buf1 = 'a'
|
|
|
|
// [11] *((byte*)(void*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'a'
|
|
|
|
ldy #0
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf1),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// *buf2 = 'b'
|
|
|
|
// [12] *((byte*)(void*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
|
2019-06-24 06:21:58 +00:00
|
|
|
lda #'b'
|
2019-06-24 17:48:18 +00:00
|
|
|
sta (buf2),y
|
2019-07-08 14:43:09 +00:00
|
|
|
// SCREEN[0] = *buf1
|
|
|
|
// [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
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN
|
2019-07-08 14:43:09 +00:00
|
|
|
// SCREEN[1] = *buf2
|
|
|
|
// [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
|
2019-06-24 06:21:58 +00:00
|
|
|
sta SCREEN+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// main::@return
|
|
|
|
// }
|
|
|
|
// [15] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc
|
2019-06-24 06:21:58 +00:00
|
|
|
malloc: {
|
2019-06-24 17:48:18 +00:00
|
|
|
.label return = 4
|
|
|
|
.label return_1 = 6
|
|
|
|
.label return_2 = 6
|
2019-07-08 14:43:09 +00:00
|
|
|
// heap_head++;
|
|
|
|
// [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head
|
2019-06-24 06:21:58 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z heap_head+1
|
2019-06-24 06:21:58 +00:00
|
|
|
!:
|
2019-07-08 14:43:09 +00:00
|
|
|
// return heap_head;
|
|
|
|
// [18] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 -- pvoz1=pvoz2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z heap_head
|
|
|
|
sta.z return_2
|
|
|
|
lda.z heap_head+1
|
|
|
|
sta.z return_2+1
|
2019-07-08 14:43:09 +00:00
|
|
|
// malloc::@return
|
|
|
|
// }
|
|
|
|
// [19] return
|
2019-06-24 06:21:58 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-08 14:43:09 +00:00
|
|
|
// File Data
|
2019-06-24 06:21:58 +00:00
|
|
|
|