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]
46 machdepCCOpts, picCCOpts,
49 #include "HsVersions.h"
51 import Module ( Module, mkModule )
52 import PrelNames ( mAIN )
53 import StaticFlags ( opt_Static, opt_PIC,
54 WayName(..), v_Ways, v_Build_tag, v_RTS_Build_tag )
55 import {-# SOURCE #-} Packages (PackageState)
56 import DriverPhases ( Phase(..), phaseInputExt )
59 import Panic ( panic, GhcException(..) )
60 import Util ( notNull, splitLongestPrefix, split, normalisePath )
61 import SrcLoc ( SrcSpan )
63 import DATA_IOREF ( readIORef )
64 import EXCEPTION ( throwDyn )
66 #ifdef mingw32_TARGET_OS
67 import Data.List ( isPrefixOf )
69 import Maybe ( fromJust )
70 import Char ( isDigit, isUpper )
72 import System.IO ( hPutStrLn, stderr )
73 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
75 -- -----------------------------------------------------------------------------
88 | Opt_D_dump_inlinings
89 | Opt_D_dump_occur_anal
93 | Opt_D_dump_simpl_iterations
102 | Opt_D_dump_worker_wrapper
103 | Opt_D_dump_rn_trace
104 | Opt_D_dump_rn_stats
106 | Opt_D_dump_simpl_stats
107 | Opt_D_dump_tc_trace
108 | Opt_D_dump_if_trace
113 | Opt_D_verbose_core2core
114 | Opt_D_verbose_stg2stg
116 | Opt_D_dump_hi_diffs
117 | Opt_D_dump_minimal_imports
122 | Opt_WarnIsError -- -Werror; makes warnings fatal
123 | Opt_WarnDuplicateExports
125 | Opt_WarnIncompletePatterns
126 | Opt_WarnIncompletePatternsRecUpd
127 | Opt_WarnMissingFields
128 | Opt_WarnMissingMethods
129 | Opt_WarnMissingSigs
130 | Opt_WarnNameShadowing
131 | Opt_WarnOverlappingPatterns
132 | Opt_WarnSimplePatterns
133 | Opt_WarnTypeDefaults
134 | Opt_WarnUnusedBinds
135 | Opt_WarnUnusedImports
136 | Opt_WarnUnusedMatches
137 | Opt_WarnDeprecations
138 | Opt_WarnDodgyImports
142 | Opt_AllowOverlappingInstances
143 | Opt_AllowUndecidableInstances
144 | Opt_AllowIncoherentInstances
145 | Opt_MonomorphismRestriction
148 | Opt_PArr -- syntactic support for parallel arrays
149 | Opt_Arrows -- Arrow-notation syntax
153 | Opt_ImplicitPrelude
154 | Opt_ScopedTypeVariables
160 | Opt_IgnoreInterfacePragmas
161 | Opt_OmitInterfacePragmas
162 | Opt_DoLambdaEtaExpansion
166 | Opt_UnboxStrictFields
174 | Opt_ExcessPrecision
175 | Opt_ReadUserPackageConf
179 | Opt_HideAllPackages
190 data DynFlags = DynFlags {
193 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
194 stgToDo :: Maybe [StgToDo], -- similarly
195 hscTarget :: HscTarget,
196 hscOutName :: String, -- name of the output file
197 extCoreName :: String, -- name of the .core output file
198 verbosity :: Int, -- verbosity level
199 optLevel :: Int, -- optimisation level
200 maxSimplIterations :: Int, -- max simplifier iterations
201 ruleCheck :: Maybe String,
202 stolen_x86_regs :: Int,
203 cmdlineHcIncludes :: [String], -- -#includes
204 importPaths :: [FilePath],
206 mainFunIs :: Maybe String,
209 wayNames :: [WayName], -- way flags from the cmd line
210 buildTag :: String, -- the global "way" (eg. "p" for prof)
211 rtsBuildTag :: String, -- the RTS "way"
214 objectDir :: Maybe String,
215 hiDir :: Maybe String,
216 stubDir :: Maybe String,
222 outputFile :: Maybe String,
223 outputHi :: Maybe String,
225 includePaths :: [String],
226 libraryPaths :: [String],
227 frameworkPaths :: [String], -- used on darwin only
228 cmdlineFrameworks :: [String], -- ditto
229 tmpDir :: String, -- no trailing '/'
231 -- options for particular phases
242 -- commands for particular phases
244 pgm_P :: (String,[Option]),
246 pgm_c :: (String,[Option]),
247 pgm_m :: (String,[Option]),
248 pgm_s :: (String,[Option]),
249 pgm_a :: (String,[Option]),
250 pgm_l :: (String,[Option]),
251 pgm_dll :: (String,[Option]),
254 extraPkgConfs :: [FilePath],
255 -- The -package-conf flags given on the command line, in the order
258 packageFlags :: [PackageFlag],
259 -- The -package and -hide-package flags from the command-line
262 pkgState :: PackageState,
268 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO ()
281 = BatchCompile -- | @ghc --make Main@
282 | Interactive -- | @ghc --interactive@
283 | OneShot -- | @ghc -c Foo.hs@
284 | JustTypecheck -- | Development environemnts, refactorer, etc.
288 isOneShot :: GhcMode -> Bool
289 isOneShot OneShot = True
290 isOneShot _other = False
292 data GhcLink -- What to do in the link step, if there is one
293 = -- Only relevant for modes
294 -- DoMake and StopBefore StopLn
295 NoLink -- Don't link at all
296 | StaticLink -- Ordinary linker [the default]
297 | MkDLL -- Make a DLL
299 isNoLink :: GhcLink -> Bool
300 isNoLink NoLink = True
301 isNoLink other = False
304 = ExposePackage String
306 | IgnorePackage String
309 | cGhcWithNativeCodeGen == "YES" = HscAsm
312 initDynFlags dflags = do
313 -- someday these will be dynamic flags
314 ways <- readIORef v_Ways
315 build_tag <- readIORef v_Build_tag
316 rts_build_tag <- readIORef v_RTS_Build_tag
319 buildTag = build_tag,
320 rtsBuildTag = rts_build_tag
326 ghcLink = StaticLink,
329 hscTarget = defaultHscTarget,
334 maxSimplIterations = 4,
337 cmdlineHcIncludes = [],
342 wayNames = panic "ways",
343 buildTag = panic "buildTag",
344 rtsBuildTag = panic "rtsBuildTag",
350 objectSuf = phaseInputExt StopLn,
351 hcSuf = phaseInputExt HCc,
354 outputFile = Nothing,
359 cmdlineFrameworks = [],
360 tmpDir = cDEFAULT_TMPDIR,
372 pgm_L = panic "pgm_L",
373 pgm_P = panic "pgm_P",
374 pgm_F = panic "pgm_F",
375 pgm_c = panic "pgm_c",
376 pgm_m = panic "pgm_m",
377 pgm_s = panic "pgm_s",
378 pgm_a = panic "pgm_a",
379 pgm_l = panic "pgm_l",
380 pgm_dll = panic "pgm_mkdll",
384 pkgState = panic "pkgState",
388 Opt_ReadUserPackageConf,
391 Opt_MonomorphismRestriction,
393 -- strictness is on by default, but this only
395 Opt_CSE, -- similarly for CSE.
396 Opt_FullLaziness, -- ...and for full laziness
398 Opt_DoLambdaEtaExpansion,
399 -- This one is important for a tiresome reason:
400 -- we want to make sure that the bindings for data
401 -- constructors are eta-expanded. This is probably
402 -- a good thing anyway, but it seems fragile.
406 -- and the default no-optimisation options:
407 Opt_IgnoreInterfacePragmas,
408 Opt_OmitInterfacePragmas
410 ] ++ standardWarnings,
412 log_action = \severity srcSpan style msg ->
414 SevInfo -> hPutStrLn stderr (show (msg style))
415 SevFatal -> hPutStrLn stderr (show (msg style))
416 _ -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
422 0 | print errors & warnings only
423 1 | minimal verbosity: print "compiling M ... done." for each module.
424 2 | equivalent to -dshow-passes
425 3 | equivalent to existing "ghc -v"
426 4 | "ghc -v -ddump-most"
427 5 | "ghc -v -ddump-all"
430 dopt :: DynFlag -> DynFlags -> Bool
431 dopt f dflags = f `elem` (flags dflags)
433 dopt_set :: DynFlags -> DynFlag -> DynFlags
434 dopt_set dfs f = dfs{ flags = f : flags dfs }
436 dopt_unset :: DynFlags -> DynFlag -> DynFlags
437 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
439 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
440 getOpts dflags opts = reverse (opts dflags)
441 -- We add to the options from the front, so we need to reverse the list
443 getVerbFlag :: DynFlags -> String
445 | verbosity dflags >= 3 = "-v"
448 setObjectDir f d = d{ objectDir = f}
449 setHiDir f d = d{ hiDir = f}
450 setStubDir f d = d{ stubDir = f}
452 setObjectSuf f d = d{ objectSuf = f}
453 setHiSuf f d = d{ hiSuf = f}
454 setHcSuf f d = d{ hcSuf = f}
456 setOutputFile f d = d{ outputFile = f}
457 setOutputHi f d = d{ outputHi = f}
459 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
460 -- Config.hs should really use Option.
461 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
463 setPgmL f d = d{ pgm_L = f}
464 setPgmF f d = d{ pgm_F = f}
465 setPgmc f d = d{ pgm_c = (f,[])}
466 setPgmm f d = d{ pgm_m = (f,[])}
467 setPgms f d = d{ pgm_s = (f,[])}
468 setPgma f d = d{ pgm_a = (f,[])}
469 setPgml f d = d{ pgm_l = (f,[])}
470 setPgmdll f d = d{ pgm_dll = (f,[])}
472 addOptL f d = d{ opt_L = f : opt_L d}
473 addOptP f d = d{ opt_P = f : opt_P d}
474 addOptF f d = d{ opt_F = f : opt_F d}
475 addOptc f d = d{ opt_c = f : opt_c d}
476 addOptm f d = d{ opt_m = f : opt_m d}
477 addOpta f d = d{ opt_a = f : opt_a d}
478 addOptl f d = d{ opt_l = f : opt_l d}
479 addOptdll f d = d{ opt_dll = f : opt_dll d}
480 addOptdep f d = d{ opt_dep = f : opt_dep d}
482 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
484 -- -----------------------------------------------------------------------------
485 -- Command-line options
487 -- When invoking external tools as part of the compilation pipeline, we
488 -- pass these a sequence of options on the command-line. Rather than
489 -- just using a list of Strings, we use a type that allows us to distinguish
490 -- between filepaths and 'other stuff'. [The reason being, of course, that
491 -- this type gives us a handle on transforming filenames, and filenames only,
492 -- to whatever format they're expected to be on a particular platform.]
495 = FileOption -- an entry that _contains_ filename(s) / filepaths.
496 String -- a non-filepath prefix that shouldn't be
497 -- transformed (e.g., "/out=")
498 String -- the filepath/filename portion
501 -----------------------------------------------------------------------------
502 -- Setting the optimisation level
504 updOptLevel :: Int -> DynFlags -> DynFlags
505 -- Set dynflags appropriate to the optimisation level
508 then dfs2{ hscTarget = HscC, optLevel = n } -- turn on -fvia-C with -O
509 else dfs2{ optLevel = n }
511 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
512 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
515 | n == 0 = opt_0_dopts
516 | otherwise = opt_1_dopts
519 | n == 0 = opt_1_dopts
520 | otherwise = opt_0_dopts
523 Opt_IgnoreInterfacePragmas,
524 Opt_OmitInterfacePragmas
533 -- -----------------------------------------------------------------------------
534 -- Standard sets of warning options
537 = [ Opt_WarnDeprecations,
538 Opt_WarnOverlappingPatterns,
539 Opt_WarnMissingFields,
540 Opt_WarnMissingMethods,
541 Opt_WarnDuplicateExports
545 = standardWarnings ++
546 [ Opt_WarnUnusedBinds,
547 Opt_WarnUnusedMatches,
548 Opt_WarnUnusedImports,
549 Opt_WarnIncompletePatterns,
555 [ Opt_WarnTypeDefaults,
556 Opt_WarnNameShadowing,
562 -- -----------------------------------------------------------------------------
563 -- CoreToDo: abstraction of core-to-core passes to run.
565 data CoreToDo -- These are diff core-to-core passes,
566 -- which may be invoked in any order,
567 -- as many times as you like.
569 = CoreDoSimplify -- The core-to-core simplifier.
572 -- Each run of the simplifier can take a different
573 -- set of simplifier-specific flags.
575 | CoreDoFloatOutwards FloatOutSwitches
580 | CoreDoWorkerWrapper
583 | CoreDoOldStrictness
586 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
587 -- matching this string
589 | CoreDoNothing -- useful when building up lists of these things
591 data SimplifierMode -- See comments in SimplMonad
595 data SimplifierSwitch
596 = MaxSimplifierIterations Int
599 data FloatOutSwitches
600 = FloatOutSw Bool -- True <=> float lambdas to top level
601 Bool -- True <=> float constants to top level,
602 -- even if they do not escape a lambda
605 -- The core-to-core pass ordering is derived from the DynFlags:
607 getCoreToDo :: DynFlags -> [CoreToDo]
609 | Just todo <- coreToDo dflags = todo -- set explicitly by user
610 | otherwise = core_todo
612 opt_level = optLevel dflags
613 max_iter = maxSimplIterations dflags
614 strictness = dopt Opt_Strictness dflags
615 full_laziness = dopt Opt_FullLaziness dflags
616 cse = dopt Opt_CSE dflags
617 rule_check = ruleCheck dflags
620 if opt_level == 0 then
622 CoreDoSimplify (SimplPhase 0) [
623 MaxSimplifierIterations max_iter
626 else {- opt_level >= 1 -} [
628 -- initial simplify: mk specialiser happy: minimum effort please
629 CoreDoSimplify SimplGently [
631 -- Don't inline anything till full laziness has bitten
632 -- In particular, inlining wrappers inhibits floating
633 -- e.g. ...(case f x of ...)...
634 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
635 -- ==> ...(case x of I# x# -> case fw x# of ...)...
636 -- and now the redex (f x) isn't floatable any more
637 -- Similarly, don't apply any rules until after full
638 -- laziness. Notably, list fusion can prevent floating.
641 -- Don't do case-of-case transformations.
642 -- This makes full laziness work better
643 MaxSimplifierIterations max_iter
646 -- Specialisation is best done before full laziness
647 -- so that overloaded functions have all their dictionary lambdas manifest
650 if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
655 CoreDoSimplify (SimplPhase 2) [
656 -- Want to run with inline phase 2 after the specialiser to give
657 -- maximum chance for fusion to work before we inline build/augment
658 -- in phase 1. This made a difference in 'ansi' where an
659 -- overloaded function wasn't inlined till too late.
660 MaxSimplifierIterations max_iter
662 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
664 CoreDoSimplify (SimplPhase 1) [
665 -- Need inline-phase2 here so that build/augment get
666 -- inlined. I found that spectral/hartel/genfft lost some useful
667 -- strictness in the function sumcode' if augment is not inlined
668 -- before strictness analysis runs
669 MaxSimplifierIterations max_iter
671 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
673 CoreDoSimplify (SimplPhase 0) [
674 -- Phase 0: allow all Ids to be inlined now
675 -- This gets foldr inlined before strictness analysis
677 MaxSimplifierIterations 3
678 -- At least 3 iterations because otherwise we land up with
679 -- huge dead expressions because of an infelicity in the
681 -- let k = BIG in foldr k z xs
682 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
683 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
687 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
689 #ifdef OLD_STRICTNESS
692 if strictness then CoreDoStrictness else CoreDoNothing,
696 CoreDoSimplify (SimplPhase 0) [
697 MaxSimplifierIterations max_iter
700 if full_laziness then
701 CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
702 True) -- Float constants
704 -- nofib/spectral/hartel/wang doubles in speed if you
705 -- do full laziness late in the day. It only happens
706 -- after fusion and other stuff, so the early pass doesn't
707 -- catch it. For the record, the redex is
708 -- f_el22 (f_el21 r_midblock)
711 -- We want CSE to follow the final full-laziness pass, because it may
712 -- succeed in commoning up things floated out by full laziness.
713 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
715 if cse then CoreCSE else CoreDoNothing,
719 -- Case-liberation for -O2. This should be after
720 -- strictness analysis and the simplification which follows it.
722 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
724 if opt_level >= 2 then
728 if opt_level >= 2 then
733 -- Final clean-up simplification:
734 CoreDoSimplify (SimplPhase 0) [
735 MaxSimplifierIterations max_iter
739 -- -----------------------------------------------------------------------------
740 -- StgToDo: abstraction of stg-to-stg passes to run.
743 = StgDoMassageForProfiling -- should be (next to) last
744 -- There's also setStgVarInfo, but its absolute "lastness"
745 -- is so critical that it is hardwired in (no flag).
748 getStgToDo :: DynFlags -> [StgToDo]
750 | Just todo <- stgToDo dflags = todo -- set explicitly by user
753 stg_stats = dopt Opt_StgStats dflags
755 todo1 = if stg_stats then [D_stg_stats] else []
757 todo2 | WayProf `elem` wayNames dflags
758 = StgDoMassageForProfiling : todo1
762 -- -----------------------------------------------------------------------------
765 dynamic_flags :: [(String, OptKind DynP)]
767 ( "n" , NoArg (setDynFlag Opt_DryRun) )
768 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
769 , ( "F" , NoArg (setDynFlag Opt_Pp))
770 , ( "#include" , HasArg (addCmdlineHCInclude) )
771 , ( "v" , OptPrefix (setVerbosity) )
773 ------- Specific phases --------------------------------------------
774 , ( "pgmL" , HasArg (upd . setPgmL) )
775 , ( "pgmP" , HasArg (upd . setPgmP) )
776 , ( "pgmF" , HasArg (upd . setPgmF) )
777 , ( "pgmc" , HasArg (upd . setPgmc) )
778 , ( "pgmm" , HasArg (upd . setPgmm) )
779 , ( "pgms" , HasArg (upd . setPgms) )
780 , ( "pgma" , HasArg (upd . setPgma) )
781 , ( "pgml" , HasArg (upd . setPgml) )
782 , ( "pgmdll" , HasArg (upd . setPgmdll) )
784 , ( "optL" , HasArg (upd . addOptL) )
785 , ( "optP" , HasArg (upd . addOptP) )
786 , ( "optF" , HasArg (upd . addOptF) )
787 , ( "optc" , HasArg (upd . addOptc) )
788 , ( "optm" , HasArg (upd . addOptm) )
789 , ( "opta" , HasArg (upd . addOpta) )
790 , ( "optl" , HasArg (upd . addOptl) )
791 , ( "optdll" , HasArg (upd . addOptdll) )
792 , ( "optdep" , HasArg (upd . addOptdep) )
794 , ( "split-objs" , NoArg (if can_split
795 then setDynFlag Opt_SplitObjs
798 -------- Linking ----------------------------------------------------
799 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
800 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
801 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
803 ------- Libraries ---------------------------------------------------
804 , ( "L" , Prefix addLibraryPath )
805 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
808 ------- Frameworks --------------------------------------------------
809 -- -framework-path should really be -F ...
810 , ( "framework-path" , HasArg addFrameworkPath )
811 , ( "framework" , HasArg (upd . addCmdlineFramework) )
813 ------- Output Redirection ------------------------------------------
814 , ( "odir" , HasArg (upd . setObjectDir . Just))
815 , ( "o" , SepArg (upd . setOutputFile . Just))
816 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
817 , ( "osuf" , HasArg (upd . setObjectSuf))
818 , ( "hcsuf" , HasArg (upd . setHcSuf))
819 , ( "hisuf" , HasArg (upd . setHiSuf))
820 , ( "hidir" , HasArg (upd . setHiDir . Just))
821 , ( "tmpdir" , HasArg (upd . setTmpDir))
822 , ( "stubdir" , HasArg (upd . setStubDir . Just))
824 ------- Keeping temporary files -------------------------------------
825 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
826 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
827 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
828 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
830 ------- Miscellaneous ----------------------------------------------
831 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
832 , ( "main-is" , SepArg setMainIs )
834 ------- recompilation checker --------------------------------------
835 , ( "recomp" , NoArg (setDynFlag Opt_RecompChecking) )
836 , ( "no-recomp" , NoArg (unSetDynFlag Opt_RecompChecking) )
838 ------- Packages ----------------------------------------------------
839 , ( "package-conf" , HasArg extraPkgConf_ )
840 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
841 , ( "package-name" , HasArg ignorePackage ) -- for compatibility
842 , ( "package" , HasArg exposePackage )
843 , ( "hide-package" , HasArg hidePackage )
844 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
845 , ( "ignore-package" , HasArg ignorePackage )
846 , ( "syslib" , HasArg exposePackage ) -- for compatibility
848 ------ HsCpp opts ---------------------------------------------------
849 , ( "D", AnySuffix (upd . addOptP) )
850 , ( "U", AnySuffix (upd . addOptP) )
852 ------- Include/Import Paths ----------------------------------------
853 , ( "I" , Prefix addIncludePath)
854 , ( "i" , OptPrefix addImportPath )
856 ------ Debugging ----------------------------------------------------
857 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
859 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
860 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
861 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
862 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
863 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
864 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
865 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
866 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
867 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
868 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
869 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
870 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
871 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
872 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
873 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
874 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
875 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
876 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
877 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
878 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
879 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
880 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
881 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace))
882 , ( "ddump-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace))
883 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
884 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
885 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats))
886 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
887 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
888 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
889 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
890 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
891 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
892 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs))
893 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
894 , ( "ddump-minimal-imports", NoArg (setDynFlag Opt_D_dump_minimal_imports))
895 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
896 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
897 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
898 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
899 , ( "dshow-passes", NoArg (do unSetDynFlag Opt_RecompChecking
902 ------ Machine dependant (-m<blah>) stuff ---------------------------
904 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
905 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
906 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
908 ------ Warning opts -------------------------------------------------
909 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
910 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
911 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
912 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
913 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
915 ------ Optimisation flags ------------------------------------------
916 , ( "O" , NoArg (upd (setOptLevel 1)))
917 , ( "Onot" , NoArg (upd (setOptLevel 0)))
918 , ( "O" , PrefixPred (all isDigit)
919 (\f -> upd (setOptLevel (read f))))
921 , ( "fmax-simplifier-iterations",
922 PrefixPred (all isDigit)
924 dfs{ maxSimplIterations = read n })) )
927 SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
929 ------ Compiler flags -----------------------------------------------
931 , ( "fno-code", NoArg (setTarget HscNothing))
932 , ( "fasm", AnySuffix (\_ -> setTarget HscAsm) )
933 , ( "fvia-c", NoArg (setTarget HscC) )
934 , ( "fvia-C", NoArg (setTarget HscC) )
935 , ( "filx", NoArg (setTarget HscILX) )
937 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
938 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
940 -- the rest of the -f* and -fno-* flags
941 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
942 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
945 -- these -f<blah> flags can all be reversed with -fno-<blah>
948 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
949 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
950 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
951 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
952 ( "warn-missing-fields", Opt_WarnMissingFields ),
953 ( "warn-missing-methods", Opt_WarnMissingMethods ),
954 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
955 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
956 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
957 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
958 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
959 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
960 ( "warn-unused-imports", Opt_WarnUnusedImports ),
961 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
962 ( "warn-deprecations", Opt_WarnDeprecations ),
963 ( "warn-orphans", Opt_WarnOrphans ),
964 ( "fi", Opt_FFI ), -- support `-ffi'...
965 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
966 ( "arrows", Opt_Arrows ), -- arrow syntax
967 ( "parr", Opt_PArr ),
969 ( "implicit-prelude", Opt_ImplicitPrelude ),
970 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
971 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
972 ( "implicit-params", Opt_ImplicitParams ),
973 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
974 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
975 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
976 ( "generics", Opt_Generics ),
977 ( "strictness", Opt_Strictness ),
978 ( "full-laziness", Opt_FullLaziness ),
980 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
981 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
982 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
983 ( "ignore-asserts", Opt_IgnoreAsserts ),
984 ( "do-eta-reduction", Opt_DoEtaReduction ),
985 ( "case-merge", Opt_CaseMerge ),
986 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
987 ( "excess-precision", Opt_ExcessPrecision ),
988 ( "asm-mangling", Opt_DoAsmMangling )
996 Opt_ScopedTypeVariables ]
998 isFFlag f = f `elem` (map fst fFlags)
999 getFFlag f = fromJust (lookup f fFlags)
1001 -- -----------------------------------------------------------------------------
1002 -- Parsing the dynamic flags.
1004 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
1005 parseDynamicFlags dflags args = do
1006 let ((leftover,errs),dflags')
1007 = runCmdLine (processArgs dynamic_flags args) dflags
1008 when (not (null errs)) $ do
1009 throwDyn (UsageError (unlines errs))
1010 return (dflags', leftover)
1013 type DynP = CmdLineP DynFlags
1015 upd :: (DynFlags -> DynFlags) -> DynP ()
1017 dfs <- getCmdLineState
1018 putCmdLineState $! (f dfs)
1020 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1021 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1022 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1024 setDumpFlag :: DynFlag -> OptKind DynP
1025 setDumpFlag dump_flag
1026 = NoArg (unSetDynFlag Opt_RecompChecking >> setDynFlag dump_flag)
1027 -- Whenver we -ddump, switch off the recompilation checker,
1028 -- else you don't see the dump!
1030 setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
1032 | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
1033 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
1035 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1037 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1040 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1042 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1044 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1046 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
1047 -- (-fvia-C, -fasm, -filx respectively).
1048 setTarget l = upd (\dfs -> case hscTarget dfs of
1049 HscC -> dfs{ hscTarget = l }
1050 HscAsm -> dfs{ hscTarget = l }
1051 HscILX -> dfs{ hscTarget = l }
1054 setOptLevel :: Int -> DynFlags -> DynFlags
1055 setOptLevel n dflags
1056 | hscTarget dflags == HscInterpreted && n > 0
1058 -- not in IO any more, oh well:
1059 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1061 = updOptLevel n dflags
1064 setMainIs :: String -> DynP ()
1066 | not (null main_fn) -- The arg looked like "Foo.baz"
1067 = upd $ \d -> d{ mainFunIs = Just main_fn,
1068 mainModIs = mkModule main_mod }
1070 | isUpper (head main_mod) -- The arg looked like "Foo"
1071 = upd $ \d -> d{ mainModIs = mkModule main_mod }
1073 | otherwise -- The arg looked like "baz"
1074 = upd $ \d -> d{ mainFunIs = Just main_mod }
1076 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1078 -----------------------------------------------------------------------------
1079 -- Paths & Libraries
1081 -- -i on its own deletes the import paths
1082 addImportPath "" = upd (\s -> s{importPaths = []})
1083 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1087 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1090 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1092 addFrameworkPath p =
1093 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1095 split_marker = ':' -- not configurable (ToDo)
1097 splitPathList :: String -> [String]
1098 splitPathList s = filter notNull (splitUp s)
1099 -- empty paths are ignored: there might be a trailing
1100 -- ':' in the initial list, for example. Empty paths can
1101 -- cause confusion when they are translated into -I options
1102 -- for passing to gcc.
1104 #ifndef mingw32_TARGET_OS
1105 splitUp xs = split split_marker xs
1107 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1109 -- That is, if "foo:bar:baz" is used, this interpreted as
1110 -- consisting of three entries, 'foo', 'bar', 'baz'.
1111 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1112 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1114 -- Notice that no attempt is made to fully replace the 'standard'
1115 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1116 -- that this will cause too much breakage for users & ':' will
1117 -- work fine even with DOS paths, if you're not insisting on being silly.
1120 splitUp (x:':':div:xs) | div `elem` dir_markers
1121 = ((x:':':div:p): splitUp rs)
1123 (p,rs) = findNextPath xs
1124 -- we used to check for existence of the path here, but that
1125 -- required the IO monad to be threaded through the command-line
1126 -- parser which is quite inconvenient. The
1127 splitUp xs = cons p (splitUp rs)
1129 (p,rs) = findNextPath xs
1134 -- will be called either when we've consumed nought or the
1135 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1136 -- finding the next split marker.
1138 case break (`elem` split_markers) xs of
1139 (p, d:ds) -> (p, ds)
1142 split_markers :: [Char]
1143 split_markers = [':', ';']
1145 dir_markers :: [Char]
1146 dir_markers = ['/', '\\']
1149 -- -----------------------------------------------------------------------------
1150 -- tmpDir, where we store temporary files.
1152 setTmpDir :: FilePath -> DynFlags -> DynFlags
1153 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1155 #if !defined(mingw32_HOST_OS)
1156 canonicalise p = normalisePath p
1158 -- Canonicalisation of temp path under win32 is a bit more
1159 -- involved: (a) strip trailing slash,
1160 -- (b) normalise slashes
1161 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1163 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1165 -- if we're operating under cygwin, and TMP/TEMP is of
1166 -- the form "/cygdrive/drive/path", translate this to
1167 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1168 -- understand /cygdrive paths.)
1170 | "/cygdrive/" `isPrefixOf` path =
1171 case drop (length "/cygdrive/") path of
1172 drive:xs@('/':_) -> drive:':':xs
1176 -- strip the trailing backslash (awful, but we only do this once).
1177 removeTrailingSlash path =
1184 -----------------------------------------------------------------------------
1185 -- Via-C compilation stuff
1187 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1188 [String]) -- for registerised HC compilations
1189 machdepCCOpts dflags
1190 #if alpha_TARGET_ARCH
1192 #ifdef HAVE_THREADED_RTS_SUPPORT
1196 -- For now, to suppress the gcc warning "call-clobbered
1197 -- register used for global register variable", we simply
1198 -- disable all warnings altogether using the -w flag. Oh well.
1200 #elif hppa_TARGET_ARCH
1201 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1202 -- (very nice, but too bad the HP /usr/include files don't agree.)
1203 = ( ["-D_HPUX_SOURCE"], [] )
1205 #elif m68k_TARGET_ARCH
1206 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1207 -- popping of args to routines to be explicit; if we let things
1208 -- be deferred 'til after an STGJUMP, imminent death is certain!
1210 -- -fomit-frame-pointer : *don't*
1211 -- It's better to have a6 completely tied up being a frame pointer
1212 -- rather than let GCC pick random things to do with it.
1213 -- (If we want to steal a6, then we would try to do things
1214 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1215 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1217 #elif i386_TARGET_ARCH
1218 -- -fno-defer-pop : basically the same game as for m68k
1220 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1221 -- the fp (%ebp) for our register maps.
1222 = let n_regs = stolen_x86_regs dflags
1225 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1226 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1229 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1230 -- Some gccs are configured with
1231 -- -momit-leaf-frame-pointer on by default, and it
1232 -- apparently takes precedence over
1233 -- -fomit-frame-pointer, so we disable it first here.
1234 "-mno-omit-leaf-frame-pointer",
1236 "-fomit-frame-pointer",
1237 -- we want -fno-builtin, because when gcc inlines
1238 -- built-in functions like memcpy() it tends to
1239 -- run out of registers, requiring -monly-n-regs
1241 "-DSTOLEN_X86_REGS="++show n_regs ]
1244 #elif ia64_TARGET_ARCH
1245 = ( [], ["-fomit-frame-pointer", "-G0"] )
1247 #elif x86_64_TARGET_ARCH
1248 = ( [], ["-fomit-frame-pointer",
1249 "-fno-asynchronous-unwind-tables",
1250 -- the unwind tables are unnecessary for HC code,
1251 -- and get in the way of -split-objs. Another option
1252 -- would be to throw them away in the mangler, but this
1254 "-fno-unit-at-a-time"
1255 -- unit-at-a-time doesn't do us any good, and screws
1256 -- up -split-objs by moving the split markers around.
1257 -- It's only turned on with -O2, but put it here just
1258 -- in case someone uses -optc-O2.
1261 #elif mips_TARGET_ARCH
1262 = ( ["-static"], [] )
1264 #elif sparc_TARGET_ARCH
1266 -- For now, to suppress the gcc warning "call-clobbered
1267 -- register used for global register variable", we simply
1268 -- disable all warnings altogether using the -w flag. Oh well.
1270 #elif powerpc_apple_darwin_TARGET
1272 -- Disable Apple's precompiling preprocessor. It's a great thing
1273 -- for "normal" programs, but it doesn't support register variable
1275 = ( [], ["-no-cpp-precomp"] )
1280 picCCOpts :: DynFlags -> [String]
1282 #if darwin_TARGET_OS
1283 -- Apple prefers to do things the other way round.
1284 -- PIC is on by default.
1285 -- -mdynamic-no-pic:
1286 -- Turn off PIC code generation.
1288 -- Don't generate "common" symbols - these are unwanted
1289 -- in dynamic libraries.
1294 = ["-mdynamic-no-pic"]
1295 #elif mingw32_TARGET_OS
1296 -- no -fPIC for Windows
1305 -- -----------------------------------------------------------------------------
1310 #if defined(i386_TARGET_ARCH) \
1311 || defined(x86_64_TARGET_ARCH) \
1312 || defined(alpha_TARGET_ARCH) \
1313 || defined(hppa_TARGET_ARCH) \
1314 || defined(m68k_TARGET_ARCH) \
1315 || defined(mips_TARGET_ARCH) \
1316 || defined(powerpc_TARGET_ARCH) \
1317 || defined(rs6000_TARGET_ARCH) \
1318 || defined(sparc_TARGET_ARCH)