From c5f260e8826529cca9dbc4024814cd122b17f325 Mon Sep 17 00:00:00 2001 From: Flight_Control Date: Tue, 4 Apr 2023 09:30:40 +0200 Subject: [PATCH] Implemented C99 compatible union initializer method. - Added test cases. - Reworked parser. - Added code redesign to avoid crashes in Initializers.java. --- .../dk/camelot64/kickc/parser/KickCParser.g4 | 7 +- .../camelot64/kickc/model/Initializers.java | 30 ++++---- .../Pass0GenerateStatementSequence.java | 34 +++------ .../kickc/test/TestProgramsFast.java | 20 +++++ src/test/kc/union-10.c | 27 +++++++ src/test/kc/union-11.c | 27 +++++++ src/test/kc/union-12.c | 29 ++++++++ src/test/kc/union-9.c | 14 ++++ src/test/target/union-10.asm | 29 ++++++++ src/test/target/union-10.dbg | 67 +++++++++++++++++ src/test/target/union-10.klog | 23 ++++++ src/test/target/union-10.prg | Bin 0 -> 25 bytes src/test/target/union-10.sym | 4 + src/test/target/union-10.vs | 4 + src/test/target/union-11.asm | 30 ++++++++ src/test/target/union-11.dbg | 69 +++++++++++++++++ src/test/target/union-11.klog | 23 ++++++ src/test/target/union-11.prg | Bin 0 -> 25 bytes src/test/target/union-11.sym | 4 + src/test/target/union-11.vs | 4 + src/test/target/union-12.asm | 30 ++++++++ src/test/target/union-12.dbg | 70 ++++++++++++++++++ src/test/target/union-12.klog | 23 ++++++ src/test/target/union-12.prg | Bin 0 -> 25 bytes src/test/target/union-12.sym | 5 ++ src/test/target/union-12.vs | 5 ++ src/test/target/union-9.asm | 29 ++++++++ src/test/target/union-9.dbg | 67 +++++++++++++++++ src/test/target/union-9.klog | 23 ++++++ src/test/target/union-9.prg | Bin 0 -> 23 bytes src/test/target/union-9.sym | 4 + src/test/target/union-9.vs | 4 + 32 files changed, 663 insertions(+), 42 deletions(-) create mode 100644 src/test/kc/union-10.c create mode 100644 src/test/kc/union-11.c create mode 100644 src/test/kc/union-12.c create mode 100644 src/test/kc/union-9.c create mode 100644 src/test/target/union-10.asm create mode 100644 src/test/target/union-10.dbg create mode 100644 src/test/target/union-10.klog create mode 100644 src/test/target/union-10.prg create mode 100644 src/test/target/union-10.sym create mode 100644 src/test/target/union-10.vs create mode 100644 src/test/target/union-11.asm create mode 100644 src/test/target/union-11.dbg create mode 100644 src/test/target/union-11.klog create mode 100644 src/test/target/union-11.prg create mode 100644 src/test/target/union-11.sym create mode 100644 src/test/target/union-11.vs create mode 100644 src/test/target/union-12.asm create mode 100644 src/test/target/union-12.dbg create mode 100644 src/test/target/union-12.klog create mode 100644 src/test/target/union-12.prg create mode 100644 src/test/target/union-12.sym create mode 100644 src/test/target/union-12.vs create mode 100644 src/test/target/union-9.asm create mode 100644 src/test/target/union-9.dbg create mode 100644 src/test/target/union-9.klog create mode 100644 src/test/target/union-9.prg create mode 100644 src/test/target/union-9.sym create mode 100644 src/test/target/union-9.vs diff --git a/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 b/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 index 67ceaeb59..83afa7132 100644 --- a/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 +++ b/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 @@ -217,12 +217,9 @@ commaExpr | commaExpr COMMA expr #commaSimple ; -initMemberExpr - : expr - ; initExpr - : (DOT initMemberExpr ASSIGN)? expr + : (DOT expr ASSIGN)? expr ; @@ -252,9 +249,9 @@ expr | expr ( '&&' ) expr #exprBinary | expr ( '||' ) expr #exprBinary | expr '?' expr COLON expr #exprTernary - | CURLY_BEGIN initExpr (COMMA initExpr )* COMMA? CURLY_END #initList | expr '=' expr #exprAssignment | expr ASSIGN_COMPOUND expr #exprAssignmentCompound + | CURLY_BEGIN initExpr (COMMA initExpr )* COMMA? CURLY_END #initList | NAME #exprId | NUMBER #exprNumber | STRING+ #exprString diff --git a/src/main/java/dk/camelot64/kickc/model/Initializers.java b/src/main/java/dk/camelot64/kickc/model/Initializers.java index f0592ba5f..6a67d0f9d 100644 --- a/src/main/java/dk/camelot64/kickc/model/Initializers.java +++ b/src/main/java/dk/camelot64/kickc/model/Initializers.java @@ -169,21 +169,25 @@ public class Initializers { for(int i = 0; i < structInitNeedSize; i++) { Variable memberDef = null; RValue memberValue = valueIt.next(); - String memberUnionName = ((ValueStructList)valueList).getMember(memberValue); - if(memberUnionName != null) { - boolean found = false; - while (memberDefIt.hasNext()) { - memberDef = memberDefIt.next(); - if (memberDef.getLocalName().contentEquals(memberUnionName)) { - found = true; - break; + if(structDefinition.isUnion()) { + String memberUnionName = ((ValueStructList)valueList).getMember(memberValue); + if(memberUnionName != null) { + boolean found = false; + while (memberDefIt.hasNext()) { + memberDef = memberDefIt.next(); + if (memberDef.getLocalName().contentEquals(memberUnionName)) { + found = true; + break; + } } + if (!found) + throw new CompileError( + "Union initializer cannot find member field " + memberUnionName + "\n" + + " Union initializer: " + valueList.toString(program), + source); + } else { + memberDef = memberDefIt.next(); } - if(!found) - throw new CompileError( - "Union initializer cannot find member field " + memberUnionName + "\n" + - " Union initializer: " + valueList.toString(program), - source); } else { memberDef = memberDefIt.next(); } diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 78db33ba0..710723bd9 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -1913,38 +1913,24 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor initValues = new ArrayList<>(); - HashMap members = new HashMap<>(); - - String member = null; - if(ctx.initMemberExpr() != null) { - member = ctx.initMemberExpr().getText(); - } - return member; - } - @Override public RValue visitInitList(KickCParser.InitListContext ctx) { List initValues = new ArrayList<>(); - HashMap members = new HashMap<>(); + HashMap initDesignators = new HashMap<>(); for(KickCParser.InitExprContext initializer : ctx.initExpr()) { - RValue member = null; String initString = initializer.getText(); - if (initializer.initMemberExpr() != null) { - if(initializer.initMemberExpr().isEmpty() == false) { - member = (RValue) visit(initializer.initMemberExpr()); - } - } - RValue rValue = (RValue) visit(initializer.expr()); - initValues.add(rValue); - if(member!=null) { - members.put(rValue, member.toString()); + if (initializer.expr().size() == 2) { + RValue member = (RValue) visit(initializer.expr(0)); + RValue rValue = (RValue) visit(initializer.expr(1)); + initValues.add(rValue); + initDesignators.put(rValue, member.toString()); + } else { + RValue rValue = (RValue) visit(initializer.expr(0)); + initValues.add(rValue); } } - return new ValueStructList(members, initValues); + return new ValueStructList(initDesignators, initValues); } @Override diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index c6cb04fe1..9a99f43fc 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -2541,6 +2541,26 @@ public class TestProgramsFast extends TestPrograms { compileAndCompare("weeip-bbslist.c"); } + @Test + public void testUnion12() throws IOException { + compileAndCompare("union-12.c"); + } + + @Test + public void testUnion11() throws IOException { + compileAndCompare("union-11.c"); + } + + @Test + public void testUnion10() throws IOException { + compileAndCompare("union-10.c"); + } + + @Test + public void testUnion9() throws IOException { + compileAndCompare("union-9.c"); + } + @Test public void testUnion8() throws IOException { compileAndCompare("union-8.c"); diff --git a/src/test/kc/union-10.c b/src/test/kc/union-10.c new file mode 100644 index 000000000..e05a9d461 --- /dev/null +++ b/src/test/kc/union-10.c @@ -0,0 +1,27 @@ +// More extensive union with C99 style designator initialization behaviour of the second element. + +struct Move { + char f; + char t; + char s; +}; + +struct Turn { + char t; + char s; + char r; + char d; +}; + +union Data { + struct Move m; + struct Turn t; +}; + +union Data data = { .t={1,2,3,4} }; + +char* const SCREEN = (char*)0x0400; + +void main() { + SCREEN[0] = data.m.f; +} \ No newline at end of file diff --git a/src/test/kc/union-11.c b/src/test/kc/union-11.c new file mode 100644 index 000000000..840f4c9a0 --- /dev/null +++ b/src/test/kc/union-11.c @@ -0,0 +1,27 @@ +// More extensive union with C99 style designator initialization behaviour of the first element. + +struct Move { + char f; + char t; + char s; +}; + +struct Turn { + char t; + char s; + char r; + char d; +}; + +union Data { + struct Move m; + struct Turn t; +}; + +union Data data = { .m={1,2,3} }; + +char* const SCREEN = (char*)0x0400; + +void main() { + SCREEN[0] = data.m.f; +} \ No newline at end of file diff --git a/src/test/kc/union-12.c b/src/test/kc/union-12.c new file mode 100644 index 000000000..a6e084637 --- /dev/null +++ b/src/test/kc/union-12.c @@ -0,0 +1,29 @@ +// More extensive union with C99 style designator initialization behaviour using const expressions. + +struct Move { + char f; + char t; + char s; +}; + +struct Turn { + char t; + char s; + char r; + char d; +}; + +union Data { + struct Move m; + struct Turn t; +}; + +const struct Move move = {1,2,3}; + +union Data data = { .m=move }; + +char* const SCREEN = (char*)0x0400; + +void main() { + SCREEN[0] = data.m.f; +} \ No newline at end of file diff --git a/src/test/kc/union-9.c b/src/test/kc/union-9.c new file mode 100644 index 000000000..bf7a6dd30 --- /dev/null +++ b/src/test/kc/union-9.c @@ -0,0 +1,14 @@ +// Minimal union with C99 style designator initialization behaviour. + +union Data { + char b; + unsigned w; +}; + +union Data data = { .w=1234 }; + +char* const SCREEN = (char*)0x0400; + +void main() { + SCREEN[0] = data.b; +} \ No newline at end of file diff --git a/src/test/target/union-10.asm b/src/test/target/union-10.asm new file mode 100644 index 000000000..a898e3900 --- /dev/null +++ b/src/test/target/union-10.asm @@ -0,0 +1,29 @@ + // File Comments +// More extensive union with C99 style designator initialization behaviour. + // Upstart +.cpu _65c02 + // Commodore 64 PRG executable file +.file [name="union-10.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label SCREEN = $400 +.segment Code + // main +main: { + // SCREEN[0] = data.m.f + // [0] *SCREEN = *((char *)(struct Move *)&data) -- _deref_pbuc1=_deref_pbuc2 + lda data + sta SCREEN + // main::@return + // } + // [1] return + rts +} + // File Data +.segment Data + data: .byte 1, 2, 3, 4 diff --git a/src/test/target/union-10.dbg b/src/test/target/union-10.dbg new file mode 100644 index 000000000..99af3ebc0 --- /dev/null +++ b/src/test/target/union-10.dbg @@ -0,0 +1,67 @@ + + + 0,KickAss.jar:/include/autoinclude.asm + 1,D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target\union-10.asm + + + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + $0814,$0817,1,29,9,29,13 + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + + + + $0814,$0817,1,29,9,29,13 + + + + + Basic,$0400,SCREEN,1,14,10,14,15 + Code,$080d,main,1,17,1,17,5 + Basic,$080b,upstartEnd,0,43,1,43,11 + Data,$0814,data,1,29,3,29,7 + + + + + + + + + diff --git a/src/test/target/union-10.klog b/src/test/target/union-10.klog new file mode 100644 index 000000000..b5a4ba607 --- /dev/null +++ b/src/test/target/union-10.klog @@ -0,0 +1,23 @@ +Output dir: D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target +parsing +flex pass 1 +flex pass 2 +flex pass 3 +Output pass +Writing prg file: union-10.prg + +Memory Map +---------- +Program-segment: + +Basic-segment: + $0801-$080c Basic + +Code-segment: + $080d-$0813 Code + +Data-segment: + $0814-$0817 Data + +Writing Vice symbol file: union-10.vs +Writing Symbol file: union-10.sym diff --git a/src/test/target/union-10.prg b/src/test/target/union-10.prg new file mode 100644 index 0000000000000000000000000000000000000000..bacbff8bf49ae915b06bb999c7a6b464d4b8d650 GIT binary patch literal 25 gcmZSN;O5|Bm}g{QX2`(6uvUblmw_dLk%^fF04os#QUCw| literal 0 HcmV?d00001 diff --git a/src/test/target/union-10.sym b/src/test/target/union-10.sym new file mode 100644 index 000000000..31ed0e570 --- /dev/null +++ b/src/test/target/union-10.sym @@ -0,0 +1,4 @@ +.label SCREEN=$400 +.label data=$814 +.label main=$80d { +} diff --git a/src/test/target/union-10.vs b/src/test/target/union-10.vs new file mode 100644 index 000000000..32545d85b --- /dev/null +++ b/src/test/target/union-10.vs @@ -0,0 +1,4 @@ +al C:400 .SCREEN +al C:814 .data +al C:80b .upstartEnd +al C:80d .main diff --git a/src/test/target/union-11.asm b/src/test/target/union-11.asm new file mode 100644 index 000000000..84b7a2c30 --- /dev/null +++ b/src/test/target/union-11.asm @@ -0,0 +1,30 @@ + // File Comments +// More extensive union with C99 style designator initialization behaviour. + // Upstart +.cpu _65c02 + // Commodore 64 PRG executable file +.file [name="union-11.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label SCREEN = $400 +.segment Code + // main +main: { + // SCREEN[0] = data.m.f + // [0] *SCREEN = *((char *)(struct Move *)&data) -- _deref_pbuc1=_deref_pbuc2 + lda data + sta SCREEN + // main::@return + // } + // [1] return + rts +} + // File Data +.segment Data + data: .byte 1, 2, 3 + .fill 1, 0 diff --git a/src/test/target/union-11.dbg b/src/test/target/union-11.dbg new file mode 100644 index 000000000..aaf6eb026 --- /dev/null +++ b/src/test/target/union-11.dbg @@ -0,0 +1,69 @@ + + + 0,KickAss.jar:/include/autoinclude.asm + 1,D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target\union-11.asm + + + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + $0814,$0816,1,29,9,29,13 + $0817,$0817,1,30,3,30,7 + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + + + + $0814,$0816,1,29,9,29,13 + $0817,$0817,1,30,3,30,7 + + + + + Basic,$0400,SCREEN,1,14,10,14,15 + Code,$080d,main,1,17,1,17,5 + Basic,$080b,upstartEnd,0,43,1,43,11 + Data,$0814,data,1,29,3,29,7 + + + + + + + + + diff --git a/src/test/target/union-11.klog b/src/test/target/union-11.klog new file mode 100644 index 000000000..9a5e5debc --- /dev/null +++ b/src/test/target/union-11.klog @@ -0,0 +1,23 @@ +Output dir: D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target +parsing +flex pass 1 +flex pass 2 +flex pass 3 +Output pass +Writing prg file: union-11.prg + +Memory Map +---------- +Program-segment: + +Basic-segment: + $0801-$080c Basic + +Code-segment: + $080d-$0813 Code + +Data-segment: + $0814-$0817 Data + +Writing Vice symbol file: union-11.vs +Writing Symbol file: union-11.sym diff --git a/src/test/target/union-11.prg b/src/test/target/union-11.prg new file mode 100644 index 0000000000000000000000000000000000000000..07026eb6d7251cc949380970b1145da09ac75e69 GIT binary patch literal 25 gcmZSN;O5|Bm}g{QX2`(6uvUblmw_dLk%^fB04ogxP5=M^ literal 0 HcmV?d00001 diff --git a/src/test/target/union-11.sym b/src/test/target/union-11.sym new file mode 100644 index 000000000..31ed0e570 --- /dev/null +++ b/src/test/target/union-11.sym @@ -0,0 +1,4 @@ +.label SCREEN=$400 +.label data=$814 +.label main=$80d { +} diff --git a/src/test/target/union-11.vs b/src/test/target/union-11.vs new file mode 100644 index 000000000..32545d85b --- /dev/null +++ b/src/test/target/union-11.vs @@ -0,0 +1,4 @@ +al C:400 .SCREEN +al C:814 .data +al C:80b .upstartEnd +al C:80d .main diff --git a/src/test/target/union-12.asm b/src/test/target/union-12.asm new file mode 100644 index 000000000..5986af0d8 --- /dev/null +++ b/src/test/target/union-12.asm @@ -0,0 +1,30 @@ + // File Comments +// More extensive union with C99 style designator initialization behaviour using const expressions. + // Upstart +.cpu _65c02 + // Commodore 64 PRG executable file +.file [name="union-12.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label SCREEN = $400 +.segment Code + // main +main: { + // SCREEN[0] = data.m.f + // [0] *SCREEN = *((char *)(struct Move *)&data) -- _deref_pbuc1=_deref_pbuc2 + lda data + sta SCREEN + // main::@return + // } + // [1] return + rts +} + // File Data +.segment Data + move: .byte 1, 2, 3 + data: .fill 1, 0 diff --git a/src/test/target/union-12.dbg b/src/test/target/union-12.dbg new file mode 100644 index 000000000..b88db7abd --- /dev/null +++ b/src/test/target/union-12.dbg @@ -0,0 +1,70 @@ + + + 0,KickAss.jar:/include/autoinclude.asm + 1,D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target\union-12.asm + + + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + $0814,$0816,1,29,9,29,13 + $0817,$0817,1,30,9,30,13 + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + + + + $0814,$0816,1,29,9,29,13 + $0817,$0817,1,30,9,30,13 + + + + + Basic,$0400,SCREEN,1,14,10,14,15 + Code,$080d,main,1,17,1,17,5 + Basic,$080b,upstartEnd,0,43,1,43,11 + Data,$0814,move,1,29,3,29,7 + Data,$0817,data,1,30,3,30,7 + + + + + + + + + diff --git a/src/test/target/union-12.klog b/src/test/target/union-12.klog new file mode 100644 index 000000000..6cf82c193 --- /dev/null +++ b/src/test/target/union-12.klog @@ -0,0 +1,23 @@ +Output dir: D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target +parsing +flex pass 1 +flex pass 2 +flex pass 3 +Output pass +Writing prg file: union-12.prg + +Memory Map +---------- +Program-segment: + +Basic-segment: + $0801-$080c Basic + +Code-segment: + $080d-$0813 Code + +Data-segment: + $0814-$0817 Data + +Writing Vice symbol file: union-12.vs +Writing Symbol file: union-12.sym diff --git a/src/test/target/union-12.prg b/src/test/target/union-12.prg new file mode 100644 index 0000000000000000000000000000000000000000..1f4888480c543bfd0aceee329ecc9b4e8bb7c1f6 GIT binary patch literal 25 gcmZSN;O5|Bm}g{QX2`(6uvVO-mw_dLk%^fB04pm4Q2+n{ literal 0 HcmV?d00001 diff --git a/src/test/target/union-12.sym b/src/test/target/union-12.sym new file mode 100644 index 000000000..6702c90da --- /dev/null +++ b/src/test/target/union-12.sym @@ -0,0 +1,5 @@ +.label move=$814 +.label SCREEN=$400 +.label data=$817 +.label main=$80d { +} diff --git a/src/test/target/union-12.vs b/src/test/target/union-12.vs new file mode 100644 index 000000000..91239332d --- /dev/null +++ b/src/test/target/union-12.vs @@ -0,0 +1,5 @@ +al C:814 .move +al C:400 .SCREEN +al C:817 .data +al C:80b .upstartEnd +al C:80d .main diff --git a/src/test/target/union-9.asm b/src/test/target/union-9.asm new file mode 100644 index 000000000..2cb18040e --- /dev/null +++ b/src/test/target/union-9.asm @@ -0,0 +1,29 @@ + // File Comments +// Minimal union with C-Standard behavior + // Upstart +.cpu _65c02 + // Commodore 64 PRG executable file +.file [name="union-9.prg", type="prg", segments="Program"] +.segmentdef Program [segments="Basic, Code, Data"] +.segmentdef Basic [start=$0801] +.segmentdef Code [start=$80d] +.segmentdef Data [startAfter="Code"] +.segment Basic +:BasicUpstart(main) + // Global Constants & labels + .label SCREEN = $400 +.segment Code + // main +main: { + // SCREEN[0] = data.b + // [0] *SCREEN = *((char *)&data) -- _deref_pbuc1=_deref_pbuc2 + lda data + sta SCREEN + // main::@return + // } + // [1] return + rts +} + // File Data +.segment Data + data: .word $4d2 diff --git a/src/test/target/union-9.dbg b/src/test/target/union-9.dbg new file mode 100644 index 000000000..4597299fe --- /dev/null +++ b/src/test/target/union-9.dbg @@ -0,0 +1,67 @@ + + + 0,KickAss.jar:/include/autoinclude.asm + 1,D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target\union-9.asm + + + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + $0814,$0815,1,29,9,29,13 + + + + + + $0801,$0802,0,38,2,38,6 + $0803,$0804,0,39,5,39,9 + $0805,$0805,0,40,5,40,9 + $0806,$0809,0,41,2,41,6 + $080a,$080a,0,42,2,42,6 + $080b,$080c,0,44,5,44,9 + + + + + + $080d,$080f,1,20,5,20,7 + $0810,$0812,1,21,5,21,7 + $0813,$0813,1,25,5,25,7 + + + + + + $0814,$0815,1,29,9,29,13 + + + + + Basic,$0400,SCREEN,1,14,10,14,15 + Code,$080d,main,1,17,1,17,5 + Basic,$080b,upstartEnd,0,43,1,43,11 + Data,$0814,data,1,29,3,29,7 + + + + + + + + + diff --git a/src/test/target/union-9.klog b/src/test/target/union-9.klog new file mode 100644 index 000000000..35301049e --- /dev/null +++ b/src/test/target/union-9.klog @@ -0,0 +1,23 @@ +Output dir: D:\Users\svenv\OneDrive\Documents\GitHub\kickc\src\test\target +parsing +flex pass 1 +flex pass 2 +flex pass 3 +Output pass +Writing prg file: union-9.prg + +Memory Map +---------- +Program-segment: + +Basic-segment: + $0801-$080c Basic + +Code-segment: + $080d-$0813 Code + +Data-segment: + $0814-$0815 Data + +Writing Vice symbol file: union-9.vs +Writing Symbol file: union-9.sym diff --git a/src/test/target/union-9.prg b/src/test/target/union-9.prg new file mode 100644 index 0000000000000000000000000000000000000000..207b0b1639c879fd2d659a584d7fe097a8983ceb GIT binary patch literal 23 ecmZSN;O5|Bm}g{QX2`(6uvUblmw_eW5(@w(6$Bmt literal 0 HcmV?d00001 diff --git a/src/test/target/union-9.sym b/src/test/target/union-9.sym new file mode 100644 index 000000000..31ed0e570 --- /dev/null +++ b/src/test/target/union-9.sym @@ -0,0 +1,4 @@ +.label SCREEN=$400 +.label data=$814 +.label main=$80d { +} diff --git a/src/test/target/union-9.vs b/src/test/target/union-9.vs new file mode 100644 index 000000000..32545d85b --- /dev/null +++ b/src/test/target/union-9.vs @@ -0,0 +1,4 @@ +al C:400 .SCREEN +al C:814 .data +al C:80b .upstartEnd +al C:80d .main