2 {-# OPTIONS -fno-warn-missing-fields #-}
3 -----------------------------------------------------------------------------
7 -- Most flags are dynamic flags, which means they can change from
8 -- compilation to compilation using OPTIONS_GHC pragmas, and in a
9 -- multi-session GHC each session can be using different dynamic
10 -- flags. Dynamic flags can also be set at the prompt in GHCi.
12 -- (c) The University of Glasgow 2005
14 -----------------------------------------------------------------------------
20 HscTarget(..), isObjectTarget,
21 GhcMode(..), isOneShot,
22 GhcLink(..), isNoLink,
26 -- Configuration of the core-to-core and stg-to-stg phases
30 SimplifierMode(..), FloatOutSwitches(..),
31 getCoreToDo, getStgToDo,
33 -- Manipulating DynFlags
34 defaultDynFlags, -- DynFlags
35 initDynFlags, -- DynFlags -> IO DynFlags
37 dopt, -- DynFlag -> DynFlags -> Bool
38 dopt_set, dopt_unset, -- DynFlags -> DynFlag -> DynFlags
39 getOpts, -- (DynFlags -> [a]) -> IO [a]
50 machdepCCOpts, picCCOpts
53 #include "HsVersions.h"
55 import Module ( Module, mkModuleName, mkModule )
57 import PrelNames ( mAIN )
58 #ifdef i386_TARGET_ARCH
59 import StaticFlags ( opt_Static )
61 import StaticFlags ( opt_PIC, WayName(..), v_Ways, v_Build_tag,
63 import {-# SOURCE #-} Packages (PackageState)
64 import DriverPhases ( Phase(..), phaseInputExt )
67 import Constants ( mAX_CONTEXT_REDUCTION_DEPTH )
68 import Panic ( panic, GhcException(..) )
69 import UniqFM ( UniqFM )
70 import Util ( notNull, splitLongestPrefix, normalisePath )
71 import Maybes ( fromJust, orElse )
72 import SrcLoc ( SrcSpan )
74 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
76 import Data.IORef ( readIORef )
77 import Control.Exception ( throwDyn )
78 import Control.Monad ( when )
79 #ifdef mingw32_TARGET_OS
80 import Data.List ( isPrefixOf )
85 import Data.Char ( isUpper )
86 import System.IO ( hPutStrLn, stderr )
89 import Breakpoints ( BkptHandler )
90 import Module ( ModuleName )
92 -- -----------------------------------------------------------------------------
105 | Opt_D_dump_inlinings
106 | Opt_D_dump_rule_firings
107 | Opt_D_dump_occur_anal
111 | Opt_D_dump_simpl_iterations
120 | Opt_D_dump_worker_wrapper
121 | Opt_D_dump_rn_trace
122 | Opt_D_dump_rn_stats
124 | Opt_D_dump_simpl_stats
125 | Opt_D_dump_tc_trace
126 | Opt_D_dump_if_trace
132 | Opt_D_verbose_core2core
133 | Opt_D_verbose_stg2stg
135 | Opt_D_dump_hi_diffs
136 | Opt_D_dump_minimal_imports
137 | Opt_D_dump_mod_cycles
138 | Opt_D_faststring_stats
143 | Opt_WarnIsError -- -Werror; makes warnings fatal
144 | Opt_WarnDuplicateExports
146 | Opt_WarnIncompletePatterns
147 | Opt_WarnIncompletePatternsRecUpd
148 | Opt_WarnMissingFields
149 | Opt_WarnMissingMethods
150 | Opt_WarnMissingSigs
151 | Opt_WarnNameShadowing
152 | Opt_WarnOverlappingPatterns
153 | Opt_WarnSimplePatterns
154 | Opt_WarnTypeDefaults
155 | Opt_WarnUnusedBinds
156 | Opt_WarnUnusedImports
157 | Opt_WarnUnusedMatches
158 | Opt_WarnDeprecations
159 | Opt_WarnDodgyImports
164 | Opt_AllowOverlappingInstances
165 | Opt_AllowUndecidableInstances
166 | Opt_AllowIncoherentInstances
167 | Opt_MonomorphismRestriction
169 | Opt_ExtendedDefaultRules -- Use GHC's extended rules for defaulting
172 | Opt_PArr -- Syntactic support for parallel arrays
173 | Opt_Arrows -- Arrow-notation syntax
177 | Opt_ImplicitPrelude
178 | Opt_ScopedTypeVariables
181 | Opt_OverloadedStrings
189 | Opt_IgnoreInterfacePragmas
190 | Opt_OmitInterfacePragmas
191 | Opt_DoLambdaEtaExpansion
193 | Opt_IgnoreBreakpoints
196 | Opt_UnboxStrictFields
205 | Opt_ExcessPrecision
206 | Opt_ReadUserPackageConf
210 | Opt_HideAllPackages
211 #if defined(GHCI) && defined(DEBUGGER)
214 | Opt_PrintBindResult
227 data DynFlags = DynFlags {
230 coreToDo :: Maybe [CoreToDo], -- reserved for -Ofile
231 stgToDo :: Maybe [StgToDo], -- similarly
232 hscTarget :: HscTarget,
233 hscOutName :: String, -- name of the output file
234 extCoreName :: String, -- name of the .core output file
235 verbosity :: Int, -- verbosity level
236 optLevel :: Int, -- optimisation level
237 maxSimplIterations :: Int, -- max simplifier iterations
238 ruleCheck :: Maybe String,
240 specThreshold :: Int, -- Threshold for function specialisation
242 stolen_x86_regs :: Int,
243 cmdlineHcIncludes :: [String], -- -#includes
244 importPaths :: [FilePath],
246 mainFunIs :: Maybe String,
247 ctxtStkDepth :: Int, -- Typechecker context stack depth
249 thisPackage :: PackageId,
252 wayNames :: [WayName], -- way flags from the cmd line
253 buildTag :: String, -- the global "way" (eg. "p" for prof)
254 rtsBuildTag :: String, -- the RTS "way"
257 objectDir :: Maybe String,
258 hiDir :: Maybe String,
259 stubDir :: Maybe String,
265 outputFile :: Maybe String,
266 outputHi :: Maybe String,
268 includePaths :: [String],
269 libraryPaths :: [String],
270 frameworkPaths :: [String], -- used on darwin only
271 cmdlineFrameworks :: [String], -- ditto
272 tmpDir :: String, -- no trailing '/'
274 ghcUsagePath :: FilePath, -- Filled in by SysTools
275 ghciUsagePath :: FilePath, -- ditto
277 hpcDir :: String, -- ^ path to store the .mix files
279 -- options for particular phases
290 -- commands for particular phases
292 pgm_P :: (String,[Option]),
294 pgm_c :: (String,[Option]),
295 pgm_m :: (String,[Option]),
296 pgm_s :: (String,[Option]),
297 pgm_a :: (String,[Option]),
298 pgm_l :: (String,[Option]),
299 pgm_dll :: (String,[Option]),
301 pgm_sysman :: String,
304 extraPkgConfs :: [FilePath],
305 topDir :: FilePath, -- filled in by SysTools
306 systemPackageConfig :: FilePath, -- ditto
307 -- The -package-conf flags given on the command line, in the order
310 packageFlags :: [PackageFlag],
311 -- The -package and -hide-package flags from the command-line
314 -- NB. do not modify this field, it is calculated by
315 -- Packages.initPackages and Packages.updatePackages.
316 pkgDatabase :: Maybe (UniqFM InstalledPackageInfo),
317 pkgState :: PackageState,
323 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO ()
326 -- breakpoint handling
327 ,bkptHandler :: Maybe (BkptHandler Module)
339 -- | will this target result in an object file on the disk?
340 isObjectTarget :: HscTarget -> Bool
341 isObjectTarget HscC = True
342 isObjectTarget HscAsm = True
343 isObjectTarget _ = False
345 -- | The 'GhcMode' tells us whether we're doing multi-module
346 -- compilation (controlled via the "GHC" API) or one-shot
347 -- (single-module) compilation. This makes a difference primarily to
348 -- the "Finder": in one-shot mode we look for interface files for
349 -- imported modules, but in multi-module mode we look for source files
350 -- in order to check whether they need to be recompiled.
352 = CompManager -- ^ --make, GHCi, etc.
353 | OneShot -- ^ ghc -c Foo.hs
354 | MkDepend -- ^ ghc -M, see Finder for why we need this
357 isOneShot :: GhcMode -> Bool
358 isOneShot OneShot = True
359 isOneShot _other = False
361 -- | What kind of linking to do.
362 data GhcLink -- What to do in the link step, if there is one
363 = NoLink -- Don't link at all
364 | LinkBinary -- Link object code into a binary
365 | LinkInMemory -- Use the in-memory dynamic linker
366 | MkDLL -- Make a DLL
369 isNoLink :: GhcLink -> Bool
370 isNoLink NoLink = True
371 isNoLink other = False
374 = ExposePackage String
376 | IgnorePackage String
380 | cGhcWithNativeCodeGen == "YES" = HscAsm
383 initDynFlags dflags = do
384 -- someday these will be dynamic flags
385 ways <- readIORef v_Ways
386 build_tag <- readIORef v_Build_tag
387 rts_build_tag <- readIORef v_RTS_Build_tag
390 buildTag = build_tag,
391 rtsBuildTag = rts_build_tag
396 ghcMode = CompManager,
397 ghcLink = LinkBinary,
400 hscTarget = defaultHscTarget,
405 maxSimplIterations = 4,
409 cmdlineHcIncludes = [],
413 ctxtStkDepth = mAX_CONTEXT_REDUCTION_DEPTH,
415 thisPackage = mainPackageId,
421 objectSuf = phaseInputExt StopLn,
422 hcSuf = phaseInputExt HCc,
425 outputFile = Nothing,
430 cmdlineFrameworks = [],
431 tmpDir = cDEFAULT_TMPDIR,
447 pkgDatabase = Nothing,
448 pkgState = panic "no package state yet: call GHC.setSessionDynFlags",
450 bkptHandler = Nothing,
453 Opt_ReadUserPackageConf,
455 Opt_MonoPatBinds, -- Experimentally, I'm making this non-standard
456 -- behaviour the default, to see if anyone notices
460 Opt_MonomorphismRestriction,
465 Opt_PrintBindResult ]
466 ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
467 -- The default -O0 options
470 log_action = \severity srcSpan style msg ->
472 SevInfo -> hPutStrLn stderr (show (msg style))
473 SevFatal -> hPutStrLn stderr (show (msg style))
474 _ -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
480 0 | print errors & warnings only
481 1 | minimal verbosity: print "compiling M ... done." for each module.
482 2 | equivalent to -dshow-passes
483 3 | equivalent to existing "ghc -v"
484 4 | "ghc -v -ddump-most"
485 5 | "ghc -v -ddump-all"
488 dopt :: DynFlag -> DynFlags -> Bool
489 dopt f dflags = f `elem` (flags dflags)
491 dopt_set :: DynFlags -> DynFlag -> DynFlags
492 dopt_set dfs f = dfs{ flags = f : flags dfs }
494 dopt_unset :: DynFlags -> DynFlag -> DynFlags
495 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
497 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
498 getOpts dflags opts = reverse (opts dflags)
499 -- We add to the options from the front, so we need to reverse the list
501 getVerbFlag :: DynFlags -> String
503 | verbosity dflags >= 3 = "-v"
506 setObjectDir f d = d{ objectDir = f}
507 setHiDir f d = d{ hiDir = f}
508 setStubDir f d = d{ stubDir = f}
510 setObjectSuf f d = d{ objectSuf = f}
511 setHiSuf f d = d{ hiSuf = f}
512 setHcSuf f d = d{ hcSuf = f}
514 setOutputFile f d = d{ outputFile = f}
515 setOutputHi f d = d{ outputHi = f}
517 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
518 -- Config.hs should really use Option.
519 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
521 setPgmL f d = d{ pgm_L = f}
522 setPgmF f d = d{ pgm_F = f}
523 setPgmc f d = d{ pgm_c = (f,[])}
524 setPgmm f d = d{ pgm_m = (f,[])}
525 setPgms f d = d{ pgm_s = (f,[])}
526 setPgma f d = d{ pgm_a = (f,[])}
527 setPgml f d = d{ pgm_l = (f,[])}
528 setPgmdll f d = d{ pgm_dll = (f,[])}
530 addOptL f d = d{ opt_L = f : opt_L d}
531 addOptP f d = d{ opt_P = f : opt_P d}
532 addOptF f d = d{ opt_F = f : opt_F d}
533 addOptc f d = d{ opt_c = f : opt_c d}
534 addOptm f d = d{ opt_m = f : opt_m d}
535 addOpta f d = d{ opt_a = f : opt_a d}
536 addOptl f d = d{ opt_l = f : opt_l d}
537 addOptdll f d = d{ opt_dll = f : opt_dll d}
538 addOptdep f d = d{ opt_dep = f : opt_dep d}
540 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
542 -- -----------------------------------------------------------------------------
543 -- Command-line options
545 -- When invoking external tools as part of the compilation pipeline, we
546 -- pass these a sequence of options on the command-line. Rather than
547 -- just using a list of Strings, we use a type that allows us to distinguish
548 -- between filepaths and 'other stuff'. [The reason being, of course, that
549 -- this type gives us a handle on transforming filenames, and filenames only,
550 -- to whatever format they're expected to be on a particular platform.]
553 = FileOption -- an entry that _contains_ filename(s) / filepaths.
554 String -- a non-filepath prefix that shouldn't be
555 -- transformed (e.g., "/out=")
556 String -- the filepath/filename portion
559 -----------------------------------------------------------------------------
560 -- Setting the optimisation level
562 updOptLevel :: Int -> DynFlags -> DynFlags
563 -- Set dynflags appropriate to the optimisation level
565 = dfs2{ optLevel = n }
567 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
568 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
570 extra_dopts = [ f | (ns,f) <- optLevelFlags, n `elem` ns ]
571 remove_dopts = [ f | (ns,f) <- optLevelFlags, n `notElem` ns ]
573 optLevelFlags :: [([Int], DynFlag)]
575 = [ ([0], Opt_IgnoreInterfacePragmas)
576 , ([0], Opt_OmitInterfacePragmas)
577 , ([1,2], Opt_IgnoreAsserts)
578 , ([1,2], Opt_DoEtaReduction)
579 , ([1,2], Opt_CaseMerge)
580 , ([1,2], Opt_Strictness)
582 , ([1,2], Opt_FullLaziness)
583 , ([2], Opt_LiberateCase)
584 , ([2], Opt_SpecConstr)
586 , ([0,1,2], Opt_DoLambdaEtaExpansion)
587 -- This one is important for a tiresome reason:
588 -- we want to make sure that the bindings for data
589 -- constructors are eta-expanded. This is probably
590 -- a good thing anyway, but it seems fragile.
593 -- -----------------------------------------------------------------------------
594 -- Standard sets of warning options
597 = [ Opt_WarnDeprecations,
598 Opt_WarnOverlappingPatterns,
599 Opt_WarnMissingFields,
600 Opt_WarnMissingMethods,
601 Opt_WarnDuplicateExports
605 = standardWarnings ++
606 [ Opt_WarnUnusedBinds,
607 Opt_WarnUnusedMatches,
608 Opt_WarnUnusedImports,
609 Opt_WarnIncompletePatterns,
615 [ Opt_WarnTypeDefaults,
616 Opt_WarnNameShadowing,
622 -- -----------------------------------------------------------------------------
623 -- CoreToDo: abstraction of core-to-core passes to run.
625 data CoreToDo -- These are diff core-to-core passes,
626 -- which may be invoked in any order,
627 -- as many times as you like.
629 = CoreDoSimplify -- The core-to-core simplifier.
632 -- Each run of the simplifier can take a different
633 -- set of simplifier-specific flags.
635 | CoreDoFloatOutwards FloatOutSwitches
640 | CoreDoWorkerWrapper
643 | CoreDoOldStrictness
646 | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules
647 -- matching this string
648 | CoreDoNothing -- Useful when building up
649 | CoreDoPasses [CoreToDo] -- lists of these things
651 data SimplifierMode -- See comments in SimplMonad
655 data SimplifierSwitch
656 = MaxSimplifierIterations Int
659 data FloatOutSwitches
660 = FloatOutSw Bool -- True <=> float lambdas to top level
661 Bool -- True <=> float constants to top level,
662 -- even if they do not escape a lambda
665 -- The core-to-core pass ordering is derived from the DynFlags:
666 runWhen :: Bool -> CoreToDo -> CoreToDo
667 runWhen True do_this = do_this
668 runWhen False do_this = CoreDoNothing
670 getCoreToDo :: DynFlags -> [CoreToDo]
672 | Just todo <- coreToDo dflags = todo -- set explicitly by user
673 | otherwise = core_todo
675 opt_level = optLevel dflags
676 max_iter = maxSimplIterations dflags
677 strictness = dopt Opt_Strictness dflags
678 full_laziness = dopt Opt_FullLaziness dflags
679 cse = dopt Opt_CSE dflags
680 spec_constr = dopt Opt_SpecConstr dflags
681 liberate_case = dopt Opt_LiberateCase dflags
682 rule_check = ruleCheck dflags
685 if opt_level == 0 then
687 CoreDoSimplify (SimplPhase 0) [
688 MaxSimplifierIterations max_iter
691 else {- opt_level >= 1 -} [
693 -- initial simplify: mk specialiser happy: minimum effort please
694 CoreDoSimplify SimplGently [
696 -- Don't inline anything till full laziness has bitten
697 -- In particular, inlining wrappers inhibits floating
698 -- e.g. ...(case f x of ...)...
699 -- ==> ...(case (case x of I# x# -> fw x#) of ...)...
700 -- ==> ...(case x of I# x# -> case fw x# of ...)...
701 -- and now the redex (f x) isn't floatable any more
702 -- Similarly, don't apply any rules until after full
703 -- laziness. Notably, list fusion can prevent floating.
705 NoCaseOfCase, -- Don't do case-of-case transformations.
706 -- This makes full laziness work better
707 MaxSimplifierIterations max_iter
710 -- Specialisation is best done before full laziness
711 -- so that overloaded functions have all their dictionary lambdas manifest
714 runWhen full_laziness (CoreDoFloatOutwards (FloatOutSw False False)),
718 CoreDoSimplify (SimplPhase 2) [
719 -- Want to run with inline phase 2 after the specialiser to give
720 -- maximum chance for fusion to work before we inline build/augment
721 -- in phase 1. This made a difference in 'ansi' where an
722 -- overloaded function wasn't inlined till too late.
723 MaxSimplifierIterations max_iter
725 case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
727 CoreDoSimplify (SimplPhase 1) [
728 -- Need inline-phase2 here so that build/augment get
729 -- inlined. I found that spectral/hartel/genfft lost some useful
730 -- strictness in the function sumcode' if augment is not inlined
731 -- before strictness analysis runs
732 MaxSimplifierIterations max_iter
734 case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
736 CoreDoSimplify (SimplPhase 0) [
737 -- Phase 0: allow all Ids to be inlined now
738 -- This gets foldr inlined before strictness analysis
740 MaxSimplifierIterations 3
741 -- At least 3 iterations because otherwise we land up with
742 -- huge dead expressions because of an infelicity in the
744 -- let k = BIG in foldr k z xs
745 -- ==> let k = BIG in letrec go = \xs -> ...(k x).... in go xs
746 -- ==> let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
750 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
752 #ifdef OLD_STRICTNESS
755 runWhen strictness (CoreDoPasses [
759 CoreDoSimplify (SimplPhase 0) [
760 MaxSimplifierIterations max_iter
763 runWhen full_laziness
764 (CoreDoFloatOutwards (FloatOutSw False -- Not lambdas
765 True)), -- Float constants
766 -- nofib/spectral/hartel/wang doubles in speed if you
767 -- do full laziness late in the day. It only happens
768 -- after fusion and other stuff, so the early pass doesn't
769 -- catch it. For the record, the redex is
770 -- f_el22 (f_el21 r_midblock)
774 -- We want CSE to follow the final full-laziness pass, because it may
775 -- succeed in commoning up things floated out by full laziness.
776 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
780 case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
782 -- Case-liberation for -O2. This should be after
783 -- strictness analysis and the simplification which follows it.
784 runWhen liberate_case (CoreDoPasses [
786 CoreDoSimplify (SimplPhase 0) [
787 MaxSimplifierIterations max_iter
788 ] ]), -- Run the simplifier after LiberateCase to vastly
789 -- reduce the possiblility of shadowing
790 -- Reason: see Note [Shadowing] in SpecConstr.lhs
792 runWhen spec_constr CoreDoSpecConstr,
794 -- Final clean-up simplification:
795 CoreDoSimplify (SimplPhase 0) [
796 MaxSimplifierIterations max_iter
800 -- -----------------------------------------------------------------------------
801 -- StgToDo: abstraction of stg-to-stg passes to run.
804 = StgDoMassageForProfiling -- should be (next to) last
805 -- There's also setStgVarInfo, but its absolute "lastness"
806 -- is so critical that it is hardwired in (no flag).
809 getStgToDo :: DynFlags -> [StgToDo]
811 | Just todo <- stgToDo dflags = todo -- set explicitly by user
814 stg_stats = dopt Opt_StgStats dflags
816 todo1 = if stg_stats then [D_stg_stats] else []
818 todo2 | WayProf `elem` wayNames dflags
819 = StgDoMassageForProfiling : todo1
823 -- -----------------------------------------------------------------------------
827 allFlags = map ('-':) $
828 [ name | (name, optkind) <- dynamic_flags, ok optkind ] ++
829 map ("fno-"++) flags ++
831 where ok (PrefixPred _ _) = False
833 flags = map fst fFlags
835 dynamic_flags :: [(String, OptKind DynP)]
837 ( "n" , NoArg (setDynFlag Opt_DryRun) )
838 , ( "cpp" , NoArg (setDynFlag Opt_Cpp))
839 , ( "F" , NoArg (setDynFlag Opt_Pp))
840 , ( "#include" , HasArg (addCmdlineHCInclude) )
841 , ( "v" , OptIntSuffix setVerbosity )
843 ------- Specific phases --------------------------------------------
844 , ( "pgmL" , HasArg (upd . setPgmL) )
845 , ( "pgmP" , HasArg (upd . setPgmP) )
846 , ( "pgmF" , HasArg (upd . setPgmF) )
847 , ( "pgmc" , HasArg (upd . setPgmc) )
848 , ( "pgmm" , HasArg (upd . setPgmm) )
849 , ( "pgms" , HasArg (upd . setPgms) )
850 , ( "pgma" , HasArg (upd . setPgma) )
851 , ( "pgml" , HasArg (upd . setPgml) )
852 , ( "pgmdll" , HasArg (upd . setPgmdll) )
854 , ( "optL" , HasArg (upd . addOptL) )
855 , ( "optP" , HasArg (upd . addOptP) )
856 , ( "optF" , HasArg (upd . addOptF) )
857 , ( "optc" , HasArg (upd . addOptc) )
858 , ( "optm" , HasArg (upd . addOptm) )
859 , ( "opta" , HasArg (upd . addOpta) )
860 , ( "optl" , HasArg (upd . addOptl) )
861 , ( "optdll" , HasArg (upd . addOptdll) )
862 , ( "optdep" , HasArg (upd . addOptdep) )
864 , ( "split-objs" , NoArg (if can_split
865 then setDynFlag Opt_SplitObjs
868 -------- Linking ----------------------------------------------------
869 , ( "c" , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
870 , ( "no-link" , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
871 , ( "-mk-dll" , NoArg (upd $ \d -> d{ ghcLink=MkDLL } ))
873 ------- Libraries ---------------------------------------------------
874 , ( "L" , Prefix addLibraryPath )
875 , ( "l" , AnySuffix (\s -> do upd (addOptl s)
878 ------- Frameworks --------------------------------------------------
879 -- -framework-path should really be -F ...
880 , ( "framework-path" , HasArg addFrameworkPath )
881 , ( "framework" , HasArg (upd . addCmdlineFramework) )
883 ------- Output Redirection ------------------------------------------
884 , ( "odir" , HasArg (upd . setObjectDir . Just))
885 , ( "o" , SepArg (upd . setOutputFile . Just))
886 , ( "ohi" , HasArg (upd . setOutputHi . Just ))
887 , ( "osuf" , HasArg (upd . setObjectSuf))
888 , ( "hcsuf" , HasArg (upd . setHcSuf))
889 , ( "hisuf" , HasArg (upd . setHiSuf))
890 , ( "hidir" , HasArg (upd . setHiDir . Just))
891 , ( "tmpdir" , HasArg (upd . setTmpDir))
892 , ( "stubdir" , HasArg (upd . setStubDir . Just))
894 ------- Keeping temporary files -------------------------------------
895 , ( "keep-hc-file" , AnySuffix (\_ -> setDynFlag Opt_KeepHcFiles))
896 , ( "keep-s-file" , AnySuffix (\_ -> setDynFlag Opt_KeepSFiles))
897 , ( "keep-raw-s-file", AnySuffix (\_ -> setDynFlag Opt_KeepRawSFiles))
898 , ( "keep-tmp-files" , AnySuffix (\_ -> setDynFlag Opt_KeepTmpFiles))
900 ------- Miscellaneous ----------------------------------------------
901 , ( "no-hs-main" , NoArg (setDynFlag Opt_NoHsMain))
902 , ( "main-is" , SepArg setMainIs )
903 , ( "haddock" , NoArg (setDynFlag Opt_Haddock) )
904 , ( "hpcdir" , SepArg setOptHpcDir )
906 ------- recompilation checker (DEPRECATED, use -fforce-recomp) -----
907 , ( "recomp" , NoArg (unSetDynFlag Opt_ForceRecomp) )
908 , ( "no-recomp" , NoArg (setDynFlag Opt_ForceRecomp) )
910 ------- Packages ----------------------------------------------------
911 , ( "package-conf" , HasArg extraPkgConf_ )
912 , ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
913 , ( "package-name" , HasArg (upd . setPackageName) )
914 , ( "package" , HasArg exposePackage )
915 , ( "hide-package" , HasArg hidePackage )
916 , ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
917 , ( "ignore-package" , HasArg ignorePackage )
918 , ( "syslib" , HasArg exposePackage ) -- for compatibility
920 ------ HsCpp opts ---------------------------------------------------
921 , ( "D", AnySuffix (upd . addOptP) )
922 , ( "U", AnySuffix (upd . addOptP) )
924 ------- Include/Import Paths ----------------------------------------
925 , ( "I" , Prefix addIncludePath)
926 , ( "i" , OptPrefix addImportPath )
928 ------ Debugging ----------------------------------------------------
929 , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats))
931 , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm)
932 , ( "ddump-asm", setDumpFlag Opt_D_dump_asm)
933 , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal)
934 , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv)
935 , ( "ddump-ds", setDumpFlag Opt_D_dump_ds)
936 , ( "ddump-flatC", setDumpFlag Opt_D_dump_flatC)
937 , ( "ddump-foreign", setDumpFlag Opt_D_dump_foreign)
938 , ( "ddump-inlinings", setDumpFlag Opt_D_dump_inlinings)
939 , ( "ddump-rule-firings", setDumpFlag Opt_D_dump_rule_firings)
940 , ( "ddump-occur-anal", setDumpFlag Opt_D_dump_occur_anal)
941 , ( "ddump-parsed", setDumpFlag Opt_D_dump_parsed)
942 , ( "ddump-rn", setDumpFlag Opt_D_dump_rn)
943 , ( "ddump-simpl", setDumpFlag Opt_D_dump_simpl)
944 , ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
945 , ( "ddump-spec", setDumpFlag Opt_D_dump_spec)
946 , ( "ddump-prep", setDumpFlag Opt_D_dump_prep)
947 , ( "ddump-stg", setDumpFlag Opt_D_dump_stg)
948 , ( "ddump-stranal", setDumpFlag Opt_D_dump_stranal)
949 , ( "ddump-tc", setDumpFlag Opt_D_dump_tc)
950 , ( "ddump-types", setDumpFlag Opt_D_dump_types)
951 , ( "ddump-rules", setDumpFlag Opt_D_dump_rules)
952 , ( "ddump-cse", setDumpFlag Opt_D_dump_cse)
953 , ( "ddump-worker-wrapper", setDumpFlag Opt_D_dump_worker_wrapper)
954 , ( "ddump-rn-trace", setDumpFlag Opt_D_dump_rn_trace)
955 , ( "ddump-if-trace", setDumpFlag Opt_D_dump_if_trace)
956 , ( "ddump-tc-trace", setDumpFlag Opt_D_dump_tc_trace)
957 , ( "ddump-splices", setDumpFlag Opt_D_dump_splices)
958 , ( "ddump-rn-stats", setDumpFlag Opt_D_dump_rn_stats)
959 , ( "ddump-opt-cmm", setDumpFlag Opt_D_dump_opt_cmm)
960 , ( "ddump-simpl-stats", setDumpFlag Opt_D_dump_simpl_stats)
961 , ( "ddump-bcos", setDumpFlag Opt_D_dump_BCOs)
962 , ( "dsource-stats", setDumpFlag Opt_D_source_stats)
963 , ( "dverbose-core2core", setDumpFlag Opt_D_verbose_core2core)
964 , ( "dverbose-stg2stg", setDumpFlag Opt_D_verbose_stg2stg)
965 , ( "ddump-hi-diffs", setDumpFlag Opt_D_dump_hi_diffs)
966 , ( "ddump-hi", setDumpFlag Opt_D_dump_hi)
967 , ( "ddump-minimal-imports", setDumpFlag Opt_D_dump_minimal_imports)
968 , ( "ddump-vect", setDumpFlag Opt_D_dump_vect)
969 , ( "ddump-hpc", setDumpFlag Opt_D_dump_hpc)
970 , ( "ddump-mod-cycles", setDumpFlag Opt_D_dump_mod_cycles)
972 , ( "dcore-lint", NoArg (setDynFlag Opt_DoCoreLinting))
973 , ( "dstg-lint", NoArg (setDynFlag Opt_DoStgLinting))
974 , ( "dcmm-lint", NoArg (setDynFlag Opt_DoCmmLinting))
975 , ( "dshow-passes", NoArg (do setDynFlag Opt_ForceRecomp
976 setVerbosity (Just 2)) )
977 , ( "dfaststring-stats", NoArg (setDynFlag Opt_D_faststring_stats))
979 ------ Machine dependant (-m<blah>) stuff ---------------------------
981 , ( "monly-2-regs", NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
982 , ( "monly-3-regs", NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
983 , ( "monly-4-regs", NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
985 ------ Warning opts -------------------------------------------------
986 , ( "W" , NoArg (mapM_ setDynFlag minusWOpts) )
987 , ( "Werror" , NoArg (setDynFlag Opt_WarnIsError) )
988 , ( "Wall" , NoArg (mapM_ setDynFlag minusWallOpts) )
989 , ( "Wnot" , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
990 , ( "w" , NoArg (mapM_ unSetDynFlag minusWallOpts) )
992 ------ Optimisation flags ------------------------------------------
993 , ( "O" , NoArg (upd (setOptLevel 1)))
994 , ( "Onot" , NoArg (upd (setOptLevel 0)))
995 , ( "O" , OptIntSuffix (\mb_n -> upd (setOptLevel (mb_n `orElse` 1))))
996 -- If the number is missing, use 1
998 , ( "fmax-simplifier-iterations", IntSuffix (\n ->
999 upd (\dfs -> dfs{ maxSimplIterations = n })) )
1001 -- liberate-case-threshold is an old flag for '-fspec-threshold'
1002 , ( "fspec-threshold", IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1003 , ( "fliberate-case-threshold", IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1005 , ( "frule-check", SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
1006 , ( "fcontext-stack" , IntSuffix $ \n -> upd $ \dfs -> dfs{ ctxtStkDepth = n })
1008 ------ Compiler flags -----------------------------------------------
1010 , ( "fasm", AnySuffix (\_ -> setObjTarget HscAsm) )
1011 , ( "fvia-c", NoArg (setObjTarget HscC) )
1012 , ( "fvia-C", NoArg (setObjTarget HscC) )
1014 , ( "fno-code", NoArg (setTarget HscNothing))
1015 , ( "fbyte-code", NoArg (setTarget HscInterpreted) )
1016 , ( "fobject-code", NoArg (setTarget defaultHscTarget) )
1018 , ( "fglasgow-exts", NoArg (mapM_ setDynFlag glasgowExtsFlags) )
1019 , ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
1022 -- the rest of the -f* and -fno-* flags
1023 , ( "fno-", PrefixPred (\f -> isFFlag f) (\f -> unSetDynFlag (getFFlag f)) )
1024 , ( "f", PrefixPred (\f -> isFFlag f) (\f -> setDynFlag (getFFlag f)) )
1027 -- these -f<blah> flags can all be reversed with -fno-<blah>
1030 ( "warn-duplicate-exports", Opt_WarnDuplicateExports ),
1031 ( "warn-hi-shadowing", Opt_WarnHiShadows ),
1032 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns ),
1033 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd ),
1034 ( "warn-missing-fields", Opt_WarnMissingFields ),
1035 ( "warn-missing-methods", Opt_WarnMissingMethods ),
1036 ( "warn-missing-signatures", Opt_WarnMissingSigs ),
1037 ( "warn-name-shadowing", Opt_WarnNameShadowing ),
1038 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns ),
1039 ( "warn-simple-patterns", Opt_WarnSimplePatterns ),
1040 ( "warn-type-defaults", Opt_WarnTypeDefaults ),
1041 ( "warn-unused-binds", Opt_WarnUnusedBinds ),
1042 ( "warn-unused-imports", Opt_WarnUnusedImports ),
1043 ( "warn-unused-matches", Opt_WarnUnusedMatches ),
1044 ( "warn-deprecations", Opt_WarnDeprecations ),
1045 ( "warn-orphans", Opt_WarnOrphans ),
1046 ( "warn-tabs", Opt_WarnTabs ),
1047 ( "fi", Opt_FFI ), -- support `-ffi'...
1048 ( "ffi", Opt_FFI ), -- ...and also `-fffi'
1049 ( "arrows", Opt_Arrows ), -- arrow syntax
1050 ( "parr", Opt_PArr ),
1052 ( "implicit-prelude", Opt_ImplicitPrelude ),
1053 ( "scoped-type-variables", Opt_ScopedTypeVariables ),
1054 ( "bang-patterns", Opt_BangPatterns ),
1055 ( "overloaded-strings", Opt_OverloadedStrings ),
1056 ( "indexed-types", Opt_IndexedTypes ),
1057 ( "monomorphism-restriction", Opt_MonomorphismRestriction ),
1058 ( "mono-pat-binds", Opt_MonoPatBinds ),
1059 ( "extended-default-rules", Opt_ExtendedDefaultRules ),
1060 ( "implicit-params", Opt_ImplicitParams ),
1061 ( "allow-overlapping-instances", Opt_AllowOverlappingInstances ),
1062 ( "allow-undecidable-instances", Opt_AllowUndecidableInstances ),
1063 ( "allow-incoherent-instances", Opt_AllowIncoherentInstances ),
1064 ( "generics", Opt_Generics ),
1065 ( "strictness", Opt_Strictness ),
1066 ( "full-laziness", Opt_FullLaziness ),
1067 ( "liberate-case", Opt_LiberateCase ),
1068 ( "spec-constr", Opt_SpecConstr ),
1070 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas ),
1071 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas ),
1072 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion ),
1073 ( "ignore-asserts", Opt_IgnoreAsserts ),
1074 ( "ignore-breakpoints", Opt_IgnoreBreakpoints),
1075 ( "do-eta-reduction", Opt_DoEtaReduction ),
1076 ( "case-merge", Opt_CaseMerge ),
1077 ( "unbox-strict-fields", Opt_UnboxStrictFields ),
1078 ( "dicts-cheap", Opt_DictsCheap ),
1079 ( "excess-precision", Opt_ExcessPrecision ),
1080 ( "asm-mangling", Opt_DoAsmMangling ),
1081 ( "print-bind-result", Opt_PrintBindResult ),
1082 #if defined(GHCI) && defined(DEBUGGER)
1083 ( "debugging", Opt_Debugging),
1085 ( "force-recomp", Opt_ForceRecomp ),
1086 ( "hpc-no-auto", Opt_Hpc_No_Auto )
1090 glasgowExtsFlags = [
1094 Opt_ScopedTypeVariables,
1097 isFFlag f = f `elem` (map fst fFlags)
1098 getFFlag f = fromJust (lookup f fFlags)
1100 -- -----------------------------------------------------------------------------
1101 -- Parsing the dynamic flags.
1103 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
1104 parseDynamicFlags dflags args = do
1105 let ((leftover,errs),dflags')
1106 = runCmdLine (processArgs dynamic_flags args) dflags
1107 when (not (null errs)) $ do
1108 throwDyn (UsageError (unlines errs))
1109 return (dflags', leftover)
1112 type DynP = CmdLineP DynFlags
1114 upd :: (DynFlags -> DynFlags) -> DynP ()
1116 dfs <- getCmdLineState
1117 putCmdLineState $! (f dfs)
1119 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1120 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1121 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1123 setDumpFlag :: DynFlag -> OptKind DynP
1124 setDumpFlag dump_flag
1125 = NoArg (setDynFlag Opt_ForceRecomp >> setDynFlag dump_flag)
1126 -- Whenver we -ddump, switch off the recompilation checker,
1127 -- else you don't see the dump!
1129 setVerbosity :: Maybe Int -> DynP ()
1130 setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
1132 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1134 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1137 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1139 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1141 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1144 | Nothing <- unpackPackageId pid
1145 = throwDyn (CmdLineError ("cannot parse \'" ++ p ++ "\' as a package identifier"))
1147 = \s -> s{ thisPackage = pid }
1149 pid = stringToPackageId p
1151 -- If we're linking a binary, then only targets that produce object
1152 -- code are allowed (requests for other target types are ignored).
1153 setTarget l = upd set
1156 | ghcLink dfs /= LinkBinary || isObjectTarget l = dfs{ hscTarget = l }
1159 -- Changes the target only if we're compiling object code. This is
1160 -- used by -fasm and -fvia-C, which switch from one to the other, but
1161 -- not from bytecode to object-code. The idea is that -fasm/-fvia-C
1162 -- can be safely used in an OPTIONS_GHC pragma.
1163 setObjTarget l = upd set
1166 | isObjectTarget (hscTarget dfs) = dfs { hscTarget = l }
1169 setOptLevel :: Int -> DynFlags -> DynFlags
1170 setOptLevel n dflags
1171 | hscTarget dflags == HscInterpreted && n > 0
1173 -- not in IO any more, oh well:
1174 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1176 = updOptLevel n dflags
1179 setMainIs :: String -> DynP ()
1181 | not (null main_fn) -- The arg looked like "Foo.baz"
1182 = upd $ \d -> d{ mainFunIs = Just main_fn,
1183 mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
1185 | isUpper (head main_mod) -- The arg looked like "Foo"
1186 = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
1188 | otherwise -- The arg looked like "baz"
1189 = upd $ \d -> d{ mainFunIs = Just main_mod }
1191 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1193 -----------------------------------------------------------------------------
1194 -- Paths & Libraries
1196 -- -i on its own deletes the import paths
1197 addImportPath "" = upd (\s -> s{importPaths = []})
1198 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1202 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1205 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1207 addFrameworkPath p =
1208 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1210 split_marker = ':' -- not configurable (ToDo)
1212 splitPathList :: String -> [String]
1213 splitPathList s = filter notNull (splitUp s)
1214 -- empty paths are ignored: there might be a trailing
1215 -- ':' in the initial list, for example. Empty paths can
1216 -- cause confusion when they are translated into -I options
1217 -- for passing to gcc.
1219 #ifndef mingw32_TARGET_OS
1220 splitUp xs = split split_marker xs
1222 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1224 -- That is, if "foo:bar:baz" is used, this interpreted as
1225 -- consisting of three entries, 'foo', 'bar', 'baz'.
1226 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1227 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1229 -- Notice that no attempt is made to fully replace the 'standard'
1230 -- split marker ':' with the Windows / DOS one, ';'. The reason being
1231 -- that this will cause too much breakage for users & ':' will
1232 -- work fine even with DOS paths, if you're not insisting on being silly.
1235 splitUp (x:':':div:xs) | div `elem` dir_markers
1236 = ((x:':':div:p): splitUp rs)
1238 (p,rs) = findNextPath xs
1239 -- we used to check for existence of the path here, but that
1240 -- required the IO monad to be threaded through the command-line
1241 -- parser which is quite inconvenient. The
1242 splitUp xs = cons p (splitUp rs)
1244 (p,rs) = findNextPath xs
1249 -- will be called either when we've consumed nought or the
1250 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1251 -- finding the next split marker.
1253 case break (`elem` split_markers) xs of
1254 (p, d:ds) -> (p, ds)
1257 split_markers :: [Char]
1258 split_markers = [':', ';']
1260 dir_markers :: [Char]
1261 dir_markers = ['/', '\\']
1264 -- -----------------------------------------------------------------------------
1265 -- tmpDir, where we store temporary files.
1267 setTmpDir :: FilePath -> DynFlags -> DynFlags
1268 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1270 #if !defined(mingw32_HOST_OS)
1271 canonicalise p = normalisePath p
1273 -- Canonicalisation of temp path under win32 is a bit more
1274 -- involved: (a) strip trailing slash,
1275 -- (b) normalise slashes
1276 -- (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1278 canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1280 -- if we're operating under cygwin, and TMP/TEMP is of
1281 -- the form "/cygdrive/drive/path", translate this to
1282 -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1283 -- understand /cygdrive paths.)
1285 | "/cygdrive/" `isPrefixOf` path =
1286 case drop (length "/cygdrive/") path of
1287 drive:xs@('/':_) -> drive:':':xs
1291 -- strip the trailing backslash (awful, but we only do this once).
1292 removeTrailingSlash path =
1299 -----------------------------------------------------------------------------
1302 setOptHpcDir :: String -> DynP ()
1303 setOptHpcDir arg = upd $ \ d -> d{hpcDir = arg}
1305 -----------------------------------------------------------------------------
1306 -- Via-C compilation stuff
1308 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1309 [String]) -- for registerised HC compilations
1310 machdepCCOpts dflags
1311 #if alpha_TARGET_ARCH
1313 #ifdef HAVE_THREADED_RTS_SUPPORT
1317 -- For now, to suppress the gcc warning "call-clobbered
1318 -- register used for global register variable", we simply
1319 -- disable all warnings altogether using the -w flag. Oh well.
1321 #elif hppa_TARGET_ARCH
1322 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1323 -- (very nice, but too bad the HP /usr/include files don't agree.)
1324 = ( ["-D_HPUX_SOURCE"], [] )
1326 #elif m68k_TARGET_ARCH
1327 -- -fno-defer-pop : for the .hc files, we want all the pushing/
1328 -- popping of args to routines to be explicit; if we let things
1329 -- be deferred 'til after an STGJUMP, imminent death is certain!
1331 -- -fomit-frame-pointer : *don't*
1332 -- It's better to have a6 completely tied up being a frame pointer
1333 -- rather than let GCC pick random things to do with it.
1334 -- (If we want to steal a6, then we would try to do things
1335 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
1336 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1338 #elif i386_TARGET_ARCH
1339 -- -fno-defer-pop : basically the same game as for m68k
1341 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1342 -- the fp (%ebp) for our register maps.
1343 = let n_regs = stolen_x86_regs dflags
1346 ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1347 -- , if suffixMatch "mingw32" cTARGETPLATFORM then "-mno-cygwin" else ""
1350 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1351 -- Some gccs are configured with
1352 -- -momit-leaf-frame-pointer on by default, and it
1353 -- apparently takes precedence over
1354 -- -fomit-frame-pointer, so we disable it first here.
1355 "-mno-omit-leaf-frame-pointer",
1357 #ifdef HAVE_GCC_HAS_NO_UNIT_AT_A_TIME
1358 "-fno-unit-at-a-time",
1359 -- unit-at-a-time doesn't do us any good, and screws
1360 -- up -split-objs by moving the split markers around.
1361 -- It's only turned on with -O2, but put it here just
1362 -- in case someone uses -optc-O2.
1364 "-fomit-frame-pointer",
1365 -- we want -fno-builtin, because when gcc inlines
1366 -- built-in functions like memcpy() it tends to
1367 -- run out of registers, requiring -monly-n-regs
1369 "-DSTOLEN_X86_REGS="++show n_regs ]
1372 #elif ia64_TARGET_ARCH
1373 = ( [], ["-fomit-frame-pointer", "-G0"] )
1375 #elif x86_64_TARGET_ARCH
1376 = ( [], ["-fomit-frame-pointer",
1377 "-fno-asynchronous-unwind-tables",
1378 -- the unwind tables are unnecessary for HC code,
1379 -- and get in the way of -split-objs. Another option
1380 -- would be to throw them away in the mangler, but this
1382 #ifdef HAVE_GCC_HAS_NO_UNIT_AT_A_TIME
1383 "-fno-unit-at-a-time",
1384 -- unit-at-a-time doesn't do us any good, and screws
1385 -- up -split-objs by moving the split markers around.
1386 -- It's only turned on with -O2, but put it here just
1387 -- in case someone uses -optc-O2.
1390 -- calling builtins like strlen() using the FFI can
1391 -- cause gcc to run out of regs, so use the external
1395 #elif sparc_TARGET_ARCH
1397 -- For now, to suppress the gcc warning "call-clobbered
1398 -- register used for global register variable", we simply
1399 -- disable all warnings altogether using the -w flag. Oh well.
1401 #elif powerpc_apple_darwin_TARGET
1403 -- Disable Apple's precompiling preprocessor. It's a great thing
1404 -- for "normal" programs, but it doesn't support register variable
1406 = ( [], ["-no-cpp-precomp"] )
1411 picCCOpts :: DynFlags -> [String]
1413 #if darwin_TARGET_OS
1414 -- Apple prefers to do things the other way round.
1415 -- PIC is on by default.
1416 -- -mdynamic-no-pic:
1417 -- Turn off PIC code generation.
1419 -- Don't generate "common" symbols - these are unwanted
1420 -- in dynamic libraries.
1425 = ["-mdynamic-no-pic"]
1426 #elif mingw32_TARGET_OS
1427 -- no -fPIC for Windows
1436 -- -----------------------------------------------------------------------------
1441 #if defined(i386_TARGET_ARCH) \
1442 || defined(x86_64_TARGET_ARCH) \
1443 || defined(alpha_TARGET_ARCH) \
1444 || defined(hppa_TARGET_ARCH) \
1445 || defined(m68k_TARGET_ARCH) \
1446 || defined(mips_TARGET_ARCH) \
1447 || defined(powerpc_TARGET_ARCH) \
1448 || defined(rs6000_TARGET_ARCH) \
1449 || defined(sparc_TARGET_ARCH)