tree.h (default_flag_random_seed): Remove.
authorNathan Sidwell <nathan@codesourcery.com>
Sun, 6 Jul 2003 14:48:56 +0000 (14:48 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Sun, 6 Jul 2003 14:48:56 +0000 (14:48 +0000)
* tree.h (default_flag_random_seed): Remove.
* toplev.h (local_tick): Declare.
* tree.c (flag_random_seed, default_flag_random_seed): Move to
toplev.c.
(append_random_chars): Don't call default_flag_random_seed.
* toplev.c (flag_random_seed): Define here. Set local_tick.
(local_tick): Define.
(randomize): New, moved from tree.c.
(print_switch_values): Adjust.
(toplev_main): Call randomize.

From-SVN: r69005

gcc/ChangeLog
gcc/toplev.c
gcc/toplev.h
gcc/tree.c
gcc/tree.h

index 54bc84f00dc9e2a3a2e00c4d910c5f7de8f14f94..da3621f50764759795983cbf85ceefe5f5935e07 100644 (file)
@@ -1,3 +1,16 @@
+2003-07-06  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * tree.h (default_flag_random_seed): Remove.
+       * toplev.h (local_tick): Declare.
+       * tree.c (flag_random_seed, default_flag_random_seed): Move to
+       toplev.c.
+       (append_random_chars): Don't call default_flag_random_seed.
+       * toplev.c (flag_random_seed): Define here. Set local_tick.
+       (local_tick): Define.
+       (randomize): New, moved from tree.c.
+       (print_switch_values): Adjust.
+       (toplev_main): Call randomize.
+
 2003-07-06  Nathan Sidwell  <nathan@codesourcery.com>
 
        * tree.h (crc32_string): Declare.
index 33374679f64eab77842aef5833a226e590e4faf2..6351b69c7a9a02c455d32507aab5134d10e005f3 100644 (file)
@@ -463,6 +463,14 @@ int mem_report = 0;
    and to print them when we are done.  */
 int flag_detailed_statistics = 0;
 
+/* A random sequence of characters, unless overridden by user. */
+const char *flag_random_seed;
+
+/* A local time stamp derived from the time of compilation. It will be
+   zero if the system cannot provide a time.  It will be -1u, if the
+   user has specified a particular random seed.  */
+unsigned local_tick;
+
 /* -f flags.  */
 
 /* Nonzero means `char' should be signed.  */
@@ -1560,6 +1568,43 @@ FILE *asm_out_file;
 FILE *aux_info_file;
 FILE *rtl_dump_file = NULL;
 
+/* Set up a default flag_random_seed and local_tick, unless the user
+   already specified one.  */
+
+static void
+randomize (void)
+{
+  if (!flag_random_seed)
+    {
+      unsigned HOST_WIDE_INT value;
+      static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
+      
+      /* Get some more or less random data.  */
+#ifdef HAVE_GETTIMEOFDAY
+      {
+       struct timeval tv;
+       
+       gettimeofday (&tv, NULL);
+       local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+      }
+#else
+      {
+       time_t now = time ();
+
+       if (now != (time_t)-1)
+         local_tick = (unsigned) now;
+      }
+#endif
+      value = local_tick ^ getpid ();
+      
+      sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
+      flag_random_seed = random_seed;
+    }
+  else
+    local_tick = -1;
+}
+
+
 /* Decode the string P as an integral parameter.
    If the string is indeed an integer return its numeric value else
    issue an Invalid Option error for the option PNAME and return DEFVAL.
@@ -4394,13 +4439,10 @@ print_switch_values (FILE *file, int pos, int max,
   const char **p;
 
   /* Fill in the -frandom-seed option, if the user didn't pass it, so
-     that it can be printed below.  This helps reproducibility.  Of
-     course, the string may never be used, but we can't tell that at
-     this point in the compile.  */
-  default_flag_random_seed ();
+     that it can be printed below.  This helps reproducibility.  */
+  randomize ();
 
   /* Print the options as passed.  */
-
   pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
                             _("options passed: "), "");
 
@@ -4969,6 +5011,8 @@ toplev_main (unsigned int argc, const char **argv)
      enough to default flags appropriately.  */
   decode_options (argc, argv);
 
+  randomize ();
+
   /* Exit early if we can (e.g. -help).  */
   if (!exit_after_options)
     do_compile ();
index e750207b92365145cb8f56bf7a2e8f7ea29452aa..e9c7e0dec5584b1ad5d89e54fa296dd199261bcb 100644 (file)
@@ -104,6 +104,9 @@ extern void fnotice                 (FILE *, const char *, ...)
 extern int wrapup_global_declarations   (union tree_node **, int);
 extern void check_global_declarations   (union tree_node **, int);
 
+/* A unique local time stamp, might be zero if none is available.  */
+extern unsigned local_tick;
+
 extern const char *progname;
 extern const char *dump_base_name;
 extern const char *aux_base_name;
index a0f5414665d9d25793e92ba61207777cbe3ea43f..b61a70b262fc825d9c135242f61f9a34476b948f 100644 (file)
@@ -4464,38 +4464,6 @@ dump_tree_statistics (void)
 \f
 #define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
 
-const char *flag_random_seed;
-
-/* Set up a default flag_random_seed value, if there wasn't one already.  */
-
-void
-default_flag_random_seed (void)
-{
-  unsigned HOST_WIDE_INT value;
-  char *new_random_seed;
-
-  if (flag_random_seed != NULL)
-    return;
-
-  /* Get some more or less random data.  */
-#ifdef HAVE_GETTIMEOFDAY
- {
-   struct timeval tv;
-
-   gettimeofday (&tv, NULL);
-   value = (((unsigned HOST_WIDE_INT) tv.tv_usec << 16)
-           ^ tv.tv_sec ^ getpid ());
- }
-#else
-  value = getpid ();
-#endif
-
-  /* This slightly overestimates the space required.  */
-  new_random_seed = xmalloc (HOST_BITS_PER_WIDE_INT / 3 + 2);
-  sprintf (new_random_seed, HOST_WIDE_INT_PRINT_UNSIGNED, value);
-  flag_random_seed = new_random_seed;
-}
-
 /* Generate a crc32 of a string.  */
 
 unsigned
@@ -4568,7 +4536,6 @@ get_file_function_name_long (const char *type)
       memcpy (q, file, len + 1);
       clean_symbol_name (q);
 
-      default_flag_random_seed ();
       sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
               crc32_string (0, flag_random_seed));
 
index 9be653250a9a95ddf0216a48a09a5539a73512c0..a11a7e5abaaf3edac4b2109c3959e7f26dc1870c 100644 (file)
@@ -2931,7 +2931,6 @@ extern void expand_start_case_dummy (void);
 extern HOST_WIDE_INT all_cases_count (tree, int *);
 extern void check_for_full_enumeration_handling (tree);
 extern void declare_nonlocal_label (tree);
-extern void default_flag_random_seed (void);
 
 /* If KIND=='I', return a suitable global initializer (constructor) name.
    If KIND=='D', return a suitable global clean-up (destructor) name.  */