This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Integrated cpp: hack specs so -traditional works


As in the subject.

It strikes me that having something in the spec language that means "else"
would be very useful, and simplify some specs.  e.g. at present we have

{A|B|C:foo}
{!A:{!B:{!C:bar}}}

would be cleaner as

{A|B|C:foo@bar}

where @ (or some other symbol) means "else", and binds with the
immediately preceding ':'.  When you're testing for
%{traditional|ftraditional|traditional-cpp:foo} not having an "else"
gets ugly, and it's what accounts for the complexity below.  Should I
have a go at trying to implement such a thing?

OK to commit the patch below?  It bootstrapped the C compiler, and
passed the preprocessor tests, including the traditional test that
failed with the integrated preprocessor until now.  Incidentally, is
"const" not a keyword with -traditional?  Neither 2.95.2 nor a
bootstrapped compiler allow me to put const char * in the test below.

Neil.

	* gcc.c (cpp_options_asm): Renamed from cpp_options; this
	forms the specs common to preprocessing assembly and C.
	Simplify existing specs accordingly.
	(cpp_options): cpp_options_asm with -lang-c and -ansi.
	Add specs to invoke tradcpp0 on the integrated preprocessor
	if any of -traditional, -traditional-cpp or -ftraditional
	 is specified, passing the output to cc1.
	* gcc.dg/cpp/tr-str.c: Update for run-time testing of
	stringification.	

Index: gcc.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/gcc.c,v
retrieving revision 1.168
diff -c -p -r1.168 gcc.c
*** gcc.c	2000/09/20 20:06:54	1.168
--- gcc.c	2000/09/22 06:07:15
*************** static const char *link_libgcc_spec = LI
*** 569,575 ****
  static const char *trad_capable_cpp =
  "%{traditional|ftraditional|traditional-cpp:trad}cpp0";
  
! static const char *cpp_options =
  "%{C:%{!E:%eGNU C does not support -C without using -E}}\
   %{std*} %{nostdinc*}\
   %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
--- 569,578 ----
  static const char *trad_capable_cpp =
  "%{traditional|ftraditional|traditional-cpp:trad}cpp0";
  
! static const char *cpp_options = "-lang-c %{ansi:-std=c89} %(cpp_options_asm)";
! 
! /* These CPP specs are common to assembler and C.  */
! static const char *cpp_options_asm =
  "%{C:%{!E:%eGNU C does not support -C without using -E}}\
   %{std*} %{nostdinc*}\
   %{C} %{v} %{A*} %{I*} %{P} %{$} %I\
*************** static struct compiler default_compilers
*** 709,720 ****
    {".c", "@c"},
    {"@c",
  #if USE_CPPLIB
!      "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
!       %{!E:%{!M:%{!MM:cc1 -lang-c %{ansi:-std=c89} %(cpp_options)\
! 			  %(cc1_options) %{!fsyntax-only:%{!S:-o %{|!pipe:%g.s} |\n\
        as %(asm_options) %{!pipe:%g.s} %A }}}}}"
  #else /* ! USE_CPPLIB */
!      "%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options) \
  			  %{!M:%{!MM:%{!E:%{!pipe:%g.i} |\n\
        cc1 %{!pipe:%g.i} %(cc1_options) %{!fsyntax-only:%{!S:-o %{|!pipe:%g.s} |\n\
        as %(asm_options) %{!pipe:%g.s} %A }}}}}\n"
--- 712,725 ----
    {".c", "@c"},
    {"@c",
  #if USE_CPPLIB
!      "%{E|M|MM:%(trad_capable_cpp) %(cpp_options)}\
!       %{!E:%{!M:%{!MM: %{traditional|ftraditional|traditional-cpp:tradcpp0 %(cpp_options) \
! 			 %{!pipe:%g.i} |\n cc1 %{!pipe:%g.i}} \
! 		%{!traditional:%{!ftraditional:%{!traditional-cpp: cc1 %(cpp_options)}}} \
! 	    %(cc1_options) %{!fsyntax-only:%{!S:-o %{|!pipe:%g.s} |\n\
        as %(asm_options) %{!pipe:%g.s} %A }}}}}"
  #else /* ! USE_CPPLIB */
!      "%(trad_capable_cpp) %(cpp_options) \
  			  %{!M:%{!MM:%{!E:%{!pipe:%g.i} |\n\
        cc1 %{!pipe:%g.i} %(cc1_options) %{!fsyntax-only:%{!S:-o %{|!pipe:%g.s} |\n\
        as %(asm_options) %{!pipe:%g.s} %A }}}}}\n"
*************** static struct compiler default_compilers
*** 722,732 ****
    },
    {"-",
     "%{!E:%e-E required when input is from standard input}\
!     %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)"},
    {".h", "@c-header"},
    {"@c-header",
     "%{!E:%eCompilation of header file requested} \
!     %(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)"},
    {".i", "@cpp-output"},
    {"@cpp-output",
     "%{!M:%{!MM:%{!E:\
--- 727,737 ----
    },
    {"-",
     "%{!E:%e-E required when input is from standard input}\
!     %(trad_capable_cpp) %(cpp_options)"},
    {".h", "@c-header"},
    {"@c-header",
     "%{!E:%eCompilation of header file requested} \
!     %(trad_capable_cpp) %(cpp_options)"},
    {".i", "@cpp-output"},
    {"@cpp-output",
     "%{!M:%{!MM:%{!E:\
*************** static struct compiler default_compilers
*** 737,743 ****
     "%{!M:%{!MM:%{!E:%{!S:as %(asm_options) %i %A }}}}"},
    {".S", "@assembler-with-cpp"},
    {"@assembler-with-cpp",
!    "%(trad_capable_cpp) -lang-asm %(cpp_options) \
  			%{!M:%{!MM:%{!E:%{!S: %{!pipe:%g.s} |\n\
      as %(asm_options) %{!pipe:%g.s} %A }}}}"},
  #include "specs.h"
--- 742,748 ----
     "%{!M:%{!MM:%{!E:%{!S:as %(asm_options) %i %A }}}}"},
    {".S", "@assembler-with-cpp"},
    {"@assembler-with-cpp",
!    "%(trad_capable_cpp) -lang-asm %(cpp_options_asm) \
  			%{!M:%{!MM:%{!E:%{!S: %{!pipe:%g.s} |\n\
      as %(asm_options) %{!pipe:%g.s} %A }}}}"},
  #include "specs.h"
*************** static struct spec_list static_specs[] =
*** 1085,1090 ****
--- 1090,1096 ----
    INIT_STATIC_SPEC ("asm_options",		&asm_options),
    INIT_STATIC_SPEC ("cpp",			&cpp_spec),
    INIT_STATIC_SPEC ("cpp_options",		&cpp_options),
+   INIT_STATIC_SPEC ("cpp_options_asm",		&cpp_options_asm),
    INIT_STATIC_SPEC ("trad_capable_cpp",		&trad_capable_cpp),
    INIT_STATIC_SPEC ("cc1",			&cc1_spec),
    INIT_STATIC_SPEC ("cc1_options",		&cc1_options),
Index: testsuite/gcc.dg/cpp/tr-str.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/gcc.dg/cpp/tr-str.c,v
retrieving revision 1.1
diff -c -p -r1.1 tr-str.c
*** tr-str.c	2000/06/27 22:26:11	1.1
--- tr-str.c	2000/09/22 06:07:23
***************
*** 1,4 ****
  /* Test whether traditional stringify works.  */
! /* { dg-do preprocess } */
  /* { dg-options "-traditional" } */
  #define foo(a, b) c="a"; d="b";
--- 1,17 ----
  /* Test whether traditional stringify works.  */
! /* { dg-do run } */
  /* { dg-options "-traditional" } */
  #define foo(a, b) c="a"; d="b";
+ 
+ extern void abort ();
+ 
+ int main ()
+ {
+   char *c, *d;
+ 
+   foo (p, q);
+   if (c[0] != 'p' || d[0] != 'q')
+     abort ();
+ 
+   exit (0);
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]