mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-20 00:29:10 +00:00
Implementation of #pragma near_seg without prameters.
There was a change needed to update the parameter parsing main algorithm, to make parameters optional instead of mandatory.
This commit is contained in:
parent
1ef785a254
commit
d7a135aaee
File diff suppressed because one or more lines are too long
2556
gen/KickCLexer.java
2556
gen/KickCLexer.java
File diff suppressed because it is too large
Load Diff
@ -51,106 +51,107 @@ ADDRESS=50
|
||||
ADDRESS_ZEROPAGE=51
|
||||
ADDRESS_MAINMEM=52
|
||||
FAR=53
|
||||
FORM_SSA=54
|
||||
FORM_MA=55
|
||||
INTRINSIC=56
|
||||
CALLINGCONVENTION=57
|
||||
IF=58
|
||||
ELSE=59
|
||||
WHILE=60
|
||||
DO=61
|
||||
FOR=62
|
||||
SWITCH=63
|
||||
RETURN=64
|
||||
BREAK=65
|
||||
CONTINUE=66
|
||||
GOTO=67
|
||||
ASM=68
|
||||
DEFAULT=69
|
||||
CASE=70
|
||||
STRUCT=71
|
||||
UNION=72
|
||||
ENUM=73
|
||||
SIZEOF=74
|
||||
TYPEID=75
|
||||
DEFINED=76
|
||||
KICKASM=77
|
||||
LOGIC_NOT=78
|
||||
SIMPLETYPE=79
|
||||
BOOLEAN=80
|
||||
KICKASM_BODY=81
|
||||
IMPORT=82
|
||||
INCLUDE=83
|
||||
PRAGMA=84
|
||||
DEFINE=85
|
||||
DEFINE_CONTINUE=86
|
||||
UNDEF=87
|
||||
IFDEF=88
|
||||
IFNDEF=89
|
||||
IFIF=90
|
||||
ELIF=91
|
||||
IFELSE=92
|
||||
ENDIF=93
|
||||
ERROR=94
|
||||
TOKEN_STRINGIZE=95
|
||||
TOKEN_MERGE=96
|
||||
NUMBER=97
|
||||
NUMFLOAT=98
|
||||
BINFLOAT=99
|
||||
DECFLOAT=100
|
||||
HEXFLOAT=101
|
||||
NUMINT=102
|
||||
BININTEGER=103
|
||||
DECINTEGER=104
|
||||
HEXINTEGER=105
|
||||
NAME=106
|
||||
STRING=107
|
||||
CHAR=108
|
||||
WS=109
|
||||
COMMENT_LINE=110
|
||||
COMMENT_BLOCK=111
|
||||
ASM_BYTE=112
|
||||
ASM_MNEMONIC=113
|
||||
ASM_IMM=114
|
||||
ASM_COLON=115
|
||||
ASM_COMMA=116
|
||||
ASM_PAR_BEGIN=117
|
||||
ASM_PAR_END=118
|
||||
ASM_BRACKET_BEGIN=119
|
||||
ASM_BRACKET_END=120
|
||||
ASM_DOT=121
|
||||
ASM_SHIFT_LEFT=122
|
||||
ASM_SHIFT_RIGHT=123
|
||||
ASM_PLUS=124
|
||||
ASM_MINUS=125
|
||||
ASM_LESS_THAN=126
|
||||
ASM_GREATER_THAN=127
|
||||
ASM_MULTIPLY=128
|
||||
ASM_DIVIDE=129
|
||||
ASM_CURLY_BEGIN=130
|
||||
ASM_CURLY_END=131
|
||||
ASM_NUMBER=132
|
||||
ASM_NUMFLOAT=133
|
||||
ASM_BINFLOAT=134
|
||||
ASM_DECFLOAT=135
|
||||
ASM_HEXFLOAT=136
|
||||
ASM_NUMINT=137
|
||||
ASM_BININTEGER=138
|
||||
ASM_DECINTEGER=139
|
||||
ASM_HEXINTEGER=140
|
||||
ASM_CHAR=141
|
||||
ASM_MULTI_REL=142
|
||||
ASM_MULTI_NAME=143
|
||||
ASM_NAME=144
|
||||
ASM_TAG=145
|
||||
ASM_WS=146
|
||||
ASM_COMMENT_LINE=147
|
||||
ASM_COMMENT_BLOCK=148
|
||||
IMPORT_SYSTEMFILE=149
|
||||
IMPORT_LOCALFILE=150
|
||||
IMPORT_WS=151
|
||||
IMPORT_COMMENT_LINE=152
|
||||
IMPORT_COMMENT_BLOCK=153
|
||||
NEAR=54
|
||||
FORM_SSA=55
|
||||
FORM_MA=56
|
||||
INTRINSIC=57
|
||||
CALLINGCONVENTION=58
|
||||
IF=59
|
||||
ELSE=60
|
||||
WHILE=61
|
||||
DO=62
|
||||
FOR=63
|
||||
SWITCH=64
|
||||
RETURN=65
|
||||
BREAK=66
|
||||
CONTINUE=67
|
||||
GOTO=68
|
||||
ASM=69
|
||||
DEFAULT=70
|
||||
CASE=71
|
||||
STRUCT=72
|
||||
UNION=73
|
||||
ENUM=74
|
||||
SIZEOF=75
|
||||
TYPEID=76
|
||||
DEFINED=77
|
||||
KICKASM=78
|
||||
LOGIC_NOT=79
|
||||
SIMPLETYPE=80
|
||||
BOOLEAN=81
|
||||
KICKASM_BODY=82
|
||||
IMPORT=83
|
||||
INCLUDE=84
|
||||
PRAGMA=85
|
||||
DEFINE=86
|
||||
DEFINE_CONTINUE=87
|
||||
UNDEF=88
|
||||
IFDEF=89
|
||||
IFNDEF=90
|
||||
IFIF=91
|
||||
ELIF=92
|
||||
IFELSE=93
|
||||
ENDIF=94
|
||||
ERROR=95
|
||||
TOKEN_STRINGIZE=96
|
||||
TOKEN_MERGE=97
|
||||
NUMBER=98
|
||||
NUMFLOAT=99
|
||||
BINFLOAT=100
|
||||
DECFLOAT=101
|
||||
HEXFLOAT=102
|
||||
NUMINT=103
|
||||
BININTEGER=104
|
||||
DECINTEGER=105
|
||||
HEXINTEGER=106
|
||||
NAME=107
|
||||
STRING=108
|
||||
CHAR=109
|
||||
WS=110
|
||||
COMMENT_LINE=111
|
||||
COMMENT_BLOCK=112
|
||||
ASM_BYTE=113
|
||||
ASM_MNEMONIC=114
|
||||
ASM_IMM=115
|
||||
ASM_COLON=116
|
||||
ASM_COMMA=117
|
||||
ASM_PAR_BEGIN=118
|
||||
ASM_PAR_END=119
|
||||
ASM_BRACKET_BEGIN=120
|
||||
ASM_BRACKET_END=121
|
||||
ASM_DOT=122
|
||||
ASM_SHIFT_LEFT=123
|
||||
ASM_SHIFT_RIGHT=124
|
||||
ASM_PLUS=125
|
||||
ASM_MINUS=126
|
||||
ASM_LESS_THAN=127
|
||||
ASM_GREATER_THAN=128
|
||||
ASM_MULTIPLY=129
|
||||
ASM_DIVIDE=130
|
||||
ASM_CURLY_BEGIN=131
|
||||
ASM_CURLY_END=132
|
||||
ASM_NUMBER=133
|
||||
ASM_NUMFLOAT=134
|
||||
ASM_BINFLOAT=135
|
||||
ASM_DECFLOAT=136
|
||||
ASM_HEXFLOAT=137
|
||||
ASM_NUMINT=138
|
||||
ASM_BININTEGER=139
|
||||
ASM_DECINTEGER=140
|
||||
ASM_HEXINTEGER=141
|
||||
ASM_CHAR=142
|
||||
ASM_MULTI_REL=143
|
||||
ASM_MULTI_NAME=144
|
||||
ASM_NAME=145
|
||||
ASM_TAG=146
|
||||
ASM_WS=147
|
||||
ASM_COMMENT_LINE=148
|
||||
ASM_COMMENT_BLOCK=149
|
||||
IMPORT_SYSTEMFILE=150
|
||||
IMPORT_LOCALFILE=151
|
||||
IMPORT_WS=152
|
||||
IMPORT_COMMENT_LINE=153
|
||||
IMPORT_COMMENT_BLOCK=154
|
||||
';'=8
|
||||
'..'=11
|
||||
'...'=12
|
||||
@ -185,41 +186,42 @@ IMPORT_COMMENT_BLOCK=153
|
||||
'__zp'=51
|
||||
'__mem'=52
|
||||
'__far'=53
|
||||
'__ssa'=54
|
||||
'__ma'=55
|
||||
'__intrinsic'=56
|
||||
'if'=58
|
||||
'else'=59
|
||||
'while'=60
|
||||
'do'=61
|
||||
'for'=62
|
||||
'switch'=63
|
||||
'return'=64
|
||||
'break'=65
|
||||
'continue'=66
|
||||
'goto'=67
|
||||
'asm'=68
|
||||
'default'=69
|
||||
'case'=70
|
||||
'struct'=71
|
||||
'union'=72
|
||||
'enum'=73
|
||||
'sizeof'=74
|
||||
'typeid'=75
|
||||
'defined'=76
|
||||
'kickasm'=77
|
||||
'!'=78
|
||||
'#import'=82
|
||||
'#include'=83
|
||||
'#pragma'=84
|
||||
'#define'=85
|
||||
'#undef'=87
|
||||
'#ifdef'=88
|
||||
'#ifndef'=89
|
||||
'#if'=90
|
||||
'#elif'=91
|
||||
'#else'=92
|
||||
'#endif'=93
|
||||
'#error'=94
|
||||
'.byte'=112
|
||||
'#'=114
|
||||
'__near'=54
|
||||
'__ssa'=55
|
||||
'__ma'=56
|
||||
'__intrinsic'=57
|
||||
'if'=59
|
||||
'else'=60
|
||||
'while'=61
|
||||
'do'=62
|
||||
'for'=63
|
||||
'switch'=64
|
||||
'return'=65
|
||||
'break'=66
|
||||
'continue'=67
|
||||
'goto'=68
|
||||
'asm'=69
|
||||
'default'=70
|
||||
'case'=71
|
||||
'struct'=72
|
||||
'union'=73
|
||||
'enum'=74
|
||||
'sizeof'=75
|
||||
'typeid'=76
|
||||
'defined'=77
|
||||
'kickasm'=78
|
||||
'!'=79
|
||||
'#import'=83
|
||||
'#include'=84
|
||||
'#pragma'=85
|
||||
'#define'=86
|
||||
'#undef'=88
|
||||
'#ifdef'=89
|
||||
'#ifndef'=90
|
||||
'#if'=91
|
||||
'#elif'=92
|
||||
'#else'=93
|
||||
'#endif'=94
|
||||
'#error'=95
|
||||
'.byte'=113
|
||||
'#'=115
|
||||
|
@ -136,7 +136,8 @@ parameterDecl
|
||||
;
|
||||
|
||||
pragma
|
||||
: PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END
|
||||
: PRAGMA NAME
|
||||
| PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END
|
||||
;
|
||||
|
||||
pragmaParam
|
||||
|
@ -325,6 +325,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
throw new CompileError("Illegal parameter " + ctx.getText(), new StatementSource(ctx));
|
||||
}
|
||||
break;
|
||||
case CParser.PRAGMA_NEAR_SEG:
|
||||
this.currentFarSegment = ""; // When the current far segment is "", any function that is far will be called as far.
|
||||
break;
|
||||
case CParser.PRAGMA_RESOURCE:
|
||||
String resourceFileName = pragmaParamString(pragmaParamSingle(ctx));
|
||||
addResourceFile(ctx, resourceFileName);
|
||||
|
@ -223,27 +223,29 @@ public class CPreprocessor implements TokenSource {
|
||||
pragmaTokens.add(pragmaType);
|
||||
pragmaTokens.addAll(skipWhitespace(cTokenSource));
|
||||
ArrayList<Token> pragmaBody = readBody(cTokenSource);
|
||||
final Token pragmaBodyStart = pragmaBody.get(0);
|
||||
// Convert space-based pragma to parenthesis-based for easier parsing
|
||||
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
||||
if(pragmaBodyStart.getType() != KickCLexer.PAR_BEGIN) {
|
||||
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
||||
// Parenthesize the parameter list
|
||||
boolean first = true;
|
||||
for(Token token : pragmaBody) {
|
||||
if(token.getChannel() != CParser.CHANNEL_WHITESPACE && !first) {
|
||||
parenthesizedBody.add(new CommonToken(KickCLexer.COMMA, ","));
|
||||
if(pragmaBody.size()>0) {
|
||||
final Token pragmaBodyStart = pragmaBody.get(0);
|
||||
// Convert space-based pragma to parenthesis-based for easier parsing
|
||||
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
||||
if (pragmaBodyStart.getType() != KickCLexer.PAR_BEGIN) {
|
||||
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
||||
// Parenthesize the parameter list
|
||||
boolean first = true;
|
||||
for (Token token : pragmaBody) {
|
||||
if (token.getChannel() != CParser.CHANNEL_WHITESPACE && !first) {
|
||||
parenthesizedBody.add(new CommonToken(KickCLexer.COMMA, ","));
|
||||
}
|
||||
parenthesizedBody.add(token);
|
||||
first = false;
|
||||
}
|
||||
parenthesizedBody.add(token);
|
||||
first = false;
|
||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_END, ")"));
|
||||
pragmaBody = parenthesizedBody;
|
||||
}
|
||||
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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
32
src/test/kc/procedure-callingconvention-phi-far-4.c
Normal file
32
src/test/kc/procedure-callingconvention-phi-far-4.c
Normal file
@ -0,0 +1,32 @@
|
||||
// Test a far call procedure with a calling convention sp
|
||||
|
||||
char* const SCREEN = (char*)0x0400;
|
||||
|
||||
void main(void) {
|
||||
SCREEN[0] = plus('0', 7);
|
||||
}
|
||||
|
||||
#pragma code_seg(stage)
|
||||
#pragma far_seg(stage, 20)
|
||||
|
||||
char plus(char a, char b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
#pragma near_seg
|
||||
|
||||
void stage_entry() {
|
||||
asm {
|
||||
lda 0
|
||||
pha
|
||||
lda #1
|
||||
sta 0
|
||||
}
|
||||
}
|
||||
|
||||
void stage_exit() {
|
||||
asm {
|
||||
pla
|
||||
sta 0
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user