-{-# OPTIONS -#include "hschooks.h" #-}
-
-----------------------------------------------------------------------------
--- $Id: DriverFlags.hs,v 1.81 2001/12/10 01:28:00 sebc Exp $
--
-- Driver flags
--
--- (c) Simon Marlow 2000
+-- (c) The University of Glasgow 2000-2003
--
-----------------------------------------------------------------------------
module DriverFlags (
processArgs, OptKind(..), static_flags, dynamic_flags,
- getDynFlags, dynFlag,
- getOpts, getVerbFlag, addCmdlineHCInclude,
+ addCmdlineHCInclude,
buildStaticHscOpts,
machdepCCOpts
) where
#include "HsVersions.h"
#include "../includes/config.h"
+import MkIface ( showIface )
import DriverState
+import DriverPhases
import DriverUtil
import SysTools
import CmdLineOpts
import Util
import Panic
-import Exception
-import IOExts
-import System ( exitWith, ExitCode(..) )
+import EXCEPTION
+import DATA_IOREF ( readIORef, writeIORef )
+import System ( exitWith, ExitCode(..) )
import IO
import Maybe
import Monad
if rest /= ""
then fio rest >> return args
else case args of
- [] -> unknownFlagErr dash_arg
+ [] -> missingArgErr dash_arg
(arg1:args1) -> fio arg1 >> return args1
SepArg fio ->
findArg spec arg
= case [ (remove_spaces rest, k)
| (pat,k) <- spec,
- Just rest <- [my_prefix_match pat arg],
+ Just rest <- [maybePrefixMatch pat arg],
arg_ok k rest arg ]
of
[] -> Nothing
arg_ok (NoArg _) rest arg = null rest
arg_ok (HasArg _) rest arg = True
arg_ok (SepArg _) rest arg = null rest
-arg_ok (Prefix _) rest arg = not (null rest)
-arg_ok (PrefixPred p _) rest arg = not (null rest) && p rest
+arg_ok (Prefix _) rest arg = notNull rest
+arg_ok (PrefixPred p _) rest arg = notNull rest && p rest
arg_ok (OptPrefix _) rest arg = True
arg_ok (PassFlag _) rest arg = null rest
arg_ok (AnySuffix _) rest arg = True
, ( "-help" , NoArg showGhcUsage)
, ( "-print-libdir" , NoArg (do getTopDir >>= putStrLn
exitWith ExitSuccess))
- , ( "-version" , NoArg (do putStrLn (cProjectName
- ++ ", version " ++ cProjectVersion)
- exitWith ExitSuccess))
+ , ( "V" , NoArg showVersion)
+ , ( "-version" , NoArg showVersion)
, ( "-numeric-version", NoArg (do putStrLn cProjectVersion
exitWith ExitSuccess))
+ ------- interfaces ----------------------------------------------------
+ , ( "-show-iface" , HasArg (\f -> do showIface f
+ exitWith ExitSuccess))
+
------- verbosity ----------------------------------------------------
, ( "n" , NoArg setDryRun )
+ ------- primary modes ------------------------------------------------
+ , ( "M" , PassFlag (setMode DoMkDependHS))
+ , ( "E" , PassFlag (setMode (StopBefore Hsc)))
+ , ( "C" , PassFlag (\f -> do setMode (StopBefore HCc) f
+ setLang HscC))
+ , ( "S" , PassFlag (setMode (StopBefore As)))
+ , ( "c" , PassFlag (setMode (StopBefore Ln)))
+ , ( "-make" , PassFlag (setMode DoMake))
+ , ( "-interactive" , PassFlag (setMode DoInteractive))
+ , ( "-mk-dll" , PassFlag (setMode DoMkDLL))
+ , ( "e" , HasArg (\s -> setMode (DoEval s) "-e"))
+
+ -- -fno-code says to stop after Hsc but don't generate any code.
+ , ( "fno-code" , PassFlag (\f -> do setMode (StopBefore HCc) f
+ setLang HscNothing
+ writeIORef v_Recomp False))
+
------- GHCi -------------------------------------------------------
, ( "ignore-dot-ghci", NoArg (writeIORef v_Read_DotGHCi False) )
, ( "read-dot-ghci" , NoArg (writeIORef v_Read_DotGHCi True) )
, ( "gransim" , NoArg (addNoDups v_Ways WayGran) )
, ( "smp" , NoArg (addNoDups v_Ways WaySMP) )
, ( "debug" , NoArg (addNoDups v_Ways WayDebug) )
+ , ( "ndp" , NoArg (addNoDups v_Ways WayNDP) )
-- ToDo: user ways
------ Debugging ----------------------------------------------------
------- Miscellaneous -----------------------------------------------
, ( "no-link-chk" , NoArg (return ()) ) -- ignored for backwards compat
, ( "no-hs-main" , NoArg (writeIORef v_NoHsMain True) )
+ , ( "main-is" , SepArg setMainIs )
------- Output Redirection ------------------------------------------
, ( "odir" , HasArg (writeIORef v_Output_dir . Just) )
, ( "o" , SepArg (writeIORef v_Output_file . Just) )
- , ( "osuf" , HasArg (writeIORef v_Object_suf . Just) )
+ , ( "osuf" , HasArg (writeIORef v_Object_suf) )
, ( "hcsuf" , HasArg (writeIORef v_HC_suf . Just) )
, ( "hisuf" , HasArg (writeIORef v_Hi_suf) )
, ( "hidir" , HasArg (writeIORef v_Hi_dir . Just) )
then do writeIORef v_Split_object_files True
add v_Opt_C "-fglobalise-toplev-names"
else hPutStrLn stderr
- "warning: don't know how to split \
+ "warning: don't know how to split \
\object files on this architecture"
) )
------- Libraries ---------------------------------------------------
, ( "L" , Prefix (addToDirList v_Library_paths) )
- , ( "l" , Prefix (add v_Cmdline_libraries) )
+ , ( "l" , AnySuffix (\s -> add v_Opt_l s >> add v_Opt_dll s) )
+#ifdef darwin_TARGET_OS
+ ------- Frameworks --------------------------------------------------
+ -- -framework-path should really be -F ...
+ , ( "framework-path" , HasArg (addToDirList v_Framework_paths) )
+ , ( "framework" , HasArg (add v_Cmdline_frameworks) )
+#endif
------- Packages ----------------------------------------------------
, ( "package-name" , HasArg (\s -> add v_Opt_C ("-inpackage="++s)) )
, ( "syslib" , HasArg (addPackage) ) -- for compatibility w/ old vsns
------- Specific phases --------------------------------------------
- , ( "pgm" , HasArg setPgm )
+ , ( "pgmL" , HasArg setPgmL )
+ , ( "pgmP" , HasArg setPgmP )
+ , ( "pgmF" , HasArg setPgmF )
+ , ( "pgmc" , HasArg setPgmc )
+ , ( "pgmm" , HasArg setPgmm )
+ , ( "pgms" , HasArg setPgms )
+ , ( "pgma" , HasArg setPgma )
+ , ( "pgml" , HasArg setPgml )
+ , ( "pgmdll" , HasArg setPgmDLL )
+#ifdef ILX
+ , ( "pgmI" , HasArg setPgmI )
+ , ( "pgmi" , HasArg setPgmi )
+#endif
, ( "optdep" , HasArg (add v_Opt_dep) )
, ( "optl" , HasArg (add v_Opt_l) )
, ( "optdll" , HasArg (add v_Opt_dll) )
----- Linker --------------------------------------------------------
+ , ( "no-link" , NoArg (writeIORef v_NoLink True) )
, ( "static" , NoArg (writeIORef v_Static True) )
, ( "dynamic" , NoArg (writeIORef v_Static False) )
, ( "rdynamic" , NoArg (return ()) ) -- ignored for compat w/ gcc
, ( "Rghc-timing" , NoArg (enableTimingStats) )
------ Compiler flags -----------------------------------------------
- , ( "O2-for-C" , NoArg (writeIORef v_minus_o2_for_C True) )
- , ( "O" , OptPrefix (setOptLevel) )
-
, ( "fno-asm-mangling" , NoArg (writeIORef v_Do_asm_mangling False) )
- , ( "fmax-simplifier-iterations",
- Prefix (writeIORef v_MaxSimplifierIterations . read) )
-
- , ( "frule-check",
- SepArg (\s -> writeIORef v_RuleCheck (Just s)) )
-
- , ( "fusagesp" , NoArg (do writeIORef v_UsageSPInf True
- add v_Opt_C "-fusagesp-on") )
-
, ( "fexcess-precision" , NoArg (do writeIORef v_Excess_precision True
add v_Opt_C "-fexcess-precision"))
- -- Optimisation flags are treated specially, so the normal
- -- -fno-* pattern below doesn't work. We therefore allow
- -- certain optimisation passes to be turned off explicitly:
- , ( "fno-strictness" , NoArg (writeIORef v_Strictness False) )
- , ( "fno-cpr" , NoArg (writeIORef v_CPR False) )
- , ( "fno-cse" , NoArg (writeIORef v_CSE False) )
-
-- 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)) )
#endif
------ HsCpp opts ---------------------------------------------------
- -- With a C compiler whose system() doesn't use a UNIX shell (i.e.
- -- mingwin gcc), -D and -U args must *not* be quoted, as the quotes
- -- will be interpreted as part of the arguments, and not stripped;
- -- on all other systems, quoting is necessary, to avoid interpretation
- -- of shell metacharacters in the arguments (e.g. green-card's
- -- -DBEGIN_GHC_ONLY='}-' trick).
-#ifndef mingw32_TARGET_OS
- , ( "D", Prefix (\s -> addOpt_P ("-D'"++s++"'") ) )
- , ( "U", Prefix (\s -> addOpt_P ("-U'"++s++"'") ) )
-#else
- , ( "D", Prefix (\s -> addOpt_P ("-D"++s) ) )
- , ( "U", Prefix (\s -> addOpt_P ("-U"++s) ) )
-#endif
+ , ( "D", AnySuffix addOpt_P )
+ , ( "U", AnySuffix addOpt_P )
------ Debugging ----------------------------------------------------
, ( "dstg-stats", NoArg (writeIORef v_StgStats True) )
, ( "ddump-tc", NoArg (setDynFlag Opt_D_dump_tc) )
, ( "ddump-types", NoArg (setDynFlag Opt_D_dump_types) )
, ( "ddump-rules", NoArg (setDynFlag Opt_D_dump_rules) )
- , ( "ddump-usagesp", NoArg (setDynFlag Opt_D_dump_usagesp) )
, ( "ddump-cse", NoArg (setDynFlag Opt_D_dump_cse) )
, ( "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-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace) )
, ( "ddump-tc-trace", NoArg (setDynFlag Opt_D_dump_tc_trace) )
+ , ( "ddump-splices", NoArg (setDynFlag Opt_D_dump_splices) )
, ( "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-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs) )
, ( "ddump-hi", NoArg (setDynFlag Opt_D_dump_hi) )
, ( "ddump-minimal-imports", NoArg (setDynFlag Opt_D_dump_minimal_imports) )
+ , ( "ddump-vect", NoArg (setDynFlag Opt_D_dump_vect) )
, ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting) )
, ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting) )
- , ( "dusagesp-lint", NoArg (setDynFlag Opt_DoUSPLinting) )
------ Machine dependant (-m<blah>) stuff ---------------------------
------ Warning opts -------------------------------------------------
, ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
+ , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
, ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
, ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
, ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
+ ------ Optimisation flags ------------------------------------------
+ , ( "O" , NoArg (setOptLevel 1))
+ , ( "Onot" , NoArg (setOptLevel 0))
+ , ( "O" , PrefixPred (all isDigit) (setOptLevel . read))
+
+ , ( "fmax-simplifier-iterations",
+ PrefixPred (all isDigit)
+ (\n -> updDynFlags (\dfs ->
+ dfs{ maxSimplIterations = read n })) )
+
+ , ( "frule-check",
+ SepArg (\s -> updDynFlags (\dfs -> dfs{ ruleCheck = Just s })))
+
------ Compiler flags -----------------------------------------------
, ( "fasm", AnySuffix (\_ -> setLang HscAsm) )
, ( "fvia-c", NoArg (setLang HscC) )
, ( "fvia-C", NoArg (setLang HscC) )
, ( "filx", NoArg (setLang HscILX) )
- , ( "fno-code", NoArg (setLang HscNothing) )
+
+ , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
+ , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
-- "active negatives"
, ( "fno-implicit-prelude", NoArg (setDynFlag Opt_NoImplicitPrelude) )
+ , ( "fno-monomorphism-restriction",
+ NoArg (setDynFlag Opt_NoMonomorphismRestriction) )
-- the rest of the -f* and -fno-* flags
, ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
( "warn-unused-imports", Opt_WarnUnusedImports ),
( "warn-unused-matches", Opt_WarnUnusedMatches ),
( "warn-deprecations", Opt_WarnDeprecations ),
- ( "glasgow-exts", Opt_GlasgowExts ),
+ ( "fi", Opt_FFI ), -- support `-ffi'...
+ ( "ffi", Opt_FFI ), -- ...and also `-fffi'
+ ( "arrows", Opt_Arrows ), -- arrow syntax
+ ( "parr", Opt_PArr ),
+ ( "th", Opt_TH ),
+ ( "implicit-params", Opt_ImplicitParams ),
( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
- ( "generics", Opt_Generics )
+ ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
+ ( "generics", Opt_Generics ),
+ ( "strictness", Opt_Strictness ),
+ ( "cse", Opt_CSE ),
+ ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
+ ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
+ ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
+ ( "ignore-asserts", Opt_IgnoreAsserts ),
+ ( "do-eta-reduction", Opt_DoEtaReduction ),
+ ( "case-merge", Opt_CaseMerge ),
+ ( "unbox-strict-fields", Opt_UnboxStrictFields )
]
+glasgowExtsFlags = [ Opt_GlasgowExts, Opt_FFI, Opt_TH, Opt_ImplicitParams ]
+
isFFlag f = f `elem` (map fst fFlags)
getFFlag f = fromJust (lookup f fFlags)
-----------------------------------------------------------------------------
-- RTS Hooks
+#if __GLASGOW_HASKELL__ >= 504
+foreign import ccall unsafe "setHeapSize" setHeapSize :: Int -> IO ()
+foreign import ccall unsafe "enableTimingStats" enableTimingStats :: IO ()
+#else
foreign import "setHeapSize" unsafe setHeapSize :: Int -> IO ()
foreign import "enableTimingStats" unsafe enableTimingStats :: IO ()
+#endif
-----------------------------------------------------------------------------
-- Build the Hsc static command line opts
opt_C_ <- getStaticOpts v_Opt_C -- misc hsc opts from the command line
- -- optimisation
- minus_o <- readIORef v_OptLevel
- let optimisation_opts =
- case minus_o of
- 0 -> hsc_minusNoO_flags
- 1 -> hsc_minusO_flags
- 2 -> hsc_minusO2_flags
- n -> throwDyn (CmdLineError ("unknown optimisation level: "
- ++ show n))
- -- ToDo: -Ofile
-
-- 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
+ let basic_opts = opt_C_
filtered_opts = filter (`notElem` anti_flags) basic_opts
static <- (do s <- readIORef v_Static; if s then return "-static"
return ( static : filtered_opts )
+setMainIs :: String -> IO ()
+setMainIs arg
+ | not (null main_mod) -- The arg looked like "Foo.baz"
+ = do { writeIORef v_MainFunIs (Just main_fn) ;
+ writeIORef v_MainModIs (Just main_mod) }
+
+ | isUpper (head main_fn) -- The arg looked like "Foo"
+ = writeIORef v_MainModIs (Just main_fn)
+
+ | otherwise -- The arg looked like "baz"
+ = writeIORef v_MainFunIs (Just main_fn)
+ where
+ (main_mod, main_fn) = split_longest_prefix arg (== '.')
+
+
-----------------------------------------------------------------------------
-- Via-C compilation stuff
machdepCCOpts
| prefixMatch "alpha" cTARGETPLATFORM
- = return ( ["-static", "-w", "-mieee"], [] )
+ = return ( ["-static", "-w", "-mieee"
+#ifdef HAVE_THREADED_RTS_SUPPORT
+ , "-D_REENTRANT"
+#endif
+ ], [] )
-- For now, to suppress the gcc warning "call-clobbered
-- register used for global register variable", we simply
-- disable all warnings altogether using the -w flag. Oh well.
-- 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",
+ return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
+-- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
+ ],
+ [ "-fno-defer-pop",
+#ifdef HAVE_GCC_MNO_OMIT_LFPTR
+ -- Some gccs are configured with
+ -- -momit-leaf-frame-pointer on by default, and it
+ -- apparently takes precedence over
+ -- -fomit-frame-pointer, so we disable it first here.
+ "-mno-omit-leaf-frame-pointer",
+#endif
+ "-fomit-frame-pointer",
+ -- we want -fno-builtin, because when gcc inlines
+ -- built-in functions like memcpy() it tends to
+ -- run out of registers, requiring -monly-n-regs
+ "-fno-builtin",
"-DSTOLEN_X86_REGS="++show n_regs ]
)
+ | prefixMatch "ia64" cTARGETPLATFORM
+ = return ( [], ["-fomit-frame-pointer", "-G0"] )
+
+ | prefixMatch "x86_64" cTARGETPLATFORM
+ = return ( [], ["-fomit-frame-pointer"] )
+
| prefixMatch "mips" cTARGETPLATFORM
= return ( ["-static"], [] )
-- disable all warnings altogether using the -w flag. Oh well.
| prefixMatch "powerpc-apple-darwin" cTARGETPLATFORM
- = return ( ["-no-cpp-precomp"], [""] )
+ -- -no-cpp-precomp:
+ -- Disable Apple's precompiling preprocessor. It's a great thing
+ -- for "normal" programs, but it doesn't support register variable
+ -- declarations.
+ -- -mdynamic-no-pic:
+ -- As we don't support haskell code in shared libraries anyway,
+ -- we might as well turn of PIC code generation and save space and time.
+ -- This is completely optional.
+ = return ( ["-no-cpp-precomp","-mdynamic-no-pic"], [] )
| prefixMatch "powerpc" cTARGETPLATFORM || prefixMatch "rs6000" cTARGETPLATFORM
= return ( ["-static"], ["-finhibit-size-directive"] )
| otherwise
= return ( [], [] )
-
+-----------------------------------------------------------------------------
+-- local utils
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_i a = updDynFlags (\s -> s{opt_i = a : opt_i s})
#endif
-addCmdlineHCInclude a = updDynFlags (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
-
-getOpts :: (DynFlags -> [a]) -> IO [a]
- -- We add to the options from the front, so we need to reverse the list
-getOpts opts = dynFlag opts >>= return . reverse
-
--- we can only change HscC to HscAsm and vice-versa with dynamic flags
--- (-fvia-C and -fasm). We can also set the new lang to ILX, via -filx.
-setLang l = updDynFlags (\ dfs -> case hscLang dfs of
- HscC -> dfs{ hscLang = l }
- HscAsm -> dfs{ hscLang = l }
- HscILX -> dfs{ hscLang = l }
- _ -> dfs)
-
setVerbosity "" = updDynFlags (\dfs -> dfs{ verbosity = 3 })
setVerbosity n
| all isDigit n = updDynFlags (\dfs -> dfs{ verbosity = read n })
| otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
-getVerbFlag = do
- verb <- dynFlag verbosity
- if verb >= 3 then return "-v" else return ""
+addCmdlineHCInclude a = updDynFlags (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
+
+-- -----------------------------------------------------------------------------
+-- Version and usage messages
+
+showVersion :: IO ()
+showVersion = do
+ putStrLn (cProjectName ++ ", version " ++ cProjectVersion)
+ exitWith ExitSuccess
+
+showGhcUsage = do
+ (ghc_usage_path,ghci_usage_path) <- getUsageMsgPaths
+ mode <- readIORef v_GhcMode
+ let usage_path
+ | mode == DoInteractive = ghci_usage_path
+ | otherwise = ghc_usage_path
+ usage <- readFile usage_path
+ dump usage
+ exitWith ExitSuccess
+ where
+ dump "" = return ()
+ dump ('$':'$':s) = hPutStr stderr progName >> dump s
+ dump (c:s) = hPutChar stderr c >> dump s