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 StaticFlags ( opt_Static, opt_PIC,
52 WayName(..), v_Ways, v_Build_tag, v_RTS_Build_tag )
53 import {-# SOURCE #-} Packages (PackageState)
54 import DriverPhases ( Phase(..), phaseInputExt )
57 import Panic ( panic, GhcException(..) )
58 import Util ( notNull, splitLongestPrefix, split, normalisePath )
60 import DATA_IOREF ( readIORef )
61 import EXCEPTION ( throwDyn )
63 import Data.List ( isPrefixOf )
64 import Maybe ( fromJust )
65 import Char ( isDigit, isUpper )
67 -- -----------------------------------------------------------------------------
80 | Opt_D_dump_inlinings
81 | Opt_D_dump_occur_anal
85 | Opt_D_dump_simpl_iterations
94 | Opt_D_dump_worker_wrapper
98 | Opt_D_dump_simpl_stats
100 | Opt_D_dump_if_trace
105 | Opt_D_verbose_core2core
106 | Opt_D_verbose_stg2stg
108 | Opt_D_dump_hi_diffs
109 | Opt_D_dump_minimal_imports
114 | Opt_WarnIsError -- -Werror; makes warnings fatal
115 | Opt_WarnDuplicateExports
117 | Opt_WarnIncompletePatterns
118 | Opt_WarnIncompletePatternsRecUpd
119 | Opt_WarnMissingFields
120 | Opt_WarnMissingMethods
121 | Opt_WarnMissingSigs
122 | Opt_WarnNameShadowing
123 | Opt_WarnOverlappingPatterns
124 | Opt_WarnSimplePatterns
125 | Opt_WarnTypeDefaults
126 | Opt_WarnUnusedBinds
127 | Opt_WarnUnusedImports
128 | Opt_WarnUnusedMatches
129 | Opt_WarnDeprecations
130 | Opt_WarnDodgyImports
134 | Opt_AllowOverlappingInstances
135 | Opt_AllowUndecidableInstances
136 | Opt_AllowIncoherentInstances
137 | Opt_MonomorphismRestriction
140 | Opt_PArr -- syntactic support for parallel arrays
141 | Opt_Arrows -- Arrow-notation syntax
145 | Opt_ImplicitPrelude
146 | Opt_ScopedTypeVariables
152 | Opt_IgnoreInterfacePragmas
153 | Opt_OmitInterfacePragmas
154 | Opt_DoLambdaEtaExpansion
158 | Opt_UnboxStrictFields
166 | Opt_ExcessPrecision
167 | Opt_ReadUserPackageConf
181 data DynFlags = DynFlags {
184 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
185 stgToDo :: Maybe [StgToDo], -- similarly
186 hscTarget :: HscTarget,
187 hscOutName :: String, -- name of the output file
188 hscStubHOutName :: String, -- name of the .stub_h output file
189 hscStubCOutName :: String, -- name of the .stub_c output file
190 extCoreName :: String, -- name of the .core output file
191 verbosity :: Int, -- verbosity level
192 optLevel :: Int, -- optimisation level
193 maxSimplIterations :: Int, -- max simplifier iterations
194 ruleCheck :: Maybe String,
195 stolen_x86_regs :: Int,
196 cmdlineHcIncludes :: [String], -- -#includes
197 importPaths :: [FilePath],
198 mainModIs :: Maybe String,
199 mainFunIs :: Maybe String,
202 wayNames :: [WayName], -- way flags from the cmd line
203 buildTag :: String, -- the global "way" (eg. "p" for prof)
204 rtsBuildTag :: String, -- the RTS "way"
207 outputDir :: Maybe String,
208 outputFile :: Maybe String,
209 outputHi :: Maybe String,
212 hiDir :: Maybe String,
214 includePaths :: [String],
215 libraryPaths :: [String],
216 frameworkPaths :: [String], -- used on darwin only
217 cmdlineFrameworks :: [String], -- ditto
218 tmpDir :: String, -- no trailing '/'
220 -- options for particular phases
231 -- commands for particular phases
233 pgm_P :: (String,[Option]),
235 pgm_c :: (String,[Option]),
236 pgm_m :: (String,[Option]),
237 pgm_s :: (String,[Option]),
238 pgm_a :: (String,[Option]),
239 pgm_l :: (String,[Option]),
240 pgm_dll :: (String,[Option]),
243 extraPkgConfs :: [FilePath],
244 -- The -package-conf flags given on the command line, in the order
247 packageFlags :: [PackageFlag],
248 -- The -package and -hide-package flags from the command-line
251 pkgState :: PackageState,
267 = BatchCompile -- | @ghc --make Main@
268 | Interactive -- | @ghc --interactive@
269 | OneShot -- | @ghc -c Foo.hs@
270 | JustTypecheck -- | Development environemnts, refactorer, etc.
274 isOneShot :: GhcMode -> Bool
275 isOneShot OneShot = True
276 isOneShot _other = False
278 data GhcLink -- What to do in the link step, if there is one
279 = -- Only relevant for modes
280 -- DoMake and StopBefore StopLn
281 NoLink -- Don't link at all
282 | StaticLink -- Ordinary linker [the default]
283 | MkDLL -- Make a DLL
285 isNoLink :: GhcLink -> Bool
286 isNoLink NoLink = True
287 isNoLink other = False
290 = ExposePackage String
292 | IgnorePackage String
295 #if defined(i386_TARGET_ARCH) || defined(sparc_TARGET_ARCH) || defined(powerpc_TARGET_ARCH)
296 | cGhcWithNativeCodeGen == "YES" = HscAsm
300 initDynFlags dflags = do
301 -- someday these will be dynamic flags
302 ways <- readIORef v_Ways
303 build_tag <- readIORef v_Build_tag
304 rts_build_tag <- readIORef v_RTS_Build_tag
307 buildTag = build_tag,
308 rtsBuildTag = rts_build_tag
314 ghcLink = StaticLink,
317 hscTarget = defaultHscTarget,
319 hscStubHOutName = "",
320 hscStubCOutName = "",
324 maxSimplIterations = 4,
327 cmdlineHcIncludes = [],
332 wayNames = panic "ways",
333 buildTag = panic "buildTag",
334 rtsBuildTag = panic "rtsBuildTag",
337 outputFile = Nothing,
339 objectSuf = phaseInputExt StopLn,
340 hcSuf = phaseInputExt HCc,
346 cmdlineFrameworks = [],
347 tmpDir = cDEFAULT_TMPDIR,
359 pgm_L = panic "pgm_L",
360 pgm_P = panic "pgm_P",
361 pgm_F = panic "pgm_F",
362 pgm_c = panic "pgm_c",
363 pgm_m = panic "pgm_m",
364 pgm_s = panic "pgm_s",
365 pgm_a = panic "pgm_a",
366 pgm_l = panic "pgm_l",
367 pgm_dll = panic "pgm_mkdll",
371 pkgState = panic "pkgState",
375 Opt_ReadUserPackageConf,
378 Opt_MonomorphismRestriction,
380 -- strictness is on by default, but this only
382 Opt_CSE, -- similarly for CSE.
383 Opt_FullLaziness, -- ...and for full laziness
385 Opt_DoLambdaEtaExpansion,
386 -- This one is important for a tiresome reason:
387 -- we want to make sure that the bindings for data
388 -- constructors are eta-expanded. This is probably
389 -- a good thing anyway, but it seems fragile.
393 -- and the default no-optimisation options:
394 Opt_IgnoreInterfacePragmas,
395 Opt_OmitInterfacePragmas
397 ] ++ standardWarnings
403 0 | print errors & warnings only
404 1 | minimal verbosity: print "compiling M ... done." for each module.
405 2 | equivalent to -dshow-passes
406 3 | equivalent to existing "ghc -v"
407 4 | "ghc -v -ddump-most"
408 5 | "ghc -v -ddump-all"
411 dopt :: DynFlag -> DynFlags -> Bool
412 dopt f dflags = f `elem` (flags dflags)
414 dopt_set :: DynFlags -> DynFlag -> DynFlags
415 dopt_set dfs f = dfs{ flags = f : flags dfs }
417 dopt_unset :: DynFlags -> DynFlag -> DynFlags
418 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
420 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
421 getOpts dflags opts = reverse (opts dflags)
422 -- We add to the options from the front, so we need to reverse the list
424 getVerbFlag :: DynFlags -> String
426 | verbosity dflags >= 3 = "-v"
429 setOutputDir f d = d{ outputDir = f}
430 setOutputFile f d = d{ outputFile = f}
431 setOutputHi f d = d{ outputHi = f}
432 setObjectSuf f d = d{ objectSuf = f}
433 setHcSuf f d = d{ hcSuf = f}
434 setHiSuf f d = d{ hiSuf = f}
435 setHiDir f d = d{ hiDir = f}
437 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
438 -- Config.hs should really use Option.
439 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
441 setPgmL f d = d{ pgm_L = f}
442 setPgmF f d = d{ pgm_F = f}
443 setPgmc f d = d{ pgm_c = (f,[])}
444 setPgmm f d = d{ pgm_m = (f,[])}
445 setPgms f d = d{ pgm_s = (f,[])}
446 setPgma f d = d{ pgm_a = (f,[])}
447 setPgml f d = d{ pgm_l = (f,[])}
448 setPgmdll f d = d{ pgm_dll = (f,[])}
450 addOptL f d = d{ opt_L = f : opt_L d}
451 addOptP f d = d{ opt_P = f : opt_P d}
452 addOptF f d = d{ opt_F = f : opt_F d}
453 addOptc f d = d{ opt_c = f : opt_c d}
454 addOptm f d = d{ opt_m = f : opt_m d}
455 addOpta f d = d{ opt_a = f : opt_a d}
456 addOptl f d = d{ opt_l = f : opt_l d}
457 addOptdll f d = d{ opt_dll = f : opt_dll d}
458 addOptdep f d = d{ opt_dep = f : opt_dep d}
460 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
462 -- -----------------------------------------------------------------------------
463 -- Command-line options
465 -- When invoking external tools as part of the compilation pipeline, we
466 -- pass these a sequence of options on the command-line. Rather than
467 -- just using a list of Strings, we use a type that allows us to distinguish
468 -- between filepaths and 'other stuff'. [The reason being, of course, that
469 -- this type gives us a handle on transforming filenames, and filenames only,
470 -- to whatever format they're expected to be on a particular platform.]
473 = FileOption -- an entry that _contains_ filename(s) / filepaths.
474 String -- a non-filepath prefix that shouldn't be
475 -- transformed (e.g., "/out=")
476 String -- the filepath/filename portion
479 -----------------------------------------------------------------------------
480 -- Setting the optimisation level
482 updOptLevel :: Int -> DynFlags -> DynFlags
483 -- Set dynflags appropriate to the optimisation level
486 then dfs2{ hscTarget = HscC, optLevel = n } -- turn on -fvia-C with -O
487 else dfs2{ optLevel = n }
489 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
490 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
493 | n == 0 = opt_0_dopts
494 | otherwise = opt_1_dopts
497 | n == 0 = opt_1_dopts
498 | otherwise = opt_0_dopts
501 Opt_IgnoreInterfacePragmas,
502 Opt_OmitInterfacePragmas
511 -- -----------------------------------------------------------------------------
512 -- Standard sets of warning options
515 = [ Opt_WarnDeprecations,
516 Opt_WarnOverlappingPatterns,
517 Opt_WarnMissingFields,
518 Opt_WarnMissingMethods,
519 Opt_WarnDuplicateExports
523 = standardWarnings ++
524 [ Opt_WarnUnusedBinds,
525 Opt_WarnUnusedMatches,
526 Opt_WarnUnusedImports,
527 Opt_WarnIncompletePatterns,
533 [ Opt_WarnTypeDefaults,
534 Opt_WarnNameShadowing,
540 -- -----------------------------------------------------------------------------
541 -- CoreToDo: abstraction of core-to-core passes to run.
543 data CoreToDo -- These are diff core-to-core passes,
544 -- which may be invoked in any order,
545 -- as many times as you like.
547 = CoreDoSimplify -- The core-to-core simplifier.
550 -- Each run of the simplifier can take a different
551 -- set of simplifier-specific flags.
553 | CoreDoFloatOutwards FloatOutSwitches
558 | CoreDoWorkerWrapper
561 | CoreDoOldStrictness
564 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
565 -- matching this string
567 | CoreDoNothing -- useful when building up lists of these things
569 data SimplifierMode -- See comments in SimplMonad
573 data SimplifierSwitch
574 = MaxSimplifierIterations Int
577 data FloatOutSwitches
578 = FloatOutSw Bool -- True <=> float lambdas to top level
579 Bool -- True <=> float constants to top level,
580 -- even if they do not escape a lambda
583 -- The core-to-core pass ordering is derived from the DynFlags:
585 getCoreToDo :: DynFlags -> [CoreToDo]
587 | Just todo <- coreToDo dflags = todo -- set explicitly by user
588 | otherwise = core_todo
590 opt_level = optLevel dflags
591 max_iter = maxSimplIterations dflags
592 strictness = dopt Opt_Strictness dflags
593 full_laziness = dopt Opt_FullLaziness dflags
594 cse = dopt Opt_CSE dflags
595 rule_check = ruleCheck dflags
598 if opt_level == 0 then
600 CoreDoSimplify (SimplPhase 0) [
601 MaxSimplifierIterations max_iter
605 else {- opt_level >= 1 -} [
607 -- initial simplify: mk specialiser happy: minimum effort please
608 CoreDoSimplify SimplGently [
610 -- Don't inline anything till full laziness has bitten
611 -- In particular, inlining wrappers inhibits floating
612 -- e.g. ...(case f x of ...)...
613 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
614 -- ==> ...(case x of I# x# -> case fw x# of ...)...
615 -- and now the redex (f x) isn't floatable any more
616 -- Similarly, don't apply any rules until after full
617 -- laziness. Notably, list fusion can prevent floating.
620 -- Don't do case-of-case transformations.
621 -- This makes full laziness work better
622 MaxSimplifierIterations max_iter
625 -- Specialisation is best done before full laziness
626 -- so that overloaded functions have all their dictionary lambdas manifest
629 if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
634 CoreDoSimplify (SimplPhase 2) [
635 -- Want to run with inline phase 2 after the specialiser to give
636 -- maximum chance for fusion to work before we inline build/augment
637 -- in phase 1. This made a difference in 'ansi' where an
638 -- overloaded function wasn't inlined till too late.
639 MaxSimplifierIterations max_iter
641 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
643 CoreDoSimplify (SimplPhase 1) [
644 -- Need inline-phase2 here so that build/augment get
645 -- inlined. I found that spectral/hartel/genfft lost some useful
646 -- strictness in the function sumcode' if augment is not inlined
647 -- before strictness analysis runs
648 MaxSimplifierIterations max_iter
650 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
652 CoreDoSimplify (SimplPhase 0) [
653 -- Phase 0: allow all Ids to be inlined now
654 -- This gets foldr inlined before strictness analysis
656 MaxSimplifierIterations 3
657 -- At least 3 iterations because otherwise we land up with
658 -- huge dead expressions because of an infelicity in the
660 -- let k = BIG in foldr k z xs
661 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
662 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
666 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
668 #ifdef OLD_STRICTNESS
671 if strictness then CoreDoStrictness else CoreDoNothing,
675 CoreDoSimplify (SimplPhase 0) [
676 MaxSimplifierIterations max_iter
679 if full_laziness then
680 CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
681 True) -- Float constants
683 -- nofib/spectral/hartel/wang doubles in speed if you
684 -- do full laziness late in the day. It only happens
685 -- after fusion and other stuff, so the early pass doesn't
686 -- catch it. For the record, the redex is
687 -- f_el22 (f_el21 r_midblock)
690 -- We want CSE to follow the final full-laziness pass, because it may
691 -- succeed in commoning up things floated out by full laziness.
692 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
694 if cse then CoreCSE else CoreDoNothing,
698 -- Case-liberation for -O2. This should be after
699 -- strictness analysis and the simplification which follows it.
701 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
703 if opt_level >= 2 then
707 if opt_level >= 2 then
712 -- Final clean-up simplification:
713 CoreDoSimplify (SimplPhase 0) [
714 MaxSimplifierIterations max_iter
718 -- -----------------------------------------------------------------------------
719 -- StgToDo: abstraction of stg-to-stg passes to run.
722 = StgDoMassageForProfiling -- should be (next to) last
723 -- There's also setStgVarInfo, but its absolute "lastness"
724 -- is so critical that it is hardwired in (no flag).
727 getStgToDo :: DynFlags -> [StgToDo]
729 | Just todo <- stgToDo dflags = todo -- set explicitly by user
732 stg_stats = dopt Opt_StgStats dflags
734 todo1 = if stg_stats then [D_stg_stats] else []
736 todo2 | WayProf `elem` wayNames dflags
737 = StgDoMassageForProfiling : todo1
741 -- -----------------------------------------------------------------------------
744 dynamic_flags :: [(String, OptKind DynP)]
746 ( "n" , NoArg (setDynFlag Opt_DryRun) )
747 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
748 , ( "F" , NoArg (setDynFlag Opt_Pp))
749 , ( "#include" , HasArg (addCmdlineHCInclude) )
750 , ( "v" , OptPrefix (setVerbosity) )
752 ------- Specific phases --------------------------------------------
753 , ( "pgmL" , HasArg (upd . setPgmL) )
754 , ( "pgmP" , HasArg (upd . setPgmP) )
755 , ( "pgmF" , HasArg (upd . setPgmF) )
756 , ( "pgmc" , HasArg (upd . setPgmc) )
757 , ( "pgmm" , HasArg (upd . setPgmm) )
758 , ( "pgms" , HasArg (upd . setPgms) )
759 , ( "pgma" , HasArg (upd . setPgma) )
760 , ( "pgml" , HasArg (upd . setPgml) )
761 , ( "pgmdll" , HasArg (upd . setPgmdll) )
763 , ( "optL" , HasArg (upd . addOptL) )
764 , ( "optP" , HasArg (upd . addOptP) )
765 , ( "optF" , HasArg (upd . addOptF) )
766 , ( "optc" , HasArg (upd . addOptc) )
767 , ( "optm" , HasArg (upd . addOptm) )
768 , ( "opta" , HasArg (upd . addOpta) )
769 , ( "optl" , HasArg (upd . addOptl) )
770 , ( "optdll" , HasArg (upd . addOptdll) )
771 , ( "optdep" , HasArg (upd . addOptdep) )
773 , ( "split-objs" , NoArg (if can_split
774 then setDynFlag Opt_SplitObjs
777 -------- Linking ----------------------------------------------------
778 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
779 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
780 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
782 ------- Libraries ---------------------------------------------------
783 , ( "L" , Prefix addLibraryPath )
784 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
787 ------- Frameworks --------------------------------------------------
788 -- -framework-path should really be -F ...
789 , ( "framework-path" , HasArg addFrameworkPath )
790 , ( "framework" , HasArg (upd . addCmdlineFramework) )
792 ------- Output Redirection ------------------------------------------
793 , ( "odir" , HasArg (upd . setOutputDir . Just))
794 , ( "o" , SepArg (upd . setOutputFile . Just))
795 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
796 , ( "osuf" , HasArg (upd . setObjectSuf))
797 , ( "hcsuf" , HasArg (upd . setHcSuf))
798 , ( "hisuf" , HasArg (upd . setHiSuf))
799 , ( "hidir" , HasArg (upd . setHiDir . Just))
800 , ( "tmpdir" , HasArg (upd . setTmpDir))
802 ------- Keeping temporary files -------------------------------------
803 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
804 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
805 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
806 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
808 ------- Miscellaneous ----------------------------------------------
809 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
810 , ( "main-is" , SepArg setMainIs )
812 ------- recompilation checker --------------------------------------
813 , ( "recomp" , NoArg (setDynFlag Opt_RecompChecking) )
814 , ( "no-recomp" , NoArg (unSetDynFlag Opt_RecompChecking) )
816 ------- Packages ----------------------------------------------------
817 , ( "package-conf" , HasArg extraPkgConf_ )
818 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
819 , ( "package-name" , HasArg ignorePackage ) -- for compatibility
820 , ( "package" , HasArg exposePackage )
821 , ( "hide-package" , HasArg hidePackage )
822 , ( "ignore-package" , HasArg ignorePackage )
823 , ( "syslib" , HasArg exposePackage ) -- for compatibility
825 ------ HsCpp opts ---------------------------------------------------
826 , ( "D", AnySuffix (upd . addOptP) )
827 , ( "U", AnySuffix (upd . addOptP) )
829 ------- Include/Import Paths ----------------------------------------
830 , ( "I" , Prefix addIncludePath)
831 , ( "i" , OptPrefix addImportPath )
833 ------ Debugging ----------------------------------------------------
834 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
836 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
837 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
838 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
839 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
840 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
841 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
842 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
843 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
844 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
845 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
846 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
847 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
848 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
849 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
850 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
851 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
852 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
853 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
854 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
855 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
856 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
857 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
858 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace))
859 , ( "ddump-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace))
860 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
861 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
862 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats))
863 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
864 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
865 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
866 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
867 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
868 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
869 , ( "ddump-hi-diffs", setDumpFlag Opt_D_dump_hi_diffs)
870 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
871 , ( "ddump-minimal-imports", setDumpFlag Opt_D_dump_minimal_imports)
872 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
873 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
874 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
875 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
876 , ( "dshow-passes", NoArg (do unSetDynFlag Opt_RecompChecking
879 ------ Machine dependant (-m<blah>) stuff ---------------------------
881 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
882 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
883 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
885 ------ Warning opts -------------------------------------------------
886 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
887 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
888 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
889 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
890 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
892 ------ Optimisation flags ------------------------------------------
893 , ( "O" , NoArg (upd (setOptLevel 1)))
894 , ( "Onot" , NoArg (upd (setOptLevel 0)))
895 , ( "O" , PrefixPred (all isDigit)
896 (\f -> upd (setOptLevel (read f))))
898 , ( "fmax-simplifier-iterations",
899 PrefixPred (all isDigit)
901 dfs{ maxSimplIterations = read n })) )
904 SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
906 ------ Compiler flags -----------------------------------------------
908 , ( "fasm", AnySuffix (\_ -> setTarget HscAsm) )
909 , ( "fvia-c", NoArg (setTarget HscC) )
910 , ( "fvia-C", NoArg (setTarget HscC) )
911 , ( "filx", NoArg (setTarget HscILX) )
913 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
914 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
916 -- the rest of the -f* and -fno-* flags
917 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
918 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
921 -- these -f<blah> flags can all be reversed with -fno-<blah>
924 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
925 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
926 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
927 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
928 ( "warn-missing-fields", Opt_WarnMissingFields ),
929 ( "warn-missing-methods", Opt_WarnMissingMethods ),
930 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
931 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
932 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
933 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
934 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
935 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
936 ( "warn-unused-imports", Opt_WarnUnusedImports ),
937 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
938 ( "warn-deprecations", Opt_WarnDeprecations ),
939 ( "warn-orphans", Opt_WarnOrphans ),
940 ( "fi", Opt_FFI ), -- support `-ffi'...
941 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
942 ( "arrows", Opt_Arrows ), -- arrow syntax
943 ( "parr", Opt_PArr ),
945 ( "implicit-prelude", Opt_ImplicitPrelude ),
946 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
947 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
948 ( "implicit-params", Opt_ImplicitParams ),
949 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
950 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
951 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
952 ( "generics", Opt_Generics ),
953 ( "strictness", Opt_Strictness ),
954 ( "full-laziness", Opt_FullLaziness ),
956 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
957 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
958 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
959 ( "ignore-asserts", Opt_IgnoreAsserts ),
960 ( "do-eta-reduction", Opt_DoEtaReduction ),
961 ( "case-merge", Opt_CaseMerge ),
962 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
963 ( "excess-precision", Opt_ExcessPrecision ),
964 ( "asm-mangling", Opt_DoAsmMangling )
972 Opt_ScopedTypeVariables ]
974 isFFlag f = f `elem` (map fst fFlags)
975 getFFlag f = fromJust (lookup f fFlags)
977 -- -----------------------------------------------------------------------------
978 -- Parsing the dynamic flags.
980 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
981 parseDynamicFlags dflags args = do
982 let ((leftover,errs),dflags')
983 = runCmdLine (processArgs dynamic_flags args) dflags
984 when (not (null errs)) $ do
985 throwDyn (UsageError (unlines errs))
986 return (dflags', leftover)
989 type DynP = CmdLineP DynFlags
991 upd :: (DynFlags -> DynFlags) -> DynP ()
993 dfs <- getCmdLineState
994 putCmdLineState $! (f dfs)
996 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
997 setDynFlag f = upd (\dfs -> dopt_set dfs f)
998 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1000 setDumpFlag :: DynFlag -> OptKind DynP
1001 setDumpFlag dump_flag
1002 = NoArg (unSetDynFlag Opt_RecompChecking >> setDynFlag dump_flag)
1003 -- Whenver we -ddump, switch off the recompilation checker,
1004 -- else you don't see the dump!
1006 setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
1008 | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
1009 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
1011 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1013 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1016 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1018 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1020 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1022 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
1023 -- (-fvia-C, -fasm, -filx respectively).
1024 setTarget l = upd (\dfs -> case hscTarget dfs of
1025 HscC -> dfs{ hscTarget = l }
1026 HscAsm -> dfs{ hscTarget = l }
1027 HscILX -> dfs{ hscTarget = l }
1030 setOptLevel :: Int -> DynFlags -> DynFlags
1031 setOptLevel n dflags
1032 | hscTarget dflags == HscInterpreted && n > 0
1034 -- not in IO any more, oh well:
1035 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1037 = updOptLevel n dflags
1040 setMainIs :: String -> DynP ()
1042 | not (null main_mod) -- The arg looked like "Foo.baz"
1043 = upd $ \d -> d{ mainFunIs = Just main_fn,
1044 mainModIs = Just main_mod }
1046 | isUpper (head main_fn) -- The arg looked like "Foo"
1047 = upd $ \d -> d{ mainModIs = Just main_fn }
1049 | otherwise -- The arg looked like "baz"
1050 = upd $ \d -> d{ mainFunIs = Just main_fn }
1052 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1055 -----------------------------------------------------------------------------
1056 -- Paths & Libraries
1058 -- -i on its own deletes the import paths
1059 addImportPath "" = upd (\s -> s{importPaths = []})
1060 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1064 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1067 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1069 addFrameworkPath p =
1070 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1072 split_marker = ':' -- not configurable (ToDo)
1074 splitPathList :: String -> [String]
1075 splitPathList s = filter notNull (splitUp s)
1076 -- empty paths are ignored: there might be a trailing
1077 -- ':' in the initial list, for example. Empty paths can
1078 -- cause confusion when they are translated into -I options
1079 -- for passing to gcc.
1081 #ifndef mingw32_TARGET_OS
1082 splitUp xs = split split_marker xs
1084 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1086 -- That is, if "foo:bar:baz" is used, this interpreted as
1087 -- consisting of three entries, 'foo', 'bar', 'baz'.
1088 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1089 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1091 -- Notice that no attempt is made to fully replace the 'standard'
1092 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1093 -- that this will cause too much breakage for users & ':' will
1094 -- work fine even with DOS paths, if you're not insisting on being silly.
1097 splitUp (x:':':div:xs) | div `elem` dir_markers
1098 = ((x:':':div:p): splitUp rs)
1100 (p,rs) = findNextPath xs
1101 -- we used to check for existence of the path here, but that
1102 -- required the IO monad to be threaded through the command-line
1103 -- parser which is quite inconvenient. The
1104 splitUp xs = cons p (splitUp rs)
1106 (p,rs) = findNextPath xs
1111 -- will be called either when we've consumed nought or the
1112 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1113 -- finding the next split marker.
1115 case break (`elem` split_markers) xs of
1116 (p, d:ds) -> (p, ds)
1119 split_markers :: [Char]
1120 split_markers = [':', ';']
1122 dir_markers :: [Char]
1123 dir_markers = ['/', '\\']
1126 -- -----------------------------------------------------------------------------
1127 -- tmpDir, where we store temporary files.
1129 setTmpDir :: FilePath -> DynFlags -> DynFlags
1130 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1132 #if !defined(mingw32_HOST_OS)
1133 canonicalise p = normalisePath p
1135 -- Canonicalisation of temp path under win32 is a bit more
1136 -- involved: (a) strip trailing slash,
1137 -- (b) normalise slashes
1138 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1140 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1142 -- if we're operating under cygwin, and TMP/TEMP is of
1143 -- the form "/cygdrive/drive/path", translate this to
1144 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1145 -- understand /cygdrive paths.)
1147 | "/cygdrive/" `isPrefixOf` path =
1148 case drop (length "/cygdrive/") path of
1149 drive:xs@('/':_) -> drive:':':xs
1153 -- strip the trailing backslash (awful, but we only do this once).
1154 removeTrailingSlash path =
1161 -----------------------------------------------------------------------------
1162 -- Via-C compilation stuff
1164 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1165 [String]) -- for registerised HC compilations
1166 machdepCCOpts dflags
1167 #if alpha_TARGET_ARCH
1169 #ifdef HAVE_THREADED_RTS_SUPPORT
1173 -- For now, to suppress the gcc warning "call-clobbered
1174 -- register used for global register variable", we simply
1175 -- disable all warnings altogether using the -w flag. Oh well.
1177 #elif hppa_TARGET_ARCH
1178 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1179 -- (very nice, but too bad the HP /usr/include files don't agree.)
1180 = ( ["-D_HPUX_SOURCE"], [] )
1182 #elif m68k_TARGET_ARCH
1183 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1184 -- popping of args to routines to be explicit; if we let things
1185 -- be deferred 'til after an STGJUMP, imminent death is certain!
1187 -- -fomit-frame-pointer : *don't*
1188 -- It's better to have a6 completely tied up being a frame pointer
1189 -- rather than let GCC pick random things to do with it.
1190 -- (If we want to steal a6, then we would try to do things
1191 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1192 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1194 #elif i386_TARGET_ARCH
1195 -- -fno-defer-pop : basically the same game as for m68k
1197 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1198 -- the fp (%ebp) for our register maps.
1199 = let n_regs = stolen_x86_regs dflags
1202 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1203 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1206 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1207 -- Some gccs are configured with
1208 -- -momit-leaf-frame-pointer on by default, and it
1209 -- apparently takes precedence over
1210 -- -fomit-frame-pointer, so we disable it first here.
1211 "-mno-omit-leaf-frame-pointer",
1213 "-fomit-frame-pointer",
1214 -- we want -fno-builtin, because when gcc inlines
1215 -- built-in functions like memcpy() it tends to
1216 -- run out of registers, requiring -monly-n-regs
1218 "-DSTOLEN_X86_REGS="++show n_regs ]
1221 #elif ia64_TARGET_ARCH
1222 = ( [], ["-fomit-frame-pointer", "-G0"] )
1224 #elif x86_64_TARGET_ARCH
1225 = ( [], ["-fomit-frame-pointer"] )
1227 #elif mips_TARGET_ARCH
1228 = ( ["-static"], [] )
1230 #elif sparc_TARGET_ARCH
1232 -- For now, to suppress the gcc warning "call-clobbered
1233 -- register used for global register variable", we simply
1234 -- disable all warnings altogether using the -w flag. Oh well.
1236 #elif powerpc_apple_darwin_TARGET
1238 -- Disable Apple's precompiling preprocessor. It's a great thing
1239 -- for "normal" programs, but it doesn't support register variable
1241 = ( [], ["-no-cpp-precomp"] )
1246 picCCOpts :: DynFlags -> [String]
1248 #if darwin_TARGET_OS
1249 -- Apple prefers to do things the other way round.
1250 -- PIC is on by default.
1251 -- -mdynamic-no-pic:
1252 -- Turn off PIC code generation.
1254 -- Don't generate "common" symbols - these are unwanted
1255 -- in dynamic libraries.
1260 = ["-mdynamic-no-pic"]
1261 #elif mingw32_TARGET_OS
1262 -- no -fPIC for Windows
1271 -- -----------------------------------------------------------------------------
1276 #if defined(i386_TARGET_ARCH) \
1277 || defined(alpha_TARGET_ARCH) \
1278 || defined(hppa_TARGET_ARCH) \
1279 || defined(m68k_TARGET_ARCH) \
1280 || defined(mips_TARGET_ARCH) \
1281 || defined(powerpc_TARGET_ARCH) \
1282 || defined(rs6000_TARGET_ARCH) \
1283 || defined(sparc_TARGET_ARCH)