1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-18 08:30:18 +00:00

Fixed logging

This commit is contained in:
jespergravgaard 2018-04-27 14:55:46 +02:00
parent 80f57ed5f1
commit 521385065d
8 changed files with 350 additions and 38 deletions

View File

@ -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();

View File

@ -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");

View File

@ -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;
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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