/* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.46 2001/08/08 14:14:08 simonmar Exp $
+ * $Id: RtsFlags.c,v 1.51 2001/10/01 11:36:28 simonmar Exp $
*
* (c) The AQUA Project, Glasgow University, 1994-1997
* (c) The GHC Team, 1998-1999
//@node Includes, Constants
//@subsection Includes
+#include "PosixSource.h"
#include "Rts.h"
#include "RtsFlags.h"
#include "RtsUtils.h"
" -k<size> Sets the initial thread stack size (default 1k) Egs: -K4k -K2m",
"",
" -A<size> Sets the minimum allocation area size (default 256k) Egs: -A1m -A10k",
-" -M<size> Sets the maximum heap size (default 64M) Egs: -M256k -M1G",
+" -M<size> Sets the maximum heap size (default unlimited) Egs: -M256k -M1G",
" -H<size> Sets the minimum heap size (default 0M) Egs: -H24m -H1G",
" -m<n> Minimum % of heap which must be available (default 3%)",
" -G<n> Number of generations (default: 2)",
return(strcmp(a, b) == 0);
}
+static void
+splitRtsFlags(char *s, int *rts_argc, char *rts_argv[])
+{
+ char *c1, *c2;
+
+ c1 = s;
+ do {
+ while (isspace(*c1)) { c1++; };
+ c2 = c1;
+ while (!isspace(*c2) && *c2 != '\0') { c2++; };
+
+ if (c1 == c2) { break; }
+
+ if (*rts_argc < MAX_RTS_ARGS-1) {
+ s = malloc(c2-c1+1);
+ strncpy(s, c1, c2-c1);
+ s[c2-c1] = '\0';
+ rts_argv[(*rts_argc)++] = s;
+ } else {
+ barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
+ }
+
+ c1 = c2;
+ } while (*c1 != '\0');
+}
+
void
setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
{
*argc = 1;
*rts_argc = 0;
+ // process arguments from the ghc_rts_opts global variable first.
+ // (arguments from the GHCRTS environment variable and the command
+ // line override these).
+ {
+ if (ghc_rts_opts != NULL) {
+ splitRtsFlags(ghc_rts_opts, rts_argc, rts_argv);
+ }
+ }
+
// process arguments from the GHCRTS environment variable first
// (arguments from the command line override these).
{
char *ghc_rts = getenv("GHCRTS");
- char *c1, *c2, *s;
if (ghc_rts != NULL) {
- c1 = ghc_rts;
- do {
- while (isspace(*c1)) { c1++; };
- c2 = c1;
- while (!isspace(*c2) && *c2 != '\0') { c2++; };
-
- if (c1 == c2) { break; }
-
- if (*rts_argc < MAX_RTS_ARGS-1) {
- s = malloc(c2-c1+1);
- strncpy(s, c1, c2-c1);
- s[c2-c1] = '\0';
- rts_argv[(*rts_argc)++] = s;
- } else {
- barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
- }
-
- c1 = c2;
- } while (*c1 != '\0');
+ splitRtsFlags(ghc_rts, rts_argc, rts_argv);
}
}
// Split arguments (argv) into PGM (argv) and RTS (rts_argv) parts
// argv[0] must be PGM argument -- leave in argv
- for (mode = PGM; arg < total_arg && ! strequal("--RTS", argv[arg]); arg++) {
- if (strequal("+RTS", argv[arg])) {
+ for (mode = PGM; arg < total_arg; arg++) {
+ // The '--RTS' argument disables all future +RTS ... -RTS processing.
+ if (strequal("--RTS", argv[arg])) {
+ arg++;
+ break;
+ }
+ // The '--' argument is passed through to the program, but
+ // disables all further +RTS ... -RTS processing.
+ else if (strequal("--", argv[arg])) {
+ break;
+ }
+ else if (strequal("+RTS", argv[arg])) {
mode = RTS;
}
else if (strequal("-RTS", argv[arg])) {
barf("too many RTS arguments (max %d)", MAX_RTS_ARGS-1);
}
}
- if (arg < total_arg) {
- /* arg must be --RTS; process remaining program arguments */
- while (++arg < total_arg) {
- argv[(*argc)++] = argv[arg];
- }
+ // process remaining program arguments
+ for (; arg < total_arg; arg++) {
+ argv[(*argc)++] = argv[arg];
}
argv[*argc] = (char *) 0;
rts_argv[*rts_argc] = (char *) 0;
/* =========== PROFILING ========================== */
case 'P': /* detailed cost centre profiling (time/alloc) */
- COST_CENTRE_USING_BUILD_ONLY(
- RtsFlags.CcFlags.doCostCentres = COST_CENTRES_VERBOSE;
- )
case 'p': /* cost centre profiling (time/alloc) */
COST_CENTRE_USING_BUILD_ONLY(
switch (rts_argv[arg][2]) {
RtsFlags.CcFlags.doCostCentres = COST_CENTRES_ALL;
break;
default:
- RtsFlags.CcFlags.doCostCentres = COST_CENTRES_SUMMARY;
- break;
+ if (rts_argv[arg][1] == 'P') {
+ RtsFlags.CcFlags.doCostCentres =
+ COST_CENTRES_VERBOSE;
+ } else {
+ RtsFlags.CcFlags.doCostCentres =
+ COST_CENTRES_SUMMARY;
+ }
+ break;
}
) break;
case 9: RtsFlags.DebugFlags.prof = rtsTrue; break;
case 10: RtsFlags.DebugFlags.gran = rtsTrue; break;
case 11: RtsFlags.DebugFlags.par = rtsTrue; break;
+ case 12: RtsFlags.DebugFlags.linker = rtsTrue; break;
default: barf("set_debug_options: only %d debug options expected",
MAX_DEBUG_OPTION);
} /* switch */