1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-01-11 04:29:53 +00:00

Added missing fragments for Janne Johansson. Closes #293

This commit is contained in:
jespergravgaard 2020-12-06 01:56:33 +01:00
parent f1605bb085
commit 50b8c78dfa
7 changed files with 401 additions and 0 deletions

View File

@ -0,0 +1,4 @@
and #{c1}
sta {m1}
lda #0
sta {m1}+1

View File

@ -62,6 +62,11 @@ public class TestPrograms {
compileAndCompare("adventofcode/2020-01.c");
}
@Test
public void testMissingBand() throws IOException, URISyntaxException {
compileAndCompare("missing-band.c");
}
// https://gitlab.com/camelot/kickc/-/issues/564
//@Test

View File

@ -0,0 +1,16 @@
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
byte bar[10]={9,1,2,3,4,5,6,7,8,9};
byte *SCREEN = $0400;
void main() {
word a=0;
a=(foo(1) & 3);
*SCREEN = (byte)a;
}
byte foo(byte x) {
return bar[x];
}

View File

@ -0,0 +1,29 @@
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
main: {
.label a = 2
// foo(1)
jsr foo
// a=(foo(1) & 3)
and #3
sta.z a
lda #0
sta.z a+1
// *SCREEN = (byte)a
lda.z a
sta SCREEN
// }
rts
}
foo: {
.const x = 1
// return bar[x];
lda bar+x
// }
rts
}
bar: .byte 9, 1, 2, 3, 4, 5, 6, 7, 8, 9

View File

@ -0,0 +1,23 @@
void main()
main: scope:[main] from
[0] phi()
[1] call foo
[2] foo::return#0 = foo::return#1
to:main::@1
main::@1: scope:[main] from main
[3] main::$0 = foo::return#0
[4] main::a#1 = main::$0 & 3
[5] *SCREEN = (byte)main::a#1
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
byte foo(byte foo::x)
foo: scope:[foo] from main
[7] foo::return#1 = *(bar+foo::x#0)
to:foo::@return
foo::@return: scope:[foo] from foo
[8] return
to:@return

View File

@ -0,0 +1,307 @@
Inlined call call __init
CONTROL FLOW GRAPH SSA
void main()
main: scope:[main] from __start::@1
main::a#0 = 0
foo::x#0 = 1
call foo
foo::return#0 = foo::return#2
to:main::@1
main::@1: scope:[main] from main
foo::return#3 = phi( main/foo::return#0 )
main::$0 = foo::return#3
main::$1 = main::$0 & 3
main::a#1 = main::$1
*SCREEN = (byte)main::a#1
to:main::@return
main::@return: scope:[main] from main::@1
return
to:@return
byte foo(byte foo::x)
foo: scope:[foo] from main
foo::x#1 = phi( main/foo::x#0 )
foo::return#1 = bar[foo::x#1]
to:foo::@return
foo::@return: scope:[foo] from foo
foo::return#4 = phi( foo/foo::return#1 )
foo::return#2 = foo::return#4
return
to:@return
void __start()
__start: scope:[__start] from
to:__start::__init1
__start::__init1: scope:[__start] from __start
to:__start::@1
__start::@1: scope:[__start] from __start::__init1
call main
to:__start::@2
__start::@2: scope:[__start] from __start::@1
to:__start::@return
__start::@return: scope:[__start] from __start::@2
return
to:@return
SYMBOL TABLE SSA
const byte* SCREEN = (byte*)$400
void __start()
const byte* bar[$a] = { 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
byte foo(byte foo::x)
byte foo::return
byte foo::return#0
byte foo::return#1
byte foo::return#2
byte foo::return#3
byte foo::return#4
byte foo::x
byte foo::x#0
byte foo::x#1
void main()
byte~ main::$0
number~ main::$1
word main::a
word main::a#0
word main::a#1
Adding number conversion cast (unumber) 1 in foo::x#0 = 1
Adding number conversion cast (unumber) 3 in main::$1 = main::$0 & 3
Adding number conversion cast (unumber) main::$1 in main::$1 = main::$0 & (unumber)3
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast foo::x#0 = (unumber)1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type 1
Finalized unsigned number type 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in main::$1 = main::$0 & 3
Alias foo::return#0 = foo::return#3
Alias main::a#1 = main::$1
Alias foo::return#1 = foo::return#4 foo::return#2
Successful SSA optimization Pass2AliasElimination
Identical Phi Values foo::x#1 foo::x#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant main::a#0 = 0
Constant foo::x#0 = 1
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant main::a#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Consolidated array index constant in *(bar+foo::x#0)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to foo:1
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Adding NOP phi() at start of main
FINAL CONTROL FLOW GRAPH
void main()
main: scope:[main] from
[0] phi()
[1] call foo
[2] foo::return#0 = foo::return#1
to:main::@1
main::@1: scope:[main] from main
[3] main::$0 = foo::return#0
[4] main::a#1 = main::$0 & 3
[5] *SCREEN = (byte)main::a#1
to:main::@return
main::@return: scope:[main] from main::@1
[6] return
to:@return
byte foo(byte foo::x)
foo: scope:[foo] from main
[7] foo::return#1 = *(bar+foo::x#0)
to:foo::@return
foo::@return: scope:[foo] from foo
[8] return
to:@return
VARIABLE REGISTER WEIGHTS
byte foo(byte foo::x)
byte foo::return
byte foo::return#0 4.0
byte foo::return#1 4.333333333333333
byte foo::x
void main()
byte~ main::$0 4.0
word main::a
word main::a#1 2.0
Initial phi equivalence classes
Added variable foo::return#0 to live range equivalence class [ foo::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::a#1 to live range equivalence class [ main::a#1 ]
Added variable foo::return#1 to live range equivalence class [ foo::return#1 ]
Complete equivalence classes
[ foo::return#0 ]
[ main::$0 ]
[ main::a#1 ]
[ foo::return#1 ]
Allocated zp[1]:2 [ foo::return#0 ]
Allocated zp[1]:3 [ main::$0 ]
Allocated zp[2]:4 [ main::a#1 ]
Allocated zp[1]:6 [ foo::return#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] main::a#1 = main::$0 & 3 [ main::a#1 ] ( [ main::a#1 ] { } ) always clobbers reg byte a
Statement [5] *SCREEN = (byte)main::a#1 [ ] ( [ ] { } ) always clobbers reg byte a
Potential registers zp[1]:2 [ foo::return#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[1]:3 [ main::$0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y ,
Potential registers zp[2]:4 [ main::a#1 ] : zp[2]:4 ,
Potential registers zp[1]:6 [ foo::return#1 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [foo] 4.33: zp[1]:6 [ foo::return#1 ] 4: zp[1]:2 [ foo::return#0 ]
Uplift Scope [main] 4: zp[1]:3 [ main::$0 ] 2: zp[2]:4 [ main::a#1 ]
Uplift Scope []
Uplifting [foo] best 54 combination reg byte a [ foo::return#1 ] reg byte a [ foo::return#0 ]
Uplifting [main] best 48 combination reg byte a [ main::$0 ] zp[2]:4 [ main::a#1 ]
Uplifting [] best 48 combination
Allocated (was zp[2]:4) zp[2]:2 [ main::a#1 ]
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// main
main: {
.label a = 2
// [1] call foo
jsr foo
// [2] foo::return#0 = foo::return#1
jmp __b1
// main::@1
__b1:
// [3] main::$0 = foo::return#0
// [4] main::a#1 = main::$0 & 3 -- vwuz1=vbuaa_band_vbuc1
and #3
sta.z a
lda #0
sta.z a+1
// [5] *SCREEN = (byte)main::a#1 -- _deref_pbuc1=_byte_vwuz1
lda.z a
sta SCREEN
jmp __breturn
// main::@return
__breturn:
// [6] return
rts
}
// foo
foo: {
.const x = 1
// [7] foo::return#1 = *(bar+foo::x#0) -- vbuaa=_deref_pbuc1
lda bar+x
jmp __breturn
// foo::@return
__breturn:
// [8] return
rts
}
// File Data
bar: .byte 9, 1, 2, 3, 4, 5, 6, 7, 8, 9
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
const byte* SCREEN = (byte*) 1024
const byte* bar[$a] = { 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
byte foo(byte foo::x)
byte foo::return
byte foo::return#0 reg byte a 4.0
byte foo::return#1 reg byte a 4.333333333333333
byte foo::x
const byte foo::x#0 x = 1
void main()
byte~ main::$0 reg byte a 4.0
word main::a
word main::a#1 a zp[2]:2 2.0
reg byte a [ foo::return#0 ]
reg byte a [ main::$0 ]
zp[2]:2 [ main::a#1 ]
reg byte a [ foo::return#1 ]
FINAL ASSEMBLER
Score: 39
// File Comments
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label SCREEN = $400
// main
main: {
.label a = 2
// foo(1)
// [1] call foo
jsr foo
// [2] foo::return#0 = foo::return#1
// main::@1
// [3] main::$0 = foo::return#0
// a=(foo(1) & 3)
// [4] main::a#1 = main::$0 & 3 -- vwuz1=vbuaa_band_vbuc1
and #3
sta.z a
lda #0
sta.z a+1
// *SCREEN = (byte)a
// [5] *SCREEN = (byte)main::a#1 -- _deref_pbuc1=_byte_vwuz1
lda.z a
sta SCREEN
// main::@return
// }
// [6] return
rts
}
// foo
foo: {
.const x = 1
// return bar[x];
// [7] foo::return#1 = *(bar+foo::x#0) -- vbuaa=_deref_pbuc1
lda bar+x
// foo::@return
// }
// [8] return
rts
}
// File Data
bar: .byte 9, 1, 2, 3, 4, 5, 6, 7, 8, 9

View File

@ -0,0 +1,17 @@
const byte* SCREEN = (byte*) 1024
const byte* bar[$a] = { 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
byte foo(byte foo::x)
byte foo::return
byte foo::return#0 reg byte a 4.0
byte foo::return#1 reg byte a 4.333333333333333
byte foo::x
const byte foo::x#0 x = 1
void main()
byte~ main::$0 reg byte a 4.0
word main::a
word main::a#1 a zp[2]:2 2.0
reg byte a [ foo::return#0 ]
reg byte a [ main::$0 ]
zp[2]:2 [ main::a#1 ]
reg byte a [ foo::return#1 ]