+{-# OPTIONS -#include "hschooks.h" #-}
+
-----------------------------------------------------------------------------
--- $Id: DriverFlags.hs,v 1.34 2000/12/12 14:35:08 simonmar Exp $
+-- $Id: DriverFlags.hs,v 1.49 2001/03/15 15:53:28 simonmar Exp $
--
-- Driver flags
--
--
-----------------------------------------------------------------------------
-module DriverFlags where
+module DriverFlags (
+ processArgs, OptKind(..), static_flags, dynamic_flags,
+ v_InitDynFlags, v_DynFlags, getDynFlags, dynFlag,
+ getOpts, getVerbFlag, addCmdlineHCInclude,
+ buildStaticHscOpts,
+ runSomething,
+ machdepCCOpts
+ ) where
#include "HsVersions.h"
-import PackageMaintenance
import DriverState
import DriverUtil
-import TmpFiles ( v_TmpDir )
+import TmpFiles ( v_TmpDir, kludgedSystem )
import CmdLineOpts
-import TmpFiles ( newTempName )
import Config
import Util
import Panic
import Exception
import IOExts
-import Directory ( removeFile )
import IO
import Maybe
import Monad
--
-- * parse the initial list of flags and remove any flags understood
-- by the driver only. Determine whether we're in multi-compilation
--- or single-compilation mode.
+-- or single-compilation mode (done in Main.main).
--
-- * gather the list of "static" hsc flags, and assign them to the global
-- static hsc flags variable.
, ( "dppr-user-length", AnySuffix (add v_Opt_C) )
-- rest of the debugging flags are dynamic
- ------- Interface files ---------------------------------------------
- , ( "hi" , NoArg (writeIORef v_ProduceHi True) )
- , ( "nohi" , NoArg (writeIORef v_ProduceHi False) )
-
--------- Profiling --------------------------------------------------
, ( "auto-dicts" , NoArg (add v_Opt_C "-fauto-sccs-on-dicts") )
, ( "auto-all" , NoArg (add v_Opt_C "-fauto-sccs-on-all-toplevs") )
, ( "package" , HasArg (addPackage) )
, ( "syslib" , HasArg (addPackage) ) -- for compatibility w/ old vsns
- , ( "-list-packages" , NoArg (listPackages) )
- , ( "-add-package" , NoArg (newPackage) )
- , ( "-delete-package" , SepArg (deletePackage) )
-
------- Specific phases --------------------------------------------
, ( "pgmL" , HasArg (writeIORef v_Pgm_L) )
, ( "pgmP" , HasArg (writeIORef v_Pgm_P) )
, ( "optl" , HasArg (add v_Opt_l) )
, ( "optdll" , HasArg (add v_Opt_dll) )
- ------ Warning opts -------------------------------------------------
- , ( "W" , NoArg (writeIORef v_Warning_opt W_) )
- , ( "Wall" , NoArg (writeIORef v_Warning_opt W_all) )
- , ( "Wnot" , NoArg (writeIORef v_Warning_opt W_not) )
- , ( "w" , NoArg (writeIORef v_Warning_opt W_not) )
-
----- Linker --------------------------------------------------------
, ( "static" , NoArg (writeIORef v_Static True) )
+ , ( "dynamic" , NoArg (writeIORef v_Static False) )
, ( "rdynamic" , NoArg (return ()) ) -- ignored for compat w/ gcc
----- RTS opts ------------------------------------------------------
, ( "H" , HasArg (setHeapSize . fromIntegral . decodeSize) )
+ , ( "Rghc-timing" , NoArg (enableTimingStats) )
------ Compiler flags -----------------------------------------------
, ( "O2-for-C" , NoArg (writeIORef v_minus_o2_for_C True) )
, ( "fno-cpr" , NoArg (writeIORef v_CPR False) )
, ( "fno-cse" , NoArg (writeIORef v_CSE False) )
- -- flags that are "active negatives"
- , ( "fno-prune-tydecls" , PassFlag (add v_Opt_C) )
- , ( "fno-prune-instdecls" , PassFlag (add v_Opt_C) )
- , ( "fno-pre-inlining" , PassFlag (add v_Opt_C) )
-
-- All other "-fno-<blah>" options cancel out "-f<blah>" on the hsc cmdline
, ( "fno-", PrefixPred (\s -> isStaticHscFlag ("f"++s))
(\s -> add v_Anti_opt_C ("-f"++s)) )
-- v_InitDynFlags
-- is the "baseline" dynamic flags, initialised from
--- the defaults and command line options.
+-- the defaults and command line options, and updated by the
+-- ':s' command in GHCi.
--
-- v_DynFlags
-- is the dynamic flags for the current compilation. It is reset
setDynFlag f = updDynFlags (\dfs -> dfs{ flags = f : flags dfs })
unSetDynFlag f = updDynFlags (\dfs -> dfs{ flags = filter (/= f) (flags dfs) })
+addOpt_L a = updDynFlags (\s -> s{opt_L = a : opt_L s})
+addOpt_P a = updDynFlags (\s -> s{opt_P = a : opt_P s})
+addOpt_c a = updDynFlags (\s -> s{opt_c = a : opt_c s})
+addOpt_a a = updDynFlags (\s -> s{opt_a = a : opt_a s})
+addOpt_m a = updDynFlags (\s -> s{opt_m = a : opt_m s})
+
+addCmdlineHCInclude a =
+ updDynFlags (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
+
+ -- we add to the options from the front, so we need to reverse the list
+getOpts :: (DynFlags -> [a]) -> IO [a]
+getOpts opts = dynFlag opts >>= return . reverse
+
-- we can only change HscC to HscAsm and vice-versa with dynamic flags
-- (-fvia-C and -fasm).
+-- NB: we can also set the new lang to ILX, via -filx. I hope this is right
setLang l = do
dfs <- readIORef v_DynFlags
case hscLang dfs of
then dfs{ verbosity = n }
else dfs)
-setVerbosity "" = updDynFlags (\dfs -> dfs{ verbosity = 2 })
+setVerbosity "" = updDynFlags (\dfs -> dfs{ verbosity = 3 })
setVerbosity n
| all isDigit n = updDynFlags (\dfs -> dfs{ verbosity = read n })
| otherwise = throwDyn (OtherError "can't parse verbosity flag (-v<n>)")
dynamic_flags = [
- ( "cpp", NoArg (updateState (\s -> s{ cpp_flag = True })) )
+ ( "cpp", NoArg (updDynFlags (\s -> s{ cppFlag = True })) )
, ( "#include", HasArg (addCmdlineHCInclude) )
, ( "v", OptPrefix (setVerbosity) )
, ( "ddump-worker-wrapper", NoArg (setDynFlag Opt_D_dump_worker_wrapper) )
, ( "dshow-passes", NoArg (setVerbosity "2") )
, ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace) )
+ , ( "ddump-tc-trace", NoArg (setDynFlag Opt_D_dump_tc_trace) )
, ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats) )
, ( "ddump-stix", NoArg (setDynFlag Opt_D_dump_stix) )
, ( "ddump-simpl-stats", NoArg (setDynFlag Opt_D_dump_simpl_stats) )
- , ( "ddump-interpsyn", NoArg (setDynFlag Opt_D_dump_InterpSyn) )
+ , ( "ddump-bcos", NoArg (setDynFlag Opt_D_dump_BCOs) )
, ( "dsource-stats", NoArg (setDynFlag Opt_D_source_stats) )
, ( "dverbose-core2core", NoArg (setDynFlag Opt_D_verbose_core2core) )
, ( "dverbose-stg2stg", NoArg (setDynFlag Opt_D_verbose_stg2stg) )
------ Machine dependant (-m<blah>) stuff ---------------------------
- , ( "monly-2-regs", NoArg (updateState (\s -> s{stolen_x86_regs = 2}) ))
- , ( "monly-3-regs", NoArg (updateState (\s -> s{stolen_x86_regs = 3}) ))
- , ( "monly-4-regs", NoArg (updateState (\s -> s{stolen_x86_regs = 4}) ))
+ , ( "monly-2-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 2}) ))
+ , ( "monly-3-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 3}) ))
+ , ( "monly-4-regs", NoArg (updDynFlags (\s -> s{stolen_x86_regs = 4}) ))
+
+ ------ Warning opts -------------------------------------------------
+ , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
+ , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
+ , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
+ , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
------ Compiler flags -----------------------------------------------
, ( "fasm", AnySuffix (\_ -> setLang HscAsm) )
, ( "fvia-c", NoArg (setLang HscC) )
, ( "fvia-C", NoArg (setLang HscC) )
+#ifdef ILX
+ , ( "filx", NoArg (setLang HscILX) )
+#endif
-- "active negatives"
, ( "fno-implicit-prelude", NoArg (setDynFlag Opt_NoImplicitPrelude) )
( "glasgow-exts", Opt_GlasgowExts ),
( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
- ( "fgenerics", Opt_Generics ),
- ( "report-compile", Opt_ReportCompile )
+ ( "generics", Opt_Generics )
]
isFFlag f = f `elem` (map fst fFlags)
pred c = isDigit c || c == '.'
floatOpt :: IORef Double -> String -> IO ()
-floatOpt ref str
- = writeIORef ref (read str :: Double)
-
-#if __GLASGOW_HASKELL__ >= 411
-foreign import "setHeapSize" unsafe setHeapSize :: Int -> IO ()
-#else
-setHeapSize :: Int -> IO () -- -H<size> is ignored
-setHeapSize _ = return ()
-#endif
+floatOpt ref str = writeIORef ref (read str :: Double)
+
+-----------------------------------------------------------------------------
+-- RTS Hooks
+
+foreign import "setHeapSize" unsafe setHeapSize :: Int -> IO ()
+foreign import "enableTimingStats" unsafe enableTimingStats :: IO ()
-----------------------------------------------------------------------------
-- Build the Hsc static command line opts
_ -> error "unknown opt level"
-- ToDo: -Ofile
- let stg_opts = [ "-flet-no-escape" ]
- -- let-no-escape always on for now
-
-- take into account -fno-* flags by removing the equivalent -f*
-- flag from our list.
anti_flags <- getStaticOpts v_Anti_opt_C
- let basic_opts = opt_C_ ++ optimisation_opts ++ stg_opts
+ let basic_opts = opt_C_ ++ optimisation_opts
filtered_opts = filter (`notElem` anti_flags) basic_opts
static <- (do s <- readIORef v_Static; if s then return "-static"
runSomething phase_name cmd
= do
verb <- dynFlag verbosity
- when (verb >= 2) $ putStrLn ("*** " ++ phase_name)
- when (verb >= 3) $ putStrLn cmd
- hFlush stdout
+ when (verb >= 2) $ hPutStrLn stderr ("*** " ++ phase_name)
+ when (verb >= 3) $ hPutStrLn stderr cmd
+ hFlush stderr
-- test for -n flag
n <- readIORef v_Dry_run
if exit_code /= ExitSuccess
then throwDyn (PhaseFailed phase_name exit_code)
- else do when (verb >= 3) (putStr "\n")
+ else do when (verb >= 3) (hPutStr stderr "\n")
return ()
+
+-----------------------------------------------------------------------------
+-- Via-C compilation stuff
+
+-- flags returned are: ( all C compilations
+-- , registerised HC compilations
+-- )
+
+machdepCCOpts
+ | prefixMatch "alpha" cTARGETPLATFORM
+ = return ( ["-static"], [] )
+
+ | prefixMatch "hppa" cTARGETPLATFORM
+ -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
+ -- (very nice, but too bad the HP /usr/include files don't agree.)
+ = return ( ["-static", "-D_HPUX_SOURCE"], [] )
+
+ | prefixMatch "m68k" cTARGETPLATFORM
+ -- -fno-defer-pop : for the .hc files, we want all the pushing/
+ -- popping of args to routines to be explicit; if we let things
+ -- be deferred 'til after an STGJUMP, imminent death is certain!
+ --
+ -- -fomit-frame-pointer : *don't*
+ -- It's better to have a6 completely tied up being a frame pointer
+ -- rather than let GCC pick random things to do with it.
+ -- (If we want to steal a6, then we would try to do things
+ -- as on iX86, where we *do* steal the frame pointer [%ebp].)
+ = return ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
+
+ | prefixMatch "i386" cTARGETPLATFORM
+ -- -fno-defer-pop : basically the same game as for m68k
+ --
+ -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
+ -- the fp (%ebp) for our register maps.
+ = do n_regs <- dynFlag stolen_x86_regs
+ sta <- readIORef v_Static
+ return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else "",
+ if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else "" ],
+ [ "-fno-defer-pop", "-fomit-frame-pointer",
+ "-DSTOLEN_X86_REGS="++show n_regs ]
+ )
+
+ | prefixMatch "mips" cTARGETPLATFORM
+ = return ( ["static"], [] )
+
+ | prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
+ = return ( ["static"], ["-finhibit-size-directive"] )
+
+ | otherwise
+ = return ( [], [] )