This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: [patch, fortran] PR18428: use libcpp for preprocessing (review of C/C++ maintainers needed)


* PING *

I now removed the already approved Fortran part from the patch and removed the diff for:

   * c-incpath.h: Renamed to ...
   * incpath.h: ... this.
   * c-incpath.c: Renamed to ...
   * incpath.c: ... this.

The now attached patch ( 8 files changed, 25 insertions(+), 90 deletions(-)) should be much easier to review. The long version can be found at: http://gcc.gnu.org/ml/gcc-patches/2008-04/msg01753.html

Tobias

Daniel Franke wrote:
Hi all.

This is to integrate libcpp into gfortran and not to rely on cc1 to do the preprocessing. The change became necessary to simplify the implementation of feature requests and fixing of problems related to preprocessing.
[...]
Hence, any workarounds using "-x f95-cpp-input" or resorting to .spec-files is now obsolete.


The C changes may be devided into two parts: firstly, the cleanup of an undocumented option and its handling; secondly, moving some functionality from gcc to libbackend to be reused by the fortran frontend (see also [1]). The latter changes should be reviewed very carefully as I am not very involved in with the build process ...
[...]
Thanks to Tom Tromey and all others who helped me to implement this so far!


gcc:
2008-04-23  Daniel Franke  <franke.daniel@gmail.com>

PR fortran/18428
* c.opt: Removed undocumented option '-lang-fortran'.
* c-common.h: Removed global variable 'lang_fortran'.
* c-opts.c (c_common_handle_option): Removed code to handle
option '-lang-fortran'.
* c-cppbuiltin.c (c_cpp_builtins): Removed conditional
definition of '__GFORTRAN__'.
(define__GNUC__): Reimplemented to use BASEVER and cpp_define_formatted.
(builtin_define_with_value_n): Removed.
* c-incpath.h: Renamed to ...
* incpath.h: ... this.
* c-incpath.c: Renamed to ...
* incpath.c: ... this.
* fix-header.c: Updated includes.
* Makefile.in: Replaced c-incpath.[ch] by incpath.[ch].
(c-cppbuiltin.o): Added dependency on and definition of BASEVER.
(OBJ-archive): Added cppdefault.o, incpath.o and prefix.o.
(PROTO_OBJS): Adjusted dependencies.
(fix-header): Likewise.



gcc/cp: 2008-04-23 Daniel Franke <franke.daniel@gmail.com>

* Makefile.in: Adjusted dependencies.

[...]

Bootstrapped and regression tested on i686-pc-linux-gnu.
Ok for trunk?
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 134518)
+++ Makefile.in	(working copy)
@@ -972,7 +972,7 @@ GCC_OBJS = gcc.o opts-common.o gcc-optio
 # Language-specific object files for C and Objective C.
 C_AND_OBJC_OBJS = attribs.o c-errors.o c-lex.o c-pragma.o c-decl.o c-typeck.o \
   c-convert.o c-aux-info.o c-common.o c-opts.o c-format.o c-semantics.o \
-  c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
+  c-ppoutput.o c-cppbuiltin.o \
   c-objc-common.o c-dump.o c-pch.o c-parser.o $(C_TARGET_OBJS) \
   c-gimplify.o tree-mudflap.o c-pretty-print.o c-omp.o
 
@@ -1228,6 +1228,8 @@ OBJS-archive = \
 	cgraph.o \
 	cgraphbuild.o \
 	cgraphunit.o \
+	cppdefault.o \
+	incpath.o \
 	ipa-cp.o \
 	ipa-inline.o \
 	ipa-prop.o \
@@ -1238,6 +1240,7 @@ OBJS-archive = \
 	ipa-utils.o \
 	ipa.o \
 	matrix-reorg.o \
+	prefix.o \
 	tree-inline.o \
 	tree-nomudflap.o \
 	varpool.o
@@ -1542,7 +1545,7 @@ xgcc$(exeext): $(GCC_OBJS) gccspec.o ver
 cpp$(exeext): $(GCC_OBJS) cppspec.o version.o intl.o prefix.o \
    version.o $(LIBDEPS) $(EXTRA_GCC_OBJS)
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GCC_OBJS) cppspec.o \
-	  intl.o prefix.o version.o $(EXTRA_GCC_OBJS) $(LIBS)
+	  intl.o version.o prefix.o $(EXTRA_GCC_OBJS) $(LIBS)
 
 # Dump a specs file to make -B./ read these specs over installed ones.
 $(SPECS): xgcc$(exeext)
@@ -1727,7 +1730,7 @@ srcextra: gcc.srcextra lang.srcextra
 gcc.srcextra: gengtype-lex.c
 	-cp -p $^ $(srcdir)
 
-c-incpath.o: c-incpath.c c-incpath.h $(CONFIG_H) $(SYSTEM_H) $(CPPLIB_H) \
+incpath.o: incpath.c incpath.h $(CONFIG_H) $(SYSTEM_H) $(CPPLIB_H) \
 		intl.h prefix.h coretypes.h $(TM_H) cppdefault.h $(TARGET_H) \
 		$(MACHMODE_H)
 
@@ -1810,13 +1813,15 @@ c-pretty-print.o : c-pretty-print.c $(C_
 c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H)		\
         $(TREE_H) $(C_PRAGMA_H) $(FLAGS_H) toplev.h langhooks.h		\
         $(TREE_INLINE_H) $(DIAGNOSTIC_H) intl.h debug.h $(C_COMMON_H)	\
-        opts.h options.h $(MKDEPS_H) c-incpath.h cppdefault.h $(TM_P_H)
+        opts.h options.h $(MKDEPS_H) incpath.h cppdefault.h $(TM_P_H)
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
 		$< $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@
 
 c-cppbuiltin.o : c-cppbuiltin.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
 	$(TREE_H) version.h $(C_COMMON_H) $(C_PRAGMA_H) $(FLAGS_H) toplev.h \
-	output.h except.h $(REAL_H) $(TARGET_H) $(TM_P_H)
+	output.h except.h $(REAL_H) $(TARGET_H) $(TM_P_H) $(BASEVER)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) -DBASEVER=$(BASEVER_s) \
+		$< $(OUTPUT_OPTION)
 
 # A file used by all variants of C and some other languages.
 
@@ -3312,7 +3317,7 @@ cppdefault.o: cppdefault.c $(CONFIG_H) $
 
 proto: config.status protoize$(exeext) unprotoize$(exeext) SYSCALLS.c.X
 
-PROTO_OBJS = intl.o version.o cppdefault.o errors.o
+PROTO_OBJS = intl.o version.o errors.o
 
 protoize$(exeext): protoize.o $(PROTO_OBJS) $(LIBDEPS)
 	$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ protoize.o $(PROTO_OBJS) $(LIBS)
@@ -3579,10 +3584,10 @@ xsys-protos.h: $(GCC_PASSES) $(srcdir)/s
 # This is nominally a 'build' program, but it's run only when host==build,
 # so we can (indeed, must) use $(LIBDEPS) and $(LIBS).
 build/fix-header$(build_exeext): build/fix-header.o build/scan-decls.o \
-  build/scan.o xsys-protos.h c-incpath.o cppdefault.o prefix.o \
+  build/scan.o xsys-protos.h \
   $(BUILD_ERRORS) $(LIBDEPS)
 	$(CC_FOR_BUILD) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) -o $@ \
-	 build/fix-header.o c-incpath.o cppdefault.o build/scan-decls.o prefix.o \
+	 build/fix-header.o build/scan-decls.o \
 	 build/scan.o $(BUILD_ERRORS) $(LIBS)
 
 build/fix-header.o: fix-header.c $(OBSTACK_H) scan.h errors.h \
Index: c-common.h
===================================================================
--- c-common.h	(revision 134518)
+++ c-common.h	(working copy)
@@ -262,8 +262,6 @@ extern c_language_kind c_language;
 #define c_dialect_cxx()		(c_language & clk_cxx)
 #define c_dialect_objc()	(c_language & clk_objc)
 
-extern bool lang_fortran;
-
 /* Information about a statement tree.  */
 
 struct stmt_tree_s GTY(()) {
Index: c-opts.c
===================================================================
--- c-opts.c	(revision 134518)
+++ c-opts.c	(working copy)
@@ -33,7 +33,7 @@ along with GCC; see the file COPYING3.  
 #include "diagnostic.h"
 #include "intl.h"
 #include "cppdefault.h"
-#include "c-incpath.h"
+#include "incpath.h"
 #include "debug.h"		/* For debug_hooks.  */
 #include "opts.h"
 #include "options.h"
@@ -72,9 +72,6 @@ static bool deps_seen;
 /* If -v seen.  */
 static bool verbose;
 
-/* If -lang-fortran seen.  */
-bool lang_fortran = false;
-
 /* Dependency output file.  */
 static const char *deps_file;
 
@@ -249,15 +246,6 @@ c_common_init_options (unsigned int argc
 	    result |= CL_C | CL_ObjC | CL_CXX | CL_ObjCXX;
 	    break;
 	  }
-
-#ifdef CL_Fortran
-      for (i = 1; i < argc; i++)
-	if (! strcmp (argv[i], "-lang-fortran"))
-	{
-	    result |= CL_Fortran;
-	    break;
-	}
-#endif
     }
 
   return result;
@@ -288,10 +276,6 @@ c_common_handle_option (size_t scode, co
 	    result = 0;
 	  break;
 	}
-#ifdef CL_Fortran
-      if (lang_fortran && (cl_options[code].flags & (CL_Fortran)))
-	break;
-#endif
       result = 0;
       break;
 
@@ -891,10 +875,6 @@ c_common_handle_option (size_t scode, co
       cpp_opts->dollars_in_ident = false;
       break;
 
-    case OPT_lang_fortran:
-      lang_fortran = true;
-      break;
-
     case OPT_lang_objc:
       cpp_opts->objc = 1;
       break;
Index: c.opt
===================================================================
--- c.opt	(revision 134518)
+++ c.opt	(working copy)
@@ -865,9 +865,6 @@ C ObjC C++ ObjC++ Joined Separate
 lang-asm
 C Undocumented
 
-lang-fortran
-C Undocumented
-
 lang-objc
 C ObjC C++ ObjC++ Undocumented
 
Index: fix-header.c
===================================================================
--- fix-header.c	(revision 134518)
+++ fix-header.c	(working copy)
@@ -78,7 +78,7 @@
 #include "obstack.h"
 #include "scan.h"
 #include "cpplib.h"
-#include "c-incpath.h"
+#include "incpath.h"
 #include "errors.h"
 
 #ifdef TARGET_EXTRA_INCLUDES
Index: cp/Make-lang.in
===================================================================
--- cp/Make-lang.in	(revision 134518)
+++ cp/Make-lang.in	(working copy)
@@ -72,7 +72,7 @@ g++-cross$(exeext): g++$(exeext)
 # Shared with C front end:
 CXX_C_OBJS = attribs.o c-common.o c-format.o c-pragma.o c-semantics.o c-lex.o \
 	c-dump.o $(CXX_TARGET_OBJS) c-pretty-print.o c-opts.o c-pch.o \
-	c-incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
+	incpath.o cppdefault.o c-ppoutput.o c-cppbuiltin.o prefix.o \
 	c-gimplify.o c-omp.o tree-inline.o
 
 # Language-specific object files for C++ and Objective C++.
Index: incpath.c
===================================================================
--- incpath.c	(revision 134518)
+++ incpath.c	(working copy)
@@ -28,7 +28,7 @@
 #include "cpplib.h"
 #include "prefix.h"
 #include "intl.h"
-#include "c-incpath.h"
+#include "incpath.h"
 #include "cppdefault.h"
 
 /* Windows does not natively support inodes, and neither does MSDOS.
Index: c-cppbuiltin.c
===================================================================
--- c-cppbuiltin.c	(revision 134518)
+++ c-cppbuiltin.c	(working copy)
@@ -48,8 +48,6 @@ along with GCC; see the file COPYING3.  
 
 /* Non-static as some targets don't use it.  */
 void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
-static void builtin_define_with_value_n (const char *, const char *,
-					 size_t);
 static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
 static void builtin_define_with_hex_fp_value (const char *, tree,
 					      int, const char *,
@@ -375,40 +373,17 @@ builtin_define_fixed_point_constants (co
 static void
 define__GNUC__ (void)
 {
-  /* The format of the version string, enforced below, is
-     ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?  */
-  const char *q, *v = version_string;
-
-  while (*v && !ISDIGIT (*v))
-    v++;
-  gcc_assert (*v && (v <= version_string || v[-1] == '-'));
-
-  q = v;
-  while (ISDIGIT (*v))
-    v++;
-  builtin_define_with_value_n ("__GNUC__", q, v - q);
-  if (c_dialect_cxx ())
-    builtin_define_with_value_n ("__GNUG__", q, v - q);
-
-  gcc_assert (*v == '.' && ISDIGIT (v[1]));
+  int major, minor, patchlevel;
 
-  q = ++v;
-  while (ISDIGIT (*v))
-    v++;
-  builtin_define_with_value_n ("__GNUC_MINOR__", q, v - q);
-
-  if (*v == '.')
-    {
-      gcc_assert (ISDIGIT (v[1]));
-      q = ++v;
-      while (ISDIGIT (*v))
-	v++;
-      builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", q, v - q);
+  if (sscanf (BASEVER, "%d.%d.%d", &major, &minor, &patchlevel) != 3)
+    {
+      sscanf (BASEVER, "%d.%d", &major, &minor);
+      patchlevel = 0;
     }
-  else
-    builtin_define_with_value_n ("__GNUC_PATCHLEVEL__", "0", 1);
+  cpp_define_formatted (parse_in, "__GNUC__=%d", major);
+  cpp_define_formatted (parse_in, "__GNUC_MINOR__=%d", minor);
+  cpp_define_formatted (parse_in, "__GNUC_PATCHLEVEL__=%d", patchlevel);
 
-  gcc_assert (!*v || *v == ' ' || *v == '-');
 }
 
 /* Define macros used by <stdint.h>.  Currently only defines limits
@@ -684,9 +659,6 @@ c_cpp_builtins (cpp_reader *pfile)
   if (flag_openmp)
     cpp_define (pfile, "_OPENMP=200505");
 
-  if (lang_fortran)
-    cpp_define (pfile, "__GFORTRAN__=1");
-
   builtin_define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
   builtin_define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
   builtin_define_type_sizeof ("__SIZEOF_LONG_LONG__",
@@ -799,23 +771,6 @@ builtin_define_with_value (const char *m
   cpp_define (parse_in, buf);
 }
 
-/* Pass an object-like macro and a value to define it to.  The third
-   parameter is the length of the expansion.  */
-static void
-builtin_define_with_value_n (const char *macro, const char *expansion, size_t elen)
-{
-  char *buf;
-  size_t mlen = strlen (macro);
-
-  /* Space for an = and a NUL.  */
-  buf = (char *) alloca (mlen + elen + 2);
-  memcpy (buf, macro, mlen);
-  buf[mlen] = '=';
-  memcpy (buf + mlen + 1, expansion, elen);
-  buf[mlen + elen + 1] = '\0';
-
-  cpp_define (parse_in, buf);
-}
 
 /* Pass an object-like macro and an integer value to define it to.  */
 static void

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