From e42c2c9ad13038699b8e8b7330fa7506a721626a Mon Sep 17 00:00:00 2001 From: epetrich Date: Sat, 26 Mar 2005 06:07:40 +0000 Subject: [PATCH] * src/SDCCmain.c (setDefaultOptions, optionsTable[], parseCmdLine), * src/z80/main.c (_keywords[]), * src/SDCCglobal.h (struct options), * src/SDCC.y, * src/SDCC.lex (isTargetKeyword, doPragma, pragma_tbl[]): new pragmas to enable/disable SDCC and C99 extensions/keywords (std_c89, std_sdcc89, std_c99, std_sdcc99). Also, equivalent command line options (--std-c89, --std-sdcc89, --std-c99, --std-sdcc99). SDCC specific keywords are always available in leading double underscore form. The C99 support is mostly missing, but it's a start. * support/regression/tests/bug-227710.c: fixed nonconforming use of reserved identifier "__data". git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3707 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 15 +++ src/SDCC.lex | 159 ++++++++++++++++++++------ src/SDCC.y | 2 +- src/SDCCglobl.h | 2 + src/SDCCmain.c | 40 ++++++- src/z80/main.c | 1 + support/regression/tests/bug-227710.c | 4 +- 7 files changed, 182 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index e91caa9c..6bd37ede 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-03-26 Erik Petrich + + * src/SDCCmain.c (setDefaultOptions, optionsTable[], parseCmdLine), + * src/z80/main.c (_keywords[]), + * src/SDCCglobal.h (struct options), + * src/SDCC.y, + * src/SDCC.lex (isTargetKeyword, doPragma, pragma_tbl[]): new pragmas + to enable/disable SDCC and C99 extensions/keywords (std_c89, std_sdcc89, + std_c99, std_sdcc99). Also, equivalent command line options (--std-c89, + --std-sdcc89, --std-c99, --std-sdcc99). SDCC specific keywords are + always available in leading double underscore form. The C99 support is + mostly missing, but it's a start. + * support/regression/tests/bug-227710.c: fixed nonconforming use of + reserved identifier "__data". + 2005-03-24 Maarten Brock * src/mcs51/peeph.def: fixed bug 1170013 diff --git a/src/SDCC.lex b/src/SDCC.lex index 43074e9d..169d9aea 100644 --- 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 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; @@ -61,18 +66,27 @@ static int checkCurrFile(char *s); %x asm %% -"_asm" { +_?"_asm" { 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); } -"_endasm" { +_?"_endasm" { 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); + } } \n { count(); @@ -81,49 +95,69 @@ static int checkCurrFile(char *s); . { dbuf_append(&asmbuff, yytext, 1); } -"at" { count(); TKEYWORD(AT); } +"at" { count(); TKEYWORDSDCC(AT); } +"__at" { count(); TKEYWORD(AT); } "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); } -"code" { count(); TKEYWORD(CODE); } +"code" { count(); TKEYWORDSDCC(CODE); } +"__code" { count(); TKEYWORD(CODE); } "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); } -"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); } -"flash" { count(); TKEYWORD(CODE); } +"flash" { count(); TKEYWORDSDCC(CODE); } +"__flash" { count(); TKEYWORD(CODE); } "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); } -"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); } -"near" { count(); TKEYWORD(DATA); } -"pdata" { count(); TKEYWORD(PDATA); } -"reentrant" { count(); TKEYWORD(REENTRANT); } -"shadowregs" { count(); TKEYWORD(SHADOWREGS); } -"wparam" { count(); TKEYWORD(WPARAM); } +"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); } -"sfr" { count(); TKEYWORD(SFR); } -"sbit" { count(); TKEYWORD(SBIT); } +"sfr" { count(); TKEYWORDSDCC(SFR); } +"__sfr" { count(); TKEYWORD(SFR); } +"sbit" { count(); TKEYWORDSDCC(SBIT); } +"__sbit" { count(); TKEYWORD(SBIT); } "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); } @@ -132,14 +166,20 @@ static int checkCurrFile(char *s); "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); } -"xdata" { count(); TKEYWORD(XDATA); } +"xdata" { count(); TKEYWORDSDCC(XDATA); } +"__xdata" { count(); TKEYWORD(XDATA); } "..." { 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); } @@ -421,7 +461,11 @@ enum pragma_id { P_DISABLEWARN, P_OPTCODESPEED, P_OPTCODESIZE, - P_OPTCODEBALANCED + P_OPTCODEBALANCED, + P_STD_C89, + P_STD_C99, + P_STD_SDCC89, + P_STD_SDCC99 }; @@ -617,7 +661,26 @@ static void doPragma(int op, char *cp) 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; } } @@ -652,6 +715,10 @@ static int process_pragma(char *s) { "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 }, /* * The following lines are deprecated pragmas, @@ -727,12 +794,30 @@ static int isTargetKeyword(char *s) 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) diff --git a/src/SDCC.y b/src/SDCC.y index 3e3c7b3e..0a4f6a8d 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -99,7 +99,7 @@ bool uselessDecl = TRUE; %token BITWISEAND UNARYMINUS IPUSH IPOP PCALL ENDFUNCTION JUMPTABLE %token RRC RLC %token CAST CALL PARAM NULLOP BLOCK LABEL RECEIVE SEND ARRAYINIT -%token DUMMY_READ_VOLATILE ENDCRITICAL SWAP +%token DUMMY_READ_VOLATILE ENDCRITICAL SWAP INLINE RESTRICT %type Interrupt_storage %type identifier declarator declarator2 declarator3 enumerator_list enumerator diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index b60bc26d..8e4e7dc1 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -251,6 +251,8 @@ struct options int vc_err_style; /* errors and warnings are compatible with Micro$oft visual studio */ int use_stdout; /* send errors to stdout instead of stderr */ int no_std_crt0; /*For the z80/gbz80 do not link default crt0.o*/ + int std_c99; /* enable C99 keywords/constructs */ + int std_sdcc; /* enable SDCC extensions to C */ /* sets */ set *calleeSavesSet; /* list of functions using callee save */ set *excludeRegsSet; /* registers excluded from saving */ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 86440ad3..8f6b7c75 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -135,6 +135,10 @@ char buffer[PATH_MAX * 2]; #define OPTION_NO_PEEP_COMMENTS "--no-peep-comments" #define OPTION_OPT_CODE_SPEED "--opt-code-speed" #define OPTION_OPT_CODE_SIZE "--opt-code-size" +#define OPTION_STD_C89 "--std-c89" +#define OPTION_STD_C99 "--std-c99" +#define OPTION_STD_SDCC89 "--std-sdcc89" +#define OPTION_STD_SDCC99 "--std-sdcc99" static const OPTION optionsTable[] = { @@ -165,7 +169,11 @@ optionsTable[] = { { 0, OPTION_DISABLE_WARNING, NULL, " Disable specific warning" }, { 0, "--debug", &options.debug, "Enable debugging symbol output" }, { 0, "--cyclomatic", &options.cyclomatic, "Display complexity of compiled functions" }, - + { 0, OPTION_STD_C89, NULL, "Use C89 standard only" }, + { 0, OPTION_STD_SDCC89, NULL, "Use C89 standard with SDCC extensions (default)" }, + { 0, OPTION_STD_C99, NULL, "Use C99 standard only (incomplete)" }, + { 0, OPTION_STD_SDCC99, NULL, "Use C99 standard with SDCC extensions (incomplete)" }, + { 0, NULL, NULL, "Code generation options"}, { 'm', NULL, NULL, "Set the port to use e.g. -mz80." }, { 'p', NULL, NULL, "Select port specific processor e.g. -mpic14 -p16f84" }, @@ -548,6 +556,8 @@ setDefaultOptions (void) options.nostdinc = 0; options.verbose = 0; options.shortis8bits = 0; + options.std_sdcc = 1; /* enable SDCC language extensions */ + options.std_c99 = 0; /* default to C89 until more C99 support */ options.stack10bit=0; @@ -1078,6 +1088,34 @@ parseCmdLine (int argc, char **argv) continue; } + if (strcmp (argv[i], OPTION_STD_C89) == 0) + { + options.std_c99 = 0; + options.std_sdcc = 0; + continue; + } + + if (strcmp (argv[i], OPTION_STD_C99) == 0) + { + options.std_c99 = 1; + options.std_sdcc = 0; + continue; + } + + if (strcmp (argv[i], OPTION_STD_SDCC89) == 0) + { + options.std_c99 = 0; + options.std_sdcc = 1; + continue; + } + + if (strcmp (argv[i], OPTION_STD_SDCC99) == 0) + { + options.std_c99 = 1; + options.std_sdcc = 1; + continue; + } + if (!port->parseOption (&argc, argv, &i)) { werror (W_UNKNOWN_OPTION, argv[i]); diff --git a/src/z80/main.c b/src/z80/main.c index 8fb6b0a2..3706b172 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -82,6 +82,7 @@ static char *_keywords[] = "at", //.p.t.20030714 adding support for 'sfr at ADDR' construct "_naked", //.p.t.20030714 adding support for '_naked' functions "critical", + "interrupt", NULL }; diff --git a/support/regression/tests/bug-227710.c b/support/regression/tests/bug-227710.c index bd16d669..013ddea8 100644 --- a/support/regression/tests/bug-227710.c +++ b/support/regression/tests/bug-227710.c @@ -2,7 +2,7 @@ */ #include -static unsigned char __data[] = { +static unsigned char dataset[] = { 1, 2, 3, 4 }; @@ -22,7 +22,7 @@ foo(void) void testPostIncrement(void) { - p = __data; + p = dataset; ASSERT(foo() == 1); ASSERT(foo() == 2); ASSERT(foo() == 3); -- 2.30.2