projects
/
fw
/
sdcc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* link/z80/lkmain.c,
[fw/sdcc]
/
src
/
SDCC.lex
diff --git
a/src/SDCC.lex
b/src/SDCC.lex
index 098e36cddc148434f42363f130cf3d813b0b163f..4f9b51887143ffac7c794b995ac355ef74005628 100644
(file)
--- a/
src/SDCC.lex
+++ b/
src/SDCC.lex
@@
-40,6
+40,11
@@
IS (u|U|l|L)*
#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
check_type())
#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
check_type())
+#define TKEYWORDSDCC(token) return (options.std_sdcc && isTargetKeyword(yytext)\
+ ? token : check_type())
+
+#define TKEYWORD99(token) return (options.std_c99 ? token : check_type())
+
extern int lineno, column;
extern char *filename;
extern int lineno, column;
extern char *filename;
@@
-61,18
+66,27
@@
static int checkCurrFile(char *s);
%x asm
%%
%x asm
%%
-"_asm" {
+
_?
"_asm" {
count();
count();
+ if (!options.std_sdcc && yytext[1] != '_')
+ return check_type();
assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL);
dbuf_init(&asmbuff, INITIAL_INLINEASM);
BEGIN(asm);
}
assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL);
dbuf_init(&asmbuff, INITIAL_INLINEASM);
BEGIN(asm);
}
-<asm>"_endasm" {
+<asm>
_?
"_endasm" {
count();
count();
- yylval.yyinline = dbuf_c_str(&asmbuff);
- dbuf_detach(&asmbuff);
- BEGIN(INITIAL);
- return (INLINEASM);
+ if (!options.std_sdcc && yytext[1] != '_')
+ {
+ dbuf_append(&asmbuff, yytext, strlen(yytext));
+ }
+ else
+ {
+ yylval.yyinline = dbuf_c_str(&asmbuff);
+ dbuf_detach(&asmbuff);
+ BEGIN(INITIAL);
+ return (INLINEASM);
+ }
}
<asm>\n {
count();
}
<asm>\n {
count();
@@
-81,47
+95,75
@@
static int checkCurrFile(char *s);
<asm>. {
dbuf_append(&asmbuff, yytext, 1);
}
<asm>. {
dbuf_append(&asmbuff, yytext, 1);
}
-"at" { count(); TKEYWORD(AT); }
+"at" { count(); TKEYWORDSDCC(AT); }
+"__at" { count(); TKEYWORD(AT); }
"auto" { count(); return(AUTO); }
"auto" { count(); return(AUTO); }
-"bit" { count(); TKEYWORD(BIT); }
+"bit" { count(); TKEYWORDSDCC(BIT); }
+"__bit" { count(); TKEYWORD(BIT); }
"break" { count(); return(BREAK); }
"case" { count(); return(CASE); }
"char" { count(); return(CHAR); }
"break" { count(); return(BREAK); }
"case" { count(); return(CASE); }
"char" { count(); return(CHAR); }
-"code" { count(); TKEYWORD(CODE); }
+"code" { count(); TKEYWORDSDCC(CODE); }
+"__code" { count(); TKEYWORD(CODE); }
"const" { count(); return(CONST); }
"continue" { count(); return(CONTINUE); }
"const" { count(); return(CONST); }
"continue" { count(); return(CONTINUE); }
-"critical" { count(); TKEYWORD(CRITICAL); }
-"data" { count(); TKEYWORD(DATA); }
+"critical" { count(); TKEYWORDSDCC(CRITICAL); }
+"__critical" { count(); TKEYWORD(CRITICAL); }
+"data" { count(); TKEYWORDSDCC(DATA); }
+"__data" { count(); TKEYWORD(DATA); }
"default" { count(); return(DEFAULT); }
"do" { count(); return(DO); }
"double" { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); }
"else" { count(); return(ELSE); }
"enum" { count(); return(ENUM); }
"extern" { count(); return(EXTERN); }
"default" { count(); return(DEFAULT); }
"do" { count(); return(DO); }
"double" { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); }
"else" { count(); return(ELSE); }
"enum" { count(); return(ENUM); }
"extern" { count(); return(EXTERN); }
-"far" { count(); TKEYWORD(XDATA); }
-"eeprom" { count(); TKEYWORD(EEPROM); }
+"far" { count(); TKEYWORDSDCC(XDATA); }
+"__far" { count(); TKEYWORD(XDATA); }
+"eeprom" { count(); TKEYWORDSDCC(EEPROM); }
+"__eeprom" { count(); TKEYWORD(EEPROM); }
"float" { count(); return(FLOAT); }
"float" { count(); return(FLOAT); }
-"flash" { count(); TKEYWORD(CODE); }
+"fixed16x16" { count(); TKEYWORDSDCC(FIXED16X16); }
+"__fixed16x16" { count(); TKEYWORD(FIXED16X16); }
+"flash" { count(); TKEYWORDSDCC(CODE); }
+"__flash" { count(); TKEYWORD(CODE); }
"for" { count(); return(FOR); }
"goto" { count(); return(GOTO); }
"for" { count(); return(FOR); }
"goto" { count(); return(GOTO); }
-"idata" { count(); TKEYWORD(IDATA); }
+"idata" { count(); TKEYWORDSDCC(IDATA); }
+"__idata" { count(); TKEYWORD(IDATA); }
"if" { count(); return(IF); }
"int" { count(); return(INT); }
"if" { count(); return(IF); }
"int" { count(); return(INT); }
-"interrupt" { count(); return(INTERRUPT); }
-"nonbanked" { count(); TKEYWORD(NONBANKED); }
-"banked" { count(); TKEYWORD(BANKED); }
+"interrupt" { count(); TKEYWORDSDCC(INTERRUPT); }
+"__interrupt" { count(); TKEYWORD(INTERRUPT); }
+"nonbanked" { count(); TKEYWORDSDCC(NONBANKED); }
+"__nonbanked" { count(); TKEYWORD(NONBANKED); }
+"banked" { count(); TKEYWORDSDCC(BANKED); }
+"__banked" { count(); TKEYWORD(BANKED); }
"long" { count(); return(LONG); }
"long" { count(); return(LONG); }
-"near" { count(); TKEYWORD(DATA); }
-"pdata" { count(); TKEYWORD(PDATA); }
-"reentrant" { count(); TKEYWORD(REENTRANT); }
+"near" { count(); TKEYWORDSDCC(DATA); }
+"__near" { count(); TKEYWORD(DATA); }
+"pdata" { count(); TKEYWORDSDCC(PDATA); }
+"__pdata" { count(); TKEYWORD(PDATA); }
+"reentrant" { count(); TKEYWORDSDCC(REENTRANT); }
+"__reentrant" { count(); TKEYWORD(REENTRANT); }
+"shadowregs" { count(); TKEYWORDSDCC(SHADOWREGS); }
+"__shadowregs" { count(); TKEYWORD(SHADOWREGS); }
+"wparam" { count(); TKEYWORDSDCC(WPARAM); }
+"__wparam" { count(); TKEYWORD(WPARAM); }
"register" { count(); return(REGISTER); }
"return" { count(); return(RETURN); }
"register" { count(); return(REGISTER); }
"return" { count(); return(RETURN); }
-"sfr" { count(); TKEYWORD(SFR); }
-"sbit" { count(); TKEYWORD(SBIT); }
+"sfr" { count(); TKEYWORDSDCC(SFR); }
+"__sfr" { count(); TKEYWORD(SFR); }
+"sfr16" { count(); TKEYWORDSDCC(SFR16); }
+"__sfr16" { count(); TKEYWORD(SFR16); }
+"sfr32" { count(); TKEYWORDSDCC(SFR32); }
+"__sfr32" { count(); TKEYWORD(SFR32); }
+"sbit" { count(); TKEYWORDSDCC(SBIT); }
+"__sbit" { count(); TKEYWORD(SBIT); }
"short" { count(); return(SHORT); }
"signed" { count(); return(SIGNED); }
"sizeof" { count(); return(SIZEOF); }
"short" { count(); return(SHORT); }
"signed" { count(); return(SIGNED); }
"sizeof" { count(); return(SIZEOF); }
-"sram" { count(); TKEYWORD(XDATA); }
+"sram" { count(); TKEYWORDSDCC(XDATA); }
+"__sram" { count(); TKEYWORD(XDATA); }
"static" { count(); return(STATIC); }
"struct" { count(); return(STRUCT); }
"switch" { count(); return(SWITCH); }
"static" { count(); return(STATIC); }
"struct" { count(); return(STRUCT); }
"switch" { count(); return(SWITCH); }
@@
-130,14
+172,20
@@
static int checkCurrFile(char *s);
"unsigned" { count(); return(UNSIGNED); }
"void" { count(); return(VOID); }
"volatile" { count(); return(VOLATILE); }
"unsigned" { count(); return(UNSIGNED); }
"void" { count(); return(VOID); }
"volatile" { count(); return(VOLATILE); }
-"using" { count(); TKEYWORD(USING); }
-"_naked" { count(); TKEYWORD(NAKED); }
+"using" { count(); TKEYWORDSDCC(USING); }
+"__using" { count(); TKEYWORD(USING); }
+"_naked" { count(); TKEYWORDSDCC(NAKED); }
+"__naked" { count(); TKEYWORD(NAKED); }
"while" { count(); return(WHILE); }
"while" { count(); return(WHILE); }
-"xdata" { count(); TKEYWORD(XDATA); }
+"xdata" { count(); TKEYWORDSDCC(XDATA); }
+"__xdata" { count(); TKEYWORD(XDATA); }
"..." { count(); return(VAR_ARGS); }
"__typeof" { count(); return TYPEOF; }
"_JavaNative" { count(); TKEYWORD(JAVANATIVE); }
"..." { count(); return(VAR_ARGS); }
"__typeof" { count(); return TYPEOF; }
"_JavaNative" { count(); TKEYWORD(JAVANATIVE); }
-"_overlay" { count(); TKEYWORD(OVERLAY); }
+"_overlay" { count(); TKEYWORDSDCC(OVERLAY); }
+"__overlay" { count(); TKEYWORD(OVERLAY); }
+"inline" { count(); TKEYWORD99(INLINE); }
+"restrict" { count(); TKEYWORD99(RESTRICT); }
{L}({L}|{D})* { count(); return(check_type()); }
0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
0[0-7]*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
{L}({L}|{D})* { count(); return(check_type()); }
0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
0[0-7]*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); }
@@
-236,7
+284,7
@@
static int checkCurrFile (char *s)
/* get the line number */
lNum = strtol(s, &tptr, 10);
/* get the line number */
lNum = strtol(s, &tptr, 10);
- if (tptr == s || !isspace(*tptr))
+ if (tptr == s || !isspace(
(unsigned char)
*tptr))
return 0;
s = tptr;
return 0;
s = tptr;
@@
-419,7
+467,13
@@
enum pragma_id {
P_DISABLEWARN,
P_OPTCODESPEED,
P_OPTCODESIZE,
P_DISABLEWARN,
P_OPTCODESPEED,
P_OPTCODESIZE,
- P_OPTCODEBALANCED
+ P_OPTCODEBALANCED,
+ P_STD_C89,
+ P_STD_C99,
+ P_STD_SDCC89,
+ P_STD_SDCC99,
+ P_CODESEG,
+ P_CONSTSEG
};
};
@@
-428,6
+482,7
@@
enum pragma_id {
STACK_DCL(options_stack, struct options *, SAVE_RESTORE_SIZE)
STACK_DCL(optimize_stack, struct optimize *, SAVE_RESTORE_SIZE)
STACK_DCL(options_stack, struct options *, SAVE_RESTORE_SIZE)
STACK_DCL(optimize_stack, struct optimize *, SAVE_RESTORE_SIZE)
+STACK_DCL(SDCCERRG_stack, struct SDCCERRG *, SAVE_RESTORE_SIZE)
/*
* cloneXxx functions should be updated every time a new set is
/*
* cloneXxx functions should be updated every time a new set is
@@
-456,7
+511,7
@@
static struct optimize *cloneOptimize(struct optimize *opt)
{
struct optimize *new_opt;
{
struct optimize *new_opt;
- new_opt = Safe_malloc(sizeof (struct opti
ons
));
+ new_opt = Safe_malloc(sizeof (struct opti
mize
));
/* clone scalar values */
*new_opt = *opt;
/* clone scalar values */
*new_opt = *opt;
@@
-464,6
+519,18
@@
static struct optimize *cloneOptimize(struct optimize *opt)
return new_opt;
}
return new_opt;
}
+static struct SDCCERRG *cloneSDCCERRG (struct SDCCERRG *val)
+{
+ struct SDCCERRG *new_val;
+
+ new_val = Safe_malloc(sizeof (struct SDCCERRG));
+
+ /* clone scalar values */
+ *new_val = *val;
+
+ return new_val;
+}
+
static void copyAndFreeOptions(struct options *dest, struct options *src)
{
/* delete dest sets */
static void copyAndFreeOptions(struct options *dest, struct options *src)
{
/* delete dest sets */
@@
-472,7
+539,7
@@
static void copyAndFreeOptions(struct options *dest, struct options *src)
/* not implemented yet: */
/* deleteSet(&dest->olaysSet); */
/* not implemented yet: */
/* deleteSet(&dest->olaysSet); */
- /*
d
opy src to dest */
+ /*
c
opy src to dest */
*dest = *src;
Safe_free(src);
*dest = *src;
Safe_free(src);
@@
-480,7
+547,15
@@
static void copyAndFreeOptions(struct options *dest, struct options *src)
static void copyAndFreeOptimize(struct optimize *dest, struct optimize *src)
{
static void copyAndFreeOptimize(struct optimize *dest, struct optimize *src)
{
- /* dopy src to dest */
+ /* copy src to dest */
+ *dest = *src;
+
+ Safe_free(src);
+}
+
+static void copyAndFreeSDCCERRG(struct SDCCERRG *dest, struct SDCCERRG *src)
+{
+ /* copy src to dest */
*dest = *src;
Safe_free(src);
*dest = *src;
Safe_free(src);
@@
-495,6
+570,7
@@
static void doPragma(int op, char *cp)
{
STACK_PUSH(options_stack, cloneOptions(&options));
STACK_PUSH(optimize_stack, cloneOptimize(&optimize));
{
STACK_PUSH(options_stack, cloneOptions(&options));
STACK_PUSH(optimize_stack, cloneOptimize(&optimize));
+ STACK_PUSH(SDCCERRG_stack, cloneSDCCERRG(&_SDCCERRG));
}
break;
}
break;
@@
-502,12
+578,16
@@
static void doPragma(int op, char *cp)
{
struct options *optionsp;
struct optimize *optimizep;
{
struct options *optionsp;
struct optimize *optimizep;
+ struct SDCCERRG *sdccerrgp;
optionsp = STACK_POP(options_stack);
copyAndFreeOptions(&options, optionsp);
optimizep = STACK_POP(optimize_stack);
copyAndFreeOptimize(&optimize, optimizep);
optionsp = STACK_POP(options_stack);
copyAndFreeOptions(&options, optionsp);
optimizep = STACK_POP(optimize_stack);
copyAndFreeOptimize(&optimize, optimizep);
+
+ sdccerrgp = STACK_POP(SDCCERRG_stack);
+ copyAndFreeSDCCERRG(&_SDCCERRG, sdccerrgp);
}
break;
}
break;
@@
-541,6
+621,7
@@
static void doPragma(int op, char *cp)
case P_LESSPEDANTIC:
options.lessPedantic = 1;
case P_LESSPEDANTIC:
options.lessPedantic = 1;
+ setErrorLogLevel(ERROR_LEVEL_WARNING);
break;
case P_CALLEE_SAVES:
break;
case P_CALLEE_SAVES:
@@
-588,7
+669,48
@@
static void doPragma(int op, char *cp)
optimize.codeSpeed = 0;
optimize.codeSize = 0;
break;
optimize.codeSpeed = 0;
optimize.codeSize = 0;
break;
+
+ case P_STD_C89:
+ options.std_c99 = 0;
+ options.std_sdcc = 0;
+ break;
+
+ case P_STD_C99:
+ options.std_c99 = 1;
+ options.std_sdcc = 0;
+ break;
+
+ case P_STD_SDCC89:
+ options.std_c99 = 0;
+ options.std_sdcc = 1;
+ break;
+
+ case P_STD_SDCC99:
+ options.std_c99 = 1;
+ options.std_sdcc = 1;
+ break;
+ case P_CODESEG:
+ {
+ char str[9];
+ char *segname = Safe_malloc(15);
+ sscanf(cp, " %8s", str);
+ str[8] = '\0';
+ sprintf(segname, "%-8.8s(CODE)", str);
+ options.code_seg = segname;
+ }
+ break;
+
+ case P_CONSTSEG:
+ {
+ char str[9];
+ char *segname = Safe_malloc(15);
+ sscanf(cp, " %8s", str);
+ str[8] = '\0';
+ sprintf(segname, "%-8.8s(CODE)", str);
+ options.const_seg = segname;
+ }
+ break;
}
}
}
}
@@
-623,6
+745,12
@@
static int process_pragma(char *s)
{ "opt_code_speed", P_OPTCODESPEED, 0 },
{ "opt_code_size", P_OPTCODESIZE, 0 },
{ "opt_code_balanced", P_OPTCODEBALANCED, 0 },
{ "opt_code_speed", P_OPTCODESPEED, 0 },
{ "opt_code_size", P_OPTCODESIZE, 0 },
{ "opt_code_balanced", P_OPTCODEBALANCED, 0 },
+ { "std_c89", P_STD_C89, 0 },
+ { "std_c99", P_STD_C99, 0 },
+ { "std_sdcc89", P_STD_SDCC89, 0 },
+ { "std_sdcc99", P_STD_SDCC99, 0 },
+ { "codeseg", P_CODESEG, 0 },
+ { "constseg", P_CONSTSEG, 0 },
/*
* The following lines are deprecated pragmas,
/*
* The following lines are deprecated pragmas,
@@
-655,14
+783,18
@@
static int process_pragma(char *s)
s += PRAGMA_LEN;
/* look for the directive */
s += PRAGMA_LEN;
/* look for the directive */
- while(isspace(*s))
+ while(isspace(
(unsigned char)
*s))
s++;
cp = s;
/* look for the end of the directive */
s++;
cp = s;
/* look for the end of the directive */
- while ((!isspace(*s)) && (*s != '\n'))
+ while ((!isspace(
(unsigned char)
*s)) && (*s != '\n'))
s++ ;
s++ ;
+ /* skip separating whitespace */
+ while (isspace((unsigned char)*s) && (*s != '\n'))
+ s++;
+
/* First give the port a chance */
if (port->process_pragma && !port->process_pragma(cp))
return 0;
/* First give the port a chance */
if (port->process_pragma && !port->process_pragma(cp))
return 0;
@@
-677,7
+809,7
@@
static int process_pragma(char *s)
if (pragma_tbl[i].deprecated != 0)
werror(W_DEPRECATED_PRAGMA, pragma_tbl[i].name);
if (pragma_tbl[i].deprecated != 0)
werror(W_DEPRECATED_PRAGMA, pragma_tbl[i].name);
- doPragma(pragma_tbl[i].id,
cp + len
);
+ doPragma(pragma_tbl[i].id,
s
);
return 0;
}
}
return 0;
}
}
@@
-694,12
+826,30
@@
static int isTargetKeyword(char *s)
if (port->keywords == NULL)
return 0;
if (port->keywords == NULL)
return 0;
- for (i = 0 ; port->keywords[i] ; i++ ) {
- if (strcmp(port->keywords[i],s) == 0)
- return 1;
- }
+
+ if (s[0] == '_' && s[1] == '_')
+ {
+ /* Keywords in the port's array have either 0 or 1 underscore, */
+ /* so skip over the appropriate number of chars when comparing */
+ for (i = 0 ; port->keywords[i] ; i++ )
+ {
+ if (port->keywords[i][0] == '_' &&
+ strcmp(port->keywords[i],s+1) == 0)
+ return 1;
+ else if (strcmp(port->keywords[i],s+2) == 0)
+ return 1;
+ }
+ }
+ else
+ {
+ for (i = 0 ; port->keywords[i] ; i++ )
+ {
+ if (strcmp(port->keywords[i],s) == 0)
+ return 1;
+ }
+ }
-
return 0;
+ return 0;
}
int yywrap(void)
}
int yywrap(void)