-{-# OPTIONS -#include "hschooks.h" #-}
-
-----------------------------------------------------------------------------
--- $Id: DriverFlags.hs,v 1.65 2001/08/15 09:32:40 rrt Exp $
+-- $Id: DriverFlags.hs,v 1.101 2002/08/29 15:44:15 simonmar Exp $
--
-- Driver flags
--
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 ( setTmpDir, setPgm, setDryRun, showGhcUsage )
+import SysTools
import CmdLineOpts
import Config
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
processArgs spec args@(('-':arg):args') spare = do
case findArg spec arg of
- Just (rest,action) -> do args' <- processOneArg action rest args
- processArgs spec args' spare
+ Just (rest,action) -> do args' <- processOneArg action rest args
+ processArgs spec args' spare
Nothing -> processArgs spec args' (('-':arg):spare)
processArgs spec (arg:args) spare =
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
-- flags further down the list with the same prefix.
static_flags =
- [ ------- help -------------------------------------------------------
- ( "?" , NoArg showGhcUsage)
- , ( "-help" , NoArg showGhcUsage)
-
-
- ------- version ----------------------------------------------------
- , ( "-version" , NoArg (do hPutStrLn stdout (cProjectName
+ [ ------- help / version ----------------------------------------------
+ ( "?" , NoArg showGhcUsage)
+ , ( "-help" , NoArg showGhcUsage)
+ , ( "-print-libdir" , NoArg (do getTopDir >>= putStrLn
+ exitWith ExitSuccess))
+ , ( "-version" , NoArg (do putStrLn (cProjectName
++ ", version " ++ cProjectVersion)
exitWith ExitSuccess))
- , ( "-numeric-version", NoArg (do hPutStrLn stdout cProjectVersion
+ , ( "-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))
+
+ -- -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 ----------------------------------------------------
, ( "keep-hc-file" , AnySuffix (\_ -> writeIORef v_Keep_hc_files True) )
, ( "keep-s-file" , AnySuffix (\_ -> writeIORef v_Keep_s_files True) )
, ( "keep-raw-s-file", AnySuffix (\_ -> writeIORef v_Keep_raw_s_files True) )
+#ifdef ILX
+ , ( "keep-il-file" , AnySuffix (\_ -> writeIORef v_Keep_il_files True) )
+ , ( "keep-ilx-file" , AnySuffix (\_ -> writeIORef v_Keep_ilx_files True) )
+#endif
, ( "keep-tmp-files" , AnySuffix (\_ -> writeIORef v_Keep_tmp_files True) )
, ( "split-objs" , NoArg (if can_split
, ( "L" , Prefix (addToDirList v_Library_paths) )
, ( "l" , Prefix (add v_Cmdline_libraries) )
+#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 )
+ , ( "pgmP" , HasArg setPgmP )
+ , ( "pgmF" , HasArg setPgmF )
+ , ( "pgmc" , HasArg setPgmc )
+ , ( "pgmm" , HasArg setPgmm )
+ , ( "pgms" , HasArg setPgms )
+ , ( "pgma" , HasArg setPgma )
+ , ( "pgml" , HasArg setPgml )
+#ifdef ILX
+ , ( "pgmI" , HasArg setPgmI )
+ , ( "pgmi" , HasArg setPgmi )
+#endif
, ( "optdep" , HasArg (add v_Opt_dep) )
, ( "optl" , HasArg (add v_Opt_l) )
------ Compiler flags -----------------------------------------------
, ( "O2-for-C" , NoArg (writeIORef v_minus_o2_for_C True) )
- , ( "O" , OptPrefix (setOptLevel) )
+ , ( "O" , NoArg (setOptLevel 1))
+ , ( "Onot" , NoArg (setOptLevel 0))
+ , ( "O" , PrefixPred (all isDigit) (setOptLevel . read))
, ( "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") )
-- -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
dynamic_flags = [
( "cpp", NoArg (updDynFlags (\s -> s{ cppFlag = True })) )
+ , ( "F", NoArg (updDynFlags (\s -> s{ ppFlag = True })) )
, ( "#include", HasArg (addCmdlineHCInclude) )
, ( "v", OptPrefix (setVerbosity) )
, ( "optL", HasArg (addOpt_L) )
, ( "optP", HasArg (addOpt_P) )
+ , ( "optF", HasArg (addOpt_F) )
, ( "optc", HasArg (addOpt_c) )
, ( "optm", HasArg (addOpt_m) )
, ( "opta", HasArg (addOpt_a) )
-- 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
+#ifndef mingw32_HOST_OS
, ( "D", Prefix (\s -> addOpt_P ("-D'"++s++"'") ) )
, ( "U", Prefix (\s -> addOpt_P ("-U'"++s++"'") ) )
#else
, ( "ddump-simpl", NoArg (setDynFlag Opt_D_dump_simpl) )
, ( "ddump-simpl-iterations", NoArg (setDynFlag Opt_D_dump_simpl_iterations) )
, ( "ddump-spec", NoArg (setDynFlag Opt_D_dump_spec) )
- , ( "ddump-sat", NoArg (setDynFlag Opt_D_dump_sat) )
+ , ( "ddump-prep", NoArg (setDynFlag Opt_D_dump_prep) )
, ( "ddump-stg", NoArg (setDynFlag Opt_D_dump_stg) )
, ( "ddump-stranal", NoArg (setDynFlag Opt_D_dump_stranal) )
, ( "ddump-tc", NoArg (setDynFlag Opt_D_dump_tc) )
, ( "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) )
-- "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-matches", Opt_WarnUnusedMatches ),
( "warn-deprecations", Opt_WarnDeprecations ),
( "glasgow-exts", Opt_GlasgowExts ),
+ ( "fi", Opt_FFI ), -- support `-ffi'...
+ ( "ffi", Opt_FFI ), -- ...and also `-fffi'
+ ( "with", Opt_With ), -- with keyword
+ ( "parr", Opt_PArr ),
( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
+ ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
( "generics", Opt_Generics )
]
0 -> hsc_minusNoO_flags
1 -> hsc_minusO_flags
2 -> hsc_minusO2_flags
- _ -> error "unknown opt level"
+ n -> throwDyn (CmdLineError ("unknown optimisation level: "
+ ++ show n))
-- ToDo: -Ofile
-- take into account -fno-* flags by removing the equivalent -f*
machdepCCOpts
| prefixMatch "alpha" cTARGETPLATFORM
- = return ( ["-static", "-Xlinker -noprefix_recognition"], [] )
+ = 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.
| prefixMatch "hppa" cTARGETPLATFORM
-- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
-- 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 "" ],
+ return ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
+-- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
+ ],
[ "-fno-defer-pop", "-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 "mips" cTARGETPLATFORM
= return ( ["-static"], [] )
+ | prefixMatch "sparc" cTARGETPLATFORM
+ = return ( [], ["-w"] )
+ -- 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.
+
+ | prefixMatch "powerpc-apple-darwin" cTARGETPLATFORM
+ = return ( ["-no-cpp-precomp"], [""] )
+
| 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_F a = updDynFlags (\s -> s{opt_F = a : opt_F 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})
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})