From b23029760ac3299acca109753725b0a31441eac7 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 5 Aug 2018 17:50:45 +0200 Subject: [PATCH] IRQ referencing outside const. --- .../camelot64/kickc/test/kc/test-interrupt.kc | 6 +- .../kickc/test/ref/test-interrupt.asm | 5 +- .../kickc/test/ref/test-interrupt.cfg | 7 +- .../kickc/test/ref/test-interrupt.log | 142 +++++++++--------- .../kickc/test/ref/test-interrupt.sym | 8 +- 5 files changed, 81 insertions(+), 87 deletions(-) diff --git a/src/test/java/dk/camelot64/kickc/test/kc/test-interrupt.kc b/src/test/java/dk/camelot64/kickc/test/kc/test-interrupt.kc index a41fc1307..f8523adde 100644 --- a/src/test/java/dk/camelot64/kickc/test/kc/test-interrupt.kc +++ b/src/test/java/dk/camelot64/kickc/test/kc/test-interrupt.kc @@ -1,19 +1,17 @@ void()** KERNEL_IRQ = $0314; - +const byte* BGCOL = $d020; +byte* FGCOL = $d021; void main() { *KERNEL_IRQ = &irq; - byte* FGCOL = $d021; while(true) { (*FGCOL)++; } } interrupt(kernel) void irq() { - byte* BGCOL = $d020; (*BGCOL)++; asm { lda $dc0d } - (*BGCOL)++; } diff --git a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.asm b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.asm index ff2651020..948b5dd6c 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.asm +++ b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.asm @@ -2,9 +2,10 @@ :BasicUpstart(main) .pc = $80d "Program" .label KERNEL_IRQ = $314 + .label BGCOL = $d020 + .label FGCOL = $d021 jsr main main: { - .label FGCOL = $d021 lda #irq @@ -14,9 +15,7 @@ main: { jmp b2 } irq: { - .label BGCOL = $d020 inc BGCOL lda $dc0d - inc BGCOL jmp $ea81 } diff --git a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.cfg b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.cfg index 264e2f14c..e203ce376 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.cfg +++ b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.cfg @@ -11,13 +11,12 @@ main: scope:[main] from @2 [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL)(void()) irq() [ ] ( main:2 [ ] ) to:main::@2 main::@2: scope:[main] from main main::@2 - [5] *((const byte*) main::FGCOL#0) ← ++ *((const byte*) main::FGCOL#0) [ ] ( main:2 [ ] ) + [5] *((const byte*) FGCOL#0) ← ++ *((const byte*) FGCOL#0) [ ] ( main:2 [ ] ) to:main::@2 irq: scope:[irq] from - [6] *((const byte*) irq::BGCOL#0) ← ++ *((const byte*) irq::BGCOL#0) [ ] ( ) + [6] *((const byte*) BGCOL#0) ← ++ *((const byte*) BGCOL#0) [ ] ( ) asm { lda$dc0d } - [8] *((const byte*) irq::BGCOL#0) ← ++ *((const byte*) irq::BGCOL#0) [ ] ( ) to:irq::@return irq::@return: scope:[irq] from irq - [9] return [ ] ( ) + [8] return [ ] ( ) to:@return diff --git a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.log b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.log index a177e27e6..1f56eb364 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/test-interrupt.log @@ -1,37 +1,35 @@ PARSING src/test/java/dk/camelot64/kickc/test/kc/test-interrupt.kc void()** KERNEL_IRQ = $0314; - +const byte* BGCOL = $d020; +byte* FGCOL = $d021; void main() { *KERNEL_IRQ = &irq; - byte* FGCOL = $d021; while(true) { (*FGCOL)++; } } interrupt(kernel) void irq() { - byte* BGCOL = $d020; (*BGCOL)++; asm { lda $dc0d } - (*BGCOL)++; } -Adding pre/post-modifier *((byte*) main::FGCOL) ← ++ *((byte*) main::FGCOL) -Adding pre/post-modifier *((byte*) irq::BGCOL) ← ++ *((byte*) irq::BGCOL) -Adding pre/post-modifier *((byte*) irq::BGCOL) ← ++ *((byte*) irq::BGCOL) +Adding pre/post-modifier *((byte*) FGCOL) ← ++ *((byte*) FGCOL) +Adding pre/post-modifier *((byte*) BGCOL) ← ++ *((byte*) BGCOL) Resolved forward reference irq to interrupt(KERNEL)(void()) irq() SYMBOLS (label) @1 (label) @2 (label) @begin (label) @end +(byte*) BGCOL +(byte*) FGCOL (void()**) KERNEL_IRQ interrupt(KERNEL)(void()) irq() (label) irq::@return -(byte*) irq::BGCOL (void()) main() (void()*~) main::$0 (label) main::@1 @@ -41,25 +39,25 @@ interrupt(KERNEL)(void()) irq() (label) main::@5 (label) main::@6 (label) main::@return -(byte*) main::FGCOL Promoting word/signed word/dword/signed dword to void()** in KERNEL_IRQ ← ((void()**)) 788 -Promoting word/dword/signed dword to byte* in main::FGCOL ← ((byte*)) 53281 -Promoting word/dword/signed dword to byte* in irq::BGCOL ← ((byte*)) 53280 +Promoting word/dword/signed dword to byte* in BGCOL ← ((byte*)) 53280 +Promoting word/dword/signed dword to byte* in FGCOL ← ((byte*)) 53281 INITIAL CONTROL FLOW GRAPH @begin: scope:[] from (void()**) KERNEL_IRQ ← ((void()**)) (word/signed word/dword/signed dword) 788 + (byte*) BGCOL ← ((byte*)) (word/dword/signed dword) 53280 + (byte*) FGCOL ← ((byte*)) (word/dword/signed dword) 53281 to:@1 main: scope:[main] from (void()*~) main::$0 ← & interrupt(KERNEL)(void()) irq() *((void()**) KERNEL_IRQ) ← (void()*~) main::$0 - (byte*) main::FGCOL ← ((byte*)) (word/dword/signed dword) 53281 to:main::@1 main::@1: scope:[main] from main main::@2 if(true) goto main::@2 to:main::@4 main::@2: scope:[main] from main::@1 main::@5 - *((byte*) main::FGCOL) ← ++ *((byte*) main::FGCOL) + *((byte*) FGCOL) ← ++ *((byte*) FGCOL) to:main::@1 main::@4: scope:[main] from main::@1 to:main::@3 @@ -75,10 +73,8 @@ main::@return: scope:[main] from main::@3 @1: scope:[] from @begin to:@2 irq: scope:[irq] from - (byte*) irq::BGCOL ← ((byte*)) (word/dword/signed dword) 53280 - *((byte*) irq::BGCOL) ← ++ *((byte*) irq::BGCOL) + *((byte*) BGCOL) ← ++ *((byte*) BGCOL) asm { lda$dc0d } - *((byte*) irq::BGCOL) ← ++ *((byte*) irq::BGCOL) to:irq::@return irq::@return: scope:[irq] from irq return @@ -95,40 +91,43 @@ Removing empty block main::@6 Removing empty block @1 PROCEDURE MODIFY VARIABLE ANALYSIS +Completing Phi functions... +Completing Phi functions... Completing Phi functions... Completing Phi functions... CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN @begin: scope:[] from (void()**) KERNEL_IRQ#0 ← ((void()**)) (word/signed word/dword/signed dword) 788 + (byte*) BGCOL#0 ← ((byte*)) (word/dword/signed dword) 53280 + (byte*) FGCOL#0 ← ((byte*)) (word/dword/signed dword) 53281 to:@2 main: scope:[main] from @2 + (byte*) FGCOL#3 ← phi( @2/(byte*) FGCOL#4 ) (void()**) KERNEL_IRQ#1 ← phi( @2/(void()**) KERNEL_IRQ#2 ) (void()*~) main::$0 ← & interrupt(KERNEL)(void()) irq() *((void()**) KERNEL_IRQ#1) ← (void()*~) main::$0 - (byte*) main::FGCOL#0 ← ((byte*)) (word/dword/signed dword) 53281 to:main::@1 main::@1: scope:[main] from main main::@2 - (byte*) main::FGCOL#2 ← phi( main/(byte*) main::FGCOL#0 main::@2/(byte*) main::FGCOL#1 ) + (byte*) FGCOL#2 ← phi( main/(byte*) FGCOL#3 main::@2/(byte*) FGCOL#1 ) if(true) goto main::@2 to:main::@return main::@2: scope:[main] from main::@1 - (byte*) main::FGCOL#1 ← phi( main::@1/(byte*) main::FGCOL#2 ) - *((byte*) main::FGCOL#1) ← ++ *((byte*) main::FGCOL#1) + (byte*) FGCOL#1 ← phi( main::@1/(byte*) FGCOL#2 ) + *((byte*) FGCOL#1) ← ++ *((byte*) FGCOL#1) to:main::@1 main::@return: scope:[main] from main::@1 return to:@return irq: scope:[irq] from - (byte*) irq::BGCOL#0 ← ((byte*)) (word/dword/signed dword) 53280 - *((byte*) irq::BGCOL#0) ← ++ *((byte*) irq::BGCOL#0) + *((byte*) BGCOL#0) ← ++ *((byte*) BGCOL#0) asm { lda$dc0d } - *((byte*) irq::BGCOL#0) ← ++ *((byte*) irq::BGCOL#0) to:irq::@return irq::@return: scope:[irq] from irq return to:@return @2: scope:[] from @begin + (byte*) FGCOL#4 ← phi( @begin/(byte*) FGCOL#0 ) (void()**) KERNEL_IRQ#2 ← phi( @begin/(void()**) KERNEL_IRQ#0 ) call main to:@3 @@ -141,41 +140,47 @@ SYMBOL TABLE SSA (label) @3 (label) @begin (label) @end +(byte*) BGCOL +(byte*) BGCOL#0 +(byte*) FGCOL +(byte*) FGCOL#0 +(byte*) FGCOL#1 +(byte*) FGCOL#2 +(byte*) FGCOL#3 +(byte*) FGCOL#4 (void()**) KERNEL_IRQ (void()**) KERNEL_IRQ#0 (void()**) KERNEL_IRQ#1 (void()**) KERNEL_IRQ#2 interrupt(KERNEL)(void()) irq() (label) irq::@return -(byte*) irq::BGCOL -(byte*) irq::BGCOL#0 (void()) main() (void()*~) main::$0 (label) main::@1 (label) main::@2 (label) main::@return -(byte*) main::FGCOL -(byte*) main::FGCOL#0 -(byte*) main::FGCOL#1 -(byte*) main::FGCOL#2 OPTIMIZING CONTROL FLOW GRAPH Culled Empty Block (label) @3 Succesful SSA optimization Pass2CullEmptyBlocks Not aliassing across scopes: KERNEL_IRQ#1 KERNEL_IRQ#2 -Alias (byte*) main::FGCOL#1 = (byte*) main::FGCOL#2 +Not aliassing across scopes: FGCOL#3 FGCOL#4 +Alias (byte*) FGCOL#1 = (byte*) FGCOL#2 Alias (void()**) KERNEL_IRQ#0 = (void()**) KERNEL_IRQ#2 +Alias (byte*) FGCOL#0 = (byte*) FGCOL#4 Succesful SSA optimization Pass2AliasElimination Not aliassing across scopes: KERNEL_IRQ#1 KERNEL_IRQ#0 -Self Phi Eliminated (byte*) main::FGCOL#1 +Not aliassing across scopes: FGCOL#3 FGCOL#0 +Self Phi Eliminated (byte*) FGCOL#1 Succesful SSA optimization Pass2SelfPhiElimination Redundant Phi (void()**) KERNEL_IRQ#1 (void()**) KERNEL_IRQ#0 -Redundant Phi (byte*) main::FGCOL#1 (byte*) main::FGCOL#0 +Redundant Phi (byte*) FGCOL#3 (byte*) FGCOL#0 +Redundant Phi (byte*) FGCOL#1 (byte*) FGCOL#3 Succesful SSA optimization Pass2RedundantPhiElimination Constant (const void()**) KERNEL_IRQ#0 = ((void()**))788 +Constant (const byte*) BGCOL#0 = ((byte*))53280 +Constant (const byte*) FGCOL#0 = ((byte*))53281 Constant (const void()*) main::$0 = &irq -Constant (const byte*) main::FGCOL#0 = ((byte*))53281 -Constant (const byte*) irq::BGCOL#0 = ((byte*))53280 Succesful SSA optimization Pass2ConstantIdentification if() condition always true - replacing block destination if(true) goto main::@2 Succesful SSA optimization Pass2ConstantIfs @@ -217,15 +222,14 @@ main: scope:[main] from @2 [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL)(void()) irq() [ ] ( main:2 [ ] ) to:main::@2 main::@2: scope:[main] from main main::@2 - [5] *((const byte*) main::FGCOL#0) ← ++ *((const byte*) main::FGCOL#0) [ ] ( main:2 [ ] ) + [5] *((const byte*) FGCOL#0) ← ++ *((const byte*) FGCOL#0) [ ] ( main:2 [ ] ) to:main::@2 irq: scope:[irq] from - [6] *((const byte*) irq::BGCOL#0) ← ++ *((const byte*) irq::BGCOL#0) [ ] ( ) + [6] *((const byte*) BGCOL#0) ← ++ *((const byte*) BGCOL#0) [ ] ( ) asm { lda$dc0d } - [8] *((const byte*) irq::BGCOL#0) ← ++ *((const byte*) irq::BGCOL#0) [ ] ( ) to:irq::@return irq::@return: scope:[irq] from irq - [9] return [ ] ( ) + [8] return [ ] ( ) to:@return DOMINATORS @@ -256,11 +260,11 @@ Loop head: irq::@return tails: irq blocks: irq depth: 1 VARIABLE REGISTER WEIGHTS +(byte*) BGCOL +(byte*) FGCOL (void()**) KERNEL_IRQ interrupt(KERNEL)(void()) irq() -(byte*) irq::BGCOL (void()) main() -(byte*) main::FGCOL Initial phi equivalence classes Complete equivalence classes @@ -272,6 +276,8 @@ INITIAL ASM .pc = $80d "Program" //SEG1 Global Constants & labels .label KERNEL_IRQ = $314 + .label BGCOL = $d020 + .label FGCOL = $d021 //SEG2 @begin bbegin: //SEG3 [1] phi from @begin to @2 [phi:@begin->@2] @@ -288,7 +294,6 @@ bend_from_b2: bend: //SEG8 main main: { - .label FGCOL = $d021 //SEG9 [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL)(void()) irq() [ ] ( main:2 [ ] ) -- _deref_pptc1=pprc2 lda #@2] @@ -353,7 +357,6 @@ bend_from_b2: bend: //SEG8 main main: { - .label FGCOL = $d021 //SEG9 [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL)(void()) irq() [ ] ( main:2 [ ] ) -- _deref_pptc1=pprc2 lda #@2] //SEG4 @2 @@ -432,7 +434,6 @@ Score: 271 //SEG7 @end //SEG8 main main: { - .label FGCOL = $d021 //SEG9 [4] *((const void()**) KERNEL_IRQ#0) ← &interrupt(KERNEL)(void()) irq() [ ] ( main:2 [ ] ) -- _deref_pptc1=pprc2 lda #