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]

MI guards for generated header files


This patch adds MI guards to genrtl.h, insn-attr.h, insn-codes.h,
insn-config.h, and insn-flags.h.  I also took the opportunity to make
the error check at exit of the affected generators a bit more robust.

I've bootstrapped the gcc subdir and run check-gcc with this patch.  I
cannot build libstdc++ or libjava right now.

zw

	* gengenrtl.c, genattr.c, gencodes.c, genconfig.c, genflags.c:
	Wrap the generated header in an #ifndef _FOO_H ... #endif block.
	Check error result of ferror, fflush, and fclose, in that order.

===================================================================
Index: gengenrtl.c
--- gengenrtl.c	2001/03/27 15:31:45	1.41
+++ gengenrtl.c	2001/03/31 16:22:02
@@ -351,7 +351,10 @@ genheader ()
 {
   int i;
   const char **fmt;
-  
+
+  puts ("#ifndef _GENRTL_H");
+  puts ("#define _GENRTL_H\n");
+
   for (fmt = formats; *fmt; ++fmt)
     gendecl (*fmt);
 
@@ -360,6 +363,8 @@ genheader ()
   for (i = 0; i < NUM_RTX_CODE; i++)
     if (! special_format (defs[i].format))
       genmacro (i);
+
+  puts ("\n#endif /* _GENRTL_H */");
 }
 
 /* Generate the text of the code file we write, genrtl.c.  */
@@ -419,7 +424,9 @@ main (argc, argv)
     genheader ();
   else
     gencode ();
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
 
-  fflush (stdout);
-  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+  return SUCCESS_EXIT_CODE;
 }
===================================================================
Index: genattr.c
--- genattr.c	2001/03/06 09:52:31	1.39
+++ genattr.c	2001/03/31 16:22:02
@@ -213,14 +213,16 @@ main (argc, argv)
   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
     return (FATAL_EXIT_CODE);
 
-  printf ("/* Generated automatically by the program `genattr'\n\
-from the machine description file `md'.  */\n\n");
+  puts ("/* Generated automatically by the program `genattr'");
+  puts ("   from the machine description file `md'.  */\n");
+  puts ("#ifndef _INSN_ATTR_H");
+  puts ("#define _INSN_ATTR_H\n");
 
   /* For compatibility, define the attribute `alternative', which is just
      a reference to the variable `which_alternative'.  */
 
-  printf ("#define HAVE_ATTR_alternative\n");
-  printf ("#define get_attr_alternative(insn) which_alternative\n");
+  puts ("#define HAVE_ATTR_alternative");
+  puts ("#define get_attr_alternative(insn) which_alternative");
      
   /* Read the machine description.  */
 
@@ -359,8 +361,12 @@ from the machine description file `md'. 
   printf("#define ATTR_FLAG_unlikely\t0x10\n");
   printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
 
-  fflush (stdout);
-  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+  puts("\n#endif /* _INSN_ATTR_H */");
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
+
+  return SUCCESS_EXIT_CODE;
 }
 
 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
===================================================================
Index: gencodes.c
--- gencodes.c	2001/01/15 13:19:31	1.38
+++ gencodes.c	2001/03/31 16:22:02
@@ -88,11 +88,11 @@ main (argc, argv)
   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
     return (FATAL_EXIT_CODE);
 
-  printf ("/* Generated automatically by the program `gencodes'\n\
-from the machine description file `md'.  */\n\n");
+  puts ("/* Generated automatically by the program `gencodes'");
+  puts ("   from the machine description file `md'.  */\n");
+  puts ("#ifndef _INSN_CODES_H");
+  puts ("#define _INSN_CODES_H\n");
 
-  printf ("#ifndef MAX_INSN_CODE\n\n");
-
   /* Read the machine description.  */
 
   insn_code_number = 0;
@@ -117,11 +117,13 @@ from the machine description file `md'. 
   traverse_md_constants (print_md_constant, stdout);
 
   output_predicate_decls ();
+
+  puts("\n#endif /* _INSN_CODES_H */");
 
-  printf ("\n#endif /* MAX_INSN_CODE */\n");
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
 
-  fflush (stdout);
-  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+  return SUCCESS_EXIT_CODE;
 }
 
 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
===================================================================
Index: genconfig.c
--- genconfig.c	2000/05/28 02:17:58	1.39
+++ genconfig.c	2001/03/31 16:22:02
@@ -280,8 +280,10 @@ main (argc, argv)
   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
     return (FATAL_EXIT_CODE);
 
-  printf ("/* Generated automatically by the program `genconfig'\n\
-from the machine description file `md'.  */\n\n");
+  puts ("/* Generated automatically by the program `genconfig'");
+  puts ("   from the machine description file `md'.  */\n");
+  puts ("#ifndef _INSN_CONFIG_H");
+  puts ("#define _INSN_CONFIG_H\n");
 
   /* Allow at least 10 operands for the sake of asm constructs.  */
   max_recog_operands = 9;  /* We will add 1 later.  */
@@ -356,8 +358,12 @@ from the machine description file `md'. 
       printf ("#define MAX_INSNS_PER_PEEP2 %d\n", max_insns_per_peep2);
     }
 
-  fflush (stdout);
-  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+  puts("\n#endif /* _INSN_CONFIG_H */");
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
+
+  return SUCCESS_EXIT_CODE;
 }
 
 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
===================================================================
Index: genflags.c
--- genflags.c	2001/03/22 18:48:29	1.36
+++ genflags.c	2001/03/31 16:22:02
@@ -233,8 +233,10 @@ main (argc, argv)
   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
     return (FATAL_EXIT_CODE);
   
-  printf ("/* Generated automatically by the program `genflags'\n\
-from the machine description file `md'.  */\n\n");
+  puts ("/* Generated automatically by the program `genflags'");
+  puts ("   from the machine description file `md'.  */\n");
+  puts ("#ifndef _INSN_FLAGS_H");
+  puts ("#define _INSN_FLAGS_H\n");
 
   /* Read the machine description.  */
 
@@ -258,8 +260,12 @@ from the machine description file `md'. 
   for (insn_ptr = insns; *insn_ptr; insn_ptr++)
     gen_proto (*insn_ptr);
 
-  fflush (stdout);
-  return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
+  puts("\n#endif /* _INSN_FLAGS_H */");
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
+
+  return SUCCESS_EXIT_CODE;
 }
 
 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */


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