[project @ 2005-04-11 14:43:06 by simonmar]
[ghc-hetmet.git] / ghc / rts / RtsFlags.c
index d79136b..3b88496 100644 (file)
@@ -1,5 +1,5 @@
+
 /* -----------------------------------------------------------------------------
- * $Id: RtsFlags.c,v 1.76 2004/09/03 15:28:40 simonmar Exp $
  *
  * (c) The AQUA Project, Glasgow University, 1994-1997
  * (c) The GHC Team, 1998-1999
@@ -152,7 +152,7 @@ void initRtsFlagsDefaults(void)
     RtsFlags.GcFlags.maxStkSize                = (8 * 1024 * 1024) / sizeof(W_);
     RtsFlags.GcFlags.initialStkSize    = 1024 / sizeof(W_);
 
-    RtsFlags.GcFlags.minAllocAreaSize   = (256 * 1024)        / BLOCK_SIZE;
+    RtsFlags.GcFlags.minAllocAreaSize   = (512 * 1024)        / BLOCK_SIZE;
     RtsFlags.GcFlags.minOldGenSize      = (1024 * 1024)       / BLOCK_SIZE;
     RtsFlags.GcFlags.maxHeapSize       = 0;    /* off by default */
     RtsFlags.GcFlags.heapSizeSuggestion        = 0;    /* none */
@@ -184,6 +184,7 @@ void initRtsFlagsDefaults(void)
     RtsFlags.DebugFlags.block_alloc    = rtsFalse;
     RtsFlags.DebugFlags.sanity         = rtsFalse;
     RtsFlags.DebugFlags.stable         = rtsFalse;
+    RtsFlags.DebugFlags.stm             = rtsFalse;
     RtsFlags.DebugFlags.prof           = rtsFalse;
     RtsFlags.DebugFlags.gran           = rtsFalse;
     RtsFlags.DebugFlags.par            = rtsFalse;
@@ -425,8 +426,9 @@ usage_text[] = {
 "  -Dr  DEBUG: gran",
 "  -DP  DEBUG: par",
 "  -Dl  DEBUG: linker",
+"  -Dm  DEBUG: stm",
 "",
-#endif // DEBUG
+#endif /* DEBUG */
 #if defined(SMP)
 "  -N<n>     Use <n> OS threads (default: 1)",
 #endif
@@ -497,21 +499,8 @@ setupRtsFlags(int *argc, char *argv[], int *rts_argc, char *rts_argv[])
     rtsBool error = rtsFalse;
     I_ mode;
     I_ arg, total_arg;
-    char *last_slash;
-
-    /* Remove directory from argv[0] -- default files in current directory */
-    if ((last_slash = (char *) strrchr(argv[0], 
-#if !defined(mingw32_TARGET_OS)
-                                      '/')
-#else
-                                      '\\')
-#endif
-                                      ) != NULL) {
-       prog_name = last_slash+1;
-    } else {
-       prog_name = argv[0];
-    }
 
+    setProgName (argv);
     total_arg = *argc;
     arg = 1;
 
@@ -730,6 +719,9 @@ error = rtsTrue;
                      case 'a':
                          RtsFlags.DebugFlags.apply = rtsTrue;
                          break;
+                     case 'm':
+                         RtsFlags.DebugFlags.stm = rtsTrue;
+                         break;
                      default:
                          bad_option( rts_argv[arg] );
                      }
@@ -981,7 +973,7 @@ error = rtsTrue;
                    error = rtsTrue;
                }
                ) 
-#endif // PROFILING
+#endif /* PROFILING */
                break;
 
 #if defined(PROFILING) 
@@ -2186,3 +2178,53 @@ bad_option(const char *s)
   errorBelch("bad RTS option: %s", s);
   stg_exit(EXIT_FAILURE);
 }
+
+/* -----------------------------------------------------------------------------
+   Getting/Setting the program's arguments.
+
+   These are used by System.Environment, and parts of the RTS.
+   -------------------------------------------------------------------------- */
+
+void
+setProgName(char *argv[])
+{
+    /* Remove directory from argv[0] -- default files in current directory */
+#if !defined(mingw32_HOST_OS)
+    char *last_slash;
+    if ( (last_slash = (char *) strrchr(argv[0], '/')) != NULL ) {
+       prog_name = last_slash+1;
+   } else {
+       prog_name = argv[0];
+   }
+#else
+    char* last_slash = argv[0] + (strlen(argv[0]) - 1);
+    while ( last_slash > argv[0] ) {
+       if ( *last_slash == '/' || *last_slash == '\\' ) {
+           prog_name = last_slash+1;
+           return;
+       }
+       last_slash--;
+    }
+    prog_name = argv[0];
+#endif
+}
+
+void
+getProgArgv(int *argc, char **argv[])
+{
+    if (argc) { *argc = prog_argc; }
+    if (argv) { *argv = prog_argv; }
+}
+
+void
+setProgArgv(int argc, char *argv[])
+{
+   /* Usually this is done by startupHaskell, so we don't need to call this. 
+      However, sometimes Hugs wants to change the arguments which Haskell
+      getArgs >>= ... will be fed.  So you can do that by calling here
+      _after_ calling startupHaskell.
+   */
+   prog_argc = argc;
+   prog_argv = argv;
+   setProgName(prog_argv);
+}