/* Code to maintain a C++ template repository.
- Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
- Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
+ 2006, 2007 Free Software Foundation, Inc.
Contributed by Jason Merrill (jason@cygnus.com)
This file is part of GCC.
obstack_free (&temporary_obstack, buf);
}
fclose (repo_file);
+
+ if (old_args && !get_random_seed (true)
+ && (buf = strstr (old_args, "'-frandom-seed=")))
+ set_random_seed (extract_string (&buf) + strlen ("-frandom-seed="));
}
static FILE *
anonymous namespaces will get the same mangling when this
file is recompiled. */
if (!strstr (args, "'-frandom-seed="))
- fprintf (repo_file, " '-frandom-seed=%s'", flag_random_seed);
+ fprintf (repo_file, " '-frandom-seed=%s'", get_random_seed (false));
fprintf (repo_file, "\n");
}
/* 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.
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
}
}
-/* 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
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
/* 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,
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)
/* toplev.h - Various declarations for functions found in toplev.c
- Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005
+ Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007
Free Software Foundation, Inc.
This file is part of GCC.
extern const char *get_src_pwd (void);
extern bool set_src_pwd (const char *);
+/* Functions used to manipulate the random seed. */
+
+extern const char *get_random_seed (bool);
+extern const char *set_random_seed (const char *);
+
#endif /* ! GCC_TOPLEV_H */