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]
Other format: [Raw text]

Changes to gcc 3.x to invoke an external cpp (updated patch 2)




Based on discussion from the mailing list, we have made adjustments to our
patch.  We took a different approach to reduce code duplication, and the
resulting implementation is cleaner and works nicely for both gcc and g++.
Note, the addition of documentation.

Background:

As of gcc 3.x, cpp has been (partially) integrated into the compiler. I say
partially because there are exceptions: in gcc (-traditional/-save-temps) and
g++ (-save-temps) do not use the integrated cpp. For the past 10 years, we have
been developing concurrency software (uC++) that piggy-backs on g++. This
software uses an additional preprocessor to change the source text *after*
being processed by cpp. For the past 10 years, we have used the -B flag to
supply our own cpp driver that first invokes the standard cpp and then our cpp.
This mechanism is ideal because it uses the logic in g++ to parse and
understand all the command line flags and files, making our job as simple as
possible.  However, with the integrated cpp, we can no longer use this
mechanism as our user-supplied cpp in the -B directory is no longer invoked
unless the -save-temps flag is used, which produces unnecessary files so this
is not a clean solution. Therefore, we need a mechanism in g++ to invoke an
external preprocessor during a compilation, that is, we need the old behaviour
of the -B flag back. We could use -traditional-cpp and name our cpp "tradcpp",
but -traditional-cpp does not work with g++. Suffice it to say we are in a
major panic with respect to this new change because its effect on us is
extreme.

Given that the behaviour we need is largely still in place (via -traditional
and -save-temps), we would like to suggest the following change to bring back
the prior behaviour of using the non-integrated cpp either from the vendor or
gcc supplied or user supplied through the -B flag. To accomplish this, we added
an additional flag to gcc/g++ (similar to the -traditional-cpp flag) to force
the use of the external cpp.  The temporary name for the flag is
-no-integrated-cpp.  We tried -external-cpp, but this conflicts with the -e
flag.  Perhaps someone who is more familiar with flag naming-conventions can
suggest a more appropriate name.

Now we are not experts at changing gcc, so there may be some details that still
need to be addressed, but these changes seem to give the desired result while
still preserving the semantics of the -traditional/-save-temps flags.

For additional information, please see our responses in the mailing list:

http://gcc.gnu.org/ml/gcc-patches/2001-12/msg00117.html
http://gcc.gnu.org/ml/gcc-patches/2001-12/msg00441.html
http://gcc.gnu.org/ml/gcc-patches/2001-12/msg00762.html

as well as the follow up discussion.

Description:

The -no-integrated-cpp flag is a cpp specific flag that causes gcc/g++ to
invoke the external cpp during compilation. (This flag provides functionality
previously available in gcc 2.X.) This flag has notable interactions with other
cpp specific flags, such as -{E|M|MM}, -save-temps and
-{traditional|ftraditional|traditional-cpp} (gcc only).  Each of these flags
already causes an external cpp to be called but performs some additional
functionality and so supercedes the use of the -no-integrated-cpp flag, i.e.,
if any of these flags is used in conjunction with the -no-integrated-cpp flag,
then the -no-integrated-cpp flag is ignored.  For example, the external cpp is
already invoked with -save-temps but the preprocessed output is saved, so also
specifying -no-integrated-cpp has no effect.

The implementation of -no-integrated-cpp is handled by leveraging the
-save-temps behaviour already implemented in the compiler.  The additional
logic specifies that the same commands are invoked for both -save-temps and
-no-integrated-cpp, except that either a permanent output file or a temporary
output file is used depending on the flag actually specified.  Note, that
specifying both -save-temps and -no-integrated-cpp results in the permanent
output file.  The advantage of this approach is that -save-temps already
handles combinations with the flags mentioned above correctly and this
behaviour is applied accordingly to -no-integrated-cpp.

Testcases:

As the changes relate strictly to the command line interface, the testcases
would simply invoke gcc/g++ with different combinations involving
-no-integrated-cpp, -save-temps and -traditional. I performed several of these
kinds of tests. However, I am not sure how to specify these types of tests.  If
you provide me with some guidance I can try to create some testcases.


ChangeLog:

2001-12-20  Ashif Harji  <asharji@uwaterloo.ca>

	* gcc.c(static struct compiler default_compilers[]): added -no-integrated-cpp flag 
               to invoke an external cpp during compilation.
          (struct option_map option_map[]): likewise
	* cp/lang-specs.h(static struct compiler default_compilers[]): added 
               -no-integrated-cpp flag to invoke an external cpp during compilation.
	* doc/invoke.texi: Document -no-integrated-cpp flag.


Bootstrapping and Testing:

On i686-pc-linux-gnu:
   - bootstrap was successful
   - no changes in testsuite results when compared to original (gcc 3.0.2)



Patch:

1>@awk[119]% diff -c3p gcc-3.0.2/gcc/gcc.c test/gcc-3.0.2/gcc/gcc.c
diff -c3p gcc-3.0.2/gcc/gcc.c test/gcc-3.0.2/gcc/gcc.c
*** gcc-3.0.2/gcc/gcc.c Tue Oct  2 19:12:34 2001
--- test/gcc-3.0.2/gcc/gcc.c    Thu Dec 20 13:03:40 2001
*************** static struct compiler default_compilers
*** 748,762 ****
        external preprocessor if -save-temps or -traditional is given.  */
       "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
        %{!E:%{!M:%{!MM:\
!         %{save-temps:%(trad_capable_cpp) -lang-c %{ansi:-std=c89}\
!               %(cpp_options) %b.i \n\
!                   cc1 -fpreprocessed %b.i %(cc1_options)}\
!         %{!save-temps:\
            %{traditional|ftraditional|traditional-cpp:\
                tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
                    cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
            %{!traditional:%{!ftraditional:%{!traditional-cpp:\
!               cc1 -lang-c %{ansi:-std=c89} %(cpp_options) %(cc1_options)}}}}\
          %{!fsyntax-only:%(invoke_as)}}}}", 0},
    {"-",
     "%{!E:%e-E required when input is from standard input}\
--- 748,762 ----
        external preprocessor if -save-temps or -traditional is given.  */
       "%{E|M|MM:%(trad_capable_cpp) -lang-c %{ansi:-std=c89} %(cpp_options)}\
        %{!E:%{!M:%{!MM:\
!         %{save-temps|no-integrated-cpp:%(trad_capable_cpp) -lang-c %{ansi:-std=c89}\
!               %(cpp_options) %{save-temps:%b.i} %{!save-temps:%g.i} \n\
!                   cc1 -fpreprocessed %{save-temps:%b.i} %{!save-temps:%g.i} %(cc1_options)}\
!         %{!save-temps:%{!no-integrated-cpp:\
            %{traditional|ftraditional|traditional-cpp:\
                tradcpp0 -lang-c %{ansi:-std=c89} %(cpp_options) %{!pipe:%g.i} |\n\
                    cc1 -fpreprocessed %{!pipe:%g.i} %(cc1_options)}\
            %{!traditional:%{!ftraditional:%{!traditional-cpp:\
!               cc1 -lang-c %{ansi:-std=c89} %(cpp_options) %(cc1_options)}}}}}\
          %{!fsyntax-only:%(invoke_as)}}}}", 0},
    {"-",
     "%{!E:%e-E required when input is from standard input}\
*************** struct option_map option_map[] =
*** 856,861 ****
--- 856,862 ----
     {"--library-directory", "-L", "a"},
     {"--machine", "-m", "aj"},
     {"--machine-", "-m", "*j"},
+    {"--no-integrated-cpp", "-no-integrated-cpp", 0},
     {"--no-line-commands", "-P", 0},
     {"--no-precompiled-includes", "-noprecomp", 0},
     {"--no-standard-includes", "-nostdinc", 0},



1>@awk[116]% diff -c3p gcc-3.0.2/gcc/cp/lang-specs.h  test/gcc-3.0.2/gcc/cp/lang-specs.h
diff -c3p gcc-3.0.2/gcc/cp/lang-specs.h  test/gcc-3.0.2/gcc/cp/lang-specs.h
*** gcc-3.0.2/gcc/cp/lang-specs.h       Thu Jun  7 20:00:32 2001
--- test/gcc-3.0.2/gcc/cp/lang-specs.h  Wed Dec 19 16:57:45 2001
*************** Boston, MA 02111-1307, USA.  */
*** 41,60 ****
         %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
         %{ansi:-D__STRICT_ANSI__ -trigraphs -$} %(cpp_options)}\
       %{!E:%{!M:%{!MM:\
!        %{save-temps:cpp0 -lang-c++ \
                    %{!no-gcc:-D__GNUG__=%v1}\
                            %{!Wno-deprecated:-D__GXX_DEPRECATED}\
                    %{!fno-exceptions:-D__EXCEPTIONS}\
                    %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
                    %{ansi:-D__STRICT_ANSI__ -trigraphs -$}\
!                   %(cpp_options) %b.ii \n}\
!       cc1plus %{save-temps:-fpreprocessed %b.ii}\
!               %{!save-temps:%(cpp_options)\
                            %{!no-gcc:-D__GNUG__=%v1} \
                                    %{!Wno-deprecated:-D__GXX_DEPRECATED}\
                            %{!fno-exceptions:-D__EXCEPTIONS}\
                            %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
!                           %{ansi:-D__STRICT_ANSI__}}\
         %{ansi:-trigraphs -$}\
         %(cc1_options) %2 %{+e1*}\
         %{!fsyntax-only:%(invoke_as)}}}}",
--- 41,61 ----
         %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
         %{ansi:-D__STRICT_ANSI__ -trigraphs -$} %(cpp_options)}\
       %{!E:%{!M:%{!MM:\
!        %{save-temps|no-integrated-cpp:cpp0 -lang-c++ \
                    %{!no-gcc:-D__GNUG__=%v1}\
                            %{!Wno-deprecated:-D__GXX_DEPRECATED}\
                    %{!fno-exceptions:-D__EXCEPTIONS}\
                    %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
                    %{ansi:-D__STRICT_ANSI__ -trigraphs -$}\
!                   %(cpp_options) %{save-temps:%b.ii} %{!save-temps:%g.ii}  \n}\
!       cc1plus %{save-temps|no-integrated-cpp:-fpreprocessed %{save-temps:%b.ii} %{!save-temps:%g.ii}}\
!              %{!save-temps:%{!no-integrated-cpp:\
!                      %(cpp_options)\
                            %{!no-gcc:-D__GNUG__=%v1} \
                                    %{!Wno-deprecated:-D__GXX_DEPRECATED}\
                            %{!fno-exceptions:-D__EXCEPTIONS}\
                            %{!fno-new-abi:-D__GXX_ABI_VERSION=100}\
!                           %{ansi:-D__STRICT_ANSI__}}}\
         %{ansi:-trigraphs -$}\
         %(cc1_options) %2 %{+e1*}\
         %{!fsyntax-only:%(invoke_as)}}}}",


1>@awk[103]% diff -c3p gcc-3.0.2/gcc/doc/invoke.texi  test/gcc-3.0.2/gcc/doc/invoke.texi
diff -c3p gcc-3.0.2/gcc/doc/invoke.texi  test/gcc-3.0.2/gcc/doc/invoke.texi
*** gcc-3.0.2/gcc/doc/invoke.texi       Wed Oct 17 05:06:44 2001
--- test/gcc-3.0.2/gcc/doc/invoke.texi  Mon Dec 24 11:29:37 2001
*************** in the following sections.
*** 160,166 ****
  -ansi  -std=@var{standard}  -aux-info @var{filename} @gol
  -fno-asm  -fno-builtin @gol
  -fhosted  -ffreestanding @gol
! -trigraphs  -traditional  -traditional-cpp @gol
  -fallow-single-precision  -fcond-mismatch @gol
  -fsigned-bitfields  -fsigned-char @gol
  -funsigned-bitfields  -funsigned-char @gol
--- 160,166 ----
  -ansi  -std=@var{standard}  -aux-info @var{filename} @gol
  -fno-asm  -fno-builtin @gol
  -fhosted  -ffreestanding @gol
! -trigraphs  -no-integrated-cpp  -traditional  -traditional-cpp @gol
  -fallow-single-precision  -fcond-mismatch @gol
  -fsigned-bitfields  -fsigned-char @gol
  -funsigned-bitfields  -funsigned-char @gol
*************** freestanding and hosted environments.
*** 1037,1042 ****
--- 1037,1048 ----
  @opindex trigraphs
  Support ISO C trigraphs.  The @option{-ansi} option (and @option{-std}
  options for strict ISO C conformance) implies @option{-trigraphs}.
+ 
+ @item -no-integrated-cpp
+ @opindex no-integrated-cpp
+ Invoke the external cpp during compilation.  The default is to use the
+ integrated cpp (internal cpp).  This option also allows a user-supplied cpp
+ via the @option{-B} option.  This flag is applicable in both C and C++ modes.
  
  @cindex traditional C language
  @cindex C language, traditional


thanks,
ashif harji


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