mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-21 07:29:14 +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_ZEROPAGE=51
|
||||||
ADDRESS_MAINMEM=52
|
ADDRESS_MAINMEM=52
|
||||||
FAR=53
|
FAR=53
|
||||||
FORM_SSA=54
|
NEAR=54
|
||||||
FORM_MA=55
|
FORM_SSA=55
|
||||||
INTRINSIC=56
|
FORM_MA=56
|
||||||
CALLINGCONVENTION=57
|
INTRINSIC=57
|
||||||
IF=58
|
CALLINGCONVENTION=58
|
||||||
ELSE=59
|
IF=59
|
||||||
WHILE=60
|
ELSE=60
|
||||||
DO=61
|
WHILE=61
|
||||||
FOR=62
|
DO=62
|
||||||
SWITCH=63
|
FOR=63
|
||||||
RETURN=64
|
SWITCH=64
|
||||||
BREAK=65
|
RETURN=65
|
||||||
CONTINUE=66
|
BREAK=66
|
||||||
GOTO=67
|
CONTINUE=67
|
||||||
ASM=68
|
GOTO=68
|
||||||
DEFAULT=69
|
ASM=69
|
||||||
CASE=70
|
DEFAULT=70
|
||||||
STRUCT=71
|
CASE=71
|
||||||
UNION=72
|
STRUCT=72
|
||||||
ENUM=73
|
UNION=73
|
||||||
SIZEOF=74
|
ENUM=74
|
||||||
TYPEID=75
|
SIZEOF=75
|
||||||
DEFINED=76
|
TYPEID=76
|
||||||
KICKASM=77
|
DEFINED=77
|
||||||
LOGIC_NOT=78
|
KICKASM=78
|
||||||
SIMPLETYPE=79
|
LOGIC_NOT=79
|
||||||
BOOLEAN=80
|
SIMPLETYPE=80
|
||||||
KICKASM_BODY=81
|
BOOLEAN=81
|
||||||
IMPORT=82
|
KICKASM_BODY=82
|
||||||
INCLUDE=83
|
IMPORT=83
|
||||||
PRAGMA=84
|
INCLUDE=84
|
||||||
DEFINE=85
|
PRAGMA=85
|
||||||
DEFINE_CONTINUE=86
|
DEFINE=86
|
||||||
UNDEF=87
|
DEFINE_CONTINUE=87
|
||||||
IFDEF=88
|
UNDEF=88
|
||||||
IFNDEF=89
|
IFDEF=89
|
||||||
IFIF=90
|
IFNDEF=90
|
||||||
ELIF=91
|
IFIF=91
|
||||||
IFELSE=92
|
ELIF=92
|
||||||
ENDIF=93
|
IFELSE=93
|
||||||
ERROR=94
|
ENDIF=94
|
||||||
TOKEN_STRINGIZE=95
|
ERROR=95
|
||||||
TOKEN_MERGE=96
|
TOKEN_STRINGIZE=96
|
||||||
NUMBER=97
|
TOKEN_MERGE=97
|
||||||
NUMFLOAT=98
|
NUMBER=98
|
||||||
BINFLOAT=99
|
NUMFLOAT=99
|
||||||
DECFLOAT=100
|
BINFLOAT=100
|
||||||
HEXFLOAT=101
|
DECFLOAT=101
|
||||||
NUMINT=102
|
HEXFLOAT=102
|
||||||
BININTEGER=103
|
NUMINT=103
|
||||||
DECINTEGER=104
|
BININTEGER=104
|
||||||
HEXINTEGER=105
|
DECINTEGER=105
|
||||||
NAME=106
|
HEXINTEGER=106
|
||||||
STRING=107
|
NAME=107
|
||||||
CHAR=108
|
STRING=108
|
||||||
WS=109
|
CHAR=109
|
||||||
COMMENT_LINE=110
|
WS=110
|
||||||
COMMENT_BLOCK=111
|
COMMENT_LINE=111
|
||||||
ASM_BYTE=112
|
COMMENT_BLOCK=112
|
||||||
ASM_MNEMONIC=113
|
ASM_BYTE=113
|
||||||
ASM_IMM=114
|
ASM_MNEMONIC=114
|
||||||
ASM_COLON=115
|
ASM_IMM=115
|
||||||
ASM_COMMA=116
|
ASM_COLON=116
|
||||||
ASM_PAR_BEGIN=117
|
ASM_COMMA=117
|
||||||
ASM_PAR_END=118
|
ASM_PAR_BEGIN=118
|
||||||
ASM_BRACKET_BEGIN=119
|
ASM_PAR_END=119
|
||||||
ASM_BRACKET_END=120
|
ASM_BRACKET_BEGIN=120
|
||||||
ASM_DOT=121
|
ASM_BRACKET_END=121
|
||||||
ASM_SHIFT_LEFT=122
|
ASM_DOT=122
|
||||||
ASM_SHIFT_RIGHT=123
|
ASM_SHIFT_LEFT=123
|
||||||
ASM_PLUS=124
|
ASM_SHIFT_RIGHT=124
|
||||||
ASM_MINUS=125
|
ASM_PLUS=125
|
||||||
ASM_LESS_THAN=126
|
ASM_MINUS=126
|
||||||
ASM_GREATER_THAN=127
|
ASM_LESS_THAN=127
|
||||||
ASM_MULTIPLY=128
|
ASM_GREATER_THAN=128
|
||||||
ASM_DIVIDE=129
|
ASM_MULTIPLY=129
|
||||||
ASM_CURLY_BEGIN=130
|
ASM_DIVIDE=130
|
||||||
ASM_CURLY_END=131
|
ASM_CURLY_BEGIN=131
|
||||||
ASM_NUMBER=132
|
ASM_CURLY_END=132
|
||||||
ASM_NUMFLOAT=133
|
ASM_NUMBER=133
|
||||||
ASM_BINFLOAT=134
|
ASM_NUMFLOAT=134
|
||||||
ASM_DECFLOAT=135
|
ASM_BINFLOAT=135
|
||||||
ASM_HEXFLOAT=136
|
ASM_DECFLOAT=136
|
||||||
ASM_NUMINT=137
|
ASM_HEXFLOAT=137
|
||||||
ASM_BININTEGER=138
|
ASM_NUMINT=138
|
||||||
ASM_DECINTEGER=139
|
ASM_BININTEGER=139
|
||||||
ASM_HEXINTEGER=140
|
ASM_DECINTEGER=140
|
||||||
ASM_CHAR=141
|
ASM_HEXINTEGER=141
|
||||||
ASM_MULTI_REL=142
|
ASM_CHAR=142
|
||||||
ASM_MULTI_NAME=143
|
ASM_MULTI_REL=143
|
||||||
ASM_NAME=144
|
ASM_MULTI_NAME=144
|
||||||
ASM_TAG=145
|
ASM_NAME=145
|
||||||
ASM_WS=146
|
ASM_TAG=146
|
||||||
ASM_COMMENT_LINE=147
|
ASM_WS=147
|
||||||
ASM_COMMENT_BLOCK=148
|
ASM_COMMENT_LINE=148
|
||||||
IMPORT_SYSTEMFILE=149
|
ASM_COMMENT_BLOCK=149
|
||||||
IMPORT_LOCALFILE=150
|
IMPORT_SYSTEMFILE=150
|
||||||
IMPORT_WS=151
|
IMPORT_LOCALFILE=151
|
||||||
IMPORT_COMMENT_LINE=152
|
IMPORT_WS=152
|
||||||
IMPORT_COMMENT_BLOCK=153
|
IMPORT_COMMENT_LINE=153
|
||||||
|
IMPORT_COMMENT_BLOCK=154
|
||||||
';'=8
|
';'=8
|
||||||
'..'=11
|
'..'=11
|
||||||
'...'=12
|
'...'=12
|
||||||
@ -185,41 +186,42 @@ IMPORT_COMMENT_BLOCK=153
|
|||||||
'__zp'=51
|
'__zp'=51
|
||||||
'__mem'=52
|
'__mem'=52
|
||||||
'__far'=53
|
'__far'=53
|
||||||
'__ssa'=54
|
'__near'=54
|
||||||
'__ma'=55
|
'__ssa'=55
|
||||||
'__intrinsic'=56
|
'__ma'=56
|
||||||
'if'=58
|
'__intrinsic'=57
|
||||||
'else'=59
|
'if'=59
|
||||||
'while'=60
|
'else'=60
|
||||||
'do'=61
|
'while'=61
|
||||||
'for'=62
|
'do'=62
|
||||||
'switch'=63
|
'for'=63
|
||||||
'return'=64
|
'switch'=64
|
||||||
'break'=65
|
'return'=65
|
||||||
'continue'=66
|
'break'=66
|
||||||
'goto'=67
|
'continue'=67
|
||||||
'asm'=68
|
'goto'=68
|
||||||
'default'=69
|
'asm'=69
|
||||||
'case'=70
|
'default'=70
|
||||||
'struct'=71
|
'case'=71
|
||||||
'union'=72
|
'struct'=72
|
||||||
'enum'=73
|
'union'=73
|
||||||
'sizeof'=74
|
'enum'=74
|
||||||
'typeid'=75
|
'sizeof'=75
|
||||||
'defined'=76
|
'typeid'=76
|
||||||
'kickasm'=77
|
'defined'=77
|
||||||
'!'=78
|
'kickasm'=78
|
||||||
'#import'=82
|
'!'=79
|
||||||
'#include'=83
|
'#import'=83
|
||||||
'#pragma'=84
|
'#include'=84
|
||||||
'#define'=85
|
'#pragma'=85
|
||||||
'#undef'=87
|
'#define'=86
|
||||||
'#ifdef'=88
|
'#undef'=88
|
||||||
'#ifndef'=89
|
'#ifdef'=89
|
||||||
'#if'=90
|
'#ifndef'=90
|
||||||
'#elif'=91
|
'#if'=91
|
||||||
'#else'=92
|
'#elif'=92
|
||||||
'#endif'=93
|
'#else'=93
|
||||||
'#error'=94
|
'#endif'=94
|
||||||
'.byte'=112
|
'#error'=95
|
||||||
'#'=114
|
'.byte'=113
|
||||||
|
'#'=115
|
||||||
|
@ -136,7 +136,8 @@ parameterDecl
|
|||||||
;
|
;
|
||||||
|
|
||||||
pragma
|
pragma
|
||||||
: PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END
|
: PRAGMA NAME
|
||||||
|
| PRAGMA NAME PAR_BEGIN pragmaParam (COMMA pragmaParam)* PAR_END
|
||||||
;
|
;
|
||||||
|
|
||||||
pragmaParam
|
pragmaParam
|
||||||
|
@ -325,6 +325,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||||||
throw new CompileError("Illegal parameter " + ctx.getText(), new StatementSource(ctx));
|
throw new CompileError("Illegal parameter " + ctx.getText(), new StatementSource(ctx));
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case CParser.PRAGMA_RESOURCE:
|
||||||
String resourceFileName = pragmaParamString(pragmaParamSingle(ctx));
|
String resourceFileName = pragmaParamString(pragmaParamSingle(ctx));
|
||||||
addResourceFile(ctx, resourceFileName);
|
addResourceFile(ctx, resourceFileName);
|
||||||
|
@ -223,27 +223,29 @@ 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);
|
if(pragmaBody.size()>0) {
|
||||||
// Convert space-based pragma to parenthesis-based for easier parsing
|
final Token pragmaBodyStart = pragmaBody.get(0);
|
||||||
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
// Convert space-based pragma to parenthesis-based for easier parsing
|
||||||
if(pragmaBodyStart.getType() != KickCLexer.PAR_BEGIN) {
|
// #pragma NAME XXX YYY \n => #pragma NAME ( XXX , YYY ) \n
|
||||||
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
if (pragmaBodyStart.getType() != KickCLexer.PAR_BEGIN) {
|
||||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
ArrayList<Token> parenthesizedBody = new ArrayList<>();
|
||||||
// Parenthesize the parameter list
|
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_BEGIN, "("));
|
||||||
boolean first = true;
|
// Parenthesize the parameter list
|
||||||
for(Token token : pragmaBody) {
|
boolean first = true;
|
||||||
if(token.getChannel() != CParser.CHANNEL_WHITESPACE && !first) {
|
for (Token token : pragmaBody) {
|
||||||
parenthesizedBody.add(new CommonToken(KickCLexer.COMMA, ","));
|
if (token.getChannel() != CParser.CHANNEL_WHITESPACE && !first) {
|
||||||
|
parenthesizedBody.add(new CommonToken(KickCLexer.COMMA, ","));
|
||||||
|
}
|
||||||
|
parenthesizedBody.add(token);
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
parenthesizedBody.add(token);
|
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_END, ")"));
|
||||||
first = false;
|
pragmaBody = parenthesizedBody;
|
||||||
}
|
}
|
||||||
parenthesizedBody.add(new CommonToken(KickCLexer.PAR_END, ")"));
|
pragmaTokens.addAll(pragmaBody);
|
||||||
pragmaBody = parenthesizedBody;
|
// 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);
|
parserPragmas.add(inputToken);
|
||||||
return true;
|
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