From 521385065dd021fdc4e350cc4cb72d86aefeb10c Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Fri, 27 Apr 2018 14:55:46 +0200 Subject: [PATCH] Fixed logging --- .../java/dk/camelot64/kickc/CompileLog.java | 4 +- .../dk/camelot64/kickc/test/TestPrograms.java | 5 + .../kickc/test/kc/double-assignment.kc | 11 + .../camelot64/kickc/test/ref/bool-pointer.log | 36 --- .../kickc/test/ref/double-assignment.asm | 12 + .../kickc/test/ref/double-assignment.cfg | 16 + .../kickc/test/ref/double-assignment.log | 293 ++++++++++++++++++ .../kickc/test/ref/double-assignment.sym | 11 + 8 files changed, 350 insertions(+), 38 deletions(-) create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/double-assignment.kc create mode 100644 src/test/java/dk/camelot64/kickc/test/ref/double-assignment.asm create mode 100644 src/test/java/dk/camelot64/kickc/test/ref/double-assignment.cfg create mode 100644 src/test/java/dk/camelot64/kickc/test/ref/double-assignment.log create mode 100644 src/test/java/dk/camelot64/kickc/test/ref/double-assignment.sym diff --git a/src/main/java/dk/camelot64/kickc/CompileLog.java b/src/main/java/dk/camelot64/kickc/CompileLog.java index f67656397..579113205 100644 --- a/src/main/java/dk/camelot64/kickc/CompileLog.java +++ b/src/main/java/dk/camelot64/kickc/CompileLog.java @@ -20,7 +20,7 @@ public class CompileLog { /** * Should fragment synthesis be verbose. */ - private boolean verboseFragmentLog = true; + private boolean verboseFragmentLog = false; /** * Should ASM optimization be verbose. @@ -35,7 +35,7 @@ public class CompileLog { /** * Should the log be output to System.out while being built */ - private boolean sysOut = true; + private boolean sysOut = false; public CompileLog() { this.log = new StringBuilder(); diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index d8c653d93..6f6cc86fa 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -44,6 +44,11 @@ public class TestPrograms { AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false); } + @Test + public void testDoubleAssignment() throws IOException, URISyntaxException { + compileAndCompare("double-assignment"); + } + @Test public void testConstWordPointer() throws IOException, URISyntaxException { compileAndCompare("const-word-pointer"); diff --git a/src/test/java/dk/camelot64/kickc/test/kc/double-assignment.kc b/src/test/java/dk/camelot64/kickc/test/kc/double-assignment.kc new file mode 100644 index 000000000..59e8fdfe6 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/double-assignment.kc @@ -0,0 +1,11 @@ +// Test that a double-assignment works. + +void main() { + byte a; + byte b; + byte* screen = $400; + a = b = 12; + screen[0] = a; + screen[1] = b; + +} \ No newline at end of file diff --git a/src/test/java/dk/camelot64/kickc/test/ref/bool-pointer.log b/src/test/java/dk/camelot64/kickc/test/ref/bool-pointer.log index 185a0586d..94bd5db39 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/bool-pointer.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/bool-pointer.log @@ -193,42 +193,6 @@ VARIABLE REGISTER WEIGHTS Initial phi equivalence classes Complete equivalence classes -New fragment synthesis _deref_pboc1=vboc2 -New fragment synthesis _deref_pboc1=vboc2 - sub-option vboaa=vboc1 -New fragment synthesis vboaa=vboc1 -New fragment synthesis vboaa=vboc1 - Successfully loaded vboaa=vboc1.asm -Fragment synthesis vboaa=vboc1 - New best, scheduling parent _deref_pboc1=vboc2 -Fragment synthesis _deref_pboc1=vboc2 - Successfully synthesized from vboaa=vboc1 -Found best fragment _deref_pboc1=vboc2 < vboaa=vboc1 score: 6.5 -New fragment synthesis _deref_pboc1_then_la1 -New fragment synthesis _deref_pboc1_then_la1 - sub-option vboaa_then_la1 -New fragment synthesis _deref_pboc1_then_la1 - sub-option vboxx_then_la1 -New fragment synthesis _deref_pboc1_then_la1 - sub-option vboyy_then_la1 -New fragment synthesis vboaa_then_la1 -New fragment synthesis vboaa_then_la1 - Successfully loaded vboaa_then_la1.asm -New fragment synthesis vboaa_then_la1 - sub-option vboxx_then_la1 -New fragment synthesis vboaa_then_la1 - sub-option vboyy_then_la1 -New fragment synthesis vboxx_then_la1 -New fragment synthesis vboxx_then_la1 - Successfully loaded vboxx_then_la1.asm -New fragment synthesis vboxx_then_la1 - sub-option vboaa_then_la1 -New fragment synthesis vboyy_then_la1 -New fragment synthesis vboyy_then_la1 - Successfully loaded vboyy_then_la1.asm -New fragment synthesis vboyy_then_la1 - sub-option vboaa_then_la1 -Fragment synthesis vboyy_then_la1 - New best, scheduling parent vboaa_then_la1 -Fragment synthesis vboyy_then_la1 - New best, scheduling parent _deref_pboc1_then_la1 -Fragment synthesis vboxx_then_la1 - New best, scheduling parent vboaa_then_la1 -Fragment synthesis vboxx_then_la1 - New best, scheduling parent _deref_pboc1_then_la1 -Fragment synthesis vboaa_then_la1 - Successfully synthesized from vboxx_then_la1 -Fragment synthesis vboaa_then_la1 - Successfully synthesized from vboyy_then_la1 -Fragment synthesis vboaa_then_la1 - New best, scheduling parent vboxx_then_la1 -Fragment synthesis vboaa_then_la1 - New best, scheduling parent vboyy_then_la1 -Fragment synthesis vboaa_then_la1 - New best, scheduling parent _deref_pboc1_then_la1 -Fragment synthesis vboyy_then_la1 - Successfully synthesized from vboaa_then_la1 -Fragment synthesis vboxx_then_la1 - Successfully synthesized from vboaa_then_la1 -Fragment synthesis _deref_pboc1_then_la1 - Successfully synthesized from vboaa_then_la1 -Fragment synthesis _deref_pboc1_then_la1 - Successfully synthesized from vboxx_then_la1 -Fragment synthesis _deref_pboc1_then_la1 - Successfully synthesized from vboyy_then_la1 -Found best fragment _deref_pboc1_then_la1 < vboaa_then_la1 score: 9.0 INITIAL ASM //SEG0 Basic Upstart diff --git a/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.asm b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.asm new file mode 100644 index 000000000..5996eac59 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.asm @@ -0,0 +1,12 @@ +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + jsr main +main: { + .label screen = $400 + .const a = $c + lda #a + sta screen+0 + sta screen+1 + rts +} diff --git a/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.cfg b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.cfg new file mode 100644 index 000000000..474d87567 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.cfg @@ -0,0 +1,16 @@ +@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*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) + [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) + to:main::@return +main::@return: scope:[main] from main + [6] return [ ] ( main:2 [ ] ) + to:@return diff --git a/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.log b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.log new file mode 100644 index 000000000..3d44473de --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.log @@ -0,0 +1,293 @@ +PARSING src/test/java/dk/camelot64/kickc/test/kc/double-assignment.kc +// Test that a double-assignment works. + +void main() { + byte a; + byte b; + byte* screen = $400; + a = b = 12; + screen[0] = a; + screen[1] = b; + +} +SYMBOLS +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +(byte) main::a +(byte) main::b +(byte*) main::screen + +Promoting word/signed word/dword/signed dword to byte* in main::screen ← ((byte*)) 1024 +INITIAL CONTROL FLOW GRAPH +@begin: scope:[] from + to:@1 +main: scope:[main] from + (byte*) main::screen ← ((byte*)) (word/signed word/dword/signed dword) 1024 + (byte) main::b ← (byte/signed byte/word/signed word/dword/signed dword) 12 + (byte) main::a ← (byte) main::b + *((byte*) main::screen + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) main::a + *((byte*) main::screen + (byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::b + to:main::@return +main::@return: scope:[main] from main + return + to:@return +@1: scope:[] from @begin + call main + to:@end +@end: scope:[] from @1 + +PROCEDURE MODIFY VARIABLE ANALYSIS + +Completing Phi functions... + +CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN +@begin: scope:[] from + to:@1 +main: scope:[main] from @1 + (byte*) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024 + (byte) main::b#0 ← (byte/signed byte/word/signed word/dword/signed dword) 12 + (byte) main::a#0 ← (byte) main::b#0 + *((byte*) main::screen#0 + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte) main::a#0 + *((byte*) main::screen#0 + (byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) main::b#0 + to:main::@return +main::@return: scope:[main] from main + return + to:@return +@1: scope:[] from @begin + call main param-assignment + to:@2 +@2: scope:[] from @1 + to:@end +@end: scope:[] from @2 + +SYMBOL TABLE SSA +(label) @1 +(label) @2 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +(byte) main::a +(byte) main::a#0 +(byte) main::b +(byte) main::b#0 +(byte*) main::screen +(byte*) main::screen#0 + +OPTIMIZING CONTROL FLOW GRAPH +Culled Empty Block (label) @2 +Succesful SSA optimization Pass2CullEmptyBlocks +Alias (byte) main::a#0 = (byte) main::b#0 +Succesful SSA optimization Pass2AliasElimination +Constant (const byte*) main::screen#0 = ((byte*))1024 +Constant (const byte) main::a#0 = 12 +Succesful SSA optimization Pass2ConstantIdentification +Consolidated array index constant in *(main::screen#0+0) +Consolidated array index constant in *(main::screen#0+1) +Succesful SSA optimization Pass2ConstantAdditionElimination +OPTIMIZING CONTROL FLOW GRAPH +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*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) + [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) + to:main::@return +main::@return: scope:[main] from main + [6] 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 +(void()) main() +(byte) main::a +(byte) main::b +(byte*) main::screen + +Initial phi equivalence classes +Complete equivalence classes + +INITIAL ASM +//SEG0 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +//SEG1 Global Constants & labels +//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: { + .label screen = $400 + .const a = $c + //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + lda #a + sta screen+0 + //SEG10 [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + lda #a + sta screen+1 + jmp breturn + //SEG11 main::@return + breturn: + //SEG12 [6] return [ ] ( main:2 [ ] ) + rts +} + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) always clobbers reg byte a +Statement [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) always clobbers reg byte a + +REGISTER UPLIFT SCOPES +Uplift Scope [main] +Uplift Scope [] + +Uplifting [main] best 33 combination +Uplifting [] best 33 combination + +ASSEMBLER BEFORE OPTIMIZATION +//SEG0 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +//SEG1 Global Constants & labels +//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: { + .label screen = $400 + .const a = $c + //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + lda #a + sta screen+0 + //SEG10 [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + lda #a + sta screen+1 + jmp breturn + //SEG11 main::@return + breturn: + //SEG12 [6] return [ ] ( main:2 [ ] ) + rts +} + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp b1 +Removing instruction jmp bend +Removing instruction jmp breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction lda #a +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 +(void()) main() +(label) main::@return +(byte) main::a +(const byte) main::a#0 a = (byte/signed byte/word/signed word/dword/signed dword) 12 +(byte) main::b +(byte*) main::screen +(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024 + + + +FINAL ASSEMBLER +Score: 22 + +//SEG0 Basic Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +//SEG1 Global Constants & labels +//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: { + .label screen = $400 + .const a = $c + //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + lda #a + sta screen+0 + //SEG10 [5] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (const byte) main::a#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 + sta screen+1 + //SEG11 main::@return + //SEG12 [6] return [ ] ( main:2 [ ] ) + rts +} + diff --git a/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.sym b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.sym new file mode 100644 index 000000000..79cd77992 --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/ref/double-assignment.sym @@ -0,0 +1,11 @@ +(label) @1 +(label) @begin +(label) @end +(void()) main() +(label) main::@return +(byte) main::a +(const byte) main::a#0 a = (byte/signed byte/word/signed word/dword/signed dword) 12 +(byte) main::b +(byte*) main::screen +(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024 +