1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-17 10:30:43 +00:00

Changed default to byte*

This commit is contained in:
jespergravgaard 2019-06-24 19:48:18 +02:00
parent 65419720c2
commit df4294414a
5 changed files with 275 additions and 163 deletions

View File

@ -15,7 +15,7 @@ void main() {
byte* heap_head = 0xc000; byte* heap_head = 0xc000;
void* malloc() { byte* malloc() {
heap_head++; heap_head++;
return heap_head; return heap_head;
} }

View File

@ -5,27 +5,40 @@
.label SCREEN = $400 .label SCREEN = $400
.label heap_head = 2 .label heap_head = 2
main: { main: {
.label buf1 = 4
.label buf2 = 6
lda #<$c000 lda #<$c000
sta heap_head sta heap_head
lda #>$c000 lda #>$c000
sta heap_head+1 sta heap_head+1
jsr malloc jsr malloc
lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
jsr malloc jsr malloc
lda #'a' lda #'a'
ldy #0 ldy #0
sta (heap_head),y sta (buf1),y
lda #'b' lda #'b'
sta (heap_head),y sta (buf2),y
lda (heap_head),y lda (buf1),y
sta SCREEN sta SCREEN
lda (heap_head),y lda (buf2),y
sta SCREEN+1 sta SCREEN+1
rts rts
} }
malloc: { malloc: {
.label return = 4
.label return_1 = 6
.label return_2 = 6
inc heap_head inc heap_head
bne !+ bne !+
inc heap_head+1 inc heap_head+1
!: !:
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
rts rts
} }

View File

@ -10,24 +10,28 @@
main: scope:[main] from @1 main: scope:[main] from @1
[4] phi() [4] phi()
[5] call malloc [5] call malloc
[6] (byte*) malloc::return#0 ← (byte*) malloc::return#2
to:main::@1 to:main::@1
main::@1: scope:[main] from main main::@1: scope:[main] from main
[6] phi() [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0
[7] call malloc [8] call malloc
[9] (byte*) malloc::return#1 ← (byte*) malloc::return#2
to:main::@2 to:main::@2
main::@2: scope:[main] from main::@1 main::@2: scope:[main] from main::@1
[8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' [10] (byte*) main::buf2#0 ← (byte*) malloc::return#1
[9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' [11] *((byte*) main::buf1#0) ← (byte) 'a'
[10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) [12] *((byte*) main::buf2#0) ← (byte) 'b'
[11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) [13] *((const byte*) SCREEN#0) ← *((byte*) main::buf1#0)
[14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*) main::buf2#0)
to:main::@return to:main::@return
main::@return: scope:[main] from main::@2 main::@return: scope:[main] from main::@2
[12] return
to:@return
malloc: scope:[malloc] from main main::@1
[13] (byte*) heap_head#10 ← phi( main/(byte*) 49152 main::@1/(byte*) heap_head#11 )
[14] (byte*) heap_head#11 ← ++ (byte*) heap_head#10
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
[15] return [15] return
to:@return to:@return
malloc: scope:[malloc] from main main::@1
[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] (byte*) malloc::return#2 ← (byte*) heap_head#11
to:malloc::@return
malloc::@return: scope:[malloc] from malloc
[19] return
to:@return

View File

@ -1,8 +1,5 @@
Adding pointer type conversion cast (byte*) SCREEN in (byte*) SCREEN ← (number) $400 Adding pointer type conversion cast (byte*) SCREEN in (byte*) SCREEN ← (number) $400
Adding pointer type conversion cast to void pointer (byte*) main::$0 in (byte*) main::buf1 ← (void*~) main::$0
Adding pointer type conversion cast to void pointer (byte*) main::$1 in (byte*) main::buf2 ← (void*~) main::$1
Adding pointer type conversion cast (byte*) heap_head in (byte*) heap_head ← (number) $c000 Adding pointer type conversion cast (byte*) heap_head in (byte*) heap_head ← (number) $c000
Adding void pointer type conversion cast (void*) heap_head in (void*) malloc::return ← (byte*) heap_head
Culled Empty Block (label) malloc::@1 Culled Empty Block (label) malloc::@1
CONTROL FLOW GRAPH SSA CONTROL FLOW GRAPH SSA
@ -12,24 +9,24 @@ CONTROL FLOW GRAPH SSA
main: scope:[main] from @2 main: scope:[main] from @2
(byte*) heap_head#13 ← phi( @2/(byte*) heap_head#14 ) (byte*) heap_head#13 ← phi( @2/(byte*) heap_head#14 )
call malloc call malloc
(void*) malloc::return#0 ← (void*) malloc::return#3 (byte*) malloc::return#0 ← (byte*) malloc::return#3
to:main::@1 to:main::@1
main::@1: scope:[main] from main main::@1: scope:[main] from main
(byte*) heap_head#7 ← phi( main/(byte*) heap_head#5 ) (byte*) heap_head#7 ← phi( main/(byte*) heap_head#5 )
(void*) malloc::return#4 ← phi( main/(void*) malloc::return#0 ) (byte*) malloc::return#4 ← phi( main/(byte*) malloc::return#0 )
(void*~) main::$0 ← (void*) malloc::return#4 (byte*~) main::$0 ← (byte*) malloc::return#4
(byte*) heap_head#0 ← (byte*) heap_head#7 (byte*) heap_head#0 ← (byte*) heap_head#7
(byte*) main::buf1#0 ← ((byte*)) (void*~) main::$0 (byte*) main::buf1#0 ← (byte*~) main::$0
call malloc call malloc
(void*) malloc::return#1 ← (void*) malloc::return#3 (byte*) malloc::return#1 ← (byte*) malloc::return#3
to:main::@2 to:main::@2
main::@2: scope:[main] from main::@1 main::@2: scope:[main] from main::@1
(byte*) main::buf1#1 ← phi( main::@1/(byte*) main::buf1#0 ) (byte*) main::buf1#1 ← phi( main::@1/(byte*) main::buf1#0 )
(byte*) heap_head#8 ← phi( main::@1/(byte*) heap_head#5 ) (byte*) heap_head#8 ← phi( main::@1/(byte*) heap_head#5 )
(void*) malloc::return#5 ← phi( main::@1/(void*) malloc::return#1 ) (byte*) malloc::return#5 ← phi( main::@1/(byte*) malloc::return#1 )
(void*~) main::$1 ← (void*) malloc::return#5 (byte*~) main::$1 ← (byte*) malloc::return#5
(byte*) heap_head#1 ← (byte*) heap_head#8 (byte*) heap_head#1 ← (byte*) heap_head#8
(byte*) main::buf2#0 ← ((byte*)) (void*~) main::$1 (byte*) main::buf2#0 ← (byte*~) main::$1
*((byte*) main::buf1#1) ← (byte) 'a' *((byte*) main::buf1#1) ← (byte) 'a'
*((byte*) main::buf2#0) ← (byte) 'b' *((byte*) main::buf2#0) ← (byte) 'b'
*((byte*) SCREEN#0 + (number) 0) ← *((byte*) main::buf1#1) *((byte*) SCREEN#0 + (number) 0) ← *((byte*) main::buf1#1)
@ -46,12 +43,12 @@ main::@return: scope:[main] from main::@2
malloc: scope:[malloc] from main main::@1 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#10 ← phi( main/(byte*) heap_head#13 main::@1/(byte*) heap_head#0 )
(byte*) heap_head#4 ← ++ (byte*) heap_head#10 (byte*) heap_head#4 ← ++ (byte*) heap_head#10
(void*) malloc::return#2 ← ((void*)) (byte*) heap_head#4 (byte*) malloc::return#2 ← (byte*) heap_head#4
to:malloc::@return to:malloc::@return
malloc::@return: scope:[malloc] from malloc malloc::@return: scope:[malloc] from malloc
(byte*) heap_head#11 ← phi( malloc/(byte*) heap_head#4 ) (byte*) heap_head#11 ← phi( malloc/(byte*) heap_head#4 )
(void*) malloc::return#6 ← phi( malloc/(void*) malloc::return#2 ) (byte*) malloc::return#6 ← phi( malloc/(byte*) malloc::return#2 )
(void*) malloc::return#3 ← (void*) malloc::return#6 (byte*) malloc::return#3 ← (byte*) malloc::return#6
(byte*) heap_head#5 ← (byte*) heap_head#11 (byte*) heap_head#5 ← (byte*) heap_head#11
return return
to:@return to:@return
@ -90,8 +87,8 @@ SYMBOL TABLE SSA
(byte*) heap_head#8 (byte*) heap_head#8
(byte*) heap_head#9 (byte*) heap_head#9
(void()) main() (void()) main()
(void*~) main::$0 (byte*~) main::$0
(void*~) main::$1 (byte*~) main::$1
(label) main::@1 (label) main::@1
(label) main::@2 (label) main::@2
(label) main::@return (label) main::@return
@ -100,25 +97,22 @@ SYMBOL TABLE SSA
(byte*) main::buf1#1 (byte*) main::buf1#1
(byte*) main::buf2 (byte*) main::buf2
(byte*) main::buf2#0 (byte*) main::buf2#0
(void*()) malloc() (byte*()) malloc()
(label) malloc::@return (label) malloc::@return
(void*) malloc::return (byte*) malloc::return
(void*) malloc::return#0 (byte*) malloc::return#0
(void*) malloc::return#1 (byte*) malloc::return#1
(void*) malloc::return#2 (byte*) malloc::return#2
(void*) malloc::return#3 (byte*) malloc::return#3
(void*) malloc::return#4 (byte*) malloc::return#4
(void*) malloc::return#5 (byte*) malloc::return#5
(void*) malloc::return#6 (byte*) malloc::return#6
Adding number conversion cast (unumber) 0 in *((byte*) SCREEN#0 + (number) 0) ← *((byte*) main::buf1#1) 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) Adding number conversion cast (unumber) 1 in *((byte*) SCREEN#0 + (number) 1) ← *((byte*) main::buf2#0)
Successful SSA optimization PassNAddNumberTypeConversions Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400 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 (byte*) heap_head#3 ← (byte*)(number) $c000
Inlining cast (void*) malloc::return#2 ← (void*)(byte*) heap_head#4
Successful SSA optimization Pass2InlineCast Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024 Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0 Simplifying constant integer cast 0
@ -128,12 +122,13 @@ Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0 Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1 Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (void*) malloc::return#0 = (void*) malloc::return#4 Alias (byte*) malloc::return#0 = (byte*) malloc::return#4
Alias (byte*) heap_head#0 = (byte*) heap_head#7 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::$0 (byte*) main::buf1#1
Alias (byte*) main::buf1#0 = (byte*) main::buf1#1 Alias (byte*) malloc::return#1 = (byte*) malloc::return#5
Alias (byte*) heap_head#1 = (byte*) heap_head#8 (byte*) heap_head#9 (byte*) heap_head#2 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*) main::buf2#0 = (byte*~) main::$1
Alias (byte*) malloc::return#2 = (byte*) malloc::return#6 (byte*) malloc::return#3
Alias (byte*) heap_head#11 = (byte*) heap_head#4 (byte*) heap_head#5 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#14 = (byte*) heap_head#3
Alias (byte*) heap_head#12 = (byte*) heap_head#6 Alias (byte*) heap_head#12 = (byte*) heap_head#6
@ -148,17 +143,6 @@ Constant (const byte*) heap_head#14 = (byte*) 49152
Successful SSA optimization Pass2ConstantIdentification Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN#0 in [16] *((const byte*) SCREEN#0 + (byte) 0) ← *((byte*) main::buf1#0) Simplifying expression containing zero SCREEN#0 in [16] *((const byte*) SCREEN#0 + (byte) 0) ← *((byte*) main::buf1#0)
Successful SSA optimization PassNSimplifyExpressionWithZero 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 Noop Cast [15] (void*) malloc::return#2 ← (void*)(byte*) heap_head#11 keeping heap_head#11
Successful SSA optimization Pass2NopCastInlining
Inlining Noop Cast [1] (void*) malloc::return#0 ← (void*)(byte*) heap_head#11 keeping heap_head#11
Inlining Noop Cast [5] (void*) malloc::return#1 ← (void*)(byte*) heap_head#11 keeping heap_head#11
Successful SSA optimization Pass2NopCastInlining
Inlining Noop Cast [2] (void*) main::buf1#0 ← (void*)(byte*) heap_head#11 keeping heap_head#11
Inlining Noop Cast [6] (void*) main::buf2#0 ← (void*)(byte*) heap_head#11 keeping heap_head#11
Successful SSA optimization Pass2NopCastInlining
Inlining constant with var siblings (const byte*) heap_head#14 Inlining constant with var siblings (const byte*) heap_head#14
Constant inlined heap_head#14 = (byte*) 49152 Constant inlined heap_head#14 = (byte*) 49152
Successful SSA optimization Pass2ConstantInlining Successful SSA optimization Pass2ConstantInlining
@ -172,10 +156,10 @@ Adding NOP phi() at start of @end
Adding NOP phi() at start of main Adding NOP phi() at start of main
CALL GRAPH CALL GRAPH
Calls in [] to main:3 Calls in [] to main:3
Calls in [main] to malloc:7 malloc:9 Calls in [main] to malloc:7 malloc:11
Created 1 initial phi equivalence classes Created 1 initial phi equivalence classes
Coalesced [8] heap_head#15 ← heap_head#11 Coalesced [10] heap_head#15 ← heap_head#11
Coalesced down to 1 phi equivalence classes Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @1 Culled Empty Block (label) @1
Culled Empty Block (label) @3 Culled Empty Block (label) @3
@ -184,7 +168,6 @@ Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1 Adding NOP phi() at start of @1
Adding NOP phi() at start of @end Adding NOP phi() at start of @end
Adding NOP phi() at start of main Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
FINAL CONTROL FLOW GRAPH FINAL CONTROL FLOW GRAPH
@begin: scope:[] from @begin: scope:[] from
@ -199,26 +182,30 @@ FINAL CONTROL FLOW GRAPH
main: scope:[main] from @1 main: scope:[main] from @1
[4] phi() [4] phi()
[5] call malloc [5] call malloc
[6] (byte*) malloc::return#0 ← (byte*) malloc::return#2
to:main::@1 to:main::@1
main::@1: scope:[main] from main main::@1: scope:[main] from main
[6] phi() [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0
[7] call malloc [8] call malloc
[9] (byte*) malloc::return#1 ← (byte*) malloc::return#2
to:main::@2 to:main::@2
main::@2: scope:[main] from main::@1 main::@2: scope:[main] from main::@1
[8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' [10] (byte*) main::buf2#0 ← (byte*) malloc::return#1
[9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' [11] *((byte*) main::buf1#0) ← (byte) 'a'
[10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) [12] *((byte*) main::buf2#0) ← (byte) 'b'
[11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) [13] *((const byte*) SCREEN#0) ← *((byte*) main::buf1#0)
[14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*) main::buf2#0)
to:main::@return to:main::@return
main::@return: scope:[main] from main::@2 main::@return: scope:[main] from main::@2
[12] return [15] return
to:@return to:@return
malloc: scope:[malloc] from main main::@1 malloc: scope:[malloc] from main main::@1
[13] (byte*) heap_head#10 ← phi( main/(byte*) 49152 main::@1/(byte*) heap_head#11 ) [16] (byte*) heap_head#10 ← phi( main/(byte*) 49152 main::@1/(byte*) heap_head#11 )
[14] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10
[18] (byte*) malloc::return#2 ← (byte*) heap_head#11
to:malloc::@return to:malloc::@return
malloc::@return: scope:[malloc] from malloc malloc::@return: scope:[malloc] from malloc
[15] return [19] return
to:@return to:@return
@ -226,18 +213,38 @@ VARIABLE REGISTER WEIGHTS
(byte*) SCREEN (byte*) SCREEN
(byte*) heap_head (byte*) heap_head
(byte*) heap_head#10 4.0 (byte*) heap_head#10 4.0
(byte*) heap_head#11 0.5 (byte*) heap_head#11 1.0
(void()) main() (void()) main()
(byte*) main::buf1 (byte*) main::buf1
(byte*) main::buf1#0 1.0
(byte*) main::buf2 (byte*) main::buf2
(void*()) malloc() (byte*) main::buf2#0 1.5
(void*) malloc::return (byte*()) malloc()
(byte*) malloc::return
(byte*) malloc::return#0 4.0
(byte*) malloc::return#1 4.0
(byte*) malloc::return#2 1.5
Initial phi equivalence classes Initial phi equivalence classes
[ heap_head#10 heap_head#11 ] [ heap_head#10 heap_head#11 ]
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 Complete equivalence classes
[ heap_head#10 heap_head#11 ] [ heap_head#10 heap_head#11 ]
[ 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 ] Allocated zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
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 INITIAL ASM
//SEG0 File Comments //SEG0 File Comments
@ -267,80 +274,122 @@ bend_from_b1:
bend: bend:
//SEG10 main //SEG10 main
main: { main: {
.label buf1 = 6
.label buf2 = $a
//SEG11 [5] call malloc //SEG11 [5] call malloc
//SEG12 [13] phi from main to malloc [phi:main->malloc] //SEG12 [16] phi from main to malloc [phi:main->malloc]
malloc_from_main: malloc_from_main:
//SEG13 [13] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1 //SEG13 [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000 lda #<$c000
sta heap_head sta heap_head
lda #>$c000 lda #>$c000
sta heap_head+1 sta heap_head+1
jsr malloc jsr malloc
//SEG14 [6] phi from main to main::@1 [phi:main->main::@1] //SEG14 [6] (byte*) malloc::return#0 ← (byte*) malloc::return#2 -- pbuz1=pbuz2
b1_from_main: lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
jmp b1 jmp b1
//SEG15 main::@1 //SEG15 main::@1
b1: b1:
//SEG16 [7] call malloc //SEG16 [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0 -- pbuz1=pbuz2
//SEG17 [13] phi from main::@1 to malloc [phi:main::@1->malloc] lda malloc.return
sta buf1
lda malloc.return+1
sta buf1+1
//SEG17 [8] call malloc
//SEG18 [16] phi from main::@1 to malloc [phi:main::@1->malloc]
malloc_from_b1: malloc_from_b1:
//SEG18 [13] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy //SEG19 [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc jsr malloc
//SEG20 [9] (byte*) malloc::return#1 ← (byte*) malloc::return#2 -- pbuz1=pbuz2
lda malloc.return_2
sta malloc.return_1
lda malloc.return_2+1
sta malloc.return_1+1
jmp b2 jmp b2
//SEG19 main::@2 //SEG21 main::@2
b2: b2:
//SEG20 [8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' -- _deref_pbuz1=vbuc1 //SEG22 [10] (byte*) main::buf2#0 ← (byte*) malloc::return#1 -- pbuz1=pbuz2
lda malloc.return_1
sta buf2
lda malloc.return_1+1
sta buf2+1
//SEG23 [11] *((byte*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a' lda #'a'
ldy #0 ldy #0
sta (heap_head),y sta (buf1),y
//SEG21 [9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' -- _deref_pbuz1=vbuc1 //SEG24 [12] *((byte*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b' lda #'b'
ldy #0 ldy #0
sta (heap_head),y sta (buf2),y
//SEG22 [10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG25 [13] *((const byte*) SCREEN#0) ← *((byte*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0 ldy #0
lda (heap_head),y lda (buf1),y
sta SCREEN sta SCREEN
//SEG23 [11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG26 [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0 ldy #0
lda (heap_head),y lda (buf2),y
sta SCREEN+1 sta SCREEN+1
jmp breturn jmp breturn
//SEG24 main::@return //SEG27 main::@return
breturn: breturn:
//SEG25 [12] return //SEG28 [15] return
rts rts
} }
//SEG26 malloc //SEG29 malloc
malloc: { malloc: {
//SEG27 [14] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1 .label return = 4
.label return_1 = 8
.label return_2 = $c
//SEG30 [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head inc heap_head
bne !+ bne !+
inc heap_head+1 inc heap_head+1
!: !:
//SEG31 [18] (byte*) malloc::return#2 ← (byte*) heap_head#11 -- pbuz1=pbuz2
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
jmp breturn jmp breturn
//SEG28 malloc::@return //SEG32 malloc::@return
breturn: breturn:
//SEG29 [15] return //SEG33 [19] return
rts rts
} }
//SEG30 File Data //SEG34 File Data
REGISTER UPLIFT POTENTIAL REGISTERS REGISTER UPLIFT POTENTIAL REGISTERS
Statement [8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' [ heap_head#11 ] ( main:2 [ heap_head#11 ] ) always clobbers reg byte a reg byte y Statement [6] (byte*) malloc::return#0 ← (byte*) malloc::return#2 [ malloc::return#0 heap_head#11 ] ( main:2 [ malloc::return#0 heap_head#11 ] ) always clobbers reg byte a
Statement [9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' [ heap_head#11 ] ( main:2 [ heap_head#11 ] ) always clobbers reg byte a reg byte y Statement [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0 [ main::buf1#0 heap_head#11 ] ( main:2 [ main::buf1#0 heap_head#11 ] ) always clobbers reg byte a
Statement [10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) [ heap_head#11 ] ( main:2 [ heap_head#11 ] ) always clobbers reg byte a reg byte y Statement [9] (byte*) malloc::return#1 ← (byte*) malloc::return#2 [ main::buf1#0 malloc::return#1 ] ( main:2 [ main::buf1#0 malloc::return#1 ] ) always clobbers reg byte a
Statement [11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y Statement [10] (byte*) main::buf2#0 ← (byte*) 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*) 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*) 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*) 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*) main::buf2#0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y
Statement [18] (byte*) malloc::return#2 ← (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 , Potential registers zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] : zp ZP_WORD:2 ,
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 REGISTER UPLIFT SCOPES
Uplift Scope [] 4.5: zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] 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 [main] Uplift Scope [] 5: zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
Uplift Scope [malloc] Uplift Scope [main] 1.5: zp ZP_WORD:10 [ main::buf2#0 ] 1: zp ZP_WORD:6 [ main::buf1#0 ]
Uplifting [] best 112 combination zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] 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 [main] best 112 combination Uplifting [] best 172 combination zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
Uplifting [malloc] best 112 combination 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 ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments //SEG0 File Comments
@ -370,64 +419,80 @@ bend_from_b1:
bend: bend:
//SEG10 main //SEG10 main
main: { main: {
.label buf1 = 4
.label buf2 = 6
//SEG11 [5] call malloc //SEG11 [5] call malloc
//SEG12 [13] phi from main to malloc [phi:main->malloc] //SEG12 [16] phi from main to malloc [phi:main->malloc]
malloc_from_main: malloc_from_main:
//SEG13 [13] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1 //SEG13 [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000 lda #<$c000
sta heap_head sta heap_head
lda #>$c000 lda #>$c000
sta heap_head+1 sta heap_head+1
jsr malloc jsr malloc
//SEG14 [6] phi from main to main::@1 [phi:main->main::@1] //SEG14 [6] (byte*) malloc::return#0 ← (byte*) malloc::return#2 -- pbuz1=pbuz2
b1_from_main: lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
jmp b1 jmp b1
//SEG15 main::@1 //SEG15 main::@1
b1: b1:
//SEG16 [7] call malloc //SEG16 [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0
//SEG17 [13] phi from main::@1 to malloc [phi:main::@1->malloc] //SEG17 [8] call malloc
//SEG18 [16] phi from main::@1 to malloc [phi:main::@1->malloc]
malloc_from_b1: malloc_from_b1:
//SEG18 [13] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy //SEG19 [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc jsr malloc
//SEG20 [9] (byte*) malloc::return#1 ← (byte*) malloc::return#2
jmp b2 jmp b2
//SEG19 main::@2 //SEG21 main::@2
b2: b2:
//SEG20 [8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' -- _deref_pbuz1=vbuc1 //SEG22 [10] (byte*) main::buf2#0 ← (byte*) malloc::return#1
//SEG23 [11] *((byte*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a' lda #'a'
ldy #0 ldy #0
sta (heap_head),y sta (buf1),y
//SEG21 [9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' -- _deref_pbuz1=vbuc1 //SEG24 [12] *((byte*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b' lda #'b'
ldy #0 ldy #0
sta (heap_head),y sta (buf2),y
//SEG22 [10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG25 [13] *((const byte*) SCREEN#0) ← *((byte*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0 ldy #0
lda (heap_head),y lda (buf1),y
sta SCREEN sta SCREEN
//SEG23 [11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG26 [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
ldy #0 ldy #0
lda (heap_head),y lda (buf2),y
sta SCREEN+1 sta SCREEN+1
jmp breturn jmp breturn
//SEG24 main::@return //SEG27 main::@return
breturn: breturn:
//SEG25 [12] return //SEG28 [15] return
rts rts
} }
//SEG26 malloc //SEG29 malloc
malloc: { malloc: {
//SEG27 [14] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1 .label return = 4
.label return_1 = 6
.label return_2 = 6
//SEG30 [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head inc heap_head
bne !+ bne !+
inc heap_head+1 inc heap_head+1
!: !:
//SEG31 [18] (byte*) malloc::return#2 ← (byte*) heap_head#11 -- pbuz1=pbuz2
lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
jmp breturn jmp breturn
//SEG28 malloc::@return //SEG32 malloc::@return
breturn: breturn:
//SEG29 [15] return //SEG33 [19] return
rts rts
} }
//SEG30 File Data //SEG34 File Data
ASSEMBLER OPTIMIZATIONS ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1 Removing instruction jmp b1
@ -445,7 +510,6 @@ Removing instruction b1_from_bbegin:
Removing instruction b1: Removing instruction b1:
Removing instruction main_from_b1: Removing instruction main_from_b1:
Removing instruction bend_from_b1: Removing instruction bend_from_b1:
Removing instruction b1_from_main:
Removing instruction malloc_from_b1: Removing instruction malloc_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend: Removing instruction bend:
@ -469,22 +533,29 @@ FINAL SYMBOL TABLE
(const byte*) SCREEN#0 SCREEN = (byte*) 1024 (const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte*) heap_head (byte*) heap_head
(byte*) heap_head#10 heap_head zp ZP_WORD:2 4.0 (byte*) heap_head#10 heap_head zp ZP_WORD:2 4.0
(byte*) heap_head#11 heap_head zp ZP_WORD:2 0.5 (byte*) heap_head#11 heap_head zp ZP_WORD:2 1.0
(void()) main() (void()) main()
(label) main::@1 (label) main::@1
(label) main::@2 (label) main::@2
(label) main::@return (label) main::@return
(byte*) main::buf1 (byte*) main::buf1
(byte*) main::buf1#0 buf1 zp ZP_WORD:4 1.0
(byte*) main::buf2 (byte*) main::buf2
(void*()) malloc() (byte*) main::buf2#0 buf2 zp ZP_WORD:6 1.5
(byte*()) malloc()
(label) malloc::@return (label) malloc::@return
(void*) malloc::return (byte*) malloc::return
(byte*) malloc::return#0 return zp ZP_WORD:4 4.0
(byte*) malloc::return#1 return#1 zp ZP_WORD:6 4.0
(byte*) malloc::return#2 return#2 zp ZP_WORD:6 1.5
zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
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 FINAL ASSEMBLER
Score: 82 Score: 106
//SEG0 File Comments //SEG0 File Comments
// Test void pointer - issues when assigning returns from malloc() // Test void pointer - issues when assigning returns from malloc()
@ -504,48 +575,65 @@ Score: 82
//SEG9 @end //SEG9 @end
//SEG10 main //SEG10 main
main: { main: {
.label buf1 = 4
.label buf2 = 6
//SEG11 [5] call malloc //SEG11 [5] call malloc
//SEG12 [13] phi from main to malloc [phi:main->malloc] //SEG12 [16] phi from main to malloc [phi:main->malloc]
//SEG13 [13] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1 //SEG13 [16] phi (byte*) heap_head#10 = (byte*) 49152 [phi:main->malloc#0] -- pbuz1=pbuc1
lda #<$c000 lda #<$c000
sta heap_head sta heap_head
lda #>$c000 lda #>$c000
sta heap_head+1 sta heap_head+1
jsr malloc jsr malloc
//SEG14 [6] phi from main to main::@1 [phi:main->main::@1] //SEG14 [6] (byte*) malloc::return#0 ← (byte*) malloc::return#2 -- pbuz1=pbuz2
lda malloc.return_2
sta malloc.return
lda malloc.return_2+1
sta malloc.return+1
//SEG15 main::@1 //SEG15 main::@1
//SEG16 [7] call malloc //SEG16 [7] (byte*) main::buf1#0 ← (byte*) malloc::return#0
//SEG17 [13] phi from main::@1 to malloc [phi:main::@1->malloc] //SEG17 [8] call malloc
//SEG18 [13] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy //SEG18 [16] phi from main::@1 to malloc [phi:main::@1->malloc]
//SEG19 [16] phi (byte*) heap_head#10 = (byte*) heap_head#11 [phi:main::@1->malloc#0] -- register_copy
jsr malloc jsr malloc
//SEG19 main::@2 //SEG20 [9] (byte*) malloc::return#1 ← (byte*) malloc::return#2
//SEG20 [8] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'a' -- _deref_pbuz1=vbuc1 //SEG21 main::@2
//SEG22 [10] (byte*) main::buf2#0 ← (byte*) malloc::return#1
//SEG23 [11] *((byte*) main::buf1#0) ← (byte) 'a' -- _deref_pbuz1=vbuc1
lda #'a' lda #'a'
ldy #0 ldy #0
sta (heap_head),y sta (buf1),y
//SEG21 [9] *((byte*)(void*)(byte*) heap_head#11) ← (byte) 'b' -- _deref_pbuz1=vbuc1 //SEG24 [12] *((byte*) main::buf2#0) ← (byte) 'b' -- _deref_pbuz1=vbuc1
lda #'b' lda #'b'
sta (heap_head),y sta (buf2),y
//SEG22 [10] *((const byte*) SCREEN#0) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG25 [13] *((const byte*) SCREEN#0) ← *((byte*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1
lda (heap_head),y lda (buf1),y
sta SCREEN sta SCREEN
//SEG23 [11] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*)(void*)(byte*) heap_head#11) -- _deref_pbuc1=_deref_pbuz1 //SEG26 [14] *((const byte*) SCREEN#0+(byte) 1) ← *((byte*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1
lda (heap_head),y lda (buf2),y
sta SCREEN+1 sta SCREEN+1
//SEG24 main::@return //SEG27 main::@return
//SEG25 [12] return //SEG28 [15] return
rts rts
} }
//SEG26 malloc //SEG29 malloc
malloc: { malloc: {
//SEG27 [14] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1 .label return = 4
.label return_1 = 6
.label return_2 = 6
//SEG30 [17] (byte*) heap_head#11 ← ++ (byte*) heap_head#10 -- pbuz1=_inc_pbuz1
inc heap_head inc heap_head
bne !+ bne !+
inc heap_head+1 inc heap_head+1
!: !:
//SEG28 malloc::@return //SEG31 [18] (byte*) malloc::return#2 ← (byte*) heap_head#11 -- pbuz1=pbuz2
//SEG29 [15] return lda heap_head
sta return_2
lda heap_head+1
sta return_2+1
//SEG32 malloc::@return
//SEG33 [19] return
rts rts
} }
//SEG30 File Data //SEG34 File Data

View File

@ -5,15 +5,22 @@
(const byte*) SCREEN#0 SCREEN = (byte*) 1024 (const byte*) SCREEN#0 SCREEN = (byte*) 1024
(byte*) heap_head (byte*) heap_head
(byte*) heap_head#10 heap_head zp ZP_WORD:2 4.0 (byte*) heap_head#10 heap_head zp ZP_WORD:2 4.0
(byte*) heap_head#11 heap_head zp ZP_WORD:2 0.5 (byte*) heap_head#11 heap_head zp ZP_WORD:2 1.0
(void()) main() (void()) main()
(label) main::@1 (label) main::@1
(label) main::@2 (label) main::@2
(label) main::@return (label) main::@return
(byte*) main::buf1 (byte*) main::buf1
(byte*) main::buf1#0 buf1 zp ZP_WORD:4 1.0
(byte*) main::buf2 (byte*) main::buf2
(void*()) malloc() (byte*) main::buf2#0 buf2 zp ZP_WORD:6 1.5
(byte*()) malloc()
(label) malloc::@return (label) malloc::@return
(void*) malloc::return (byte*) malloc::return
(byte*) malloc::return#0 return zp ZP_WORD:4 4.0
(byte*) malloc::return#1 return#1 zp ZP_WORD:6 4.0
(byte*) malloc::return#2 return#2 zp ZP_WORD:6 1.5
zp ZP_WORD:2 [ heap_head#10 heap_head#11 ] zp ZP_WORD:2 [ heap_head#10 heap_head#11 ]
zp ZP_WORD:4 [ malloc::return#0 main::buf1#0 ]
zp ZP_WORD:6 [ malloc::return#1 main::buf2#0 malloc::return#2 ]