From e8f8c8a5a143a088419bcd33fe3591c54f3fb128 Mon Sep 17 00:00:00 2001 From: borutr Date: Thu, 7 Aug 2008 21:44:41 +0000 Subject: [PATCH] * src/SDCCval.c, src/SDCCmain.c, src/SDCC.lex, device/lib/pic/Makefile.rules, device/lib/ds390/Makefile.in, device/lib/ds400/Makefile.in, device/lib/hc08/Makefile.in, support/cpp/libcpp/lex.c, doc/sdccman.lyx: applied modified patsh 2038174: Add support for binary constants v2 thanks Mauro Giachero git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5205 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 17 +++++-- device/lib/ds390/Makefile.in | 2 +- device/lib/ds400/Makefile.in | 2 +- device/lib/hc08/Makefile.in | 2 +- device/lib/pic/Makefile.rules | 2 +- doc/sdccman.lyx | 35 +++++++++++++ src/SDCC.lex | 10 ++++ src/SDCCmain.c | 16 +++++- src/SDCCval.c | 31 +++++------- support/cpp/libcpp/lex.c | 95 +++++++++++++++++++++++++---------- 10 files changed, 159 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 069ab8ed..13c22265 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-08-07 Borut Razem + + * src/SDCCval.c, src/SDCCmain.c, src/SDCC.lex, + device/lib/pic/Makefile.rules, device/lib/ds390/Makefile.in, + device/lib/ds400/Makefile.in, device/lib/hc08/Makefile.in, + support/cpp/libcpp/lex.c, doc/sdccman.lyx: + applied modified patsh 2038174: Add support for binary constants v2 + thanks Mauro Giachero + 2008-08-04 Raphael Neider * doc/sdccman.lyx, @@ -1081,8 +1090,8 @@ 2007-11-12 Borut Razem - * as\z80\asmain.c, as\z80\asm.h, as\z80\assym.c, as\z80\asdata.c, - as\z80\asout.c, as\z80\aslist.c: + * as/z80/asmain.c, as/z80/asm.h, as/z80/assym.c, as/z80/asdata.c, + as/z80/asout.c, as/z80/aslist.c: fixed bug #1817005 - as-z80 chokes on long labels 2007-11-11 Maarten Brock @@ -5551,8 +5560,8 @@ 2006-04-18 Borut Razem - * support/scripts/sdcc.nsi: removed unexisting ${DEV_ROOT}\lib\pic\*.o, - ${DEV_ROOT}\lib\src\pic\libdev\*.S, ${DEV_ROOT}\lib\src\pic\libdev\*.inc + * support/scripts/sdcc.nsi: removed unexisting ${DEV_ROOT}/lib/pic/*.o, + ${DEV_ROOT}/lib/src/pic/libdev/*.S, ${DEV_ROOT}/lib/src/pic/libdev/*.inc 2006-04-17 Borut Razem diff --git a/device/lib/ds390/Makefile.in b/device/lib/ds390/Makefile.in index 3dda5c5c..4dbedf34 100644 --- a/device/lib/ds390/Makefile.in +++ b/device/lib/ds390/Makefile.in @@ -10,7 +10,7 @@ OBJECTS = tinibios.rel memcpyx.rel lcd390.rel i2c390.rel rtc390.rel putchar.rel SOURCES = $(patsubst %.rel,%.c,$(OBJECTS)) CPPFLAGS = -I$(srcdir)/../../include -CFLAGS = -mds390 $(CPPFLAGS) $(VERBOSE) --std-c89 +CFLAGS = -mds390 $(CPPFLAGS) $(VERBOSE) --std-c99 all: $(OBJECTS) libds390.lib diff --git a/device/lib/ds400/Makefile.in b/device/lib/ds400/Makefile.in index fab404a6..234df089 100644 --- a/device/lib/ds400/Makefile.in +++ b/device/lib/ds400/Makefile.in @@ -10,7 +10,7 @@ OBJECTS = tinibios.rel memcpyx.rel ds400rom.rel SOURCES = $(patsubst %.rel,%.c,$(OBJECTS)) CPPFLAGS = -I$(srcdir)/../../include -CFLAGS = -mds400 $(CPPFLAGS) $(VERBOSE) --std-c89 +CFLAGS = -mds400 $(CPPFLAGS) $(VERBOSE) --std-c99 all: $(OBJECTS) libds400.lib diff --git a/device/lib/hc08/Makefile.in b/device/lib/hc08/Makefile.in index 5482da00..56596653 100644 --- a/device/lib/hc08/Makefile.in +++ b/device/lib/hc08/Makefile.in @@ -15,7 +15,7 @@ CC = $(SCC) AS = $(SAS) ASFLAGS = -plosgff -CFLAGS = -I$(srcdir)/../../include -I. --std-c89 +CFLAGS = -I$(srcdir)/../../include -I. --std-c99 all: $(LIB) diff --git a/device/lib/pic/Makefile.rules b/device/lib/pic/Makefile.rules index 3cb7efb8..6813ae03 100644 --- a/device/lib/pic/Makefile.rules +++ b/device/lib/pic/Makefile.rules @@ -58,7 +58,7 @@ recurse : force $(Q)+for DIR in $(SUBDIRS) ; do \ [ -f "$(srcdir)/$${DIR}.ignore" ] && $(GREP) "^$${ARCH}$$" "$${DIR}.ignore" > /dev/null 2>&1 || ( \ $(MKDIR) "$(top_builddir)/$(builddir)/$${DIR}"; \ - $(MAKE) -C "$${DIR}" builddir="$(builddir)/$${DIR}" $(MAKECMDGOALS); \ + CFLAGS="$(CFLAGS)" $(MAKE) -C "$${DIR}" builddir="$(builddir)/$${DIR}" $(MAKECMDGOALS); \ ) || exit 1; \ done else diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 746bb8be..f0035c83 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -1158,6 +1158,14 @@ b = !b; /* toggles b */ In previous versions, both forms would have toggled the bit. \end_layout +\begin_layout Itemize +in older versions, the preprocessor was always called with -std=c99 regardless + of the --std-xxx setting. + This is no longer true, and can cause compilation failures on code built + with --std-c89 but using c99 preprocessor features, such as one-line (//) + comments +\end_layout + \begin_layout Standard \emph on @@ -8028,6 +8036,7 @@ linkOption[,linkOption] \end_inset + \begin_inset LatexCommand \label{lyx:-Wl option} \end_inset @@ -10834,6 +10843,7 @@ status collapsed \end_inset + \begin_inset LatexCommand \label{lyx:-codeseg} \end_inset @@ -13213,6 +13223,31 @@ The xdata storage class declares a variable that can reside anywhere in \end_inset +\end_layout + +\begin_layout Section +Other SDCC language extensions +\begin_inset LatexCommand \index{Other SDCC language extensions} + +\end_inset + + +\end_layout + +\begin_layout Subsection +Binary constants +\end_layout + +\begin_layout Standard +SDCC supports the use of binary constants, such as 0b01100010. + This feature is only enabled when the compiler is invoked using --std-sdccxx. +\end_layout + +\begin_layout Standard +\begin_inset VSpace bigskip +\end_inset + + \end_layout \begin_layout Section diff --git a/src/SDCC.lex b/src/SDCC.lex index 6567003c..0fc43d00 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -22,6 +22,7 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +B [0-1] D [0-9] L [a-zA-Z_$] H [a-fA-F0-9] @@ -199,6 +200,15 @@ _?"_asm" { count(); return(check_type()); } +0[bB]{B}+{IS}? { + if (!options.std_sdcc) + { + yyerror("binary (0b) constants are not allowed in ISO C"); + } + count(); + yylval.val = constVal(yytext); + return(CONSTANT); +} 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } 0[0-7]*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } [1-9]{D}*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } diff --git a/src/SDCCmain.c b/src/SDCCmain.c index ec234ecb..cfdbb10a 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -283,7 +283,7 @@ static const char *_baseValues[] = { NULL }; -static const char *_preCmd = "{cpp} -nostdinc -Wall -std=c99 {cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\""; +static const char *_preCmd = "{cpp} -nostdinc -Wall {cppstd}{cppextraopts} \"{fullsrcfilename}\" \"{cppoutfilename}\""; PORT *port; @@ -2254,6 +2254,20 @@ initValues (void) setMainValue ("linkdstfilename", "{stdlinkdstfilename}"); } + /* + * Make sure the preprocessor is called with the "-std" option + * corresponding to the --std used to start sdcc + */ + if (options.std_c99) + { + if (!options.std_sdcc) + setMainValue ("cppstd", "-std=c99 "); + } + else + { + if (!options.std_sdcc) + setMainValue ("cppstd", "-std=c89 "); + } } static void doPrintSearchDirs(void) diff --git a/src/SDCCval.c b/src/SDCCval.c index 649388f7..de08d2a6 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -698,9 +698,9 @@ constFixed16x16Val (const char *s) value *constVal (const char *s) { value *val; - bool hex = FALSE, octal = FALSE; char *p; double dval; + bool is_integral = 0; val = newValue (); /* alloc space for value */ @@ -710,27 +710,22 @@ value *constVal (const char *s) SPEC_NOUN (val->type) = V_CHAR; SPEC_USIGN (val->type) = 0; - if (s[0] == '0') - { - if (s[1] == 'x' || s[1] == 'X') - hex = TRUE; - else if (isdigit(s[1])) - octal = TRUE; - } - errno = 0; - if (hex || octal) + if (s[0] == '0') { - dval = strtoul (s, &p, 0); - if (errno) - { - dval = 4294967295.0; - werror (W_INVALID_INT_CONST, s, dval); - } + if (s[1] == 'b' || s[1] == 'B') + dval = strtoul (s + 2, &p, 2); + else + dval = strtoul (s, &p, 0); + is_integral = 1; } else + dval = strtod (s, &p); + + if (errno) { - dval = strtod(s, &p); + dval = 4294967295.0; + werror (W_INVALID_INT_CONST, s, dval); } /* Setup the flags first */ @@ -779,7 +774,7 @@ value *constVal (const char *s) } else if (dval > 0x7fff && !SPEC_USIGN (val->type)) { /* check if we have to promote to long int */ - if ((hex || octal) && /* hex or octal constants may be stored in unsigned type */ + if (is_integral && /* integral (hex, octal and binary) constants may be stored in unsigned type */ dval <= 0xffff) { SPEC_USIGN (val->type) = 1; diff --git a/support/cpp/libcpp/lex.c b/support/cpp/libcpp/lex.c index 78df1dff..ab04177e 100644 --- a/support/cpp/libcpp/lex.c +++ b/support/cpp/libcpp/lex.c @@ -622,7 +622,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) #define get_effective_char(pfile) (*pfile->buffer->cur++) #define BACKUP() (--pfile->buffer->cur) - enum num_type_e { NT_DEC, NT_HEX } num_type = NT_DEC; + enum num_type_e { NT_DEC, NT_HEX, NT_BIN } num_type = NT_DEC; enum num_part_e { NP_WHOLE, NP_FRACT, NP_EXP, NP_INT_SUFFIX, NP_FLOAT_SUFFIX } num_part = NP_WHOLE; uchar c = *(pfile->buffer->cur - 1); @@ -636,7 +636,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_FRACT; ++len; obstack_1grow (stack, '.'); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } else { @@ -645,7 +645,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) has_whole = 1; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); switch (c) { @@ -654,14 +654,25 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_type = NT_HEX; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); + break; + + case 'B': + case 'b': + if (!CPP_OPTION (pfile, std)) + { + num_type = NT_BIN; + ++len; + obstack_1grow (stack, c); + c = get_effective_char (pfile); + } break; case '.': num_part = NP_FRACT; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); break; } } @@ -679,7 +690,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) has_whole = 1; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } if ('.' == c) @@ -687,7 +698,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_FRACT; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } else if ('E' == c || 'e' == c) @@ -697,21 +708,53 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_EXP; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } else break; } } - else + else if (NT_HEX == num_type) { while (ISXDIGIT (c)) { has_whole = 1; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); + } + + if ('.' == c) + { + num_part = NP_FRACT; + ++len; + obstack_1grow (stack, c); + c = get_effective_char (pfile); + continue; + } + else if ('P' == c || 'p' == c) + { + if (has_whole || has_fract) + { + num_part = NP_EXP; + ++len; + obstack_1grow (stack, c); + c = get_effective_char (pfile); + continue; + } + else + break; + } + } + else /* (NT_BIN == num_type) */ + { + while ((c=='0') || (c=='1')) + { + has_whole = 1; + ++len; + obstack_1grow (stack, c); + c = get_effective_char (pfile); } if ('.' == c) @@ -719,7 +762,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_FRACT; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } else if ('P' == c || 'p' == c) @@ -729,7 +772,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_EXP; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } else @@ -747,7 +790,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) has_fract = 1; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } if ('E' == c || 'e' == c) @@ -757,7 +800,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_EXP; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } } @@ -769,7 +812,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) has_fract = 1; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } if ('P' == c || 'p' == c) @@ -779,7 +822,7 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) num_part = NP_EXP; ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); continue; } } @@ -792,14 +835,14 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } while (ISDIGIT (c)) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } num_part = NP_FLOAT_SUFFIX; @@ -812,20 +855,20 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); if (c == prevc) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } } else if ('U' == c || 'u' == c) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } break; @@ -834,13 +877,13 @@ pedantic_lex_number (cpp_reader *pfile, cpp_string *number) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } else if ('L' == c || 'l' == c) { ++len; obstack_1grow (stack, c); - c = get_effective_char(pfile); + c = get_effective_char (pfile); } break; } @@ -1303,7 +1346,7 @@ _cpp_lex_direct (cpp_reader *pfile) { struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; - if (CPP_OPTION(pfile, pedantic_parse_number)) + if (CPP_OPTION (pfile, pedantic_parse_number)) pedantic_lex_number (pfile, &result->val.str); else lex_number (pfile, &result->val.str, &nst); @@ -1341,7 +1384,7 @@ _cpp_lex_direct (cpp_reader *pfile) /* SDCC _asm specific */ /* handle _asm ... _endasm ; */ - if (CPP_OPTION(pfile, preproc_asm) == 0 && result->val.node == pfile->spec_nodes.n__asm) + if (CPP_OPTION (pfile, preproc_asm) == 0 && result->val.node == pfile->spec_nodes.n__asm) { comment_start = buffer->cur; result->type = CPP_ASM; @@ -1484,7 +1527,7 @@ _cpp_lex_direct (cpp_reader *pfile) { struct normalize_state nst = INITIAL_NORMALIZE_STATE; result->type = CPP_NUMBER; - if (CPP_OPTION(pfile, pedantic_parse_number)) + if (CPP_OPTION (pfile, pedantic_parse_number)) pedantic_lex_number (pfile, &result->val.str); else lex_number (pfile, &result->val.str, &nst); -- 2.30.2