mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-01 16:51:12 +00:00
#816 Pragma with no parameter and no parenthesis
This commit is contained in:
parent
adb9688acb
commit
2478ea034f
@ -136,7 +136,7 @@ parameterDecl
|
|||||||
;
|
;
|
||||||
|
|
||||||
pragma
|
pragma
|
||||||
: PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END
|
: PRAGMA NAME PAR_BEGIN (pragmaParam (COMMA pragmaParam)* )? PAR_END
|
||||||
;
|
;
|
||||||
|
|
||||||
pragmaParam
|
pragmaParam
|
||||||
|
@ -223,10 +223,9 @@ public class CPreprocessor implements TokenSource {
|
|||||||
pragmaTokens.add(pragmaType);
|
pragmaTokens.add(pragmaType);
|
||||||
pragmaTokens.addAll(skipWhitespace(cTokenSource));
|
pragmaTokens.addAll(skipWhitespace(cTokenSource));
|
||||||
ArrayList<Token> pragmaBody = readBody(cTokenSource);
|
ArrayList<Token> pragmaBody = readBody(cTokenSource);
|
||||||
final Token pragmaBodyStart = pragmaBody.get(0);
|
|
||||||
// Convert space-based pragma to parenthesis-based for easier parsing
|
// Convert space-based pragma to parenthesis-based for easier parsing
|
||||||
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
||||||
if(pragmaBodyStart.getType() != KickCLexer.PAR_BEGIN) {
|
if(pragmaBody.isEmpty() || pragmaBody.get(0).getType() != KickCLexer.PAR_BEGIN) {
|
||||||
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
||||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
||||||
// Parenthesize the parameter list
|
// Parenthesize the parameter list
|
||||||
|
@ -546,6 +546,11 @@ public class TestProgramsFast extends TestPrograms {
|
|||||||
compileAndCompare("pragma-unknown.c");
|
compileAndCompare("pragma-unknown.c");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPragmaNoParametersNoParenthesis() throws IOException {
|
||||||
|
compileAndCompare("pragma-noparam-noparen.c");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorFormatter() throws IOException {
|
public void testErrorFormatter() throws IOException {
|
||||||
// Error on a char
|
// Error on a char
|
||||||
|
8
src/test/kc/pragma-noparam-noparen.c
Normal file
8
src/test/kc/pragma-noparam-noparen.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// Test that #pragma works with no parenthesis and no parameters
|
||||||
|
|
||||||
|
#pragma nobank
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
char * const SCREEN = (char*) 0x0400;
|
||||||
|
*SCREEN = 'a';
|
||||||
|
}
|
18
src/test/ref/pragma-noparam-noparen.asm
Normal file
18
src/test/ref/pragma-noparam-noparen.asm
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Test that #pragma works with no parenthesis and no parameters
|
||||||
|
// Commodore 64 PRG executable file
|
||||||
|
.file [name="pragma-noparam-noparen.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)
|
||||||
|
.segment Code
|
||||||
|
main: {
|
||||||
|
.label SCREEN = $400
|
||||||
|
// *SCREEN = 'a'
|
||||||
|
lda #'a'
|
||||||
|
sta SCREEN
|
||||||
|
// }
|
||||||
|
rts
|
||||||
|
}
|
8
src/test/ref/pragma-noparam-noparen.cfg
Normal file
8
src/test/ref/pragma-noparam-noparen.cfg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
void main()
|
||||||
|
main: scope:[main] from
|
||||||
|
[0] *main::SCREEN = 'a'
|
||||||
|
to:main::@return
|
||||||
|
main::@return: scope:[main] from main
|
||||||
|
[1] return
|
||||||
|
to:@return
|
135
src/test/ref/pragma-noparam-noparen.log
Normal file
135
src/test/ref/pragma-noparam-noparen.log
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
Warning! Unknown #pragma nobank
|
||||||
|
|
||||||
|
CONTROL FLOW GRAPH SSA
|
||||||
|
|
||||||
|
void main()
|
||||||
|
main: scope:[main] from __start
|
||||||
|
*main::SCREEN = 'a'
|
||||||
|
to:main::@return
|
||||||
|
main::@return: scope:[main] from main
|
||||||
|
return
|
||||||
|
to:@return
|
||||||
|
|
||||||
|
void __start()
|
||||||
|
__start: scope:[__start] from
|
||||||
|
call main
|
||||||
|
to:__start::@1
|
||||||
|
__start::@1: scope:[__start] from __start
|
||||||
|
to:__start::@return
|
||||||
|
__start::@return: scope:[__start] from __start::@1
|
||||||
|
return
|
||||||
|
to:@return
|
||||||
|
|
||||||
|
SYMBOL TABLE SSA
|
||||||
|
void __start()
|
||||||
|
void main()
|
||||||
|
__constant char * const main::SCREEN = (char *)$400
|
||||||
|
|
||||||
|
Simplifying constant pointer cast (char *) 1024
|
||||||
|
Successful SSA optimization PassNCastSimplification
|
||||||
|
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
|
||||||
|
CALL GRAPH
|
||||||
|
|
||||||
|
Created 0 initial phi equivalence classes
|
||||||
|
Coalesced down to 0 phi equivalence classes
|
||||||
|
|
||||||
|
FINAL CONTROL FLOW GRAPH
|
||||||
|
|
||||||
|
void main()
|
||||||
|
main: scope:[main] from
|
||||||
|
[0] *main::SCREEN = 'a'
|
||||||
|
to:main::@return
|
||||||
|
main::@return: scope:[main] from main
|
||||||
|
[1] return
|
||||||
|
to:@return
|
||||||
|
|
||||||
|
|
||||||
|
VARIABLE REGISTER WEIGHTS
|
||||||
|
void main()
|
||||||
|
|
||||||
|
Initial phi equivalence classes
|
||||||
|
Complete equivalence classes
|
||||||
|
REGISTER UPLIFT POTENTIAL REGISTERS
|
||||||
|
Statement [0] *main::SCREEN = 'a' [ ] ( [ ] { } ) always clobbers reg byte a
|
||||||
|
|
||||||
|
REGISTER UPLIFT SCOPES
|
||||||
|
Uplift Scope [main]
|
||||||
|
Uplift Scope []
|
||||||
|
|
||||||
|
Uplifting [main] best 15 combination
|
||||||
|
Uplifting [] best 15 combination
|
||||||
|
|
||||||
|
ASSEMBLER BEFORE OPTIMIZATION
|
||||||
|
// File Comments
|
||||||
|
// Test that #pragma works with no parenthesis and no parameters
|
||||||
|
// Upstart
|
||||||
|
// Commodore 64 PRG executable file
|
||||||
|
.file [name="pragma-noparam-noparen.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
|
||||||
|
.segment Code
|
||||||
|
// main
|
||||||
|
main: {
|
||||||
|
.label SCREEN = $400
|
||||||
|
// [0] *main::SCREEN = 'a' -- _deref_pbuc1=vbuc2
|
||||||
|
lda #'a'
|
||||||
|
sta SCREEN
|
||||||
|
jmp __breturn
|
||||||
|
// main::@return
|
||||||
|
__breturn:
|
||||||
|
// [1] return
|
||||||
|
rts
|
||||||
|
}
|
||||||
|
// File Data
|
||||||
|
|
||||||
|
ASSEMBLER OPTIMIZATIONS
|
||||||
|
Removing instruction jmp __breturn
|
||||||
|
Succesful ASM optimization Pass5NextJumpElimination
|
||||||
|
Removing instruction __breturn:
|
||||||
|
Succesful ASM optimization Pass5UnusedLabelElimination
|
||||||
|
|
||||||
|
FINAL SYMBOL TABLE
|
||||||
|
void main()
|
||||||
|
__constant char * const main::SCREEN = (char *) 1024
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FINAL ASSEMBLER
|
||||||
|
Score: 12
|
||||||
|
|
||||||
|
// File Comments
|
||||||
|
// Test that #pragma works with no parenthesis and no parameters
|
||||||
|
// Upstart
|
||||||
|
// Commodore 64 PRG executable file
|
||||||
|
.file [name="pragma-noparam-noparen.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
|
||||||
|
.segment Code
|
||||||
|
// main
|
||||||
|
main: {
|
||||||
|
.label SCREEN = $400
|
||||||
|
// *SCREEN = 'a'
|
||||||
|
// [0] *main::SCREEN = 'a' -- _deref_pbuc1=vbuc2
|
||||||
|
lda #'a'
|
||||||
|
sta SCREEN
|
||||||
|
// main::@return
|
||||||
|
// }
|
||||||
|
// [1] return
|
||||||
|
rts
|
||||||
|
}
|
||||||
|
// File Data
|
||||||
|
|
3
src/test/ref/pragma-noparam-noparen.sym
Normal file
3
src/test/ref/pragma-noparam-noparen.sym
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
void main()
|
||||||
|
__constant char * const main::SCREEN = (char *) 1024
|
||||||
|
|
Loading…
Reference in New Issue
Block a user