Make some profiling flags dynamic
[ghc-hetmet.git] / compiler / main / StaticFlagParser.hs
index c0a501e..7ed4c4c 100644 (file)
@@ -16,6 +16,7 @@ module StaticFlagParser (parseStaticFlags) where
 import StaticFlags
 import CmdLineParser
 import Config
+import SrcLoc
 import Util
 import Panic
 
@@ -27,23 +28,39 @@ import Data.List
 -----------------------------------------------------------------------------
 -- Static flags
 
-parseStaticFlags :: [String] -> IO ([String], [String])
+-- | Parses GHC's static flags from a list of command line arguments.
+--
+-- These flags are static in the sense that they can be set only once and they
+-- are global, meaning that they affect every instance of GHC running;
+-- multiple GHC threads will use the same flags.
+--
+-- This function must be called before any session is started, i.e., before
+-- the first call to 'GHC.withGhc'.
+--
+-- Static flags are more of a hack and are static for more or less historical
+-- reasons.  In the long run, most static flags should eventually become
+-- dynamic flags.
+--
+-- XXX: can we add an auto-generated list of static flags here?
+--
+parseStaticFlags :: [Located String] -> IO ([Located String], [Located String])
 parseStaticFlags args = do
   ready <- readIORef v_opt_C_ready
   when ready $ ghcError (ProgramError "Too late for parseStaticFlags: call it before newSession")
 
   (leftover, errs, warns1) <- processArgs static_flags args
-  when (not (null errs)) $ ghcError (UsageError (unlines errs))
+  when (not (null errs)) $ ghcError $ errorsToGhcException errs
 
     -- deal with the way flags: the way (eg. prof) gives rise to
     -- further flags, some of which might be static.
   way_flags <- findBuildTag
+  let way_flags' = map (mkGeneralLocated "in way flags") way_flags
 
     -- if we're unregisterised, add some more flags
   let unreg_flags | cGhcUnregisterised == "YES" = unregFlags
                  | otherwise = []
 
-  (more_leftover, errs, warns2) <- processArgs static_flags (unreg_flags ++ way_flags)
+  (more_leftover, errs, warns2) <- processArgs static_flags (unreg_flags ++ way_flags')
 
     -- see sanity code in staticOpts
   writeIORef v_opt_C_ready True
@@ -52,16 +69,19 @@ parseStaticFlags args = do
     -- Be careful to do this *after* all processArgs,
     -- because evaluating tablesNextToCode involves looking at the global
     -- static flags.  Those pesky global variables...
-  let cg_flags | tablesNextToCode = ["-optc-DTABLES_NEXT_TO_CODE"]
-              | otherwise        = []
+  let cg_flags | tablesNextToCode = map (mkGeneralLocated "in cg_flags")
+                                        ["-optc-DTABLES_NEXT_TO_CODE"]
+               | otherwise        = []
 
     -- HACK: -fexcess-precision is both a static and a dynamic flag.  If
     -- the static flag parser has slurped it, we must return it as a 
     -- leftover too.  ToDo: make -fexcess-precision dynamic only.
-  let excess_prec | opt_SimplExcessPrecision = ["-fexcess-precision"]
-                  | otherwise                = []
+  let excess_prec
+       | opt_SimplExcessPrecision = map (mkGeneralLocated "in excess_prec")
+                                        ["-fexcess-precision"]
+       | otherwise                = []
 
-  when (not (null errs)) $ ghcError (UsageError (unlines errs))
+  when (not (null errs)) $ ghcError $ errorsToGhcException errs
   return (excess_prec ++ cg_flags ++ more_leftover ++ leftover,
           warns1 ++ warns2)
 
@@ -102,24 +122,9 @@ static_flags = [
   , Flag "dppr-user-length"  (AnySuffix addOpt) Supported
   , Flag "dopt-fuel"         (AnySuffix addOpt) Supported
   , Flag "dno-debug-output"  (PassFlag addOpt) Supported
+  , Flag "dstub-dead-values" (PassFlag addOpt) Supported
       -- rest of the debugging flags are dynamic
 
-        --------- Profiling --------------------------------------------------
-  , Flag "auto-all"       (NoArg (addOpt "-fauto-sccs-on-all-toplevs"))
-         Supported
-  , Flag "auto"           (NoArg (addOpt "-fauto-sccs-on-exported-toplevs"))
-         Supported
-  , Flag "caf-all"        (NoArg (addOpt "-fauto-sccs-on-individual-cafs"))
-         Supported
-         -- "ignore-sccs"  doesn't work  (ToDo)
-
-  , Flag "no-auto-all"    (NoArg (removeOpt "-fauto-sccs-on-all-toplevs"))
-         Supported
-  , Flag "no-auto"        (NoArg (removeOpt "-fauto-sccs-on-exported-toplevs"))
-         Supported
-  , Flag "no-caf-all"     (NoArg (removeOpt "-fauto-sccs-on-individual-cafs"))
-         Supported
-
         ----- Linker --------------------------------------------------------
   , Flag "static"         (PassFlag addOpt) Supported
   , Flag "dynamic"        (NoArg (removeOpt "-static")) Supported
@@ -138,16 +143,12 @@ static_flags = [
          Supported
 
         -- Pass all remaining "-f<blah>" options to hsc
-  , Flag "f"                      (AnySuffixPred (isStaticFlag) addOpt)
-         Supported
+  , Flag "f" (AnySuffixPred isStaticFlag addOpt) Supported
   ]
 
 isStaticFlag :: String -> Bool
 isStaticFlag f =
   f `elem` [
-    "fauto-sccs-on-all-toplevs",
-    "fauto-sccs-on-exported-toplevs",
-    "fauto-sccs-on-individual-cafs",
     "fscc-profiling",
     "fdicts-strict",
     "fspec-inline-join-points",
@@ -156,10 +157,11 @@ isStaticFlag f =
     "fgransim",
     "fno-hi-version-check",
     "dno-black-holing",
-    "fno-method-sharing",
     "fno-state-hack",
+    "fsimple-list-literals",
     "fno-ds-multi-tyvar",
     "fruntime-types",
+    "fpass-case-bndr-to-join-points",
     "fno-pre-inlining",
     "fexcess-precision",
     "static",
@@ -181,8 +183,8 @@ isStaticFlag f =
     "funfolding-keeness-factor"
      ]
 
-unregFlags :: [String]
-unregFlags = 
+unregFlags :: [Located String]
+unregFlags = map (mkGeneralLocated "in unregFlags")
    [ "-optc-DNO_REGS"
    , "-optc-DUSE_MINIINTERPRETER"
    , "-fno-asm-mangling"