1 -----------------------------------------------------------------------------
5 -- Most flags are dynamic flags, which means they can change from
6 -- compilation to compilation using OPTIONS_GHC pragmas, and in a
7 -- multi-session GHC each session can be using different dynamic
8 -- flags. Dynamic flags can also be set at the prompt in GHCi.
10 -- (c) The University of Glasgow 2005
12 -----------------------------------------------------------------------------
19 GhcMode(..), isOneShot,
20 GhcLink(..), isNoLink,
24 -- Configuration of the core-to-core and stg-to-stg phases
28 SimplifierMode(..), FloatOutSwitches(..),
29 getCoreToDo, getStgToDo,
31 -- Manipulating DynFlags
32 defaultDynFlags, -- DynFlags
33 initDynFlags, -- DynFlags -> IO DynFlags
35 dopt, -- DynFlag -> DynFlags -> Bool
36 dopt_set, dopt_unset, -- DynFlags -> DynFlag -> DynFlags
37 getOpts, -- (DynFlags -> [a]) -> IO [a]
47 machdepCCOpts, picCCOpts,
50 #include "HsVersions.h"
52 import Module ( Module, mkModule )
53 import PrelNames ( mAIN )
54 import StaticFlags ( opt_Static, opt_PIC,
55 WayName(..), v_Ways, v_Build_tag, v_RTS_Build_tag )
56 import {-# SOURCE #-} Packages (PackageState)
57 import DriverPhases ( Phase(..), phaseInputExt )
60 import Panic ( panic, GhcException(..) )
61 import Util ( notNull, splitLongestPrefix, split, normalisePath )
62 import SrcLoc ( SrcSpan )
64 import DATA_IOREF ( readIORef )
65 import EXCEPTION ( throwDyn )
67 #ifdef mingw32_TARGET_OS
68 import Data.List ( isPrefixOf )
70 import Maybe ( fromJust )
71 import Char ( isDigit, isUpper )
73 import System.IO ( hPutStrLn, stderr )
74 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
76 -- -----------------------------------------------------------------------------
89 | Opt_D_dump_inlinings
90 | Opt_D_dump_occur_anal
94 | Opt_D_dump_simpl_iterations
103 | Opt_D_dump_worker_wrapper
104 | Opt_D_dump_rn_trace
105 | Opt_D_dump_rn_stats
107 | Opt_D_dump_simpl_stats
108 | Opt_D_dump_tc_trace
109 | Opt_D_dump_if_trace
114 | Opt_D_verbose_core2core
115 | Opt_D_verbose_stg2stg
117 | Opt_D_dump_hi_diffs
118 | Opt_D_dump_minimal_imports
119 | Opt_D_faststring_stats
124 | Opt_WarnIsError -- -Werror; makes warnings fatal
125 | Opt_WarnDuplicateExports
127 | Opt_WarnIncompletePatterns
128 | Opt_WarnIncompletePatternsRecUpd
129 | Opt_WarnMissingFields
130 | Opt_WarnMissingMethods
131 | Opt_WarnMissingSigs
132 | Opt_WarnNameShadowing
133 | Opt_WarnOverlappingPatterns
134 | Opt_WarnSimplePatterns
135 | Opt_WarnTypeDefaults
136 | Opt_WarnUnusedBinds
137 | Opt_WarnUnusedImports
138 | Opt_WarnUnusedMatches
139 | Opt_WarnDeprecations
140 | Opt_WarnDodgyImports
144 | Opt_AllowOverlappingInstances
145 | Opt_AllowUndecidableInstances
146 | Opt_AllowIncoherentInstances
147 | Opt_MonomorphismRestriction
150 | Opt_PArr -- syntactic support for parallel arrays
151 | Opt_Arrows -- Arrow-notation syntax
155 | Opt_ImplicitPrelude
156 | Opt_ScopedTypeVariables
163 | Opt_IgnoreInterfacePragmas
164 | Opt_OmitInterfacePragmas
165 | Opt_DoLambdaEtaExpansion
169 | Opt_UnboxStrictFields
177 | Opt_ExcessPrecision
178 | Opt_ReadUserPackageConf
182 | Opt_HideAllPackages
193 data DynFlags = DynFlags {
196 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
197 stgToDo :: Maybe [StgToDo], -- similarly
198 hscTarget :: HscTarget,
199 hscOutName :: String, -- name of the output file
200 extCoreName :: String, -- name of the .core output file
201 verbosity :: Int, -- verbosity level
202 optLevel :: Int, -- optimisation level
203 maxSimplIterations :: Int, -- max simplifier iterations
204 ruleCheck :: Maybe String,
205 stolen_x86_regs :: Int,
206 cmdlineHcIncludes :: [String], -- -#includes
207 importPaths :: [FilePath],
209 mainFunIs :: Maybe String,
212 wayNames :: [WayName], -- way flags from the cmd line
213 buildTag :: String, -- the global "way" (eg. "p" for prof)
214 rtsBuildTag :: String, -- the RTS "way"
217 objectDir :: Maybe String,
218 hiDir :: Maybe String,
219 stubDir :: Maybe String,
225 outputFile :: Maybe String,
226 outputHi :: Maybe String,
228 includePaths :: [String],
229 libraryPaths :: [String],
230 frameworkPaths :: [String], -- used on darwin only
231 cmdlineFrameworks :: [String], -- ditto
232 tmpDir :: String, -- no trailing '/'
234 -- options for particular phases
245 -- commands for particular phases
247 pgm_P :: (String,[Option]),
249 pgm_c :: (String,[Option]),
250 pgm_m :: (String,[Option]),
251 pgm_s :: (String,[Option]),
252 pgm_a :: (String,[Option]),
253 pgm_l :: (String,[Option]),
254 pgm_dll :: (String,[Option]),
257 extraPkgConfs :: [FilePath],
258 -- The -package-conf flags given on the command line, in the order
261 packageFlags :: [PackageFlag],
262 -- The -package and -hide-package flags from the command-line
265 pkgState :: PackageState,
271 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO ()
284 = BatchCompile -- | @ghc --make Main@
285 | Interactive -- | @ghc --interactive@
286 | OneShot -- | @ghc -c Foo.hs@
287 | JustTypecheck -- | Development environemnts, refactorer, etc.
291 isOneShot :: GhcMode -> Bool
292 isOneShot OneShot = True
293 isOneShot _other = False
295 data GhcLink -- What to do in the link step, if there is one
296 = -- Only relevant for modes
297 -- DoMake and StopBefore StopLn
298 NoLink -- Don't link at all
299 | StaticLink -- Ordinary linker [the default]
300 | MkDLL -- Make a DLL
302 isNoLink :: GhcLink -> Bool
303 isNoLink NoLink = True
304 isNoLink other = False
307 = ExposePackage String
309 | IgnorePackage String
312 | cGhcWithNativeCodeGen == "YES" = HscAsm
315 initDynFlags dflags = do
316 -- someday these will be dynamic flags
317 ways <- readIORef v_Ways
318 build_tag <- readIORef v_Build_tag
319 rts_build_tag <- readIORef v_RTS_Build_tag
322 buildTag = build_tag,
323 rtsBuildTag = rts_build_tag
329 ghcLink = StaticLink,
332 hscTarget = defaultHscTarget,
337 maxSimplIterations = 4,
340 cmdlineHcIncludes = [],
345 wayNames = panic "ways",
346 buildTag = panic "buildTag",
347 rtsBuildTag = panic "rtsBuildTag",
353 objectSuf = phaseInputExt StopLn,
354 hcSuf = phaseInputExt HCc,
357 outputFile = Nothing,
362 cmdlineFrameworks = [],
363 tmpDir = cDEFAULT_TMPDIR,
375 pgm_L = panic "pgm_L",
376 pgm_P = panic "pgm_P",
377 pgm_F = panic "pgm_F",
378 pgm_c = panic "pgm_c",
379 pgm_m = panic "pgm_m",
380 pgm_s = panic "pgm_s",
381 pgm_a = panic "pgm_a",
382 pgm_l = panic "pgm_l",
383 pgm_dll = panic "pgm_mkdll",
387 pkgState = panic "pkgState",
391 Opt_ReadUserPackageConf,
394 Opt_MonomorphismRestriction,
396 -- strictness is on by default, but this only
398 Opt_CSE, -- similarly for CSE.
399 Opt_FullLaziness, -- ...and for full laziness
401 Opt_DoLambdaEtaExpansion,
402 -- This one is important for a tiresome reason:
403 -- we want to make sure that the bindings for data
404 -- constructors are eta-expanded. This is probably
405 -- a good thing anyway, but it seems fragile.
409 -- and the default no-optimisation options:
410 Opt_IgnoreInterfacePragmas,
411 Opt_OmitInterfacePragmas
413 ] ++ standardWarnings,
415 log_action = \severity srcSpan style msg ->
417 SevInfo -> hPutStrLn stderr (show (msg style))
418 SevFatal -> hPutStrLn stderr (show (msg style))
419 _ -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
425 0 | print errors & warnings only
426 1 | minimal verbosity: print "compiling M ... done." for each module.
427 2 | equivalent to -dshow-passes
428 3 | equivalent to existing "ghc -v"
429 4 | "ghc -v -ddump-most"
430 5 | "ghc -v -ddump-all"
433 dopt :: DynFlag -> DynFlags -> Bool
434 dopt f dflags = f `elem` (flags dflags)
436 dopt_set :: DynFlags -> DynFlag -> DynFlags
437 dopt_set dfs f = dfs{ flags = f : flags dfs }
439 dopt_unset :: DynFlags -> DynFlag -> DynFlags
440 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
442 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
443 getOpts dflags opts = reverse (opts dflags)
444 -- We add to the options from the front, so we need to reverse the list
446 getVerbFlag :: DynFlags -> String
448 | verbosity dflags >= 3 = "-v"
451 setObjectDir f d = d{ objectDir = f}
452 setHiDir f d = d{ hiDir = f}
453 setStubDir f d = d{ stubDir = f}
455 setObjectSuf f d = d{ objectSuf = f}
456 setHiSuf f d = d{ hiSuf = f}
457 setHcSuf f d = d{ hcSuf = f}
459 setOutputFile f d = d{ outputFile = f}
460 setOutputHi f d = d{ outputHi = f}
462 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
463 -- Config.hs should really use Option.
464 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
466 setPgmL f d = d{ pgm_L = f}
467 setPgmF f d = d{ pgm_F = f}
468 setPgmc f d = d{ pgm_c = (f,[])}
469 setPgmm f d = d{ pgm_m = (f,[])}
470 setPgms f d = d{ pgm_s = (f,[])}
471 setPgma f d = d{ pgm_a = (f,[])}
472 setPgml f d = d{ pgm_l = (f,[])}
473 setPgmdll f d = d{ pgm_dll = (f,[])}
475 addOptL f d = d{ opt_L = f : opt_L d}
476 addOptP f d = d{ opt_P = f : opt_P d}
477 addOptF f d = d{ opt_F = f : opt_F d}
478 addOptc f d = d{ opt_c = f : opt_c d}
479 addOptm f d = d{ opt_m = f : opt_m d}
480 addOpta f d = d{ opt_a = f : opt_a d}
481 addOptl f d = d{ opt_l = f : opt_l d}
482 addOptdll f d = d{ opt_dll = f : opt_dll d}
483 addOptdep f d = d{ opt_dep = f : opt_dep d}
485 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
487 -- -----------------------------------------------------------------------------
488 -- Command-line options
490 -- When invoking external tools as part of the compilation pipeline, we
491 -- pass these a sequence of options on the command-line. Rather than
492 -- just using a list of Strings, we use a type that allows us to distinguish
493 -- between filepaths and 'other stuff'. [The reason being, of course, that
494 -- this type gives us a handle on transforming filenames, and filenames only,
495 -- to whatever format they're expected to be on a particular platform.]
498 = FileOption -- an entry that _contains_ filename(s) / filepaths.
499 String -- a non-filepath prefix that shouldn't be
500 -- transformed (e.g., "/out=")
501 String -- the filepath/filename portion
504 -----------------------------------------------------------------------------
505 -- Setting the optimisation level
507 updOptLevel :: Int -> DynFlags -> DynFlags
508 -- Set dynflags appropriate to the optimisation level
511 then dfs2{ hscTarget = HscC, optLevel = n } -- turn on -fvia-C with -O
512 else dfs2{ optLevel = n }
514 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
515 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
518 | n == 0 = opt_0_dopts
519 | otherwise = opt_1_dopts
522 | n == 0 = opt_1_dopts
523 | otherwise = opt_0_dopts
526 Opt_IgnoreInterfacePragmas,
527 Opt_OmitInterfacePragmas
536 -- -----------------------------------------------------------------------------
537 -- Standard sets of warning options
540 = [ Opt_WarnDeprecations,
541 Opt_WarnOverlappingPatterns,
542 Opt_WarnMissingFields,
543 Opt_WarnMissingMethods,
544 Opt_WarnDuplicateExports
548 = standardWarnings ++
549 [ Opt_WarnUnusedBinds,
550 Opt_WarnUnusedMatches,
551 Opt_WarnUnusedImports,
552 Opt_WarnIncompletePatterns,
558 [ Opt_WarnTypeDefaults,
559 Opt_WarnNameShadowing,
565 -- -----------------------------------------------------------------------------
566 -- CoreToDo: abstraction of core-to-core passes to run.
568 data CoreToDo -- These are diff core-to-core passes,
569 -- which may be invoked in any order,
570 -- as many times as you like.
572 = CoreDoSimplify -- The core-to-core simplifier.
575 -- Each run of the simplifier can take a different
576 -- set of simplifier-specific flags.
578 | CoreDoFloatOutwards FloatOutSwitches
583 | CoreDoWorkerWrapper
586 | CoreDoOldStrictness
589 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
590 -- matching this string
592 | CoreDoNothing -- useful when building up lists of these things
594 data SimplifierMode -- See comments in SimplMonad
598 data SimplifierSwitch
599 = MaxSimplifierIterations Int
602 data FloatOutSwitches
603 = FloatOutSw Bool -- True <=> float lambdas to top level
604 Bool -- True <=> float constants to top level,
605 -- even if they do not escape a lambda
608 -- The core-to-core pass ordering is derived from the DynFlags:
610 getCoreToDo :: DynFlags -> [CoreToDo]
612 | Just todo <- coreToDo dflags = todo -- set explicitly by user
613 | otherwise = core_todo
615 opt_level = optLevel dflags
616 max_iter = maxSimplIterations dflags
617 strictness = dopt Opt_Strictness dflags
618 full_laziness = dopt Opt_FullLaziness dflags
619 cse = dopt Opt_CSE dflags
620 rule_check = ruleCheck dflags
623 if opt_level == 0 then
625 CoreDoSimplify (SimplPhase 0) [
626 MaxSimplifierIterations max_iter
629 else {- opt_level >= 1 -} [
631 -- initial simplify: mk specialiser happy: minimum effort please
632 CoreDoSimplify SimplGently [
634 -- Don't inline anything till full laziness has bitten
635 -- In particular, inlining wrappers inhibits floating
636 -- e.g. ...(case f x of ...)...
637 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
638 -- ==> ...(case x of I# x# -> case fw x# of ...)...
639 -- and now the redex (f x) isn't floatable any more
640 -- Similarly, don't apply any rules until after full
641 -- laziness. Notably, list fusion can prevent floating.
644 -- Don't do case-of-case transformations.
645 -- This makes full laziness work better
646 MaxSimplifierIterations max_iter
649 -- Specialisation is best done before full laziness
650 -- so that overloaded functions have all their dictionary lambdas manifest
653 if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
658 CoreDoSimplify (SimplPhase 2) [
659 -- Want to run with inline phase 2 after the specialiser to give
660 -- maximum chance for fusion to work before we inline build/augment
661 -- in phase 1. This made a difference in 'ansi' where an
662 -- overloaded function wasn't inlined till too late.
663 MaxSimplifierIterations max_iter
665 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
667 CoreDoSimplify (SimplPhase 1) [
668 -- Need inline-phase2 here so that build/augment get
669 -- inlined. I found that spectral/hartel/genfft lost some useful
670 -- strictness in the function sumcode' if augment is not inlined
671 -- before strictness analysis runs
672 MaxSimplifierIterations max_iter
674 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
676 CoreDoSimplify (SimplPhase 0) [
677 -- Phase 0: allow all Ids to be inlined now
678 -- This gets foldr inlined before strictness analysis
680 MaxSimplifierIterations 3
681 -- At least 3 iterations because otherwise we land up with
682 -- huge dead expressions because of an infelicity in the
684 -- let k = BIG in foldr k z xs
685 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
686 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
690 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
692 #ifdef OLD_STRICTNESS
695 if strictness then CoreDoStrictness else CoreDoNothing,
699 CoreDoSimplify (SimplPhase 0) [
700 MaxSimplifierIterations max_iter
703 if full_laziness then
704 CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
705 True) -- Float constants
707 -- nofib/spectral/hartel/wang doubles in speed if you
708 -- do full laziness late in the day. It only happens
709 -- after fusion and other stuff, so the early pass doesn't
710 -- catch it. For the record, the redex is
711 -- f_el22 (f_el21 r_midblock)
714 -- We want CSE to follow the final full-laziness pass, because it may
715 -- succeed in commoning up things floated out by full laziness.
716 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
718 if cse then CoreCSE else CoreDoNothing,
722 -- Case-liberation for -O2. This should be after
723 -- strictness analysis and the simplification which follows it.
725 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
727 if opt_level >= 2 then
731 if opt_level >= 2 then
736 -- Final clean-up simplification:
737 CoreDoSimplify (SimplPhase 0) [
738 MaxSimplifierIterations max_iter
742 -- -----------------------------------------------------------------------------
743 -- StgToDo: abstraction of stg-to-stg passes to run.
746 = StgDoMassageForProfiling -- should be (next to) last
747 -- There's also setStgVarInfo, but its absolute "lastness"
748 -- is so critical that it is hardwired in (no flag).
751 getStgToDo :: DynFlags -> [StgToDo]
753 | Just todo <- stgToDo dflags = todo -- set explicitly by user
756 stg_stats = dopt Opt_StgStats dflags
758 todo1 = if stg_stats then [D_stg_stats] else []
760 todo2 | WayProf `elem` wayNames dflags
761 = StgDoMassageForProfiling : todo1
765 -- -----------------------------------------------------------------------------
769 allFlags = map ('-':) $
770 [ name | (name, optkind) <- dynamic_flags, ok optkind ] ++
771 map ("fno-"++) flags ++
773 where ok (PrefixPred _ _) = False
775 flags = map fst fFlags
777 dynamic_flags :: [(String, OptKind DynP)]
779 ( "n" , NoArg (setDynFlag Opt_DryRun) )
780 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
781 , ( "F" , NoArg (setDynFlag Opt_Pp))
782 , ( "#include" , HasArg (addCmdlineHCInclude) )
783 , ( "v" , OptPrefix (setVerbosity) )
785 ------- Specific phases --------------------------------------------
786 , ( "pgmL" , HasArg (upd . setPgmL) )
787 , ( "pgmP" , HasArg (upd . setPgmP) )
788 , ( "pgmF" , HasArg (upd . setPgmF) )
789 , ( "pgmc" , HasArg (upd . setPgmc) )
790 , ( "pgmm" , HasArg (upd . setPgmm) )
791 , ( "pgms" , HasArg (upd . setPgms) )
792 , ( "pgma" , HasArg (upd . setPgma) )
793 , ( "pgml" , HasArg (upd . setPgml) )
794 , ( "pgmdll" , HasArg (upd . setPgmdll) )
796 , ( "optL" , HasArg (upd . addOptL) )
797 , ( "optP" , HasArg (upd . addOptP) )
798 , ( "optF" , HasArg (upd . addOptF) )
799 , ( "optc" , HasArg (upd . addOptc) )
800 , ( "optm" , HasArg (upd . addOptm) )
801 , ( "opta" , HasArg (upd . addOpta) )
802 , ( "optl" , HasArg (upd . addOptl) )
803 , ( "optdll" , HasArg (upd . addOptdll) )
804 , ( "optdep" , HasArg (upd . addOptdep) )
806 , ( "split-objs" , NoArg (if can_split
807 then setDynFlag Opt_SplitObjs
810 -------- Linking ----------------------------------------------------
811 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
812 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
813 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
815 ------- Libraries ---------------------------------------------------
816 , ( "L" , Prefix addLibraryPath )
817 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
820 ------- Frameworks --------------------------------------------------
821 -- -framework-path should really be -F ...
822 , ( "framework-path" , HasArg addFrameworkPath )
823 , ( "framework" , HasArg (upd . addCmdlineFramework) )
825 ------- Output Redirection ------------------------------------------
826 , ( "odir" , HasArg (upd . setObjectDir . Just))
827 , ( "o" , SepArg (upd . setOutputFile . Just))
828 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
829 , ( "osuf" , HasArg (upd . setObjectSuf))
830 , ( "hcsuf" , HasArg (upd . setHcSuf))
831 , ( "hisuf" , HasArg (upd . setHiSuf))
832 , ( "hidir" , HasArg (upd . setHiDir . Just))
833 , ( "tmpdir" , HasArg (upd . setTmpDir))
834 , ( "stubdir" , HasArg (upd . setStubDir . Just))
836 ------- Keeping temporary files -------------------------------------
837 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
838 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
839 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
840 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
842 ------- Miscellaneous ----------------------------------------------
843 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
844 , ( "main-is" , SepArg setMainIs )
846 ------- recompilation checker --------------------------------------
847 , ( "recomp" , NoArg (setDynFlag Opt_RecompChecking) )
848 , ( "no-recomp" , NoArg (unSetDynFlag Opt_RecompChecking) )
850 ------- Packages ----------------------------------------------------
851 , ( "package-conf" , HasArg extraPkgConf_ )
852 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
853 , ( "package-name" , HasArg ignorePackage ) -- for compatibility
854 , ( "package" , HasArg exposePackage )
855 , ( "hide-package" , HasArg hidePackage )
856 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
857 , ( "ignore-package" , HasArg ignorePackage )
858 , ( "syslib" , HasArg exposePackage ) -- for compatibility
860 ------ HsCpp opts ---------------------------------------------------
861 , ( "D", AnySuffix (upd . addOptP) )
862 , ( "U", AnySuffix (upd . addOptP) )
864 ------- Include/Import Paths ----------------------------------------
865 , ( "I" , Prefix addIncludePath)
866 , ( "i" , OptPrefix addImportPath )
868 ------ Debugging ----------------------------------------------------
869 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
871 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
872 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
873 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
874 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
875 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
876 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
877 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
878 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
879 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
880 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
881 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
882 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
883 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
884 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
885 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
886 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
887 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
888 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
889 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
890 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
891 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
892 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
893 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace))
894 , ( "ddump-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace))
895 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
896 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
897 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats))
898 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
899 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
900 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
901 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
902 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
903 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
904 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs))
905 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
906 , ( "ddump-minimal-imports", NoArg (setDynFlag Opt_D_dump_minimal_imports))
907 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
908 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
909 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
910 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
911 , ( "dshow-passes", NoArg (do unSetDynFlag Opt_RecompChecking
913 , ( "dfaststring-stats", NoArg (setDynFlag Opt_D_faststring_stats))
915 ------ Machine dependant (-m<blah>) stuff ---------------------------
917 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
918 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
919 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
921 ------ Warning opts -------------------------------------------------
922 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
923 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
924 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
925 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
926 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
928 ------ Optimisation flags ------------------------------------------
929 , ( "O" , NoArg (upd (setOptLevel 1)))
930 , ( "Onot" , NoArg (upd (setOptLevel 0)))
931 , ( "O" , PrefixPred (all isDigit)
932 (\f -> upd (setOptLevel (read f))))
934 , ( "fmax-simplifier-iterations",
935 PrefixPred (all isDigit)
937 dfs{ maxSimplIterations = read n })) )
940 SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
942 ------ Compiler flags -----------------------------------------------
944 , ( "fno-code", NoArg (setTarget HscNothing))
945 , ( "fasm", AnySuffix (\_ -> setTarget HscAsm) )
946 , ( "fvia-c", NoArg (setTarget HscC) )
947 , ( "fvia-C", NoArg (setTarget HscC) )
948 , ( "filx", NoArg (setTarget HscILX) )
950 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
951 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
953 -- the rest of the -f* and -fno-* flags
954 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
955 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
958 -- these -f<blah> flags can all be reversed with -fno-<blah>
961 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
962 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
963 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
964 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
965 ( "warn-missing-fields", Opt_WarnMissingFields ),
966 ( "warn-missing-methods", Opt_WarnMissingMethods ),
967 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
968 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
969 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
970 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
971 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
972 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
973 ( "warn-unused-imports", Opt_WarnUnusedImports ),
974 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
975 ( "warn-deprecations", Opt_WarnDeprecations ),
976 ( "warn-orphans", Opt_WarnOrphans ),
977 ( "fi", Opt_FFI ), -- support `-ffi'...
978 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
979 ( "arrows", Opt_Arrows ), -- arrow syntax
980 ( "parr", Opt_PArr ),
982 ( "implicit-prelude", Opt_ImplicitPrelude ),
983 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
984 ( "bang-patterns", Opt_BangPatterns ),
985 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
986 ( "implicit-params", Opt_ImplicitParams ),
987 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
988 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
989 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
990 ( "generics", Opt_Generics ),
991 ( "strictness", Opt_Strictness ),
992 ( "full-laziness", Opt_FullLaziness ),
994 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
995 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
996 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
997 ( "ignore-asserts", Opt_IgnoreAsserts ),
998 ( "do-eta-reduction", Opt_DoEtaReduction ),
999 ( "case-merge", Opt_CaseMerge ),
1000 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
1001 ( "excess-precision", Opt_ExcessPrecision ),
1002 ( "asm-mangling", Opt_DoAsmMangling )
1005 glasgowExtsFlags = [
1010 Opt_ScopedTypeVariables,
1013 isFFlag f = f `elem` (map fst fFlags)
1014 getFFlag f = fromJust (lookup f fFlags)
1016 -- -----------------------------------------------------------------------------
1017 -- Parsing the dynamic flags.
1019 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
1020 parseDynamicFlags dflags args = do
1021 let ((leftover,errs),dflags')
1022 = runCmdLine (processArgs dynamic_flags args) dflags
1023 when (not (null errs)) $ do
1024 throwDyn (UsageError (unlines errs))
1025 return (dflags', leftover)
1028 type DynP = CmdLineP DynFlags
1030 upd :: (DynFlags -> DynFlags) -> DynP ()
1032 dfs <- getCmdLineState
1033 putCmdLineState $! (f dfs)
1035 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1036 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1037 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1039 setDumpFlag :: DynFlag -> OptKind DynP
1040 setDumpFlag dump_flag
1041 = NoArg (unSetDynFlag Opt_RecompChecking >> setDynFlag dump_flag)
1042 -- Whenver we -ddump, switch off the recompilation checker,
1043 -- else you don't see the dump!
1045 setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
1047 | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
1048 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
1050 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1052 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1055 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1057 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1059 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1061 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
1062 -- (-fvia-C, -fasm, -filx respectively).
1063 setTarget l = upd (\dfs -> case hscTarget dfs of
1064 HscC -> dfs{ hscTarget = l }
1065 HscAsm -> dfs{ hscTarget = l }
1066 HscILX -> dfs{ hscTarget = l }
1069 setOptLevel :: Int -> DynFlags -> DynFlags
1070 setOptLevel n dflags
1071 | hscTarget dflags == HscInterpreted && n > 0
1073 -- not in IO any more, oh well:
1074 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1076 = updOptLevel n dflags
1079 setMainIs :: String -> DynP ()
1081 | not (null main_fn) -- The arg looked like "Foo.baz"
1082 = upd $ \d -> d{ mainFunIs = Just main_fn,
1083 mainModIs = mkModule main_mod }
1085 | isUpper (head main_mod) -- The arg looked like "Foo"
1086 = upd $ \d -> d{ mainModIs = mkModule main_mod }
1088 | otherwise -- The arg looked like "baz"
1089 = upd $ \d -> d{ mainFunIs = Just main_mod }
1091 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1093 -----------------------------------------------------------------------------
1094 -- Paths & Libraries
1096 -- -i on its own deletes the import paths
1097 addImportPath "" = upd (\s -> s{importPaths = []})
1098 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1102 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1105 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1107 addFrameworkPath p =
1108 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1110 split_marker = ':' -- not configurable (ToDo)
1112 splitPathList :: String -> [String]
1113 splitPathList s = filter notNull (splitUp s)
1114 -- empty paths are ignored: there might be a trailing
1115 -- ':' in the initial list, for example. Empty paths can
1116 -- cause confusion when they are translated into -I options
1117 -- for passing to gcc.
1119 #ifndef mingw32_TARGET_OS
1120 splitUp xs = split split_marker xs
1122 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1124 -- That is, if "foo:bar:baz" is used, this interpreted as
1125 -- consisting of three entries, 'foo', 'bar', 'baz'.
1126 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1127 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1129 -- Notice that no attempt is made to fully replace the 'standard'
1130 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1131 -- that this will cause too much breakage for users & ':' will
1132 -- work fine even with DOS paths, if you're not insisting on being silly.
1135 splitUp (x:':':div:xs) | div `elem` dir_markers
1136 = ((x:':':div:p): splitUp rs)
1138 (p,rs) = findNextPath xs
1139 -- we used to check for existence of the path here, but that
1140 -- required the IO monad to be threaded through the command-line
1141 -- parser which is quite inconvenient. The
1142 splitUp xs = cons p (splitUp rs)
1144 (p,rs) = findNextPath xs
1149 -- will be called either when we've consumed nought or the
1150 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1151 -- finding the next split marker.
1153 case break (`elem` split_markers) xs of
1154 (p, d:ds) -> (p, ds)
1157 split_markers :: [Char]
1158 split_markers = [':', ';']
1160 dir_markers :: [Char]
1161 dir_markers = ['/', '\\']
1164 -- -----------------------------------------------------------------------------
1165 -- tmpDir, where we store temporary files.
1167 setTmpDir :: FilePath -> DynFlags -> DynFlags
1168 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1170 #if !defined(mingw32_HOST_OS)
1171 canonicalise p = normalisePath p
1173 -- Canonicalisation of temp path under win32 is a bit more
1174 -- involved: (a) strip trailing slash,
1175 -- (b) normalise slashes
1176 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1178 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1180 -- if we're operating under cygwin, and TMP/TEMP is of
1181 -- the form "/cygdrive/drive/path", translate this to
1182 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1183 -- understand /cygdrive paths.)
1185 | "/cygdrive/" `isPrefixOf` path =
1186 case drop (length "/cygdrive/") path of
1187 drive:xs@('/':_) -> drive:':':xs
1191 -- strip the trailing backslash (awful, but we only do this once).
1192 removeTrailingSlash path =
1199 -----------------------------------------------------------------------------
1200 -- Via-C compilation stuff
1202 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1203 [String]) -- for registerised HC compilations
1204 machdepCCOpts dflags
1205 #if alpha_TARGET_ARCH
1207 #ifdef HAVE_THREADED_RTS_SUPPORT
1211 -- For now, to suppress the gcc warning "call-clobbered
1212 -- register used for global register variable", we simply
1213 -- disable all warnings altogether using the -w flag. Oh well.
1215 #elif hppa_TARGET_ARCH
1216 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1217 -- (very nice, but too bad the HP /usr/include files don't agree.)
1218 = ( ["-D_HPUX_SOURCE"], [] )
1220 #elif m68k_TARGET_ARCH
1221 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1222 -- popping of args to routines to be explicit; if we let things
1223 -- be deferred 'til after an STGJUMP, imminent death is certain!
1225 -- -fomit-frame-pointer : *don't*
1226 -- It's better to have a6 completely tied up being a frame pointer
1227 -- rather than let GCC pick random things to do with it.
1228 -- (If we want to steal a6, then we would try to do things
1229 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1230 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1232 #elif i386_TARGET_ARCH
1233 -- -fno-defer-pop : basically the same game as for m68k
1235 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1236 -- the fp (%ebp) for our register maps.
1237 = let n_regs = stolen_x86_regs dflags
1240 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1241 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1244 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1245 -- Some gccs are configured with
1246 -- -momit-leaf-frame-pointer on by default, and it
1247 -- apparently takes precedence over
1248 -- -fomit-frame-pointer, so we disable it first here.
1249 "-mno-omit-leaf-frame-pointer",
1251 "-fomit-frame-pointer",
1252 -- we want -fno-builtin, because when gcc inlines
1253 -- built-in functions like memcpy() it tends to
1254 -- run out of registers, requiring -monly-n-regs
1256 "-DSTOLEN_X86_REGS="++show n_regs ]
1259 #elif ia64_TARGET_ARCH
1260 = ( [], ["-fomit-frame-pointer", "-G0"] )
1262 #elif x86_64_TARGET_ARCH
1263 = ( [], ["-fomit-frame-pointer",
1264 "-fno-asynchronous-unwind-tables",
1265 -- the unwind tables are unnecessary for HC code,
1266 -- and get in the way of -split-objs. Another option
1267 -- would be to throw them away in the mangler, but this
1269 "-fno-unit-at-a-time"
1270 -- unit-at-a-time doesn't do us any good, and screws
1271 -- up -split-objs by moving the split markers around.
1272 -- It's only turned on with -O2, but put it here just
1273 -- in case someone uses -optc-O2.
1276 #elif mips_TARGET_ARCH
1277 = ( ["-static"], [] )
1279 #elif sparc_TARGET_ARCH
1281 -- For now, to suppress the gcc warning "call-clobbered
1282 -- register used for global register variable", we simply
1283 -- disable all warnings altogether using the -w flag. Oh well.
1285 #elif powerpc_apple_darwin_TARGET
1287 -- Disable Apple's precompiling preprocessor. It's a great thing
1288 -- for "normal" programs, but it doesn't support register variable
1290 = ( [], ["-no-cpp-precomp"] )
1295 picCCOpts :: DynFlags -> [String]
1297 #if darwin_TARGET_OS
1298 -- Apple prefers to do things the other way round.
1299 -- PIC is on by default.
1300 -- -mdynamic-no-pic:
1301 -- Turn off PIC code generation.
1303 -- Don't generate "common" symbols - these are unwanted
1304 -- in dynamic libraries.
1309 = ["-mdynamic-no-pic"]
1310 #elif mingw32_TARGET_OS
1311 -- no -fPIC for Windows
1320 -- -----------------------------------------------------------------------------
1325 #if defined(i386_TARGET_ARCH) \
1326 || defined(x86_64_TARGET_ARCH) \
1327 || defined(alpha_TARGET_ARCH) \
1328 || defined(hppa_TARGET_ARCH) \
1329 || defined(m68k_TARGET_ARCH) \
1330 || defined(mips_TARGET_ARCH) \
1331 || defined(powerpc_TARGET_ARCH) \
1332 || defined(rs6000_TARGET_ARCH) \
1333 || defined(sparc_TARGET_ARCH)