From: borutr Date: Fri, 8 Dec 2006 19:18:20 +0000 (+0000) Subject: * support/cpp2/sdcc.h: removed x*alloc() macros X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=fdf251efe9b7d321c8ebbccfecdb999f3b9e11d7;p=fw%2Fsdcc * support/cpp2/sdcc.h: removed x*alloc() macros * support/cpp2/libiberty.h: uncommented out x*alloc() declarations * support/cpp2/Makefile.bcc, support/cpp2/Makefile.in, support/cpp2/sdcpp.sdc: x*alloc files added to the project * support/cpp2/system.h: moved #include "sdcc.h" * support/cpp2/libiberty/xexit.c, support/cpp2/libiberty/xmalloc.c, support/cpp2/libiberty/xstrdup.c, support/cpp2/libiberty/xstrerror.c: added * support/cpp2/sdcppinit.c: added -isysroot, -fsigned-char, -funsigned-char options * support/cpp2/sdcppmain.c: fixed bug 1611411 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4505 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 2978b09f..4aaba94e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-12-08 Borut Razem + + * support/cpp2/sdcc.h: removed x*alloc() macros + * support/cpp2/libiberty.h: uncommented out x*alloc() declarations + * support/cpp2/Makefile.bcc, support/cpp2/Makefile.in, + support/cpp2/sdcpp.sdc: x*alloc files added to the project + * support/cpp2/system.h: moved #include "sdcc.h" + * support/cpp2/libiberty/xexit.c, support/cpp2/libiberty/xmalloc.c, + support/cpp2/libiberty/xstrdup.c, support/cpp2/libiberty/xstrerror.c: + added + * support/cpp2/sdcppinit.c: added -isysroot, -fsigned-char, + -funsigned-char options + * support/cpp2/sdcppmain.c: fixed bug 1611411 + 2006-12-07 Borut Razem * support/cpp2/cpplib.c: reverted sdcpp special handling of _Pragma() diff --git a/support/cpp2/Makefile.bcc b/support/cpp2/Makefile.bcc index f342da16..69728c09 100644 --- a/support/cpp2/Makefile.bcc +++ b/support/cpp2/Makefile.bcc @@ -12,7 +12,8 @@ OBJECTS = sdcppmain.obj sdcppinit.obj \ hashtable.obj mkdeps.obj prefix.obj version.obj mbchar.obj \ line-map.obj cpptrad.obj \ safe-ctype.obj obstack.obj splay-tree.obj lbasename.obj \ - hex.obj concat.obj + hex.obj concat.obj \ + xmalloc.obj xstrdup.obj xexit.obj xstrerror.obj TARGET = $(PRJDIR)/bin/sdcpp.exe @@ -30,3 +31,7 @@ splay-tree.obj: libiberty\splay-tree.c lbasename.obj: libiberty\lbasename.c hex.obj: libiberty\hex.c concat.obj: libiberty\concat.c +xmalloc.obj: libiberty\xmalloc.c +xstrdup.obj: libiberty\xstrdup.c +xexit.obj: libiberty\xexit.c +xstrerror.obj: libiberty\xstrerror.c diff --git a/support/cpp2/Makefile.in b/support/cpp2/Makefile.in index 092a3538..e4561198 100644 --- a/support/cpp2/Makefile.in +++ b/support/cpp2/Makefile.in @@ -221,7 +221,8 @@ libcpp.a: $(LIBCPP_OBJS) -$(RANLIB) libcpp.a MY_LIBIBERTY_BITS = safe-ctype.o obstack.o splay-tree.o \ - lbasename.o hex.o concat.o + lbasename.o hex.o concat.o \ + xmalloc.o xstrdup.o xstrerror.o xexit.o $(TARGET): sdcppmain.o sdcppinit.o $(MY_LIBIBERTY_BITS) libcpp.a $(LIBDEPS) mkdir -p $(dir $@) @@ -253,6 +254,14 @@ hex.o: $(LIBIBERTY_DIR)/hex.c $(CONFIG_H) $(LIBCPP_DEPS) $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) concat.o: $(LIBIBERTY_DIR)/concat.c $(CONFIG_H) $(LIBCPP_DEPS) $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) +xmalloc.o: $(LIBIBERTY_DIR)/xmalloc.c $(CONFIG_H) $(LIBCPP_DEPS) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) +xstrdup.o: $(LIBIBERTY_DIR)/xstrdup.c $(CONFIG_H) $(LIBCPP_DEPS) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) +xexit.o: $(LIBIBERTY_DIR)/xexit.c $(CONFIG_H) $(LIBCPP_DEPS) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) +xstrerror.o: $(LIBIBERTY_DIR)/xstrerror.c $(CONFIG_H) $(LIBCPP_DEPS) + $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION) cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) cppdefault.h Makefile $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ $(PREPROCESSOR_DEFINES) \ diff --git a/support/cpp2/libiberty.h b/support/cpp2/libiberty.h index 1c50e817..c7317755 100644 --- a/support/cpp2/libiberty.h +++ b/support/cpp2/libiberty.h @@ -260,7 +260,6 @@ extern int xatexit (void (*fn) (void)); extern void xexit (int status) ATTRIBUTE_NORETURN; -#if 0 /* SDCC specific */ /* Set the program name used by xmalloc. */ extern void xmalloc_set_program_name (const char *); @@ -296,7 +295,6 @@ extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC; /* Copy an existing memory buffer to a new memory buffer without fail. */ extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC; -#endif /* Physical memory routines. Return values are in BYTES. */ extern double physmem_total (void); diff --git a/support/cpp2/libiberty/xexit.c b/support/cpp2/libiberty/xexit.c new file mode 100644 index 00000000..421e5e23 --- /dev/null +++ b/support/cpp2/libiberty/xexit.c @@ -0,0 +1,52 @@ +/* xexit.c -- Run any exit handlers, then exit. + Copyright (C) 1994, 95, 1997 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, write +to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + +/* + +@deftypefn Replacement void xexit (int @var{code}) + +Terminates the program. If any functions have been registered with +the @code{xatexit} replacement function, they will be called first. +Termination is handled via the system's normal @code{exit} call. + +@end deftypefn + +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#include "libiberty.h" + + +/* This variable is set by xatexit if it is called. This way, xmalloc + doesn't drag xatexit into the link. */ +void (*_xexit_cleanup) (void); + +void +xexit (int code) +{ + if (_xexit_cleanup != NULL) + (*_xexit_cleanup) (); + exit (code); +} diff --git a/support/cpp2/libiberty/xmalloc.c b/support/cpp2/libiberty/xmalloc.c new file mode 100644 index 00000000..3e97aab5 --- /dev/null +++ b/support/cpp2/libiberty/xmalloc.c @@ -0,0 +1,184 @@ +/* memory allocation routines with error checking. + Copyright 1989, 90, 91, 92, 93, 94 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + +/* + +@deftypefn Replacement void* xmalloc (size_t) + +Allocate memory without fail. If @code{malloc} fails, this will print +a message to @code{stderr} (using the name set by +@code{xmalloc_set_program_name}, +if any) and then call @code{xexit}. Note that it is therefore safe for +a program to contain @code{#define malloc xmalloc} in its source. + +@end deftypefn + +@deftypefn Replacement void* xrealloc (void *@var{ptr}, size_t @var{size}) +Reallocate memory without fail. This routine functions like @code{realloc}, +but will behave the same as @code{xmalloc} if memory cannot be found. + +@end deftypefn + +@deftypefn Replacement void* xcalloc (size_t @var{nelem}, size_t @var{elsize}) + +Allocate memory without fail, and set it to zero. This routine functions +like @code{calloc}, but will behave the same as @code{xmalloc} if memory +cannot be found. + +@end deftypefn + +@deftypefn Replacement void xmalloc_set_program_name (const char *@var{name}) + +You can use this to set the name of the program used by +@code{xmalloc_failed} when printing a failure message. + +@end deftypefn + +@deftypefn Replacement void xmalloc_failed (size_t) + +This function is not meant to be called by client code, and is listed +here for completeness only. If any of the allocation routines fail, this +function will be called to print an error message and terminate execution. + +@end deftypefn + +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "ansidecl.h" +#include "libiberty.h" + +#include + +#include + +#if VMS +#include +#include +#else +/* For systems with larger pointers than ints, these must be declared. */ +# if HAVE_STDLIB_H && HAVE_UNISTD_H && HAVE_DECL_MALLOC \ + && HAVE_DECL_REALLOC && HAVE_DECL_CALLOC && HAVE_DECL_SBRK +# include +# include +# else +# ifdef __cplusplus +extern "C" { +# endif /* __cplusplus */ +void *malloc (size_t); +void *realloc (void *, size_t); +void *calloc (size_t, size_t); +void *sbrk (ptrdiff_t); +# ifdef __cplusplus +} +# endif /* __cplusplus */ +# endif /* HAVE_STDLIB_H ... */ +#endif /* VMS */ + +/* The program name if set. */ +static const char *name = ""; + +#ifdef HAVE_SBRK +/* The initial sbrk, set when the program name is set. Not used for win32 + ports other than cygwin32. */ +static char *first_break = NULL; +#endif /* HAVE_SBRK */ + +void +xmalloc_set_program_name (const char *s) +{ + name = s; +#ifdef HAVE_SBRK + /* Win32 ports other than cygwin32 don't have brk() */ + if (first_break == NULL) + first_break = (char *) sbrk (0); +#endif /* HAVE_SBRK */ +} + +void +xmalloc_failed (size_t size) +{ +#ifdef HAVE_SBRK + extern char **environ; + size_t allocated; + + if (first_break != NULL) + allocated = (char *) sbrk (0) - first_break; + else + allocated = (char *) sbrk (0) - (char *) &environ; + fprintf (stderr, + "\n%s%sout of memory allocating %lu bytes after a total of %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) size, (unsigned long) allocated); +#else /* HAVE_SBRK */ + fprintf (stderr, + "\n%s%sout of memory allocating %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) size); +#endif /* HAVE_SBRK */ + xexit (1); +} + +PTR +xmalloc (size_t size) +{ + PTR newmem; + + if (size == 0) + size = 1; + newmem = malloc (size); + if (!newmem) + xmalloc_failed (size); + + return (newmem); +} + +PTR +xcalloc (size_t nelem, size_t elsize) +{ + PTR newmem; + + if (nelem == 0 || elsize == 0) + nelem = elsize = 1; + + newmem = calloc (nelem, elsize); + if (!newmem) + xmalloc_failed (nelem * elsize); + + return (newmem); +} + +PTR +xrealloc (PTR oldmem, size_t size) +{ + PTR newmem; + + if (size == 0) + size = 1; + if (!oldmem) + newmem = malloc (size); + else + newmem = realloc (oldmem, size); + if (!newmem) + xmalloc_failed (size); + + return (newmem); +} diff --git a/support/cpp2/libiberty/xstrdup.c b/support/cpp2/libiberty/xstrdup.c new file mode 100644 index 00000000..9ac2ea03 --- /dev/null +++ b/support/cpp2/libiberty/xstrdup.c @@ -0,0 +1,36 @@ +/* xstrdup.c -- Duplicate a string in memory, using xmalloc. + This trivial function is in the public domain. + Ian Lance Taylor, Cygnus Support, December 1995. */ + +/* + +@deftypefn Replacement char* xstrdup (const char *@var{s}) + +Duplicates a character string without fail, using @code{xmalloc} to +obtain memory. + +@end deftypefn + +*/ + +#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_STRING_H +#include +#else +# ifdef HAVE_STRINGS_H +# include +# endif +#endif +#include "ansidecl.h" +#include "libiberty.h" + +char * +xstrdup (const char *s) +{ + register size_t len = strlen (s) + 1; + register char *ret = XNEWVEC (char, len); + return (char *) memcpy (ret, s, len); +} diff --git a/support/cpp2/libiberty/xstrerror.c b/support/cpp2/libiberty/xstrerror.c new file mode 100644 index 00000000..2ea2200e --- /dev/null +++ b/support/cpp2/libiberty/xstrerror.c @@ -0,0 +1,79 @@ +/* xstrerror.c -- jacket routine for more robust strerror() usage. + Fri Jun 16 18:30:00 1995 Pat Rankin + This code is in the public domain. */ + +/* + +@deftypefn Replacement char* xstrerror (int @var{errnum}) + +Behaves exactly like the standard @code{strerror} function, but +will never return a @code{NULL} pointer. + +@end deftypefn + +*/ + +#include + +#include "config.h" +#include "libiberty.h" + +#ifdef VMS +# include +# if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES) +# ifdef __cplusplus +extern "C" { +# endif /* __cplusplus */ +extern char *strerror (int,...); +# define DONT_DECLARE_STRERROR +# ifdef __cplusplus +} +# endif /* __cplusplus */ +# endif +#endif /* VMS */ + + +#ifndef DONT_DECLARE_STRERROR +# ifdef __cplusplus +extern "C" { +# endif /* __cplusplus */ +extern char *strerror (int); +# ifdef __cplusplus +} +# endif /* __cplusplus */ +#endif + +/* If strerror returns NULL, we'll format the number into a static buffer. */ + +#define ERRSTR_FMT "undocumented error #%d" +static char xstrerror_buf[sizeof ERRSTR_FMT + 20]; + +/* Like strerror, but result is never a null pointer. */ + +char * +xstrerror (int errnum) +{ + char *errstr; +#ifdef VMS + char *(*vmslib_strerror) (int,...); + + /* Override any possibly-conflicting declaration from system header. */ + vmslib_strerror = (char *(*) (int,...)) strerror; + /* Second argument matters iff first is EVMSERR, but it's simpler to + pass it unconditionally. `vaxc$errno' is declared in + and maintained by the run-time library in parallel to `errno'. + We assume that `errnum' corresponds to the last value assigned to + errno by the run-time library, hence vaxc$errno will be relevant. */ + errstr = (*vmslib_strerror) (errnum, vaxc$errno); +#else + errstr = strerror (errnum); +#endif + + /* If `errnum' is out of range, result might be NULL. We'll fix that. */ + if (!errstr) + { + sprintf (xstrerror_buf, ERRSTR_FMT, errnum); + errstr = xstrerror_buf; + } + return errstr; +} diff --git a/support/cpp2/sdcc.h b/support/cpp2/sdcc.h index c405e766..90922d8d 100644 --- a/support/cpp2/sdcc.h +++ b/support/cpp2/sdcc.h @@ -1,12 +1,3 @@ -/* Various stuff needed to hack the build for SDCC. */ -#define xmalloc malloc -#define xstrdup strdup -#define xrealloc realloc -#define xcalloc calloc - -#define xstrerror strerror -#define xmalloc_set_program_name(n) /* nada */ - /* * From defaults.h */ diff --git a/support/cpp2/sdcpp.dsp b/support/cpp2/sdcpp.dsp index faa24650..0e9b737c 100644 --- a/support/cpp2/sdcpp.dsp +++ b/support/cpp2/sdcpp.dsp @@ -187,6 +187,22 @@ SOURCE=".\libiberty\splay-tree.c" SOURCE=.\version.c # End Source File +# Begin Source File + +SOURCE=.\libiberty\xexit.c +# End Source File +# Begin Source File + +SOURCE=.\libiberty\xmalloc.c +# End Source File +# Begin Source File + +SOURCE=.\libiberty\xstrdup.c +# End Source File +# Begin Source File + +SOURCE=.\libiberty\xstrerror.c +# End Source File # End Group # Begin Group "Header Files" diff --git a/support/cpp2/sdcppinit.c b/support/cpp2/sdcppinit.c index 95a1925b..1c96fddc 100644 --- a/support/cpp2/sdcppinit.c +++ b/support/cpp2/sdcppinit.c @@ -1,6 +1,6 @@ /* CPP Library. Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. Contributed by Per Bothner, 1994-95. Based on CCCP program by Paul Rubin, June 1986 Adapted to ANSI C, Richard Stallman, Jan 1987 @@ -532,6 +532,7 @@ cpp_create_reader (lang) CPP_OPTION (pfile, operator_names) = 1; CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99); + CPP_OPTION (pfile, sysroot) = cpp_SYSROOT; /* SDCC _asm specific */ CPP_OPTION (pfile, preproc_asm) = 1; @@ -811,13 +812,21 @@ init_standard_includes (pfile) || (CPP_OPTION (pfile, cplusplus) && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) { - /* Does this dir start with the prefix? */ + /* Should we be translating sysrooted dirs too? Assume + that iprefix and sysroot are mutually exclusive, for + now. */ + if (p->add_sysroot && CPP_OPTION (pfile, sysroot) + && *(CPP_OPTION (pfile, sysroot))) + continue; + + /* Does this dir start with the prefix? */ if (!strncmp (p->fname, default_prefix, default_len)) { /* Yes; change prefix and add to search list. */ int flen = strlen (p->fname); int this_len = specd_len + flen - default_len; - char *str = (char *) xmalloc (this_len + 1); + + char *str = (char *) xmalloc (this_len + 1); memcpy (str, specd_prefix, specd_len); memcpy (str + specd_len, p->fname + default_len, @@ -829,7 +838,6 @@ init_standard_includes (pfile) } } - /* Search ordinary names for GNU include directories. */ for (p = cpp_include_defaults; p->fname; p++) { /* Some standard dirs are only for C++. */ @@ -837,7 +845,16 @@ init_standard_includes (pfile) || (CPP_OPTION (pfile, cplusplus) && !CPP_OPTION (pfile, no_standard_cplusplus_includes))) { - char *str = update_path (p->fname, p->component); + char *str; + + /* Should this dir start with the sysroot? */ + if (p->add_sysroot && CPP_OPTION (pfile, sysroot) + && *(CPP_OPTION (pfile, sysroot))) + str = concat (CPP_OPTION (pfile, sysroot), p->fname, NULL); + + else + str = update_path (p->fname, p->component); + append_include_chain (pfile, str, SYSTEM, p->cxx_aware); } } @@ -1081,68 +1098,6 @@ cpp_finish_options (pfile) free_chain (CPP_OPTION (pfile, pending)->directive_head); } -/* Use mkdeps.c to output dependency information. */ -static void -output_deps (cpp_reader *pfile) -{ - /* Stream on which to print the dependency information. */ - FILE *deps_stream = 0; - const char *const deps_mode = - CPP_OPTION (pfile, deps.append) ? "a" : "w"; - - if (CPP_OPTION (pfile, deps.file)[0] == '\0') - deps_stream = stdout; - else - { - deps_stream = fopen (CPP_OPTION (pfile, deps.file), deps_mode); - if (deps_stream == 0) - { - cpp_errno (pfile, DL_ERROR, CPP_OPTION (pfile, deps.file)); - return; - } - } - - deps_write (pfile->deps, deps_stream, 72); - - if (CPP_OPTION (pfile, deps.phony_targets)) - deps_phony_targets (pfile->deps, deps_stream); - - /* Don't close stdout. */ - if (deps_stream != stdout) - { - if (ferror (deps_stream) || fclose (deps_stream) != 0) - cpp_error (pfile, DL_ERROR, "I/O error on output"); - } -} - -/* This is called at the end of preprocessing. It pops the - last buffer and writes dependency output. It should also - clear macro definitions, such that you could call cpp_start_read - with a new filename to restart processing. */ -void -sdcpp_finish (cpp_reader *pfile) -{ - /* Warn about unused macros before popping the final buffer. */ - if (CPP_OPTION (pfile, warn_unused_macros)) - cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL); - - /* cpplex.c leaves the final buffer on the stack. This it so that - it returns an unending stream of CPP_EOFs to the client. If we - popped the buffer, we'd dereference a NULL buffer pointer and - segfault. It's nice to allow the client to do worry-free excess - cpp_get_token calls. */ - while (pfile->buffer) - _cpp_pop_buffer (pfile); - - /* Don't write the deps file if preprocessing has failed. */ - if (CPP_OPTION (pfile, deps.style) && pfile->errors == 0) - output_deps (pfile); - - /* Report on headers that could use multiple include guards. */ - if (CPP_OPTION (pfile, print_include_names)) - _cpp_report_missing_guards (pfile); -} - /* Push the next buffer on the stack given by -include, if any. */ void _cpp_maybe_push_include_file (pfile) @@ -1267,6 +1222,7 @@ new_pending_directive (pend, text, handler) DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \ DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \ DEF_OPT("fshow-column", 0, OPT_fshow_column) \ + DEF_OPT("fsigned-char", 0, OPT_fsigned_char) \ DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \ DEF_OPT("funsigned-char", 0, OPT_funsigned_char) \ DEF_OPT("h", 0, OPT_h) \ @@ -1274,6 +1230,7 @@ new_pending_directive (pend, text, handler) DEF_OPT("imacros", no_fil, OPT_imacros) \ DEF_OPT("include", no_fil, OPT_include) \ DEF_OPT("iprefix", no_pth, OPT_iprefix) \ + DEF_OPT("isysroot", no_dir, OPT_isysroot) \ DEF_OPT("isystem", no_dir, OPT_isystem) \ DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \ DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \ @@ -1476,6 +1433,12 @@ cpp_handle_option (pfile, argc, argv) CPP_OPTION (pfile, tabstop) = tabstop; } break; + case OPT_fsigned_char: + CPP_OPTION (pfile, unsigned_char) = 0; + break; + case OPT_funsigned_char: + CPP_OPTION (pfile, unsigned_char) = 1; + break; case OPT_w: CPP_OPTION (pfile, inhibit_warnings) = 1; break; @@ -1539,7 +1502,10 @@ cpp_handle_option (pfile, argc, argv) CPP_OPTION (pfile, include_prefix) = arg; CPP_OPTION (pfile, include_prefix_len) = strlen (arg); break; - case OPT_lang_c: + case OPT_isysroot: + CPP_OPTION (pfile, sysroot) = arg; + break; + case OPT_lang_c: cpp_set_lang (pfile, CLK_GNUC89); break; case OPT_lang_cplusplus: @@ -1867,6 +1833,7 @@ Switches:\n\ -iwithprefix Add to the end of the system include path\n\ -iwithprefixbefore Add to the end of the main include path\n\ -isystem Add to the start of the system include path\n\ + -isysroot Set to be the system root directory\n\ "), stdout); fputs (_("\ -idirafter Add to the end of the system include path\n\ @@ -1951,6 +1918,8 @@ Switches:\n\ fputs (_("\ -fpreprocessed Treat the input file as already preprocessed\n\ -ftabstop= Distance between tab stops for column reporting\n\ + -fsigned-char Make \"char\" signed by default\n\ + -funsigned-char Make \"char\" unsigned by default\n\ -P Do not generate #line directives\n\ -$ Do not allow '$' in identifiers\n\ -remap Remap file names when including files\n\ diff --git a/support/cpp2/sdcppmain.c b/support/cpp2/sdcppmain.c index 1ac1a9ec..ee8db298 100644 --- a/support/cpp2/sdcppmain.c +++ b/support/cpp2/sdcppmain.c @@ -35,6 +35,9 @@ /* True if we have seen a "fatal" error. */ #define CPP_FATAL_ERRORS(PFILE) (cpp_errors (PFILE) >= CPP_FATAL_LIMIT) +extern void sdcpp_finish (cpp_reader *pfile); + + const char *progname; /* Needs to be global. */ @@ -201,6 +204,55 @@ do_preprocessing (cpp_reader *pfile, int argc, char **argv) cpp_preprocess_file (pfile, pfile->opts.in_fname, outf); } +/* Print a fatal I/O error message. Argument are like printf. + Also include a system error message based on `errno'. */ +void +fatal_io_error VPARAMS ((const char *msgid, ...)) +{ + va_list ap; + + va_start (ap, msgid); + fprintf (stderr, "%s: %s: ", progname, xstrerror (errno)); + vfprintf(stderr, msgid, ap); + va_end (ap); + exit (FATAL_EXIT_CODE); +} + +/* Common finish hook for the C, ObjC and C++ front ends. */ +void +common_finish (cpp_reader *pfile) +{ + FILE *deps_stream = NULL; + + if (CPP_OPTION (pfile, deps.style) != DEPS_NONE) + { + const char *const deps_mode = + CPP_OPTION (pfile, deps.append) ? "a" : "w"; + + /* If -M or -MM was seen without -MF, default output to the + output stream. */ + if (CPP_OPTION (pfile, deps.file)[0] == '\0') + deps_stream = stdout; + else + { + deps_stream = fopen (CPP_OPTION (pfile, deps.file), deps_mode); + if (deps_stream == 0) + { + cpp_errno (pfile, DL_ERROR, CPP_OPTION (pfile, deps.file)); + return; + } + } + } + + /* For performance, avoid tearing down cpplib's internal structures + with cpp_destroy (). */ + cpp_finish (pfile, deps_stream); + + if (deps_stream && deps_stream != stdout + && (ferror (deps_stream) || fclose (deps_stream))) + fatal_io_error ("closing dependency file %s", CPP_OPTION (pfile, deps.file)); +} + int main (int argc, char **argv) { @@ -213,6 +265,8 @@ main (int argc, char **argv) do_preprocessing (pfile, argc, argv); + common_finish(pfile); + cpp_destroy (pfile); return SUCCESS_EXIT_CODE; diff --git a/support/cpp2/system.h b/support/cpp2/system.h index 07b188ae..28b1137d 100644 --- a/support/cpp2/system.h +++ b/support/cpp2/system.h @@ -396,7 +396,6 @@ extern void abort PARAMS ((void)); /* Get libiberty declarations. */ #include "libiberty.h" -#include "sdcc.h" #include "symcat.h" /* Provide a default for the HOST_BIT_BUCKET. @@ -549,4 +548,7 @@ typedef char _Bool; #endif /* GCC >= 3.0 */ +/* SDCC specific */ +#include "sdcc.h" + #endif /* ! GCC_SYSTEM_H */