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 )
59 import SrcLoc ( SrcSpan )
61 import DATA_IOREF ( readIORef )
62 import EXCEPTION ( throwDyn )
64 #ifdef mingw32_TARGET_OS
65 import Data.List ( isPrefixOf )
67 import Maybe ( fromJust )
68 import Char ( isDigit, isUpper )
70 import System.IO ( hPutStrLn, stderr )
71 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
73 -- -----------------------------------------------------------------------------
86 | Opt_D_dump_inlinings
87 | Opt_D_dump_occur_anal
91 | Opt_D_dump_simpl_iterations
100 | Opt_D_dump_worker_wrapper
101 | Opt_D_dump_rn_trace
102 | Opt_D_dump_rn_stats
104 | Opt_D_dump_simpl_stats
105 | Opt_D_dump_tc_trace
106 | Opt_D_dump_if_trace
111 | Opt_D_verbose_core2core
112 | Opt_D_verbose_stg2stg
114 | Opt_D_dump_hi_diffs
115 | Opt_D_dump_minimal_imports
120 | Opt_WarnIsError -- -Werror; makes warnings fatal
121 | Opt_WarnDuplicateExports
123 | Opt_WarnIncompletePatterns
124 | Opt_WarnIncompletePatternsRecUpd
125 | Opt_WarnMissingFields
126 | Opt_WarnMissingMethods
127 | Opt_WarnMissingSigs
128 | Opt_WarnNameShadowing
129 | Opt_WarnOverlappingPatterns
130 | Opt_WarnSimplePatterns
131 | Opt_WarnTypeDefaults
132 | Opt_WarnUnusedBinds
133 | Opt_WarnUnusedImports
134 | Opt_WarnUnusedMatches
135 | Opt_WarnDeprecations
136 | Opt_WarnDodgyImports
140 | Opt_AllowOverlappingInstances
141 | Opt_AllowUndecidableInstances
142 | Opt_AllowIncoherentInstances
143 | Opt_MonomorphismRestriction
146 | Opt_PArr -- syntactic support for parallel arrays
147 | Opt_Arrows -- Arrow-notation syntax
151 | Opt_ImplicitPrelude
152 | Opt_ScopedTypeVariables
158 | Opt_IgnoreInterfacePragmas
159 | Opt_OmitInterfacePragmas
160 | Opt_DoLambdaEtaExpansion
164 | Opt_UnboxStrictFields
172 | Opt_ExcessPrecision
173 | Opt_ReadUserPackageConf
177 | Opt_HideAllPackages
188 data DynFlags = DynFlags {
191 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
192 stgToDo :: Maybe [StgToDo], -- similarly
193 hscTarget :: HscTarget,
194 hscOutName :: String, -- name of the output file
195 hscStubHOutName :: String, -- name of the .stub_h output file
196 hscStubCOutName :: String, -- name of the .stub_c 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],
205 mainModIs :: Maybe String,
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 outputDir :: Maybe String,
215 outputFile :: Maybe String,
216 outputHi :: Maybe String,
219 hiDir :: Maybe String,
221 includePaths :: [String],
222 libraryPaths :: [String],
223 frameworkPaths :: [String], -- used on darwin only
224 cmdlineFrameworks :: [String], -- ditto
225 tmpDir :: String, -- no trailing '/'
227 -- options for particular phases
238 -- commands for particular phases
240 pgm_P :: (String,[Option]),
242 pgm_c :: (String,[Option]),
243 pgm_m :: (String,[Option]),
244 pgm_s :: (String,[Option]),
245 pgm_a :: (String,[Option]),
246 pgm_l :: (String,[Option]),
247 pgm_dll :: (String,[Option]),
250 extraPkgConfs :: [FilePath],
251 -- The -package-conf flags given on the command line, in the order
254 packageFlags :: [PackageFlag],
255 -- The -package and -hide-package flags from the command-line
258 pkgState :: PackageState,
264 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO ()
277 = BatchCompile -- | @ghc --make Main@
278 | Interactive -- | @ghc --interactive@
279 | OneShot -- | @ghc -c Foo.hs@
280 | JustTypecheck -- | Development environemnts, refactorer, etc.
284 isOneShot :: GhcMode -> Bool
285 isOneShot OneShot = True
286 isOneShot _other = False
288 data GhcLink -- What to do in the link step, if there is one
289 = -- Only relevant for modes
290 -- DoMake and StopBefore StopLn
291 NoLink -- Don't link at all
292 | StaticLink -- Ordinary linker [the default]
293 | MkDLL -- Make a DLL
295 isNoLink :: GhcLink -> Bool
296 isNoLink NoLink = True
297 isNoLink other = False
300 = ExposePackage String
302 | IgnorePackage String
305 | cGhcWithNativeCodeGen == "YES" = HscAsm
308 initDynFlags dflags = do
309 -- someday these will be dynamic flags
310 ways <- readIORef v_Ways
311 build_tag <- readIORef v_Build_tag
312 rts_build_tag <- readIORef v_RTS_Build_tag
315 buildTag = build_tag,
316 rtsBuildTag = rts_build_tag
322 ghcLink = StaticLink,
325 hscTarget = defaultHscTarget,
327 hscStubHOutName = "",
328 hscStubCOutName = "",
332 maxSimplIterations = 4,
335 cmdlineHcIncludes = [],
340 wayNames = panic "ways",
341 buildTag = panic "buildTag",
342 rtsBuildTag = panic "rtsBuildTag",
345 outputFile = Nothing,
347 objectSuf = phaseInputExt StopLn,
348 hcSuf = phaseInputExt HCc,
354 cmdlineFrameworks = [],
355 tmpDir = cDEFAULT_TMPDIR,
367 pgm_L = panic "pgm_L",
368 pgm_P = panic "pgm_P",
369 pgm_F = panic "pgm_F",
370 pgm_c = panic "pgm_c",
371 pgm_m = panic "pgm_m",
372 pgm_s = panic "pgm_s",
373 pgm_a = panic "pgm_a",
374 pgm_l = panic "pgm_l",
375 pgm_dll = panic "pgm_mkdll",
379 pkgState = panic "pkgState",
383 Opt_ReadUserPackageConf,
386 Opt_MonomorphismRestriction,
388 -- strictness is on by default, but this only
390 Opt_CSE, -- similarly for CSE.
391 Opt_FullLaziness, -- ...and for full laziness
393 Opt_DoLambdaEtaExpansion,
394 -- This one is important for a tiresome reason:
395 -- we want to make sure that the bindings for data
396 -- constructors are eta-expanded. This is probably
397 -- a good thing anyway, but it seems fragile.
401 -- and the default no-optimisation options:
402 Opt_IgnoreInterfacePragmas,
403 Opt_OmitInterfacePragmas
405 ] ++ standardWarnings,
407 log_action = \severity srcSpan style msg ->
409 SevInfo -> hPutStrLn stderr (show (msg style))
410 SevFatal -> hPutStrLn stderr (show (msg style))
411 _ -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
417 0 | print errors & warnings only
418 1 | minimal verbosity: print "compiling M ... done." for each module.
419 2 | equivalent to -dshow-passes
420 3 | equivalent to existing "ghc -v"
421 4 | "ghc -v -ddump-most"
422 5 | "ghc -v -ddump-all"
425 dopt :: DynFlag -> DynFlags -> Bool
426 dopt f dflags = f `elem` (flags dflags)
428 dopt_set :: DynFlags -> DynFlag -> DynFlags
429 dopt_set dfs f = dfs{ flags = f : flags dfs }
431 dopt_unset :: DynFlags -> DynFlag -> DynFlags
432 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
434 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
435 getOpts dflags opts = reverse (opts dflags)
436 -- We add to the options from the front, so we need to reverse the list
438 getVerbFlag :: DynFlags -> String
440 | verbosity dflags >= 3 = "-v"
443 setOutputDir f d = d{ outputDir = f}
444 setOutputFile f d = d{ outputFile = f}
445 setOutputHi f d = d{ outputHi = f}
446 setObjectSuf f d = d{ objectSuf = f}
447 setHcSuf f d = d{ hcSuf = f}
448 setHiSuf f d = d{ hiSuf = f}
449 setHiDir f d = d{ hiDir = f}
451 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
452 -- Config.hs should really use Option.
453 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
455 setPgmL f d = d{ pgm_L = f}
456 setPgmF f d = d{ pgm_F = f}
457 setPgmc f d = d{ pgm_c = (f,[])}
458 setPgmm f d = d{ pgm_m = (f,[])}
459 setPgms f d = d{ pgm_s = (f,[])}
460 setPgma f d = d{ pgm_a = (f,[])}
461 setPgml f d = d{ pgm_l = (f,[])}
462 setPgmdll f d = d{ pgm_dll = (f,[])}
464 addOptL f d = d{ opt_L = f : opt_L d}
465 addOptP f d = d{ opt_P = f : opt_P d}
466 addOptF f d = d{ opt_F = f : opt_F d}
467 addOptc f d = d{ opt_c = f : opt_c d}
468 addOptm f d = d{ opt_m = f : opt_m d}
469 addOpta f d = d{ opt_a = f : opt_a d}
470 addOptl f d = d{ opt_l = f : opt_l d}
471 addOptdll f d = d{ opt_dll = f : opt_dll d}
472 addOptdep f d = d{ opt_dep = f : opt_dep d}
474 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
476 -- -----------------------------------------------------------------------------
477 -- Command-line options
479 -- When invoking external tools as part of the compilation pipeline, we
480 -- pass these a sequence of options on the command-line. Rather than
481 -- just using a list of Strings, we use a type that allows us to distinguish
482 -- between filepaths and 'other stuff'. [The reason being, of course, that
483 -- this type gives us a handle on transforming filenames, and filenames only,
484 -- to whatever format they're expected to be on a particular platform.]
487 = FileOption -- an entry that _contains_ filename(s) / filepaths.
488 String -- a non-filepath prefix that shouldn't be
489 -- transformed (e.g., "/out=")
490 String -- the filepath/filename portion
493 -----------------------------------------------------------------------------
494 -- Setting the optimisation level
496 updOptLevel :: Int -> DynFlags -> DynFlags
497 -- Set dynflags appropriate to the optimisation level
500 then dfs2{ hscTarget = HscC, optLevel = n } -- turn on -fvia-C with -O
501 else dfs2{ optLevel = n }
503 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
504 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
507 | n == 0 = opt_0_dopts
508 | otherwise = opt_1_dopts
511 | n == 0 = opt_1_dopts
512 | otherwise = opt_0_dopts
515 Opt_IgnoreInterfacePragmas,
516 Opt_OmitInterfacePragmas
525 -- -----------------------------------------------------------------------------
526 -- Standard sets of warning options
529 = [ Opt_WarnDeprecations,
530 Opt_WarnOverlappingPatterns,
531 Opt_WarnMissingFields,
532 Opt_WarnMissingMethods,
533 Opt_WarnDuplicateExports
537 = standardWarnings ++
538 [ Opt_WarnUnusedBinds,
539 Opt_WarnUnusedMatches,
540 Opt_WarnUnusedImports,
541 Opt_WarnIncompletePatterns,
547 [ Opt_WarnTypeDefaults,
548 Opt_WarnNameShadowing,
554 -- -----------------------------------------------------------------------------
555 -- CoreToDo: abstraction of core-to-core passes to run.
557 data CoreToDo -- These are diff core-to-core passes,
558 -- which may be invoked in any order,
559 -- as many times as you like.
561 = CoreDoSimplify -- The core-to-core simplifier.
564 -- Each run of the simplifier can take a different
565 -- set of simplifier-specific flags.
567 | CoreDoFloatOutwards FloatOutSwitches
572 | CoreDoWorkerWrapper
575 | CoreDoOldStrictness
578 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
579 -- matching this string
581 | CoreDoNothing -- useful when building up lists of these things
583 data SimplifierMode -- See comments in SimplMonad
587 data SimplifierSwitch
588 = MaxSimplifierIterations Int
591 data FloatOutSwitches
592 = FloatOutSw Bool -- True <=> float lambdas to top level
593 Bool -- True <=> float constants to top level,
594 -- even if they do not escape a lambda
597 -- The core-to-core pass ordering is derived from the DynFlags:
599 getCoreToDo :: DynFlags -> [CoreToDo]
601 | Just todo <- coreToDo dflags = todo -- set explicitly by user
602 | otherwise = core_todo
604 opt_level = optLevel dflags
605 max_iter = maxSimplIterations dflags
606 strictness = dopt Opt_Strictness dflags
607 full_laziness = dopt Opt_FullLaziness dflags
608 cse = dopt Opt_CSE dflags
609 rule_check = ruleCheck dflags
612 if opt_level == 0 then
614 CoreDoSimplify (SimplPhase 0) [
615 MaxSimplifierIterations max_iter
618 else {- opt_level >= 1 -} [
620 -- initial simplify: mk specialiser happy: minimum effort please
621 CoreDoSimplify SimplGently [
623 -- Don't inline anything till full laziness has bitten
624 -- In particular, inlining wrappers inhibits floating
625 -- e.g. ...(case f x of ...)...
626 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
627 -- ==> ...(case x of I# x# -> case fw x# of ...)...
628 -- and now the redex (f x) isn't floatable any more
629 -- Similarly, don't apply any rules until after full
630 -- laziness. Notably, list fusion can prevent floating.
633 -- Don't do case-of-case transformations.
634 -- This makes full laziness work better
635 MaxSimplifierIterations max_iter
638 -- Specialisation is best done before full laziness
639 -- so that overloaded functions have all their dictionary lambdas manifest
642 if full_laziness then CoreDoFloatOutwards (FloatOutSw False False)
647 CoreDoSimplify (SimplPhase 2) [
648 -- Want to run with inline phase 2 after the specialiser to give
649 -- maximum chance for fusion to work before we inline build/augment
650 -- in phase 1. This made a difference in 'ansi' where an
651 -- overloaded function wasn't inlined till too late.
652 MaxSimplifierIterations max_iter
654 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
656 CoreDoSimplify (SimplPhase 1) [
657 -- Need inline-phase2 here so that build/augment get
658 -- inlined. I found that spectral/hartel/genfft lost some useful
659 -- strictness in the function sumcode' if augment is not inlined
660 -- before strictness analysis runs
661 MaxSimplifierIterations max_iter
663 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
665 CoreDoSimplify (SimplPhase 0) [
666 -- Phase 0: allow all Ids to be inlined now
667 -- This gets foldr inlined before strictness analysis
669 MaxSimplifierIterations 3
670 -- At least 3 iterations because otherwise we land up with
671 -- huge dead expressions because of an infelicity in the
673 -- let k = BIG in foldr k z xs
674 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
675 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
679 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
681 #ifdef OLD_STRICTNESS
684 if strictness then CoreDoStrictness else CoreDoNothing,
688 CoreDoSimplify (SimplPhase 0) [
689 MaxSimplifierIterations max_iter
692 if full_laziness then
693 CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
694 True) -- Float constants
696 -- nofib/spectral/hartel/wang doubles in speed if you
697 -- do full laziness late in the day. It only happens
698 -- after fusion and other stuff, so the early pass doesn't
699 -- catch it. For the record, the redex is
700 -- f_el22 (f_el21 r_midblock)
703 -- We want CSE to follow the final full-laziness pass, because it may
704 -- succeed in commoning up things floated out by full laziness.
705 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
707 if cse then CoreCSE else CoreDoNothing,
711 -- Case-liberation for -O2. This should be after
712 -- strictness analysis and the simplification which follows it.
714 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
716 if opt_level >= 2 then
720 if opt_level >= 2 then
725 -- Final clean-up simplification:
726 CoreDoSimplify (SimplPhase 0) [
727 MaxSimplifierIterations max_iter
731 -- -----------------------------------------------------------------------------
732 -- StgToDo: abstraction of stg-to-stg passes to run.
735 = StgDoMassageForProfiling -- should be (next to) last
736 -- There's also setStgVarInfo, but its absolute "lastness"
737 -- is so critical that it is hardwired in (no flag).
740 getStgToDo :: DynFlags -> [StgToDo]
742 | Just todo <- stgToDo dflags = todo -- set explicitly by user
745 stg_stats = dopt Opt_StgStats dflags
747 todo1 = if stg_stats then [D_stg_stats] else []
749 todo2 | WayProf `elem` wayNames dflags
750 = StgDoMassageForProfiling : todo1
754 -- -----------------------------------------------------------------------------
757 dynamic_flags :: [(String, OptKind DynP)]
759 ( "n" , NoArg (setDynFlag Opt_DryRun) )
760 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
761 , ( "F" , NoArg (setDynFlag Opt_Pp))
762 , ( "#include" , HasArg (addCmdlineHCInclude) )
763 , ( "v" , OptPrefix (setVerbosity) )
765 ------- Specific phases --------------------------------------------
766 , ( "pgmL" , HasArg (upd . setPgmL) )
767 , ( "pgmP" , HasArg (upd . setPgmP) )
768 , ( "pgmF" , HasArg (upd . setPgmF) )
769 , ( "pgmc" , HasArg (upd . setPgmc) )
770 , ( "pgmm" , HasArg (upd . setPgmm) )
771 , ( "pgms" , HasArg (upd . setPgms) )
772 , ( "pgma" , HasArg (upd . setPgma) )
773 , ( "pgml" , HasArg (upd . setPgml) )
774 , ( "pgmdll" , HasArg (upd . setPgmdll) )
776 , ( "optL" , HasArg (upd . addOptL) )
777 , ( "optP" , HasArg (upd . addOptP) )
778 , ( "optF" , HasArg (upd . addOptF) )
779 , ( "optc" , HasArg (upd . addOptc) )
780 , ( "optm" , HasArg (upd . addOptm) )
781 , ( "opta" , HasArg (upd . addOpta) )
782 , ( "optl" , HasArg (upd . addOptl) )
783 , ( "optdll" , HasArg (upd . addOptdll) )
784 , ( "optdep" , HasArg (upd . addOptdep) )
786 , ( "split-objs" , NoArg (if can_split
787 then setDynFlag Opt_SplitObjs
790 -------- Linking ----------------------------------------------------
791 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
792 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
793 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
795 ------- Libraries ---------------------------------------------------
796 , ( "L" , Prefix addLibraryPath )
797 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
800 ------- Frameworks --------------------------------------------------
801 -- -framework-path should really be -F ...
802 , ( "framework-path" , HasArg addFrameworkPath )
803 , ( "framework" , HasArg (upd . addCmdlineFramework) )
805 ------- Output Redirection ------------------------------------------
806 , ( "odir" , HasArg (upd . setOutputDir . Just))
807 , ( "o" , SepArg (upd . setOutputFile . Just))
808 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
809 , ( "osuf" , HasArg (upd . setObjectSuf))
810 , ( "hcsuf" , HasArg (upd . setHcSuf))
811 , ( "hisuf" , HasArg (upd . setHiSuf))
812 , ( "hidir" , HasArg (upd . setHiDir . Just))
813 , ( "tmpdir" , HasArg (upd . setTmpDir))
815 ------- Keeping temporary files -------------------------------------
816 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
817 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
818 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
819 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
821 ------- Miscellaneous ----------------------------------------------
822 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
823 , ( "main-is" , SepArg setMainIs )
825 ------- recompilation checker --------------------------------------
826 , ( "recomp" , NoArg (setDynFlag Opt_RecompChecking) )
827 , ( "no-recomp" , NoArg (unSetDynFlag Opt_RecompChecking) )
829 ------- Packages ----------------------------------------------------
830 , ( "package-conf" , HasArg extraPkgConf_ )
831 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
832 , ( "package-name" , HasArg ignorePackage ) -- for compatibility
833 , ( "package" , HasArg exposePackage )
834 , ( "hide-package" , HasArg hidePackage )
835 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
836 , ( "ignore-package" , HasArg ignorePackage )
837 , ( "syslib" , HasArg exposePackage ) -- for compatibility
839 ------ HsCpp opts ---------------------------------------------------
840 , ( "D", AnySuffix (upd . addOptP) )
841 , ( "U", AnySuffix (upd . addOptP) )
843 ------- Include/Import Paths ----------------------------------------
844 , ( "I" , Prefix addIncludePath)
845 , ( "i" , OptPrefix addImportPath )
847 ------ Debugging ----------------------------------------------------
848 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
850 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
851 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
852 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
853 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
854 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
855 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
856 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
857 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
858 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
859 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
860 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
861 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
862 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
863 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
864 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
865 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
866 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
867 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
868 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
869 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
870 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
871 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
872 , ( "ddump-rn-trace", NoArg (setDynFlag Opt_D_dump_rn_trace))
873 , ( "ddump-if-trace", NoArg (setDynFlag Opt_D_dump_if_trace))
874 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
875 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
876 , ( "ddump-rn-stats", NoArg (setDynFlag Opt_D_dump_rn_stats))
877 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
878 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
879 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
880 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
881 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
882 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
883 , ( "ddump-hi-diffs", NoArg (setDynFlag Opt_D_dump_hi_diffs))
884 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
885 , ( "ddump-minimal-imports", setDumpFlag Opt_D_dump_minimal_imports)
886 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
887 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
888 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
889 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
890 , ( "dshow-passes", NoArg (do unSetDynFlag Opt_RecompChecking
893 ------ Machine dependant (-m<blah>) stuff ---------------------------
895 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
896 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
897 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
899 ------ Warning opts -------------------------------------------------
900 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
901 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
902 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
903 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
904 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
906 ------ Optimisation flags ------------------------------------------
907 , ( "O" , NoArg (upd (setOptLevel 1)))
908 , ( "Onot" , NoArg (upd (setOptLevel 0)))
909 , ( "O" , PrefixPred (all isDigit)
910 (\f -> upd (setOptLevel (read f))))
912 , ( "fmax-simplifier-iterations",
913 PrefixPred (all isDigit)
915 dfs{ maxSimplIterations = read n })) )
918 SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
920 ------ Compiler flags -----------------------------------------------
922 , ( "fno-code", NoArg (setTarget HscNothing))
923 , ( "fasm", AnySuffix (\_ -> setTarget HscAsm) )
924 , ( "fvia-c", NoArg (setTarget HscC) )
925 , ( "fvia-C", NoArg (setTarget HscC) )
926 , ( "filx", NoArg (setTarget HscILX) )
928 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
929 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
931 -- the rest of the -f* and -fno-* flags
932 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
933 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
936 -- these -f<blah> flags can all be reversed with -fno-<blah>
939 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
940 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
941 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
942 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
943 ( "warn-missing-fields", Opt_WarnMissingFields ),
944 ( "warn-missing-methods", Opt_WarnMissingMethods ),
945 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
946 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
947 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
948 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
949 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
950 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
951 ( "warn-unused-imports", Opt_WarnUnusedImports ),
952 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
953 ( "warn-deprecations", Opt_WarnDeprecations ),
954 ( "warn-orphans", Opt_WarnOrphans ),
955 ( "fi", Opt_FFI ), -- support `-ffi'...
956 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
957 ( "arrows", Opt_Arrows ), -- arrow syntax
958 ( "parr", Opt_PArr ),
960 ( "implicit-prelude", Opt_ImplicitPrelude ),
961 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
962 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
963 ( "implicit-params", Opt_ImplicitParams ),
964 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
965 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
966 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
967 ( "generics", Opt_Generics ),
968 ( "strictness", Opt_Strictness ),
969 ( "full-laziness", Opt_FullLaziness ),
971 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
972 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
973 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
974 ( "ignore-asserts", Opt_IgnoreAsserts ),
975 ( "do-eta-reduction", Opt_DoEtaReduction ),
976 ( "case-merge", Opt_CaseMerge ),
977 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
978 ( "excess-precision", Opt_ExcessPrecision ),
979 ( "asm-mangling", Opt_DoAsmMangling )
987 Opt_ScopedTypeVariables ]
989 isFFlag f = f `elem` (map fst fFlags)
990 getFFlag f = fromJust (lookup f fFlags)
992 -- -----------------------------------------------------------------------------
993 -- Parsing the dynamic flags.
995 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
996 parseDynamicFlags dflags args = do
997 let ((leftover,errs),dflags')
998 = runCmdLine (processArgs dynamic_flags args) dflags
999 when (not (null errs)) $ do
1000 throwDyn (UsageError (unlines errs))
1001 return (dflags', leftover)
1004 type DynP = CmdLineP DynFlags
1006 upd :: (DynFlags -> DynFlags) -> DynP ()
1008 dfs <- getCmdLineState
1009 putCmdLineState $! (f dfs)
1011 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1012 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1013 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1015 setDumpFlag :: DynFlag -> OptKind DynP
1016 setDumpFlag dump_flag
1017 = NoArg (unSetDynFlag Opt_RecompChecking >> setDynFlag dump_flag)
1018 -- Whenver we -ddump, switch off the recompilation checker,
1019 -- else you don't see the dump!
1021 setVerbosity "" = upd (\dfs -> dfs{ verbosity = 3 })
1023 | all isDigit n = upd (\dfs -> dfs{ verbosity = read n })
1024 | otherwise = throwDyn (UsageError "can't parse verbosity flag (-v<n>)")
1026 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1028 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1031 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1033 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1035 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1037 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags
1038 -- (-fvia-C, -fasm, -filx respectively).
1039 setTarget l = upd (\dfs -> case hscTarget dfs of
1040 HscC -> dfs{ hscTarget = l }
1041 HscAsm -> dfs{ hscTarget = l }
1042 HscILX -> dfs{ hscTarget = l }
1045 setOptLevel :: Int -> DynFlags -> DynFlags
1046 setOptLevel n dflags
1047 | hscTarget dflags == HscInterpreted && n > 0
1049 -- not in IO any more, oh well:
1050 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1052 = updOptLevel n dflags
1055 setMainIs :: String -> DynP ()
1057 | not (null main_fn) -- The arg looked like "Foo.baz"
1058 = upd $ \d -> d{ mainFunIs = Just main_fn,
1059 mainModIs = Just main_mod }
1061 | isUpper (head main_mod) -- The arg looked like "Foo"
1062 = upd $ \d -> d{ mainModIs = Just main_mod }
1064 | otherwise -- The arg looked like "baz"
1065 = upd $ \d -> d{ mainFunIs = Just main_mod }
1067 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1069 -----------------------------------------------------------------------------
1070 -- Paths & Libraries
1072 -- -i on its own deletes the import paths
1073 addImportPath "" = upd (\s -> s{importPaths = []})
1074 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1078 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1081 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1083 addFrameworkPath p =
1084 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1086 split_marker = ':' -- not configurable (ToDo)
1088 splitPathList :: String -> [String]
1089 splitPathList s = filter notNull (splitUp s)
1090 -- empty paths are ignored: there might be a trailing
1091 -- ':' in the initial list, for example. Empty paths can
1092 -- cause confusion when they are translated into -I options
1093 -- for passing to gcc.
1095 #ifndef mingw32_TARGET_OS
1096 splitUp xs = split split_marker xs
1098 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1100 -- That is, if "foo:bar:baz" is used, this interpreted as
1101 -- consisting of three entries, 'foo', 'bar', 'baz'.
1102 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1103 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1105 -- Notice that no attempt is made to fully replace the 'standard'
1106 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1107 -- that this will cause too much breakage for users & ':' will
1108 -- work fine even with DOS paths, if you're not insisting on being silly.
1111 splitUp (x:':':div:xs) | div `elem` dir_markers
1112 = ((x:':':div:p): splitUp rs)
1114 (p,rs) = findNextPath xs
1115 -- we used to check for existence of the path here, but that
1116 -- required the IO monad to be threaded through the command-line
1117 -- parser which is quite inconvenient. The
1118 splitUp xs = cons p (splitUp rs)
1120 (p,rs) = findNextPath xs
1125 -- will be called either when we've consumed nought or the
1126 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1127 -- finding the next split marker.
1129 case break (`elem` split_markers) xs of
1130 (p, d:ds) -> (p, ds)
1133 split_markers :: [Char]
1134 split_markers = [':', ';']
1136 dir_markers :: [Char]
1137 dir_markers = ['/', '\\']
1140 -- -----------------------------------------------------------------------------
1141 -- tmpDir, where we store temporary files.
1143 setTmpDir :: FilePath -> DynFlags -> DynFlags
1144 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1146 #if !defined(mingw32_HOST_OS)
1147 canonicalise p = normalisePath p
1149 -- Canonicalisation of temp path under win32 is a bit more
1150 -- involved: (a) strip trailing slash,
1151 -- (b) normalise slashes
1152 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1154 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1156 -- if we're operating under cygwin, and TMP/TEMP is of
1157 -- the form "/cygdrive/drive/path", translate this to
1158 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1159 -- understand /cygdrive paths.)
1161 | "/cygdrive/" `isPrefixOf` path =
1162 case drop (length "/cygdrive/") path of
1163 drive:xs@('/':_) -> drive:':':xs
1167 -- strip the trailing backslash (awful, but we only do this once).
1168 removeTrailingSlash path =
1175 -----------------------------------------------------------------------------
1176 -- Via-C compilation stuff
1178 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1179 [String]) -- for registerised HC compilations
1180 machdepCCOpts dflags
1181 #if alpha_TARGET_ARCH
1183 #ifdef HAVE_THREADED_RTS_SUPPORT
1187 -- For now, to suppress the gcc warning "call-clobbered
1188 -- register used for global register variable", we simply
1189 -- disable all warnings altogether using the -w flag. Oh well.
1191 #elif hppa_TARGET_ARCH
1192 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1193 -- (very nice, but too bad the HP /usr/include files don't agree.)
1194 = ( ["-D_HPUX_SOURCE"], [] )
1196 #elif m68k_TARGET_ARCH
1197 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1198 -- popping of args to routines to be explicit; if we let things
1199 -- be deferred 'til after an STGJUMP, imminent death is certain!
1201 -- -fomit-frame-pointer : *don't*
1202 -- It's better to have a6 completely tied up being a frame pointer
1203 -- rather than let GCC pick random things to do with it.
1204 -- (If we want to steal a6, then we would try to do things
1205 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1206 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1208 #elif i386_TARGET_ARCH
1209 -- -fno-defer-pop : basically the same game as for m68k
1211 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1212 -- the fp (%ebp) for our register maps.
1213 = let n_regs = stolen_x86_regs dflags
1216 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1217 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1220 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1221 -- Some gccs are configured with
1222 -- -momit-leaf-frame-pointer on by default, and it
1223 -- apparently takes precedence over
1224 -- -fomit-frame-pointer, so we disable it first here.
1225 "-mno-omit-leaf-frame-pointer",
1227 "-fomit-frame-pointer",
1228 -- we want -fno-builtin, because when gcc inlines
1229 -- built-in functions like memcpy() it tends to
1230 -- run out of registers, requiring -monly-n-regs
1232 "-DSTOLEN_X86_REGS="++show n_regs ]
1235 #elif ia64_TARGET_ARCH
1236 = ( [], ["-fomit-frame-pointer", "-G0"] )
1238 #elif x86_64_TARGET_ARCH
1239 = ( [], ["-fomit-frame-pointer",
1240 "-fno-asynchronous-unwind-tables"
1241 -- the unwind tables are unnecessary for HC code,
1242 -- and get in the way of -split-objs. Another option
1243 -- would be to throw them away in the mangler, but this
1247 #elif mips_TARGET_ARCH
1248 = ( ["-static"], [] )
1250 #elif sparc_TARGET_ARCH
1252 -- For now, to suppress the gcc warning "call-clobbered
1253 -- register used for global register variable", we simply
1254 -- disable all warnings altogether using the -w flag. Oh well.
1256 #elif powerpc_apple_darwin_TARGET
1258 -- Disable Apple's precompiling preprocessor. It's a great thing
1259 -- for "normal" programs, but it doesn't support register variable
1261 = ( [], ["-no-cpp-precomp"] )
1266 picCCOpts :: DynFlags -> [String]
1268 #if darwin_TARGET_OS
1269 -- Apple prefers to do things the other way round.
1270 -- PIC is on by default.
1271 -- -mdynamic-no-pic:
1272 -- Turn off PIC code generation.
1274 -- Don't generate "common" symbols - these are unwanted
1275 -- in dynamic libraries.
1280 = ["-mdynamic-no-pic"]
1281 #elif mingw32_TARGET_OS
1282 -- no -fPIC for Windows
1291 -- -----------------------------------------------------------------------------
1296 #if defined(i386_TARGET_ARCH) \
1297 || defined(x86_64_TARGET_ARCH) \
1298 || defined(alpha_TARGET_ARCH) \
1299 || defined(hppa_TARGET_ARCH) \
1300 || defined(m68k_TARGET_ARCH) \
1301 || defined(mips_TARGET_ARCH) \
1302 || defined(powerpc_TARGET_ARCH) \
1303 || defined(rs6000_TARGET_ARCH) \
1304 || defined(sparc_TARGET_ARCH)