Hi Segher,

On 7/19/21 2:15 PM, Segher Boessenkool wrote:
Hi!

On Thu, Jun 17, 2021 at 10:18:54AM -0500, Bill Schmidt wrote:
        * config/rs6000/rs6000-gen-builtins.c (rbtree.h): New #include.
        (num_bifs): New variable.
        (num_ovld_stanzas): Likewise.
        (num_ovlds): Likewise.
        (parse_codes): New enum.
        (bif_rbt): New variable.
        (ovld_rbt): Likewise.
        (fntype_rbt): Likewise.
        (bifo_rbt): Likewise.
        (parse_bif): New stub function.
        (create_bif_order): Likewise.
        (parse_ovld): Likewise.
        (write_header_file): Likewise.
        (write_init_file): Likewise.
        (write_defines_file): Likewise.
        (delete_output_files): New function.
        (main): Likewise.
+/* Parse the built-in file.  */
+static parse_codes
+parse_bif (void)
+{
+  return PC_OK;
+}
Baby steps :-)

+/* Write everything to the header file (rs6000-builtins.h).  */
+static int
+write_header_file (void)
+{
+  return 1;
+}
What does the return value mean?  Please document it in a comment.  Same
for other functions (where the function name does not make it obvious
what the return value is).

+static void
+delete_output_files (void)
+{
+  /* Depending on whence we're called, some of these may already be
+     closed.  Don't check for errors.  */
+  fclose (header_file);
+  fclose (init_file);
+  fclose (defines_file);
+
+  unlink (header_path);
+  unlink (init_path);
+  unlink (defines_path);
+}
What are header_path etc.?  It is a very good idea to make sure this is
never something terrible to call unlink on (including making sure the
delete_output_files function is *obviously* never called if creating the
files didn't succeed).

See the main function.  All three files are guaranteed to have been opened for writing when this is called, but some of them may have already been closed.  So the fclose calls may fail to do anything, but the unlinks will always delete the output files. This is done to avoid leaving garbage lying around after a parsing failure.


+/* Main program to convert flat files into built-in initialization code.  */
+int
+main (int argc, const char **argv)
+{
+  if (argc != 6)
+    {
+      fprintf (stderr,
+              "Five arguments required: two input file and three output "
+              "files.\n");
Two input file_s_ :-)  (Or s/file //).

+  pgm_path = argv[0];
This isn't portable (depending on what you use it for -- argv[0] is not
necessarily a path at all).

The only thing it's used for is as a documentation string in the output files, indicating the path to the program that built them. So long as argv[0] is a NULL-terminated string, which it had better be, this is harmless.

ISO C11:  "If the value of|argc|is greater than zero, the string pointed to by|argv[0]|represents the program name;|argv[0][0]|shall be the null character if the program name is not available from the host environment."

So I think we're good here.


+  bif_file = fopen (bif_path, "r");
+  if (!bif_file)
+    {
+      fprintf (stderr, "Cannot find input built-in file '%s'.\n", bif_path);
+      exit (1);
+    }
Say s/find/open/ in the error?

+      fprintf (stderr, "Cannot find input overload file '%s'.\n", ovld_path);
(more)

Okay with those trivialities, and the unlink stuff looked at.  Thanks!

I'll get this cleaned up and post what I commit.  Thanks!

Bill




Segher

Reply via email to