PARSING src/test/java/dk/camelot64/kickc/test/kc/arrays-init.kc

byte[3] b;
byte[] c = {'c', 'm', 'l'};
byte[] d = "cml";

byte* SCREEN = $400;

void main() {
    b[0] = 'c';
    *SCREEN = b[0];
    *(SCREEN+1) = c[1];
    *(SCREEN+2) = d[2];
}

STATEMENTS
  (byte[3]) b ← { fill( 3, 0) }
  (byte[]) c ← { (byte) 'c', (byte) 'm', (byte) 'l' }
  (byte[]) d ← (string) "cml"
  (byte*) SCREEN ← (word/signed word/dword/signed dword) 1024
proc (void()) main()
  *((byte[3]) b + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c'
  *((byte*) SCREEN) ← *((byte[3]) b + (byte/signed byte/word/signed word/dword/signed dword) 0)
  (byte*~) main::$0 ← (byte*) SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$0) ← *((byte[]) c + (byte/signed byte/word/signed word/dword/signed dword) 1)
  (byte*~) main::$1 ← (byte*) SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 2
  *((byte*~) main::$1) ← *((byte[]) d + (byte/signed byte/word/signed word/dword/signed dword) 2)
main::@return:
  return 
endproc // main()
  call main 

SYMBOLS
(byte*) SCREEN
(byte[3]) b
(byte[]) c
(byte[]) d
(void()) main()
(byte*~) main::$0
(byte*~) main::$1
(label) main::@return

Promoting word/signed word/dword/signed dword to byte* in SCREEN ← ((byte*)) 1024
INITIAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  (byte[3]) b ← { fill( 3, 0) }
  (byte[]) c ← { (byte) 'c', (byte) 'm', (byte) 'l' }
  (byte[]) d ← (string) "cml"
  (byte*) SCREEN ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from
  *((byte[3]) b + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c'
  *((byte*) SCREEN) ← *((byte[3]) b + (byte/signed byte/word/signed word/dword/signed dword) 0)
  (byte*~) main::$0 ← (byte*) SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$0) ← *((byte[]) c + (byte/signed byte/word/signed word/dword/signed dword) 1)
  (byte*~) main::$1 ← (byte*) SCREEN + (byte/signed byte/word/signed word/dword/signed dword) 2
  *((byte*~) main::$1) ← *((byte[]) d + (byte/signed byte/word/signed word/dword/signed dword) 2)
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@end
@end: scope:[]  from @1

Creating constant string variable for inline (const string) $0 "cml"
PROCEDURE MODIFY VARIABLE ANALYSIS

Completing Phi functions...
Completing Phi functions...

CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[]  from
  (byte[3]) b#0 ← { fill( 3, 0) }
  (byte[]) c#0 ← { (byte) 'c', (byte) 'm', (byte) 'l' }
  (byte[]) d#0 ← (const string) $0
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from @1
  (byte*) SCREEN#1 ← phi( @1/(byte*) SCREEN#2 )
  *((byte[3]) b#0 + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c'
  *((byte*) SCREEN#1) ← *((byte[3]) b#0 + (byte/signed byte/word/signed word/dword/signed dword) 0)
  (byte*~) main::$0 ← (byte*) SCREEN#1 + (byte/signed byte/word/signed word/dword/signed dword) 1
  *((byte*~) main::$0) ← *((byte[]) c#0 + (byte/signed byte/word/signed word/dword/signed dword) 1)
  (byte*~) main::$1 ← (byte*) SCREEN#1 + (byte/signed byte/word/signed word/dword/signed dword) 2
  *((byte*~) main::$1) ← *((byte[]) d#0 + (byte/signed byte/word/signed word/dword/signed dword) 2)
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  (byte*) SCREEN#2 ← phi( @begin/(byte*) SCREEN#0 )
  call main param-assignment
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(const string) $0 = (string) "cml"
(label) @1
(label) @2
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#2
(byte[3]) b
(byte[3]) b#0
(byte[]) c
(byte[]) c#0
(byte[]) d
(byte[]) d#0
(void()) main()
(byte*~) main::$0
(byte*~) main::$1
(label) main::@return

OPTIMIZING CONTROL FLOW GRAPH
Culled Empty Block (label) @2
Succesful SSA optimization Pass2CullEmptyBlocks
Not aliassing across scopes: SCREEN#1 SCREEN#2
Alias (byte*) SCREEN#0 = (byte*) SCREEN#2 
Succesful SSA optimization Pass2AliasElimination
Not aliassing across scopes: SCREEN#1 SCREEN#0
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#0
Succesful SSA optimization Pass2RedundantPhiElimination
Constant (const byte[3]) b#0 = { fill( 3, 0) }
Constant (const byte[]) c#0 = { 'c', 'm', 'l' }
Constant (const string) d#0 = $0
Constant (const byte*) SCREEN#0 = ((byte*))1024
Succesful SSA optimization Pass2ConstantIdentification
Constant (const byte*) main::$0 = SCREEN#0+1
Constant (const byte*) main::$1 = SCREEN#0+2
Succesful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(b#0+0)
Consolidated array index constant in *(b#0+0)
Consolidated array index constant in *(c#0+1)
Consolidated array index constant in *(d#0+2)
Succesful SSA optimization Pass2ConstantAdditionElimination
OPTIMIZING CONTROL FLOW GRAPH
Constant inlined main::$1 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2
Constant inlined $0 = (const string) d#0
Constant inlined main::$0 = (const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1
Succesful SSA optimization Pass2ConstantInlining
Block Sequence Planned @begin @1 @end main main::@return 
Block Sequence Planned @begin @1 @end main main::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Propagating live ranges...
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Block Sequence Planned @begin @1 @end main main::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Propagating live ranges...

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi() [ ] ( )
  to:@1
@1: scope:[]  from @begin
  [1] phi() [ ] ( )
  [2] call main param-assignment [ ] ( )
  to:@end
@end: scope:[]  from @1
  [3] phi() [ ] ( )
main: scope:[main]  from @1
  [4] *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c' [ ] ( main:2 [ ] )
  [5] *((const byte*) SCREEN#0) ← *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) [ ] ( main:2 [ ] )
  [6] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← *((const byte[]) c#0+(byte/signed byte/word/signed word/dword/signed dword) 1) [ ] ( main:2 [ ] )
  [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← *((const string) d#0+(byte/signed byte/word/signed word/dword/signed dword) 2) [ ] ( main:2 [ ] )
  to:main::@return
main::@return: scope:[main]  from main
  [8] return  [ ] ( main:2 [ ] )
  to:@return

DOMINATORS
@begin dominated by  @begin 
@1 dominated by  @1 @begin 
@end dominated by  @1 @begin @end 
main dominated by  @1 @begin main 
main::@return dominated by  main::@return @1 @begin main 

NATURAL LOOPS

NATURAL LOOPS WITH DEPTH
Found 0 loops in scope []
Found 0 loops in scope [main]


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(byte[3]) b
(byte[]) c
(byte[]) d
(void()) main()

Initial phi equivalence classes
Complete equivalence classes

INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG7 @end
bend:
//SEG8 main
main: {
  //SEG9 [4] *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c' [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta b+0
  //SEG10 [5] *((const byte*) SCREEN#0) ← *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda b+0
    sta SCREEN
  //SEG11 [6] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← *((const byte[]) c#0+(byte/signed byte/word/signed word/dword/signed dword) 1) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda c+1
    sta SCREEN+1
  //SEG12 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← *((const string) d#0+(byte/signed byte/word/signed word/dword/signed dword) 2) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda d+2
    sta SCREEN+2
    jmp breturn
  //SEG13 main::@return
  breturn:
  //SEG14 [8] return  [ ] ( main:2 [ ] )
    rts
}
  b: .fill 3, 0
  c: .byte 'c', 'm', 'l'
  d: .text "cml"

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) SCREEN#0) ← *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [6] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← *((const byte[]) c#0+(byte/signed byte/word/signed word/dword/signed dword) 1) [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← *((const string) d#0+(byte/signed byte/word/signed word/dword/signed dword) 2) [ ] ( main:2 [ ] ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 51 combination 
Uplifting [] best 51 combination 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG4 @1
b1:
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG7 @end
bend:
//SEG8 main
main: {
  //SEG9 [4] *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c' [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta b+0
  //SEG10 [5] *((const byte*) SCREEN#0) ← *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda b+0
    sta SCREEN
  //SEG11 [6] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← *((const byte[]) c#0+(byte/signed byte/word/signed word/dword/signed dword) 1) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda c+1
    sta SCREEN+1
  //SEG12 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← *((const string) d#0+(byte/signed byte/word/signed word/dword/signed dword) 2) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda d+2
    sta SCREEN+2
    jmp breturn
  //SEG13 main::@return
  breturn:
  //SEG14 [8] return  [ ] ( main:2 [ ] )
    rts
}
  b: .fill 3, 0
  c: .byte 'c', 'm', 'l'
  d: .text "cml"

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda b+0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction bbegin:
Removing instruction b1_from_bbegin:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(byte[3]) b
(const byte[3]) b#0 b = { fill( 3, 0) }
(byte[]) c
(const byte[]) c#0 c = { (byte) 'c', (byte) 'm', (byte) 'l' }
(byte[]) d
(const string) d#0 d = (string) "cml"
(void()) main()
(label) main::@return



FINAL ASSEMBLER
Score: 38

//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
  .label SCREEN = $400
//SEG2 @begin
//SEG3 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG4 @1
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @1 to @end [phi:@1->@end]
//SEG7 @end
//SEG8 main
main: {
  //SEG9 [4] *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) 'c' [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta b+0
  //SEG10 [5] *((const byte*) SCREEN#0) ← *((const byte[3]) b#0+(byte/signed byte/word/signed word/dword/signed dword) 0) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    sta SCREEN
  //SEG11 [6] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← *((const byte[]) c#0+(byte/signed byte/word/signed word/dword/signed dword) 1) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda c+1
    sta SCREEN+1
  //SEG12 [7] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← *((const string) d#0+(byte/signed byte/word/signed word/dword/signed dword) 2) [ ] ( main:2 [ ] ) -- _deref_pbuc1=_deref_pbuc2 
    lda d+2
    sta SCREEN+2
  //SEG13 main::@return
  //SEG14 [8] return  [ ] ( main:2 [ ] )
    rts
}
  b: .fill 3, 0
  c: .byte 'c', 'm', 'l'
  d: .text "cml"

