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 #ifdef mingw32_TARGET_OS
64 import Data.List ( isPrefixOf )
66 import Maybe ( fromJust )
67 import Char ( isDigit, isUpper )
69 -- -----------------------------------------------------------------------------
82 | Opt_D_dump_inlinings
83 | Opt_D_dump_occur_anal
87 | Opt_D_dump_simpl_iterations
96 | Opt_D_dump_worker_wrapper
100 | Opt_D_dump_simpl_stats
101 | Opt_D_dump_tc_trace
102 | Opt_D_dump_if_trace
107 | Opt_D_verbose_core2core
108 | Opt_D_verbose_stg2stg
110 | Opt_D_dump_hi_diffs
111 | Opt_D_dump_minimal_imports
116 | Opt_WarnIsError -- -Werror; makes warnings fatal
117 | Opt_WarnDuplicateExports
119 | Opt_WarnIncompletePatterns
120 | Opt_WarnIncompletePatternsRecUpd
121 | Opt_WarnMissingFields
122 | Opt_WarnMissingMethods
123 | Opt_WarnMissingSigs
124 | Opt_WarnNameShadowing
125 | Opt_WarnOverlappingPatterns
126 | Opt_WarnSimplePatterns
127 | Opt_WarnTypeDefaults
128 | Opt_WarnUnusedBinds
129 | Opt_WarnUnusedImports
130 | Opt_WarnUnusedMatches
131 | Opt_WarnDeprecations
132 | Opt_WarnDodgyImports
136 | Opt_AllowOverlappingInstances
137 | Opt_AllowUndecidableInstances
138 | Opt_AllowIncoherentInstances
139 | Opt_MonomorphismRestriction
142 | Opt_PArr -- syntactic support for parallel arrays
143 | Opt_Arrows -- Arrow-notation syntax
147 | Opt_ImplicitPrelude
148 | Opt_ScopedTypeVariables
154 | Opt_IgnoreInterfacePragmas
155 | Opt_OmitInterfacePragmas
156 | Opt_DoLambdaEtaExpansion
160 | Opt_UnboxStrictFields
168 | Opt_ExcessPrecision
169 | Opt_ReadUserPackageConf
173 | Opt_HideAllPackages
184 data DynFlags = DynFlags {
187 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
188 stgToDo :: Maybe [StgToDo], -- similarly
189 hscTarget :: HscTarget,
190 hscOutName :: String, -- name of the output file
191 hscStubHOutName :: String, -- name of the .stub_h output file
192 hscStubCOutName :: String, -- name of the .stub_c output file
193 extCoreName :: String, -- name of the .core output file
194 verbosity :: Int, -- verbosity level
195 optLevel :: Int, -- optimisation level
196 maxSimplIterations :: Int, -- max simplifier iterations
197 ruleCheck :: Maybe String,
198 stolen_x86_regs :: Int,
199 cmdlineHcIncludes :: [String], -- -#includes
200 importPaths :: [FilePath],
201 mainModIs :: Maybe String,
202 mainFunIs :: Maybe String,
205 wayNames :: [WayName], -- way flags from the cmd line
206 buildTag :: String, -- the global "way" (eg. "p" for prof)
207 rtsBuildTag :: String, -- the RTS "way"
210 outputDir :: Maybe String,
211 outputFile :: Maybe String,
212 outputHi :: Maybe String,
215 hiDir :: Maybe String,
217 includePaths :: [String],
218 libraryPaths :: [String],
219 frameworkPaths :: [String], -- used on darwin only
220 cmdlineFrameworks :: [String], -- ditto
221 tmpDir :: String, -- no trailing '/'
223 -- options for particular phases
234 -- commands for particular phases
236 pgm_P :: (String,[Option]),
238 pgm_c :: (String,[Option]),
239 pgm_m :: (String,[Option]),
240 pgm_s :: (String,[Option]),
241 pgm_a :: (String,[Option]),
242 pgm_l :: (String,[Option]),
243 pgm_dll :: (String,[Option]),
246 extraPkgConfs :: [FilePath],
247 -- The -package-conf flags given on the command line, in the order
250 packageFlags :: [PackageFlag],
251 -- The -package and -hide-package flags from the command-line
254 pkgState :: PackageState,
270 = BatchCompile -- | @ghc --make Main@
271 | Interactive -- | @ghc --interactive@
272 | OneShot -- | @ghc -c Foo.hs@
273 | JustTypecheck -- | Development environemnts, refactorer, etc.
277 isOneShot :: GhcMode -> Bool
278 isOneShot OneShot = True
279 isOneShot _other = False
281 data GhcLink -- What to do in the link step, if there is one
282 = -- Only relevant for modes
283 -- DoMake and StopBefore StopLn
284 NoLink -- Don't link at all
285 | StaticLink -- Ordinary linker [the default]
286 | MkDLL -- Make a DLL
288 isNoLink :: GhcLink -> Bool
289 isNoLink NoLink = True
290 isNoLink other = False
293 = ExposePackage String
295 | IgnorePackage String
298 | cGhcWithNativeCodeGen == "YES" = HscAsm
301 initDynFlags dflags = do
302 -- someday these will be dynamic flags
303 ways <- readIORef v_Ways
304 build_tag <- readIORef v_Build_tag
305 rts_build_tag <- readIORef v_RTS_Build_tag
308 buildTag = build_tag,
309 rtsBuildTag = rts_build_tag
315 ghcLink = StaticLink,
318 hscTarget = defaultHscTarget,
320 hscStubHOutName = "",
321 hscStubCOutName = "",
325 maxSimplIterations = 4,
328 cmdlineHcIncludes = [],
333 wayNames = panic "ways",
334 buildTag = panic "buildTag",
335 rtsBuildTag = panic "rtsBuildTag",
338 outputFile = Nothing,
340 objectSuf = phaseInputExt StopLn,
341 hcSuf = phaseInputExt HCc,
347 cmdlineFrameworks = [],
348 tmpDir = cDEFAULT_TMPDIR,
360 pgm_L = panic "pgm_L",
361 pgm_P = panic "pgm_P",
362 pgm_F = panic "pgm_F",
363 pgm_c = panic "pgm_c",
364 pgm_m = panic "pgm_m",
365 pgm_s = panic "pgm_s",
366 pgm_a = panic "pgm_a",
367 pgm_l = panic "pgm_l",
368 pgm_dll = panic "pgm_mkdll",
372 pkgState = panic "pkgState",
376 Opt_ReadUserPackageConf,
379 Opt_MonomorphismRestriction,
381 -- strictness is on by default, but this only
383 Opt_CSE, -- similarly for CSE.
384 Opt_FullLaziness, -- ...and for full laziness
386 Opt_DoLambdaEtaExpansion,
387 -- This one is important for a tiresome reason:
388 -- we want to make sure that the bindings for data
389 -- constructors are eta-expanded. This is probably
390 -- a good thing anyway, but it seems fragile.
394 -- and the default no-optimisation options:
395 Opt_IgnoreInterfacePragmas,
396 Opt_OmitInterfacePragmas
398 ] ++ standardWarnings
404 0 | print errors & warnings only
405 1 | minimal verbosity: print "compiling M ... done." for each module.
406 2 | equivalent to -dshow-passes
407 3 | equivalent to existing "ghc -v"
408 4 | "ghc -v -ddump-most"
409 5 | "ghc -v -ddump-all"
412 dopt :: DynFlag -> DynFlags -> Bool
413 dopt f dflags = f `elem` (flags dflags)
415 dopt_set :: DynFlags -> DynFlag -> DynFlags
416 dopt_set dfs f = dfs{ flags = f : flags dfs }
418 dopt_unset :: DynFlags -> DynFlag -> DynFlags
419 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
421 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
422 getOpts dflags opts = reverse (opts dflags)
423 -- We add to the options from the front, so we need to reverse the list
425 getVerbFlag :: DynFlags -> String
427 | verbosity dflags >= 3 = "-v"
430 setOutputDir f d = d{ outputDir = f}
431 setOutputFile f d = d{ outputFile = f}
432 setOutputHi f d = d{ outputHi = f}
433 setObjectSuf f d = d{ objectSuf = f}
434 setHcSuf f d = d{ hcSuf = f}
435 setHiSuf f d = d{ hiSuf = f}
436 setHiDir f d = d{ hiDir = f}
438 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
439 -- Config.hs should really use Option.
440 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
442 setPgmL f d = d{ pgm_L = f}
443 setPgmF f d = d{ pgm_F = f}
444 setPgmc f d = d{ pgm_c = (f,[])}
445 setPgmm f d = d{ pgm_m = (f,[])}
446 setPgms f d = d{ pgm_s = (f,[])}
447 setPgma f d = d{ pgm_a = (f,[])}
448 setPgml f d = d{ pgm_l = (f,[])}
449 setPgmdll f d = d{ pgm_dll = (f,[])}
451 addOptL f d = d{ opt_L = f : opt_L d}
452 addOptP f d = d{ opt_P = f : opt_P d}
453 addOptF f d = d{ opt_F = f : opt_F d}
454 addOptc f d = d{ opt_c = f : opt_c d}
455 addOptm f d = d{ opt_m = f : opt_m d}
456 addOpta f d = d{ opt_a = f : opt_a d}
457 addOptl f d = d{ opt_l = f : opt_l d}
458 addOptdll f d = d{ opt_dll = f : opt_dll d}
459 addOptdep f d = d{ opt_dep = f : opt_dep d}
461 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
463 -- -----------------------------------------------------------------------------
464 -- Command-line options
466 -- When invoking external tools as part of the compilation pipeline, we
467 -- pass these a sequence of options on the command-line. Rather than
468 -- just using a list of Strings, we use a type that allows us to distinguish
469 -- between filepaths and 'other stuff'. [The reason being, of course, that
470 -- this type gives us a handle on transforming filenames, and filenames only,
471 -- to whatever format they're expected to be on a particular platform.]
474 = FileOption -- an entry that _contains_ filename(s) / filepaths.
475 String -- a non-filepath prefix that shouldn't be
476 -- transformed (e.g., "/out=")
477 String -- the filepath/filename portion
480 -----------------------------------------------------------------------------
481 -- Setting the optimisation level
483 updOptLevel :: Int -> DynFlags -> DynFlags
484 -- Set dynflags appropriate to the optimisation level
487 then dfs2{ hscTarget = HscC, optLevel = n } -- turn on -fvia-C with -O
488 else dfs2{ optLevel = n }
490 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
491 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
494 | n == 0 = opt_0_dopts
495 | otherwise = opt_1_dopts
498 | n == 0 = opt_1_dopts
499 | otherwise = opt_0_dopts
502 Opt_IgnoreInterfacePragmas,
503 Opt_OmitInterfacePragmas
512 -- -----------------------------------------------------------------------------
513 -- Standard sets of warning options
516 = [ Opt_WarnDeprecations,
517 Opt_WarnOverlappingPatterns,
518 Opt_WarnMissingFields,
519 Opt_WarnMissingMethods,
520 Opt_WarnDuplicateExports
524 = standardWarnings ++
525 [ Opt_WarnUnusedBinds,
526 Opt_WarnUnusedMatches,
527 Opt_WarnUnusedImports,
528 Opt_WarnIncompletePatterns,
534 [ Opt_WarnTypeDefaults,
535 Opt_WarnNameShadowing,
541 -- -----------------------------------------------------------------------------
542 -- CoreToDo: abstraction of core-to-core passes to run.
544 data CoreToDo -- These are diff core-to-core passes,
545 -- which may be invoked in any order,
546 -- as many times as you like.
548 = CoreDoSimplify -- The core-to-core simplifier.
551 -- Each run of the simplifier can take a different
552 -- set of simplifier-specific flags.
554 | CoreDoFloatOutwards FloatOutSwitches
559 | CoreDoWorkerWrapper
562 | CoreDoOldStrictness
565 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
566 -- matching this string
568 | CoreDoNothing -- useful when building up lists of these things
570 data SimplifierMode -- See comments in SimplMonad
574 data SimplifierSwitch
575 = MaxSimplifierIterations Int
578 data FloatOutSwitches
579 = FloatOutSw Bool -- True <=> float lambdas to top level
580 Bool -- True <=> float constants to top level,
581 -- even if they do not escape a lambda
584 -- The core-to-core pass ordering is derived from the DynFlags:
586 getCoreToDo :: DynFlags -> [CoreToDo]
588 | Just todo <- coreToDo dflags = todo -- set explicitly by user
589 | otherwise = core_todo
591 opt_level = optLevel dflags
592 max_iter = maxSimplIterations dflags
593 strictness = dopt Opt_Strictness dflags
594 full_laziness = dopt Opt_FullLaziness dflags
595 cse = dopt Opt_CSE dflags
596 rule_check = ruleCheck dflags
599 if opt_level == 0 then
601 CoreDoSimplify (SimplPhase 0) [
602 MaxSimplifierIterations max_iter
606 else {- opt_level >= 1 -} [
608 -- initial simplify: mk specialiser happy: minimum effort please
609 CoreDoSimplify SimplGently [
611 -- Don't inline anything till full laziness has bitten
612 -- In particular, inlining wrappers inhibits floating
613 -- e.g. ...(case f x of ...)...
614 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
615 -- ==> ...(case x of I# x# -> case fw x# of ...)...
616 -- and now the redex (f x) isn't floatable any more
617 -- Similarly, don't apply any rules until after full
618 -- laziness. Notably, list fusion can prevent floating.
621 -- Don't do case-of-case transformations.
622 -- This makes full laziness work better
623 MaxSimplifierIterations max_iter
626 -- Specialisation is best done before full laziness
627 -- so that overloaded functions have all their dictionary lambdas manifest
630 if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
635 CoreDoSimplify (SimplPhase 2) [
636 -- Want to run with inline phase 2 after the specialiser to give
637 -- maximum chance for fusion to work before we inline build/augment
638 -- in phase 1. This made a difference in 'ansi' where an
639 -- overloaded function wasn't inlined till too late.
640 MaxSimplifierIterations max_iter
642 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
644 CoreDoSimplify (SimplPhase 1) [
645 -- Need inline-phase2 here so that build/augment get
646 -- inlined. I found that spectral/hartel/genfft lost some useful
647 -- strictness in the function sumcode' if augment is not inlined
648 -- before strictness analysis runs
649 MaxSimplifierIterations max_iter
651 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
653 CoreDoSimplify (SimplPhase 0) [
654 -- Phase 0: allow all Ids to be inlined now
655 -- This gets foldr inlined before strictness analysis
657 MaxSimplifierIterations 3
658 -- At least 3 iterations because otherwise we land up with
659 -- huge dead expressions because of an infelicity in the
661 -- let k = BIG in foldr k z xs
662 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
663 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
667 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
669 #ifdef OLD_STRICTNESS
672 if strictness then CoreDoStrictness else CoreDoNothing,
676 CoreDoSimplify (SimplPhase 0) [
677 MaxSimplifierIterations max_iter
680 if full_laziness then
681 CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
682 True) -- Float constants
684 -- nofib/spectral/hartel/wang doubles in speed if you
685 -- do full laziness late in the day. It only happens
686 -- after fusion and other stuff, so the early pass doesn't
687 -- catch it. For the record, the redex is
688 -- f_el22 (f_el21 r_midblock)
691 -- We want CSE to follow the final full-laziness pass, because it may
692 -- succeed in commoning up things floated out by full laziness.
693 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
695 if cse then CoreCSE else CoreDoNothing,
699 -- Case-liberation for -O2. This should be after
700 -- strictness analysis and the simplification which follows it.
702 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
704 if opt_level >= 2 then
708 if opt_level >= 2 then
713 -- Final clean-up simplification:
714 CoreDoSimplify (SimplPhase 0) [
715 MaxSimplifierIterations max_iter
719 -- -----------------------------------------------------------------------------
720 -- StgToDo: abstraction of stg-to-stg passes to run.
723 = StgDoMassageForProfiling -- should be (next to) last
724 -- There's also setStgVarInfo, but its absolute "lastness"
725 -- is so critical that it is hardwired in (no flag).
728 getStgToDo :: DynFlags -> [StgToDo]
730 | Just todo <- stgToDo dflags = todo -- set explicitly by user
733 stg_stats = dopt Opt_StgStats dflags
735 todo1 = if stg_stats then [D_stg_stats] else []
737 todo2 | WayProf `elem` wayNames dflags
738 = StgDoMassageForProfiling : todo1
742 -- -----------------------------------------------------------------------------
745 dynamic_flags :: [(String, OptKind DynP)]
747 ( "n" , NoArg (setDynFlag Opt_DryRun) )
748 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
749 , ( "F" , NoArg (setDynFlag Opt_Pp))
750 , ( "#include" , HasArg (addCmdlineHCInclude) )
751 , ( "v" , OptPrefix (setVerbosity) )
753 ------- Specific phases --------------------------------------------
754 , ( "pgmL" , HasArg (upd . setPgmL) )
755 , ( "pgmP" , HasArg (upd . setPgmP) )
756 , ( "pgmF" , HasArg (upd . setPgmF) )
757 , ( "pgmc" , HasArg (upd . setPgmc) )
758 , ( "pgmm" , HasArg (upd . setPgmm) )
759 , ( "pgms" , HasArg (upd . setPgms) )
760 , ( "pgma" , HasArg (upd . setPgma) )
761 , ( "pgml" , HasArg (upd . setPgml) )
762 , ( "pgmdll" , HasArg (upd . setPgmdll) )
764 , ( "optL" , HasArg (upd . addOptL) )
765 , ( "optP" , HasArg (upd . addOptP) )
766 , ( "optF" , HasArg (upd . addOptF) )
767 , ( "optc" , HasArg (upd . addOptc) )
768 , ( "optm" , HasArg (upd . addOptm) )
769 , ( "opta" , HasArg (upd . addOpta) )
770 , ( "optl" , HasArg (upd . addOptl) )
771 , ( "optdll" , HasArg (upd . addOptdll) )
772 , ( "optdep" , HasArg (upd . addOptdep) )
774 , ( "split-objs" , NoArg (if can_split
775 then setDynFlag Opt_SplitObjs
778 -------- Linking ----------------------------------------------------
779 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
780 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
781 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
783 ------- Libraries ---------------------------------------------------
784 , ( "L" , Prefix addLibraryPath )
785 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
788 ------- Frameworks --------------------------------------------------
789 -- -framework-path should really be -F ...
790 , ( "framework-path" , HasArg addFrameworkPath )
791 , ( "framework" , HasArg (upd . addCmdlineFramework) )
793 ------- Output Redirection ------------------------------------------
794 , ( "odir" , HasArg (upd . setOutputDir . Just))
795 , ( "o" , SepArg (upd . setOutputFile . Just))
796 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
797 , ( "osuf" , HasArg (upd . setObjectSuf))
798 , ( "hcsuf" , HasArg (upd . setHcSuf))
799 , ( "hisuf" , HasArg (upd . setHiSuf))
800 , ( "hidir" , HasArg (upd . setHiDir . Just))
801 , ( "tmpdir" , HasArg (upd . setTmpDir))
803 ------- Keeping temporary files -------------------------------------
804 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
805 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
806 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
807 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
809 ------- Miscellaneous ----------------------------------------------
810 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
811 , ( "main-is" , SepArg setMainIs )
813 ------- recompilation checker --------------------------------------
814 , ( "recomp" , NoArg (setDynFlag Opt_RecompChecking) )
815 , ( "no-recomp" , NoArg (unSetDynFlag Opt_RecompChecking) )
817 ------- Packages ----------------------------------------------------
818 , ( "package-conf" , HasArg extraPkgConf_ )
819 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
820 , ( "package-name" , HasArg ignorePackage ) -- for compatibility
821 , ( "package" , HasArg exposePackage )
822 , ( "hide-package" , HasArg hidePackage )
823 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
824 , ( "ignore-package" , HasArg ignorePackage )
825 , ( "syslib" , HasArg exposePackage ) -- for compatibility
827 ------ HsCpp opts ---------------------------------------------------
828 , ( "D", AnySuffix (upd . addOptP) )
829 , ( "U", AnySuffix (upd . addOptP) )
831 ------- Include/Import Paths ----------------------------------------
832 , ( "I" , Prefix addIncludePath)
833 , ( "i" , OptPrefix addImportPath )
835 ------ Debugging ----------------------------------------------------
836 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
838 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
839 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
840 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
841 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
842 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
843 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
844 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
845 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
846 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
847 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
848 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
849 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
850 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
851 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
852 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
853 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
854 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
855 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
856 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
857 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
858 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
859 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
860 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace))
861 , ( "ddump-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace))
862 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
863 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
864 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats))
865 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
866 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
867 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
868 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
869 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
870 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
871 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs))
872 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
873 , ( "ddump-minimal-imports", setDumpFlag Opt_D_dump_minimal_imports)
874 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
875 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
876 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
877 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
878 , ( "dshow-passes", NoArg (do unSetDynFlag Opt_RecompChecking
881 ------ Machine dependant (-m<blah>) stuff ---------------------------
883 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
884 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
885 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
887 ------ Warning opts -------------------------------------------------
888 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
889 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
890 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
891 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
892 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
894 ------ Optimisation flags ------------------------------------------
895 , ( "O" , NoArg (upd (setOptLevel 1)))
896 , ( "Onot" , NoArg (upd (setOptLevel 0)))
897 , ( "O" , PrefixPred (all isDigit)
898 (\f -> upd (setOptLevel (read f))))
900 , ( "fmax-simplifier-iterations",
901 PrefixPred (all isDigit)
903 dfs{ maxSimplIterations = read n })) )
906 SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
908 ------ Compiler flags -----------------------------------------------
910 , ( "fno-code", NoArg (setTarget HscNothing))
911 , ( "fasm", AnySuffix (\_ -> setTarget HscAsm) )
912 , ( "fvia-c", NoArg (setTarget HscC) )
913 , ( "fvia-C", NoArg (setTarget HscC) )
914 , ( "filx", NoArg (setTarget HscILX) )
916 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
917 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
919 -- the rest of the -f* and -fno-* flags
920 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
921 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
924 -- these -f<blah> flags can all be reversed with -fno-<blah>
927 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
928 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
929 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
930 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
931 ( "warn-missing-fields", Opt_WarnMissingFields ),
932 ( "warn-missing-methods", Opt_WarnMissingMethods ),
933 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
934 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
935 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
936 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
937 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
938 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
939 ( "warn-unused-imports", Opt_WarnUnusedImports ),
940 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
941 ( "warn-deprecations", Opt_WarnDeprecations ),
942 ( "warn-orphans", Opt_WarnOrphans ),
943 ( "fi", Opt_FFI ), -- support `-ffi'...
944 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
945 ( "arrows", Opt_Arrows ), -- arrow syntax
946 ( "parr", Opt_PArr ),
948 ( "implicit-prelude", Opt_ImplicitPrelude ),
949 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
950 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
951 ( "implicit-params", Opt_ImplicitParams ),
952 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
953 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
954 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
955 ( "generics", Opt_Generics ),
956 ( "strictness", Opt_Strictness ),
957 ( "full-laziness", Opt_FullLaziness ),
959 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
960 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
961 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
962 ( "ignore-asserts", Opt_IgnoreAsserts ),
963 ( "do-eta-reduction", Opt_DoEtaReduction ),
964 ( "case-merge", Opt_CaseMerge ),
965 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
966 ( "excess-precision", Opt_ExcessPrecision ),
967 ( "asm-mangling", Opt_DoAsmMangling )
975 Opt_ScopedTypeVariables ]
977 isFFlag f = f `elem` (map fst fFlags)
978 getFFlag f = fromJust (lookup f fFlags)
980 -- -----------------------------------------------------------------------------
981 -- Parsing the dynamic flags.
983 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
984 parseDynamicFlags dflags args = do
985 let ((leftover,errs),dflags')
986 = runCmdLine (processArgs dynamic_flags args) dflags
987 when (not (null errs)) $ do
988 throwDyn (UsageError (unlines errs))
989 return (dflags', leftover)
992 type DynP = CmdLineP DynFlags
994 upd :: (DynFlags -> DynFlags) -> DynP ()
996 dfs <- getCmdLineState
997 putCmdLineState $! (f dfs)
999 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1000 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1001 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1003 setDumpFlag :: DynFlag -> OptKind DynP
1004 setDumpFlag dump_flag
1005 = NoArg (unSetDynFlag Opt_RecompChecking >> setDynFlag dump_flag)
1006 -- Whenver we -ddump, switch off the recompilation checker,
1007 -- else you don't see the dump!
1009 setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
1011 | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
1012 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
1014 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1016 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1019 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1021 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1023 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1025 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
1026 -- (-fvia-C, -fasm, -filx respectively).
1027 setTarget l = upd (\dfs -> case hscTarget dfs of
1028 HscC -> dfs{ hscTarget = l }
1029 HscAsm -> dfs{ hscTarget = l }
1030 HscILX -> dfs{ hscTarget = l }
1033 setOptLevel :: Int -> DynFlags -> DynFlags
1034 setOptLevel n dflags
1035 | hscTarget dflags == HscInterpreted && n > 0
1037 -- not in IO any more, oh well:
1038 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1040 = updOptLevel n dflags
1043 setMainIs :: String -> DynP ()
1045 | not (null main_fn) -- The arg looked like "Foo.baz"
1046 = upd $ \d -> d{ mainFunIs = Just main_fn,
1047 mainModIs = Just main_mod }
1049 | isUpper (head main_mod) -- The arg looked like "Foo"
1050 = upd $ \d -> d{ mainModIs = Just main_mod }
1052 | otherwise -- The arg looked like "baz"
1053 = upd $ \d -> d{ mainFunIs = Just main_mod }
1055 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1057 -----------------------------------------------------------------------------
1058 -- Paths & Libraries
1060 -- -i on its own deletes the import paths
1061 addImportPath "" = upd (\s -> s{importPaths = []})
1062 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1066 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1069 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1071 addFrameworkPath p =
1072 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1074 split_marker = ':' -- not configurable (ToDo)
1076 splitPathList :: String -> [String]
1077 splitPathList s = filter notNull (splitUp s)
1078 -- empty paths are ignored: there might be a trailing
1079 -- ':' in the initial list, for example. Empty paths can
1080 -- cause confusion when they are translated into -I options
1081 -- for passing to gcc.
1083 #ifndef mingw32_TARGET_OS
1084 splitUp xs = split split_marker xs
1086 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1088 -- That is, if "foo:bar:baz" is used, this interpreted as
1089 -- consisting of three entries, 'foo', 'bar', 'baz'.
1090 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1091 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1093 -- Notice that no attempt is made to fully replace the 'standard'
1094 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1095 -- that this will cause too much breakage for users & ':' will
1096 -- work fine even with DOS paths, if you're not insisting on being silly.
1099 splitUp (x:':':div:xs) | div `elem` dir_markers
1100 = ((x:':':div:p): splitUp rs)
1102 (p,rs) = findNextPath xs
1103 -- we used to check for existence of the path here, but that
1104 -- required the IO monad to be threaded through the command-line
1105 -- parser which is quite inconvenient. The
1106 splitUp xs = cons p (splitUp rs)
1108 (p,rs) = findNextPath xs
1113 -- will be called either when we've consumed nought or the
1114 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1115 -- finding the next split marker.
1117 case break (`elem` split_markers) xs of
1118 (p, d:ds) -> (p, ds)
1121 split_markers :: [Char]
1122 split_markers = [':', ';']
1124 dir_markers :: [Char]
1125 dir_markers = ['/', '\\']
1128 -- -----------------------------------------------------------------------------
1129 -- tmpDir, where we store temporary files.
1131 setTmpDir :: FilePath -> DynFlags -> DynFlags
1132 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1134 #if !defined(mingw32_HOST_OS)
1135 canonicalise p = normalisePath p
1137 -- Canonicalisation of temp path under win32 is a bit more
1138 -- involved: (a) strip trailing slash,
1139 -- (b) normalise slashes
1140 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1142 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1144 -- if we're operating under cygwin, and TMP/TEMP is of
1145 -- the form "/cygdrive/drive/path", translate this to
1146 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1147 -- understand /cygdrive paths.)
1149 | "/cygdrive/" `isPrefixOf` path =
1150 case drop (length "/cygdrive/") path of
1151 drive:xs@('/':_) -> drive:':':xs
1155 -- strip the trailing backslash (awful, but we only do this once).
1156 removeTrailingSlash path =
1163 -----------------------------------------------------------------------------
1164 -- Via-C compilation stuff
1166 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1167 [String]) -- for registerised HC compilations
1168 machdepCCOpts dflags
1169 #if alpha_TARGET_ARCH
1171 #ifdef HAVE_THREADED_RTS_SUPPORT
1175 -- For now, to suppress the gcc warning "call-clobbered
1176 -- register used for global register variable", we simply
1177 -- disable all warnings altogether using the -w flag. Oh well.
1179 #elif hppa_TARGET_ARCH
1180 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1181 -- (very nice, but too bad the HP /usr/include files don't agree.)
1182 = ( ["-D_HPUX_SOURCE"], [] )
1184 #elif m68k_TARGET_ARCH
1185 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1186 -- popping of args to routines to be explicit; if we let things
1187 -- be deferred 'til after an STGJUMP, imminent death is certain!
1189 -- -fomit-frame-pointer : *don't*
1190 -- It's better to have a6 completely tied up being a frame pointer
1191 -- rather than let GCC pick random things to do with it.
1192 -- (If we want to steal a6, then we would try to do things
1193 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1194 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1196 #elif i386_TARGET_ARCH
1197 -- -fno-defer-pop : basically the same game as for m68k
1199 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1200 -- the fp (%ebp) for our register maps.
1201 = let n_regs = stolen_x86_regs dflags
1204 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1205 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1208 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1209 -- Some gccs are configured with
1210 -- -momit-leaf-frame-pointer on by default, and it
1211 -- apparently takes precedence over
1212 -- -fomit-frame-pointer, so we disable it first here.
1213 "-mno-omit-leaf-frame-pointer",
1215 "-fomit-frame-pointer",
1216 -- we want -fno-builtin, because when gcc inlines
1217 -- built-in functions like memcpy() it tends to
1218 -- run out of registers, requiring -monly-n-regs
1220 "-DSTOLEN_X86_REGS="++show n_regs ]
1223 #elif ia64_TARGET_ARCH
1224 = ( [], ["-fomit-frame-pointer", "-G0"] )
1226 #elif x86_64_TARGET_ARCH
1227 = ( [], ["-fomit-frame-pointer",
1228 "-fno-asynchronous-unwind-tables"
1229 -- the unwind tables are unnecessary for HC code,
1230 -- and get in the way of -split-objs. Another option
1231 -- would be to throw them away in the mangler, but this
1235 #elif mips_TARGET_ARCH
1236 = ( ["-static"], [] )
1238 #elif sparc_TARGET_ARCH
1240 -- For now, to suppress the gcc warning "call-clobbered
1241 -- register used for global register variable", we simply
1242 -- disable all warnings altogether using the -w flag. Oh well.
1244 #elif powerpc_apple_darwin_TARGET
1246 -- Disable Apple's precompiling preprocessor. It's a great thing
1247 -- for "normal" programs, but it doesn't support register variable
1249 = ( [], ["-no-cpp-precomp"] )
1254 picCCOpts :: DynFlags -> [String]
1256 #if darwin_TARGET_OS
1257 -- Apple prefers to do things the other way round.
1258 -- PIC is on by default.
1259 -- -mdynamic-no-pic:
1260 -- Turn off PIC code generation.
1262 -- Don't generate "common" symbols - these are unwanted
1263 -- in dynamic libraries.
1268 = ["-mdynamic-no-pic"]
1269 #elif mingw32_TARGET_OS
1270 -- no -fPIC for Windows
1279 -- -----------------------------------------------------------------------------
1284 #if defined(i386_TARGET_ARCH) \
1285 || defined(x86_64_TARGET_ARCH) \
1286 || defined(alpha_TARGET_ARCH) \
1287 || defined(hppa_TARGET_ARCH) \
1288 || defined(m68k_TARGET_ARCH) \
1289 || defined(mips_TARGET_ARCH) \
1290 || defined(powerpc_TARGET_ARCH) \
1291 || defined(rs6000_TARGET_ARCH) \
1292 || defined(sparc_TARGET_ARCH)