diff --git a/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 b/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 index 178005132..0bfba0d7d 100644 --- a/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 +++ b/src/main/antlr4/dk/camelot64/kickc/parser/KickCParser.g4 @@ -136,8 +136,8 @@ parameterDecl ; pragma - : PRAGMA NAME PAR_BEGIN PAR_END #pragmaNoParameters - | PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END #pragmaParameters + : PRAGMA NAME + | PRAGMA NAME (PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END)? ; pragmaParam diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index 504dc117c..4a3dcaf4b 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -42,7 +42,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor scopeStack; /** All #pragma constructor_for() statements. Collected during parsing and handled by {@link #generate()} before returning. */ - private final List pragmaConstructorFors; + private final List pragmaConstructorFors; public Pass0GenerateStatementSequence(CParser cParser, KickCParser.FileContext fileCtx, Program program, Procedure.CallingConvention initialCallingConvention, StringEncoding defaultEncoding, String defaultInterruptType) { @@ -148,7 +148,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor constructorProcs = new ArrayList<>(); - for(KickCParser.PragmaParametersContext pragmaConstructorFor : pragmaConstructorFors) { + for(KickCParser.PragmaContext pragmaConstructorFor : pragmaConstructorFors) { final List names = pragmaConstructorFor.pragmaParam(); if(names.size() < 2) throw new CompileError("#pragma constructor_for requires at least 2 parameters.", new StatementSource(pragmaConstructorFor)); @@ -237,29 +237,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor parenthesizedBody = new ArrayList<>(); - parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "(")); - parenthesizedBody.add(new CommonToken(KickCLexer.PAR_END, ")")); - pragmaBody = parenthesizedBody; - pragmaTokens.addAll(pragmaBody); - // Pass on the #pragma to the parser - and mark it as already handled - cTokenSource.addSourceFirst(new ListTokenSource(pragmaTokens)); } parserPragmas.add(inputToken); return true; diff --git a/src/test/kc/call-banked-phi-case-3-near-1.c b/src/test/kc/call-banked-phi-case-3-near-1.c index feb43dbda..2743d4b5c 100644 --- a/src/test/kc/call-banked-phi-case-3-near-1.c +++ b/src/test/kc/call-banked-phi-case-3-near-1.c @@ -30,6 +30,10 @@ char* const SCREEN = (char*)0x0400; +#pragma code_seg(Code) +void main(void) { + SCREEN[0] = plus('0', 7); // close call +} #pragma code_seg(RAM_Bank1) #pragma bank(cx16_ram, 1) @@ -43,8 +47,4 @@ char min(char a, char b) { return a+b; } -#pragma code_seg(Code) -void main(void) { - SCREEN[0] = plus('0', 7); // close call -} diff --git a/src/test/ref/call-banked-phi-case-3-near-1.cfg b/src/test/ref/call-banked-phi-case-3-near-1.cfg index 4a0b60f9d..3a2aea220 100644 --- a/src/test/ref/call-banked-phi-case-3-near-1.cfg +++ b/src/test/ref/call-banked-phi-case-3-near-1.cfg @@ -20,7 +20,7 @@ plus::@return: scope:[plus] from plus [6] return to:@return -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) min: scope:[min] from plus [7] phi() to:min::@return diff --git a/src/test/ref/call-banked-phi-case-3-near-1.log b/src/test/ref/call-banked-phi-case-3-near-1.log index 60b08c7d8..fde569cc1 100644 --- a/src/test/ref/call-banked-phi-case-3-near-1.log +++ b/src/test/ref/call-banked-phi-case-3-near-1.log @@ -2,6 +2,22 @@ Loading link script "call-banked-phi.ld" CONTROL FLOW GRAPH SSA +void main() +main: scope:[main] from __start + plus::a#0 = '0' + plus::b#0 = 7 + call plus + plus::return#0 = plus::return#2 + to:main::@1 +main::@1: scope:[main] from main + plus::return#3 = phi( main/plus::return#0 ) + main::$0 = plus::return#3 + SCREEN[0] = main::$0 + to:main::@return +main::@return: scope:[main] from main::@1 + return + to:@return + __bank(cx16_ram, 1) char plus(char a , char b) plus: scope:[plus] from main plus::b#1 = phi( main/plus::b#0 ) @@ -14,15 +30,15 @@ plus: scope:[plus] from main plus::@1: scope:[plus] from plus min::return#3 = phi( plus/min::return#0 ) plus::$0 = min::return#3 - plus::return#0 = plus::$0 + plus::return#1 = plus::$0 to:plus::@return plus::@return: scope:[plus] from plus::@1 - plus::return#3 = phi( plus::@1/plus::return#0 ) - plus::return#1 = plus::return#3 + plus::return#4 = phi( plus::@1/plus::return#1 ) + plus::return#2 = plus::return#4 return to:@return -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) min: scope:[min] from plus min::b#1 = phi( plus/min::b#0 ) min::a#1 = phi( plus/min::a#0 ) @@ -35,22 +51,6 @@ min::@return: scope:[min] from min return to:@return -void main() -main: scope:[main] from __start - plus::a#0 = '0' - plus::b#0 = 7 - call plus - plus::return#2 = plus::return#1 - to:main::@1 -main::@1: scope:[main] from main - plus::return#4 = phi( main/plus::return#2 ) - main::$0 = plus::return#4 - SCREEN[0] = main::$0 - to:main::@return -main::@return: scope:[main] from main::@1 - return - to:@return - void __start() __start: scope:[__start] from call main @@ -66,7 +66,7 @@ __constant char * const SCREEN = (char *)$400 void __start() void main() char main::$0 -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) char min::$0 char min::a char min::a#0 @@ -107,10 +107,10 @@ Successful SSA optimization PassNCastSimplification Finalized unsigned number type (char) 7 Finalized unsigned number type (char) 0 Successful SSA optimization PassNFinalizeNumberTypeConversions +Alias plus::return#0 = plus::return#3 Alias min::return#0 = min::return#3 -Alias plus::return#0 = plus::$0 plus::return#3 plus::return#1 +Alias plus::return#1 = plus::$0 plus::return#4 plus::return#2 Alias min::return#1 = min::$0 min::return#4 min::return#2 -Alias plus::return#2 = plus::return#4 Successful SSA optimization Pass2AliasElimination Identical Phi Values plus::a#1 plus::a#0 Identical Phi Values plus::b#1 plus::b#0 @@ -123,31 +123,31 @@ Successful SSA optimization Pass2ConstantIdentification Constant min::a#0 = plus::a#0 Constant min::b#0 = plus::b#0 Successful SSA optimization Pass2ConstantIdentification -Simplifying expression containing zero SCREEN in [15] SCREEN[0] = main::$0 +Simplifying expression containing zero SCREEN in [5] SCREEN[0] = main::$0 Successful SSA optimization PassNSimplifyExpressionWithZero Removing unused procedure __start Removing unused procedure block __start Removing unused procedure block __start::@1 Removing unused procedure block __start::@return Successful SSA optimization PassNEliminateEmptyStart -Constant right-side identified [4] min::return#1 = min::a#0 + min::b#0 +Constant right-side identified [9] min::return#1 = min::a#0 + min::b#0 Successful SSA optimization Pass2ConstantRValueConsolidation Constant min::return#1 = min::a#0+min::b#0 Successful SSA optimization Pass2ConstantIdentification Constant min::return#0 = min::return#1 Successful SSA optimization Pass2ConstantIdentification -Constant plus::return#0 = min::return#0 +Constant plus::return#1 = min::return#0 Successful SSA optimization Pass2ConstantIdentification -Constant plus::return#2 = plus::return#0 +Constant plus::return#0 = plus::return#1 Successful SSA optimization Pass2ConstantIdentification -Constant main::$0 = plus::return#2 +Constant main::$0 = plus::return#0 Successful SSA optimization Pass2ConstantIdentification Inlining constant with different constant siblings min::return#0 Constant inlined plus::return#0 = min::return#1 Constant inlined main::$0 = min::return#1 +Constant inlined plus::return#1 = min::return#1 Constant inlined min::a#0 = plus::a#0 Constant inlined min::return#0 = min::return#1 -Constant inlined plus::return#2 = min::return#1 Constant inlined min::b#0 = plus::b#0 Successful SSA optimization Pass2ConstantInlining Adding NOP phi() at start of main @@ -188,7 +188,7 @@ plus::@return: scope:[plus] from plus [6] return to:@return -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) min: scope:[min] from plus [7] phi() to:min::@return @@ -199,7 +199,7 @@ min::@return: scope:[min] from min VARIABLE REGISTER WEIGHTS void main() -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) char min::a char min::b char min::return @@ -215,15 +215,15 @@ Statement [1] call plus [ ] ( [ ] { } ) always clobbers reg byte a Statement [2] *SCREEN = min::return#1 [ ] ( [ ] { } ) always clobbers reg byte a REGISTER UPLIFT SCOPES +Uplift Scope [main] Uplift Scope [plus] Uplift Scope [min] -Uplift Scope [main] Uplift Scope [] -Uplifting [plus] best 93 combination -Uplifting [min] best 93 combination -Uplifting [main] best 93 combination -Uplifting [] best 93 combination +Uplifting [main] best 90 combination +Uplifting [plus] best 90 combination +Uplifting [min] best 90 combination +Uplifting [] best 90 combination ASSEMBLER BEFORE OPTIMIZATION // File Comments @@ -277,10 +277,9 @@ main: { // [1] call plus // [4] phi from main to plus [phi:main->plus] -- call_phi_close_cx16_ram plus_from_main: - lda.z 0 - pha lda #1 sta.z 0 + pha jsr plus pla sta.z 0 @@ -299,7 +298,6 @@ main: { .segment RAM_Bank1 // plus // char plus(char a, char b) -// banked : bank area='cx16_ram', bank=1 plus: { .label a = '0' .label b = 7 @@ -343,7 +341,7 @@ Succesful ASM optimization Pass5UnusedLabelElimination FINAL SYMBOL TABLE __constant char * const SCREEN = (char *) 1024 void main() -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) char min::a char min::b char min::return @@ -358,7 +356,7 @@ char plus::return FINAL ASSEMBLER -Score: 54 +Score: 51 // File Comments /** @@ -411,10 +409,9 @@ main: { // plus('0', 7) // [1] call plus // [4] phi from main to plus [phi:main->plus] -- call_phi_close_cx16_ram - lda.z 0 - pha lda #1 sta.z 0 + pha jsr plus pla sta.z 0 @@ -431,7 +428,6 @@ main: { .segment RAM_Bank1 // plus // char plus(char a, char b) -// banked : bank area='cx16_ram', bank=1 plus: { .label a = '0' .label b = 7 diff --git a/src/test/ref/call-banked-phi-case-3-near-1.sym b/src/test/ref/call-banked-phi-case-3-near-1.sym index 9e4219f22..09b563343 100644 --- a/src/test/ref/call-banked-phi-case-3-near-1.sym +++ b/src/test/ref/call-banked-phi-case-3-near-1.sym @@ -1,6 +1,6 @@ __constant char * const SCREEN = (char *) 1024 void main() -char min(char a , char b) +__bank(cx16_ram, 1) char min(char a , char b) char min::a char min::b char min::return