diff options
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r-- | gcc/toplev.c | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c index 4ad6f1d..8a471d8 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1,6 +1,6 @@ /* Top level of GCC compilers (cc1, cc1plus, etc.) Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GCC. @@ -239,7 +239,7 @@ int in_system_header = 0; int flag_detailed_statistics = 0; /* A random sequence of characters, unless overridden by user. */ -const char *flag_random_seed; +static 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 @@ -451,23 +451,20 @@ announce_function (tree decl) } } -/* Set up a default flag_random_seed and local_tick, unless the user - already specified one. */ +/* Initialize local_tick with the time of day, or -1 if + flag_random_seed is set. */ static void -randomize (void) +init_local_tick (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; + struct timeval tv; - gettimeofday (&tv, NULL); + gettimeofday (&tv, NULL); local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000; } #else @@ -478,15 +475,47 @@ randomize (void) local_tick = (unsigned) now; } #endif - value = local_tick ^ getpid (); - - sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); - flag_random_seed = random_seed; } - else if (!local_tick) + else local_tick = -1; } +/* Set up a default flag_random_seed and local_tick, unless the user + already specified one. Must be called after init_local_tick. */ + +static void +init_random_seed (void) +{ + unsigned HOST_WIDE_INT value; + static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; + + value = local_tick ^ getpid (); + + sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); + flag_random_seed = random_seed; +} + +/* Obtain the random_seed string. Unless NOINIT, initialize it if + it's not provided in the command line. */ + +const char * +get_random_seed (bool noinit) +{ + if (!flag_random_seed && !noinit) + init_random_seed (); + return flag_random_seed; +} + +/* Modify the random_seed string to VAL. Return its previous + value. */ + +const char * +set_random_seed (const char *val) +{ + const char *old = flag_random_seed; + flag_random_seed = val; + return old; +} /* Decode the string P as an integral parameter. If the string is indeed an integer return its numeric value else @@ -1277,7 +1306,8 @@ print_switch_values (print_switch_fn_type print_fn) /* Fill in the -frandom-seed option, if the user didn't pass it, so that it can be printed below. This helps reproducibility. */ - randomize (); + if (!flag_random_seed) + init_random_seed (); /* Print the options as passed. */ pos = print_single_switch (print_fn, pos, @@ -2119,7 +2149,7 @@ toplev_main (unsigned int argc, const char **argv) enough to default flags appropriately. */ decode_options (argc, argv); - randomize (); + init_local_tick (); /* Exit early if we can (e.g. -help). */ if (!exit_after_options) |