Commit a0d85b75 by Dave Brolley Committed by Dave Brolley

Integrate cpplib into the C and C++ front ends.

Wed Jun 10 13:07:02 1998  Dave Brolley  <brolley@cygnus.com>
	* objc/objc-act.c: Add cpplib declarations.
	(lang_decode_option): Initialize cpplib if necessary.
	(lang_decode_option): New argc/argv interface.
	* tree.h (lang_decode_option): New argc/argv interface.
	* toplev.c (lang_options): Add cpp options.
	(main): New interface for lang_decode_option.
	* gcc.c (default_compilers): Don't call cpp for a cpplib-enabled C compiler
	unless -E, -M or -MM is specified.
	* cpplib.h (cpp_handle_option): New function.
	* cpplib.c (cpp_handle_option): New function.
	(cpp_handle_options): Now calls cpp_handle_option.
	* c-tree.h (c_decode_option): New argc/argv interface.
	* c-lex.c (init_parse): cpplib now initialized in c_decode_option.
	* c-lang.c (lang_decode_option): New argc/argv interface.
	* c-decl.c: Add cpplib declarations.
	(c_decode_option): New argc/argv interface.
	(c_decode_option): Call cpp_handle_option.
	(c_decode_option): Now returns number of strings processed.

From-SVN: r20407
parent 0875c2f3
Wed Jun 10 13:07:02 1998 Dave Brolley <brolley@cygnus.com>
* objc/objc-act.c: Add cpplib declarations.
(lang_decode_option): Initialize cpplib if necessary.
(lang_decode_option): New argc/argv interface.
* tree.h (lang_decode_option): New argc/argv interface.
* toplev.c (lang_options): Add cpp options.
(main): New interface for lang_decode_option.
* gcc.c (default_compilers): Don't call cpp for a cpplib-enabled C compiler
unless -E, -M or -MM is specified.
* cpplib.h (cpp_handle_option): New function.
* cpplib.c (cpp_handle_option): New function.
(cpp_handle_options): Now calls cpp_handle_option.
* c-tree.h (c_decode_option): New argc/argv interface.
* c-lex.c (init_parse): cpplib now initialized in c_decode_option.
* c-lang.c (lang_decode_option): New argc/argv interface.
* c-decl.c: Add cpplib declarations.
(c_decode_option): New argc/argv interface.
(c_decode_option): Call cpp_handle_option.
(c_decode_option): Now returns number of strings processed.
Wed Jun 10 09:47:13 1998 Richard Earnshaw (rearnsha@arm.com) Wed Jun 10 09:47:13 1998 Richard Earnshaw (rearnsha@arm.com)
* unroll.c (verify_addresses): Use validate_replace_rtx to undo the * unroll.c (verify_addresses): Use validate_replace_rtx to undo the
......
...@@ -6,6 +6,13 @@ time as we can formally start documenting the interface this file will ...@@ -6,6 +6,13 @@ time as we can formally start documenting the interface this file will
serve as a repository for information on these interface and any incompatable serve as a repository for information on these interface and any incompatable
changes we've made. changes we've made.
Jun 10, 1998:
The interface to lang_decode_option has changed. It now uses and argc/argv
interface to allow for options that use more than one input string. The new
declaration is: int lang_decode_option (int argc, char** argv). It now
returns the number of input strings processed, or 0 if the option is
unknown.
Jun 7, 1998: Jun 7, 1998:
Front-ends must now define lang_init_options. It is safe for this Front-ends must now define lang_init_options. It is safe for this
function to do nothing. See c-lang.c. function to do nothing. See c-lang.c.
......
...@@ -35,6 +35,13 @@ Boston, MA 02111-1307, USA. */ ...@@ -35,6 +35,13 @@ Boston, MA 02111-1307, USA. */
#include "c-lex.h" #include "c-lex.h"
#include "toplev.h" #include "toplev.h"
#if USE_CPPLIB
#include "cpplib.h"
extern cpp_reader parse_in;
extern cpp_options parse_options;
static int cpp_initialized;
#endif
/* In grokdeclarator, distinguish syntactic contexts of declarators. */ /* In grokdeclarator, distinguish syntactic contexts of declarators. */
enum decl_context enum decl_context
{ NORMAL, /* Ordinary declaration */ { NORMAL, /* Ordinary declaration */
...@@ -578,13 +585,28 @@ int warn_sign_compare = -1; ...@@ -578,13 +585,28 @@ int warn_sign_compare = -1;
int dollars_in_ident = DOLLARS_IN_IDENTIFIERS; int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
/* Decode the string P as a language-specific option for C. /* Decode the string P as a language-specific option for C.
Return 1 if it is recognized (and handle it); Return the number of strings consumed. */
return 0 if not recognized. */
int int
c_decode_option (p) c_decode_option (argc, argv)
char *p; int argc;
char **argv;
{ {
int strings_processed;
char *p = argv[0];
#if USE_CPPLIB
if (! cpp_initialized)
{
cpp_reader_init (&parse_in);
parse_in.data = &parse_options;
cpp_options_init (&parse_options);
cpp_initialized = 1;
}
strings_processed = cpp_handle_option (&parse_in, argc, argv);
#else
strings_processed = 0;
#endif /* ! USE_CPPLIB */
if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
{ {
flag_traditional = 1; flag_traditional = 1;
...@@ -799,7 +821,7 @@ c_decode_option (p) ...@@ -799,7 +821,7 @@ c_decode_option (p)
warn_unknown_pragmas = 1; warn_unknown_pragmas = 1;
} }
else else
return 0; return strings_processed;
return 1; return 1;
} }
......
...@@ -31,10 +31,11 @@ Boston, MA 02111-1307, USA. */ ...@@ -31,10 +31,11 @@ Boston, MA 02111-1307, USA. */
is an alternative to a function in objc-actions.c. */ is an alternative to a function in objc-actions.c. */
int int
lang_decode_option (p) lang_decode_option (argc, argv)
char *p; int argc;
char **argv;
{ {
return c_decode_option (p); return c_decode_option (argc, argv);
} }
void void
......
...@@ -200,10 +200,6 @@ init_parse (filename) ...@@ -200,10 +200,6 @@ init_parse (filename)
yy_cur = "\n"; yy_cur = "\n";
yy_lim = yy_cur+1; yy_lim = yy_cur+1;
cpp_reader_init (&parse_in);
parse_in.data = &parse_options;
cpp_options_init (&parse_options);
cpp_handle_options (&parse_in, 0, NULL); /* FIXME */
parse_in.show_column = 1; parse_in.show_column = 1;
if (! cpp_start_read (&parse_in, filename)) if (! cpp_start_read (&parse_in, filename))
abort (); abort ();
......
...@@ -263,7 +263,7 @@ extern tree build_enumerator PROTO((tree, tree)); ...@@ -263,7 +263,7 @@ extern tree build_enumerator PROTO((tree, tree));
extern tree builtin_function PROTO((char *, tree, enum built_in_function function_, char *)); extern tree builtin_function PROTO((char *, tree, enum built_in_function function_, char *));
/* Add qualifiers to a type, in the fashion for C. */ /* Add qualifiers to a type, in the fashion for C. */
extern tree c_build_type_variant PROTO((tree, int, int)); extern tree c_build_type_variant PROTO((tree, int, int));
extern int c_decode_option PROTO((char *)); extern int c_decode_option PROTO((int, char **));
extern void c_mark_varargs PROTO((void)); extern void c_mark_varargs PROTO((void));
extern tree check_identifier PROTO((tree, tree)); extern tree check_identifier PROTO((tree, tree));
extern void clear_parm_order PROTO((void)); extern void clear_parm_order PROTO((void));
......
...@@ -6234,20 +6234,17 @@ push_pending (pfile, cmd, arg) ...@@ -6234,20 +6234,17 @@ push_pending (pfile, cmd, arg)
CPP_OPTIONS (pfile)->pending = pend; CPP_OPTIONS (pfile)->pending = pend;
} }
/* Handle command-line options in (argc, argv). /* Handle one command-line option in (argc, argv).
Can be called multiple times, to handle multiple sets of options. Can be called multiple times, to handle multiple sets of options.
Returns if an unrecognized option is seen. Returns number of strings consumed. */
Returns number of handled arguments. */
int int
cpp_handle_options (pfile, argc, argv) cpp_handle_option (pfile, argc, argv)
cpp_reader *pfile; cpp_reader *pfile;
int argc; int argc;
char **argv; char **argv;
{ {
int i;
struct cpp_options *opts = CPP_OPTIONS (pfile); struct cpp_options *opts = CPP_OPTIONS (pfile);
for (i = 0; i < argc; i++) { int i = 0;
if (argv[i][0] != '-') { if (argv[i][0] != '-') {
if (opts->out_fname != NULL) if (opts->out_fname != NULL)
{ {
...@@ -6646,7 +6643,7 @@ cpp_handle_options (pfile, argc, argv) ...@@ -6646,7 +6643,7 @@ cpp_handle_options (pfile, argc, argv)
push_pending (pfile, "-U", argv[i] + 2); push_pending (pfile, "-U", argv[i] + 2);
else if (i + 1 == argc) else if (i + 1 == argc)
{ {
cpp_fatal (pfile, "Macro name missing after -U option"); cpp_fatal (pfile, "Macro name missing after -U option", NULL);
return argc; return argc;
} }
else else
...@@ -6734,6 +6731,28 @@ cpp_handle_options (pfile, argc, argv) ...@@ -6734,6 +6731,28 @@ cpp_handle_options (pfile, argc, argv)
return i; return i;
} }
} }
return i + 1;
}
/* Handle command-line options in (argc, argv).
Can be called multiple times, to handle multiple sets of options.
Returns if an unrecognized option is seen.
Returns number of strings consumed. */
int
cpp_handle_options (pfile, argc, argv)
cpp_reader *pfile;
int argc;
char **argv;
{
int i;
int strings_processed;
for (i = 0; i < argc; i += strings_processed)
{
strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
if (strings_processed == 0)
break;
} }
return i; return i;
} }
......
...@@ -94,6 +94,7 @@ extern void parse_clear_mark PARAMS ((struct parse_marker *)); ...@@ -94,6 +94,7 @@ extern void parse_clear_mark PARAMS ((struct parse_marker *));
extern void parse_goto_mark PARAMS((struct parse_marker *, cpp_reader *)); extern void parse_goto_mark PARAMS((struct parse_marker *, cpp_reader *));
extern void parse_move_mark PARAMS((struct parse_marker *, cpp_reader *)); extern void parse_move_mark PARAMS((struct parse_marker *, cpp_reader *));
extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **)); extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
extern enum cpp_token cpp_get_token PARAMS ((cpp_reader *)); extern enum cpp_token cpp_get_token PARAMS ((cpp_reader *));
extern void cpp_skip_hspace PARAMS((cpp_reader *)); extern void cpp_skip_hspace PARAMS((cpp_reader *));
......
...@@ -597,7 +597,46 @@ static struct compiler default_compilers[] = ...@@ -597,7 +597,46 @@ static struct compiler default_compilers[] =
/* Next come the entries for C. */ /* Next come the entries for C. */
{".c", {"@c"}}, {".c", {"@c"}},
{"@c", {"@c",
{"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ {
#if USE_CPPLIB
#define CPP_FOR_C \
"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
%{C:%{!E:%eGNU C does not support -C without using -E}}\
%{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
-undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
%{ansi:-trigraphs -D__STRICT_ANSI__}\
%{!undef:%{!ansi:%p} %P} %{trigraphs} \
%c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
%{traditional} %{ftraditional:-traditional}\
%{traditional-cpp:-traditional}\
%{g*} %{W*} %{w} %{pedantic*} %{H} %{d*} %C %{D*} %{U*} %{i*} %Z\
%i %{E:%W{o*}}%{M:%W{o*}}%{MM:%W{o*}}\n"
"%{E:"CPP_FOR_C"}"
"%{!E:%{M:"CPP_FOR_C"}"
"%{!M:%{MM:"CPP_FOR_C"}"
"%{!MM:cc1 %i %1 \
-lang-c%{ansi:89} %{nostdinc*} %{A*} %{I*} %I\
%{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
%{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
-undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
%{ansi:-trigraphs -D__STRICT_ANSI__}\
%{!undef:%{!ansi:%p} %P} %{trigraphs} \
%c %{Os:-D__OPTIMIZE_SIZE__} %{O*:%{!O0:-D__OPTIMIZE__}}\
%{H} %C %{D*} %{U*} %{i*} %Z\
%{ftraditional:-traditional}\
%{traditional-cpp:-traditional}\
%{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
%{aux-info*}\
%{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi} \
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
%{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
%{!S:as %a %Y\
%{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
%{!pipe:%g.s} %A\n }}}}"
}},
#else /* ! USE_CPPLIB */
"cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
%{C:%{!E:%eGNU C does not support -C without using -E}}\ %{C:%{!E:%eGNU C does not support -C without using -E}}\
%{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\ %{M} %{MM} %{MD:-MD %b.d} %{MMD:-MMD %b.d} %{MG}\
-undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\ -undef -D__GNUC__=%v1 -D__GNUC_MINOR__=%v2\
...@@ -617,7 +656,9 @@ static struct compiler default_compilers[] = ...@@ -617,7 +656,9 @@ static struct compiler default_compilers[] =
%{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\ %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
%{!S:as %a %Y\ %{!S:as %a %Y\
%{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\ %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
%{!pipe:%g.s} %A\n }}}}"}}, %{!pipe:%g.s} %A\n }}}}"
}},
#endif /* ! USE_CPPLIB */
{"-", {"-",
{"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\ {"%{E:cpp -lang-c%{ansi:89} %{nostdinc*} %{C} %{v} %{A*} %{I*} %{P} %I\
%{C:%{!E:%eGNU C does not support -C without using -E}}\ %{C:%{!E:%eGNU C does not support -C without using -E}}\
......
...@@ -894,6 +894,19 @@ char *lang_options[] = ...@@ -894,6 +894,19 @@ char *lang_options[] =
"-Wno-protocol", "-Wno-protocol",
"-print-objc-runtime-info", "-print-objc-runtime-info",
/* These are for languages with USE_CPPLIB. */
"-A",
"-D",
"-I",
"-iprefix",
"-isystem",
"-lang-c",
"-lang-c89",
"-lang-c++",
"-nostdinc++",
"-U",
"-undef",
#include "options.h" #include "options.h"
0 0
}; };
...@@ -3853,9 +3866,13 @@ main (argc, argv, envp) ...@@ -3853,9 +3866,13 @@ main (argc, argv, envp)
strlen (lang_options[j]))) strlen (lang_options[j])))
break; break;
if (lang_options[j] != 0) if (lang_options[j] != 0)
{
/* If the option is valid for *some* language, /* If the option is valid for *some* language,
treat it as valid even if this language doesn't understand it. */ treat it as valid even if this language doesn't understand it. */
lang_decode_option (argv[i]); int strings_processed = lang_decode_option (argc - i, argv + i);
if (strings_processed != 0)
i += strings_processed - 1;
}
else if (argv[i][0] == '-' && argv[i][1] != 0) else if (argv[i][0] == '-' && argv[i][1] != 0)
{ {
register char *str = argv[i] + 1; register char *str = argv[i] + 1;
......
...@@ -1967,7 +1967,7 @@ extern int yyparse PROTO((void)); ...@@ -1967,7 +1967,7 @@ extern int yyparse PROTO((void));
/* Function called with option as argument /* Function called with option as argument
to decode options starting with -f or -W or +. to decode options starting with -f or -W or +.
It should return nonzero if it handles the option. */ It should return nonzero if it handles the option. */
extern int lang_decode_option PROTO((char *)); extern int lang_decode_option PROTO((int, char **));
/* Functions for processing symbol declarations. */ /* Functions for processing symbol declarations. */
/* Function to enter a new lexical scope. /* Function to enter a new lexical scope.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment