module StaticFlagParser (parseStaticFlags) where
#include "HsVersions.h"
import StaticFlags
import CmdLineParser
import Config
import SrcLoc
import Util
import Panic
import Control.Monad
import Data.Char
import Data.IORef
import Data.List
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 $ errorsToGhcException errs
way_flags <- getWayFlags
let way_flags' = map (mkGeneralLocated "in way flags") way_flags
let unreg_flags | cGhcUnregisterised == "YES" = unregFlags
| otherwise = []
(more_leftover, errs, warns2) <- processArgs static_flags (unreg_flags ++ way_flags')
writeIORef v_opt_C_ready True
let cg_flags | tablesNextToCode = map (mkGeneralLocated "in cg_flags")
["-optc-DTABLES_NEXT_TO_CODE"]
| otherwise = []
let excess_prec
| opt_SimplExcessPrecision = map (mkGeneralLocated "in excess_prec")
["-fexcess-precision"]
| otherwise = []
when (not (null errs)) $ ghcError $ errorsToGhcException errs
return (excess_prec ++ cg_flags ++ more_leftover ++ leftover,
warns1 ++ warns2)
static_flags :: [Flag IO]
static_flags = [
Flag "ignore-dot-ghci" (PassFlag addOpt) Supported
, Flag "read-dot-ghci" (NoArg (removeOpt "-ignore-dot-ghci")) Supported
, Flag "prof" (NoArg (addWay WayProf)) Supported
, Flag "eventlog" (NoArg (addWay WayEventLog)) Supported
, Flag "parallel" (NoArg (addWay WayPar)) Supported
, Flag "gransim" (NoArg (addWay WayGran)) Supported
, Flag "smp" (NoArg (addWay WayThreaded))
(Deprecated "Use -threaded instead")
, Flag "debug" (NoArg (addWay WayDebug)) Supported
, Flag "ndp" (NoArg (addWay WayNDP)) Supported
, Flag "threaded" (NoArg (addWay WayThreaded)) Supported
, Flag "ticky" (PassFlag (\f -> do addOpt f; addWay WayDebug)) Supported
, Flag "dppr-debug" (PassFlag addOpt) Supported
, Flag "dsuppress-uniques" (PassFlag addOpt) Supported
, 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
, Flag "static" (PassFlag addOpt) Supported
, Flag "dynamic" (NoArg (removeOpt "-static" >> addWay WayDyn)) Supported
, Flag "rdynamic" (NoArg (return ())) Supported
, Flag "H" (HasArg (setHeapSize . fromIntegral . decodeSize))
Supported
, Flag "Rghc-timing" (NoArg (enableTimingStats)) Supported
, Flag "fPIC" (PassFlag setPIC) Supported
, Flag "fno-"
(PrefixPred (\s -> isStaticFlag ("f"++s)) (\s -> removeOpt ("-f"++s)))
Supported
, Flag "f" (AnySuffixPred isStaticFlag addOpt) Supported
]
setPIC :: String -> IO ()
setPIC | cGhcWithNativeCodeGen == "YES" || cGhcUnregisterised == "YES"
= addOpt
| otherwise
= ghcError $ CmdLineError "-fPIC is not supported on this platform"
isStaticFlag :: String -> Bool
isStaticFlag f =
f `elem` [
"fscc-profiling",
"fdicts-strict",
"fspec-inline-join-points",
"firrefutable-tuples",
"fparallel",
"fgransim",
"fno-hi-version-check",
"dno-black-holing",
"fno-state-hack",
"fsimple-list-literals",
"fno-ds-multi-tyvar",
"fruntime-types",
"fno-pre-inlining",
"fexcess-precision",
"static",
"fhardwire-lib-paths",
"funregisterised",
"fcpr-off",
"ferror-spans",
"fPIC",
"fhpc"
]
|| any (`isPrefixOf` f) [
"fliberate-case-threshold",
"fmax-worker-args",
"fhistory-size",
"funfolding-creation-threshold",
"funfolding-use-threshold",
"funfolding-fun-discount",
"funfolding-keeness-factor"
]
unregFlags :: [Located String]
unregFlags = map (mkGeneralLocated "in unregFlags")
[ "-optc-DNO_REGS"
, "-optc-DUSE_MINIINTERPRETER"
, "-fno-asm-mangling"
, "-funregisterised"
, "-fvia-C" ]
decodeSize :: String -> Integer
decodeSize str
| c == "" = truncate n
| c == "K" || c == "k" = truncate (n * 1000)
| c == "M" || c == "m" = truncate (n * 1000 * 1000)
| c == "G" || c == "g" = truncate (n * 1000 * 1000 * 1000)
| otherwise = ghcError (CmdLineError ("can't decode size: " ++ str))
where (m, c) = span pred str
n = readRational m
pred c = isDigit c || c == '.'
foreign import ccall unsafe "setHeapSize" setHeapSize :: Int -> IO ()
foreign import ccall unsafe "enableTimingStats" enableTimingStats :: IO ()