Add separate functions for querying DynFlag and ExtensionFlag options
[ghc.git] / compiler / main / DynFlags.hs
1 {-# OPTIONS_GHC -w #-}
2 -- Temporary, until rtsIsProfiled is fixed
3
4 -- |
5 -- Dynamic flags
6 --
7 --
8 -- (c) The University of Glasgow 2005
9 --
10
11 -- Most flags are dynamic flags, which means they can change from
12 -- compilation to compilation using @OPTIONS_GHC@ pragmas, and in a
13 -- multi-session GHC each session can be using different dynamic
14 -- flags. Dynamic flags can also be set at the prompt in GHCi.
15 module DynFlags (
16 -- * Dynamic flags and associated configuration types
17 DynFlag(..),
18 ExtensionFlag(..),
19 glasgowExtsFlags,
20 flattenExtensionFlags,
21 ensureFlattenedExtensionFlags,
22 dopt,
23 dopt_set,
24 dopt_unset,
25 xopt,
26 xopt_set,
27 xopt_unset,
28 xopt_set_flattened,
29 xopt_unset_flattened,
30 DynFlags(..),
31 RtsOptsEnabled(..),
32 HscTarget(..), isObjectTarget, defaultObjectTarget,
33 GhcMode(..), isOneShot,
34 GhcLink(..), isNoLink,
35 PackageFlag(..),
36 Option(..), showOpt,
37 DynLibLoader(..),
38 fFlags, fLangFlags, xFlags,
39 dphPackage,
40 wayNames,
41
42 -- ** Manipulating DynFlags
43 defaultDynFlags, -- DynFlags
44 initDynFlags, -- DynFlags -> IO DynFlags
45
46 getOpts, -- DynFlags -> (DynFlags -> [a]) -> [a]
47 getVerbFlag,
48 updOptLevel,
49 setTmpDir,
50 setPackageName,
51 doingTickyProfiling,
52
53 -- ** Parsing DynFlags
54 parseDynamicFlags,
55 parseDynamicNoPackageFlags,
56 allFlags,
57
58 supportedLanguagesAndExtensions,
59
60 -- ** DynFlag C compiler options
61 machdepCCOpts, picCCOpts,
62
63 -- * Configuration of the stg-to-stg passes
64 StgToDo(..),
65 getStgToDo,
66
67 -- * Compiler configuration suitable for display to the user
68 Printable(..),
69 compilerInfo
70 #ifdef GHCI
71 -- Only in stage 2 can we be sure that the RTS
72 -- exposes the appropriate runtime boolean
73 , rtsIsProfiled
74 #endif
75 ) where
76
77 #include "HsVersions.h"
78
79 #ifndef OMIT_NATIVE_CODEGEN
80 import Platform
81 #endif
82 import Module
83 import PackageConfig
84 import PrelNames ( mAIN )
85 import StaticFlags
86 import {-# SOURCE #-} Packages (PackageState)
87 import DriverPhases ( Phase(..), phaseInputExt )
88 import Config
89 import CmdLineParser
90 import Constants ( mAX_CONTEXT_REDUCTION_DEPTH )
91 import Panic
92 import Util
93 import Maybes ( orElse )
94 import SrcLoc
95 import FastString
96 import Outputable
97 import Foreign.C ( CInt )
98 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
99
100 import System.IO.Unsafe ( unsafePerformIO )
101 import Data.IORef
102 import Control.Monad ( when )
103
104 import Data.Char
105 import Data.List
106 import Data.Map (Map)
107 import qualified Data.Map as Map
108 import System.FilePath
109 import System.IO ( stderr, hPutChar )
110
111 -- -----------------------------------------------------------------------------
112 -- DynFlags
113
114 -- | Enumerates the simple on-or-off dynamic flags
115 data DynFlag
116
117 -- debugging flags
118 = Opt_D_dump_cmm
119 | Opt_D_dump_cmmz
120 | Opt_D_dump_cmmz_pretty
121 | Opt_D_dump_cps_cmm
122 | Opt_D_dump_cvt_cmm
123 | Opt_D_dump_asm
124 | Opt_D_dump_asm_native
125 | Opt_D_dump_asm_liveness
126 | Opt_D_dump_asm_coalesce
127 | Opt_D_dump_asm_regalloc
128 | Opt_D_dump_asm_regalloc_stages
129 | Opt_D_dump_asm_conflicts
130 | Opt_D_dump_asm_stats
131 | Opt_D_dump_asm_expanded
132 | Opt_D_dump_llvm
133 | Opt_D_dump_cpranal
134 | Opt_D_dump_deriv
135 | Opt_D_dump_ds
136 | Opt_D_dump_flatC
137 | Opt_D_dump_foreign
138 | Opt_D_dump_inlinings
139 | Opt_D_dump_rule_firings
140 | Opt_D_dump_occur_anal
141 | Opt_D_dump_parsed
142 | Opt_D_dump_rn
143 | Opt_D_dump_simpl
144 | Opt_D_dump_simpl_iterations
145 | Opt_D_dump_simpl_phases
146 | Opt_D_dump_spec
147 | Opt_D_dump_prep
148 | Opt_D_dump_stg
149 | Opt_D_dump_stranal
150 | Opt_D_dump_tc
151 | Opt_D_dump_types
152 | Opt_D_dump_rules
153 | Opt_D_dump_cse
154 | Opt_D_dump_worker_wrapper
155 | Opt_D_dump_rn_trace
156 | Opt_D_dump_rn_stats
157 | Opt_D_dump_opt_cmm
158 | Opt_D_dump_simpl_stats
159 | Opt_D_dump_tc_trace
160 | Opt_D_dump_if_trace
161 | Opt_D_dump_splices
162 | Opt_D_dump_BCOs
163 | Opt_D_dump_vect
164 | Opt_D_dump_hpc
165 | Opt_D_dump_rtti
166 | Opt_D_source_stats
167 | Opt_D_verbose_core2core
168 | Opt_D_verbose_stg2stg
169 | Opt_D_dump_hi
170 | Opt_D_dump_hi_diffs
171 | Opt_D_dump_minimal_imports
172 | Opt_D_dump_mod_cycles
173 | Opt_D_dump_view_pattern_commoning
174 | Opt_D_faststring_stats
175 | Opt_DumpToFile -- ^ Append dump output to files instead of stdout.
176 | Opt_D_no_debug_output
177 | Opt_DoCoreLinting
178 | Opt_DoStgLinting
179 | Opt_DoCmmLinting
180 | Opt_DoAsmLinting
181
182 | Opt_WarnIsError -- -Werror; makes warnings fatal
183 | Opt_WarnDuplicateExports
184 | Opt_WarnHiShadows
185 | Opt_WarnImplicitPrelude
186 | Opt_WarnIncompletePatterns
187 | Opt_WarnIncompletePatternsRecUpd
188 | Opt_WarnMissingFields
189 | Opt_WarnMissingImportList
190 | Opt_WarnMissingMethods
191 | Opt_WarnMissingSigs
192 | Opt_WarnNameShadowing
193 | Opt_WarnOverlappingPatterns
194 | Opt_WarnSimplePatterns
195 | Opt_WarnTypeDefaults
196 | Opt_WarnMonomorphism
197 | Opt_WarnUnusedBinds
198 | Opt_WarnUnusedImports
199 | Opt_WarnUnusedMatches
200 | Opt_WarnWarningsDeprecations
201 | Opt_WarnDeprecatedFlags
202 | Opt_WarnDodgyExports
203 | Opt_WarnDodgyImports
204 | Opt_WarnOrphans
205 | Opt_WarnTabs
206 | Opt_WarnUnrecognisedPragmas
207 | Opt_WarnDodgyForeignImports
208 | Opt_WarnLazyUnliftedBindings
209 | Opt_WarnUnusedDoBind
210 | Opt_WarnWrongDoBind
211 | Opt_WarnAlternativeLayoutRuleTransitional
212
213 | Opt_PrintExplicitForalls
214
215 -- optimisation opts
216 | Opt_Strictness
217 | Opt_FullLaziness
218 | Opt_FloatIn
219 | Opt_Specialise
220 | Opt_StaticArgumentTransformation
221 | Opt_CSE
222 | Opt_LiberateCase
223 | Opt_SpecConstr
224 | Opt_DoLambdaEtaExpansion
225 | Opt_IgnoreAsserts
226 | Opt_DoEtaReduction
227 | Opt_CaseMerge
228 | Opt_UnboxStrictFields
229 | Opt_MethodSharing
230 | Opt_DictsCheap
231 | Opt_EnableRewriteRules -- Apply rewrite rules during simplification
232 | Opt_Vectorise
233 | Opt_RegsGraph -- do graph coloring register allocation
234 | Opt_RegsIterative -- do iterative coalescing graph coloring register allocation
235
236 -- Interface files
237 | Opt_IgnoreInterfacePragmas
238 | Opt_OmitInterfacePragmas
239 | Opt_ExposeAllUnfoldings
240
241 -- profiling opts
242 | Opt_AutoSccsOnAllToplevs
243 | Opt_AutoSccsOnExportedToplevs
244 | Opt_AutoSccsOnIndividualCafs
245
246 -- misc opts
247 | Opt_Pp
248 | Opt_ForceRecomp
249 | Opt_DryRun
250 | Opt_DoAsmMangling
251 | Opt_ExcessPrecision
252 | Opt_EagerBlackHoling
253 | Opt_ReadUserPackageConf
254 | Opt_NoHsMain
255 | Opt_SplitObjs
256 | Opt_StgStats
257 | Opt_HideAllPackages
258 | Opt_PrintBindResult
259 | Opt_Haddock
260 | Opt_HaddockOptions
261 | Opt_Hpc_No_Auto
262 | Opt_BreakOnException
263 | Opt_BreakOnError
264 | Opt_PrintEvldWithShow
265 | Opt_PrintBindContents
266 | Opt_GenManifest
267 | Opt_EmbedManifest
268 | Opt_EmitExternalCore
269 | Opt_SharedImplib
270 | Opt_BuildingCabalPackage
271 | Opt_SSE2
272
273 -- temporary flags
274 | Opt_RunCPS
275 | Opt_RunCPSZ
276 | Opt_ConvertToZipCfgAndBack
277 | Opt_AutoLinkPackages
278 | Opt_ImplicitImportQualified
279 | Opt_TryNewCodeGen
280
281 -- keeping stuff
282 | Opt_KeepHiDiffs
283 | Opt_KeepHcFiles
284 | Opt_KeepSFiles
285 | Opt_KeepRawSFiles
286 | Opt_KeepTmpFiles
287 | Opt_KeepRawTokenStream
288 | Opt_KeepLlvmFiles
289
290 deriving (Eq, Show)
291
292 data Language = Haskell98 | Haskell2010
293
294 data ExtensionFlag
295 = Opt_Cpp
296 | Opt_OverlappingInstances
297 | Opt_UndecidableInstances
298 | Opt_IncoherentInstances
299 | Opt_MonomorphismRestriction
300 | Opt_MonoPatBinds
301 | Opt_MonoLocalBinds
302 | Opt_RelaxedPolyRec -- Deprecated
303 | Opt_ExtendedDefaultRules -- Use GHC's extended rules for defaulting
304 | Opt_ForeignFunctionInterface
305 | Opt_UnliftedFFITypes
306 | Opt_GHCForeignImportPrim
307 | Opt_PArr -- Syntactic support for parallel arrays
308 | Opt_Arrows -- Arrow-notation syntax
309 | Opt_TemplateHaskell
310 | Opt_QuasiQuotes
311 | Opt_ImplicitParams
312 | Opt_Generics -- "Derivable type classes"
313 | Opt_ImplicitPrelude
314 | Opt_ScopedTypeVariables
315 | Opt_UnboxedTuples
316 | Opt_BangPatterns
317 | Opt_TypeFamilies
318 | Opt_OverloadedStrings
319 | Opt_DisambiguateRecordFields
320 | Opt_RecordWildCards
321 | Opt_RecordPuns
322 | Opt_ViewPatterns
323 | Opt_GADTs
324 | Opt_NPlusKPatterns
325 | Opt_DoAndIfThenElse
326
327 | Opt_StandaloneDeriving
328 | Opt_DeriveDataTypeable
329 | Opt_DeriveFunctor
330 | Opt_DeriveTraversable
331 | Opt_DeriveFoldable
332
333 | Opt_TypeSynonymInstances
334 | Opt_FlexibleContexts
335 | Opt_FlexibleInstances
336 | Opt_ConstrainedClassMethods
337 | Opt_MultiParamTypeClasses
338 | Opt_FunctionalDependencies
339 | Opt_UnicodeSyntax
340 | Opt_PolymorphicComponents
341 | Opt_ExistentialQuantification
342 | Opt_MagicHash
343 | Opt_EmptyDataDecls
344 | Opt_KindSignatures
345 | Opt_ParallelListComp
346 | Opt_TransformListComp
347 | Opt_GeneralizedNewtypeDeriving
348 | Opt_RecursiveDo
349 | Opt_DoRec
350 | Opt_PostfixOperators
351 | Opt_TupleSections
352 | Opt_PatternGuards
353 | Opt_LiberalTypeSynonyms
354 | Opt_Rank2Types
355 | Opt_RankNTypes
356 | Opt_ImpredicativeTypes
357 | Opt_TypeOperators
358 | Opt_PackageImports
359 | Opt_NewQualifiedOperators
360 | Opt_ExplicitForAll
361 | Opt_AlternativeLayoutRule
362 | Opt_AlternativeLayoutRuleTransitional
363 | Opt_DatatypeContexts
364 deriving (Eq, Show)
365
366 -- | Contains not only a collection of 'DynFlag's but also a plethora of
367 -- information relating to the compilation of a single file or GHC session
368 data DynFlags = DynFlags {
369 ghcMode :: GhcMode,
370 ghcLink :: GhcLink,
371 hscTarget :: HscTarget,
372 hscOutName :: String, -- ^ Name of the output file
373 extCoreName :: String, -- ^ Name of the .hcr output file
374 verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
375 optLevel :: Int, -- ^ Optimisation level
376 simplPhases :: Int, -- ^ Number of simplifier phases
377 maxSimplIterations :: Int, -- ^ Max simplifier iterations
378 shouldDumpSimplPhase :: Maybe String,
379 ruleCheck :: Maybe String,
380 strictnessBefore :: [Int], -- ^ Additional demand analysis
381
382 specConstrThreshold :: Maybe Int, -- ^ Threshold for SpecConstr
383 specConstrCount :: Maybe Int, -- ^ Max number of specialisations for any one function
384 liberateCaseThreshold :: Maybe Int, -- ^ Threshold for LiberateCase
385
386 #ifndef OMIT_NATIVE_CODEGEN
387 targetPlatform :: Platform, -- ^ The platform we're compiling for. Used by the NCG.
388 #endif
389 stolen_x86_regs :: Int,
390 cmdlineHcIncludes :: [String], -- ^ @\-\#includes@
391 importPaths :: [FilePath],
392 mainModIs :: Module,
393 mainFunIs :: Maybe String,
394 ctxtStkDepth :: Int, -- ^ Typechecker context stack depth
395
396 dphBackend :: DPHBackend,
397
398 thisPackage :: PackageId, -- ^ name of package currently being compiled
399
400 -- ways
401 ways :: [Way], -- ^ Way flags from the command line
402 buildTag :: String, -- ^ The global \"way\" (e.g. \"p\" for prof)
403 rtsBuildTag :: String, -- ^ The RTS \"way\"
404
405 -- For object splitting
406 splitInfo :: Maybe (String,Int),
407
408 -- paths etc.
409 objectDir :: Maybe String,
410 dylibInstallName :: Maybe String,
411 hiDir :: Maybe String,
412 stubDir :: Maybe String,
413
414 objectSuf :: String,
415 hcSuf :: String,
416 hiSuf :: String,
417
418 outputFile :: Maybe String,
419 outputHi :: Maybe String,
420 dynLibLoader :: DynLibLoader,
421
422 -- | This is set by 'DriverPipeline.runPipeline' based on where
423 -- its output is going.
424 dumpPrefix :: Maybe FilePath,
425
426 -- | Override the 'dumpPrefix' set by 'DriverPipeline.runPipeline'.
427 -- Set by @-ddump-file-prefix@
428 dumpPrefixForce :: Maybe FilePath,
429
430 includePaths :: [String],
431 libraryPaths :: [String],
432 frameworkPaths :: [String], -- used on darwin only
433 cmdlineFrameworks :: [String], -- ditto
434 tmpDir :: String, -- no trailing '/'
435
436 ghcUsagePath :: FilePath, -- Filled in by SysTools
437 ghciUsagePath :: FilePath, -- ditto
438 rtsOpts :: Maybe String,
439 rtsOptsEnabled :: RtsOptsEnabled,
440
441 hpcDir :: String, -- ^ Path to store the .mix files
442
443 -- options for particular phases
444 opt_L :: [String],
445 opt_P :: [String],
446 opt_F :: [String],
447 opt_c :: [String],
448 opt_m :: [String],
449 opt_a :: [String],
450 opt_l :: [String],
451 opt_windres :: [String],
452 opt_lo :: [String], -- LLVM: llvm optimiser
453 opt_lc :: [String], -- LLVM: llc static compiler
454
455 -- commands for particular phases
456 pgm_L :: String,
457 pgm_P :: (String,[Option]),
458 pgm_F :: String,
459 pgm_c :: (String,[Option]),
460 pgm_m :: (String,[Option]),
461 pgm_s :: (String,[Option]),
462 pgm_a :: (String,[Option]),
463 pgm_l :: (String,[Option]),
464 pgm_dll :: (String,[Option]),
465 pgm_T :: String,
466 pgm_sysman :: String,
467 pgm_windres :: String,
468 pgm_lo :: (String,[Option]), -- LLVM: opt llvm optimiser
469 pgm_lc :: (String,[Option]), -- LLVM: llc static compiler
470
471 -- For ghc -M
472 depMakefile :: FilePath,
473 depIncludePkgDeps :: Bool,
474 depExcludeMods :: [ModuleName],
475 depSuffixes :: [String],
476
477 -- Package flags
478 extraPkgConfs :: [FilePath],
479 topDir :: FilePath, -- filled in by SysTools
480 systemPackageConfig :: FilePath, -- ditto
481 -- ^ The @-package-conf@ flags given on the command line, in the order
482 -- they appeared.
483
484 packageFlags :: [PackageFlag],
485 -- ^ The @-package@ and @-hide-package@ flags from the command-line
486
487 -- Package state
488 -- NB. do not modify this field, it is calculated by
489 -- Packages.initPackages and Packages.updatePackages.
490 pkgDatabase :: Maybe [PackageConfig],
491 pkgState :: PackageState,
492
493 -- Temporary files
494 -- These have to be IORefs, because the defaultCleanupHandler needs to
495 -- know what to clean when an exception happens
496 filesToClean :: IORef [FilePath],
497 dirsToClean :: IORef (Map FilePath FilePath),
498
499 -- hsc dynamic flags
500 flags :: [DynFlag],
501 language :: Maybe Language,
502 extensionFlags :: Either [OnOff ExtensionFlag]
503 [ExtensionFlag],
504
505 -- | Message output action: use "ErrUtils" instead of this if you can
506 log_action :: Severity -> SrcSpan -> PprStyle -> Message -> IO (),
507
508 haddockOptions :: Maybe String
509 }
510
511 wayNames :: DynFlags -> [WayName]
512 wayNames = map wayName . ways
513
514 -- | The target code type of the compilation (if any).
515 --
516 -- Whenever you change the target, also make sure to set 'ghcLink' to
517 -- something sensible.
518 --
519 -- 'HscNothing' can be used to avoid generating any output, however, note
520 -- that:
521 --
522 -- * This will not run the desugaring step, thus no warnings generated in
523 -- this step will be output. In particular, this includes warnings related
524 -- to pattern matching. You can run the desugarer manually using
525 -- 'GHC.desugarModule'.
526 --
527 -- * If a program uses Template Haskell the typechecker may try to run code
528 -- from an imported module. This will fail if no code has been generated
529 -- for this module. You can use 'GHC.needsTemplateHaskell' to detect
530 -- whether this might be the case and choose to either switch to a
531 -- different target or avoid typechecking such modules. (The latter may
532 -- preferable for security reasons.)
533 --
534 data HscTarget
535 = HscC -- ^ Generate C code.
536 | HscAsm -- ^ Generate assembly using the native code generator.
537 | HscLlvm -- ^ Generate assembly using the llvm code generator.
538 | HscJava -- ^ Generate Java bytecode.
539 | HscInterpreted -- ^ Generate bytecode. (Requires 'LinkInMemory')
540 | HscNothing -- ^ Don't generate any code. See notes above.
541 deriving (Eq, Show)
542
543 -- | Will this target result in an object file on the disk?
544 isObjectTarget :: HscTarget -> Bool
545 isObjectTarget HscC = True
546 isObjectTarget HscAsm = True
547 isObjectTarget HscLlvm = True
548 isObjectTarget _ = False
549
550 -- | The 'GhcMode' tells us whether we're doing multi-module
551 -- compilation (controlled via the "GHC" API) or one-shot
552 -- (single-module) compilation. This makes a difference primarily to
553 -- the "Finder": in one-shot mode we look for interface files for
554 -- imported modules, but in multi-module mode we look for source files
555 -- in order to check whether they need to be recompiled.
556 data GhcMode
557 = CompManager -- ^ @\-\-make@, GHCi, etc.
558 | OneShot -- ^ @ghc -c Foo.hs@
559 | MkDepend -- ^ @ghc -M@, see "Finder" for why we need this
560 deriving Eq
561
562 instance Outputable GhcMode where
563 ppr CompManager = ptext (sLit "CompManager")
564 ppr OneShot = ptext (sLit "OneShot")
565 ppr MkDepend = ptext (sLit "MkDepend")
566
567 isOneShot :: GhcMode -> Bool
568 isOneShot OneShot = True
569 isOneShot _other = False
570
571 -- | What to do in the link step, if there is one.
572 data GhcLink
573 = NoLink -- ^ Don't link at all
574 | LinkBinary -- ^ Link object code into a binary
575 | LinkInMemory -- ^ Use the in-memory dynamic linker (works for both
576 -- bytecode and object code).
577 | LinkDynLib -- ^ Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
578 deriving (Eq, Show)
579
580 isNoLink :: GhcLink -> Bool
581 isNoLink NoLink = True
582 isNoLink _ = False
583
584 -- Is it worth evaluating this Bool and caching it in the DynFlags value
585 -- during initDynFlags?
586 doingTickyProfiling :: DynFlags -> Bool
587 doingTickyProfiling _ = opt_Ticky
588 -- XXX -ticky is a static flag, because it implies -debug which is also
589 -- static. If the way flags were made dynamic, we could fix this.
590
591 data PackageFlag
592 = ExposePackage String
593 | ExposePackageId String
594 | HidePackage String
595 | IgnorePackage String
596 deriving Eq
597
598 defaultHscTarget :: HscTarget
599 defaultHscTarget = defaultObjectTarget
600
601 -- | The 'HscTarget' value corresponding to the default way to create
602 -- object files on the current platform.
603 defaultObjectTarget :: HscTarget
604 defaultObjectTarget
605 | cGhcWithNativeCodeGen == "YES" = HscAsm
606 | otherwise = HscC
607
608 data DynLibLoader
609 = Deployable
610 | SystemDependent
611 deriving Eq
612
613 data RtsOptsEnabled = RtsOptsNone | RtsOptsSafeOnly | RtsOptsAll
614
615 -- | Used by 'GHC.newSession' to partially initialize a new 'DynFlags' value
616 initDynFlags :: DynFlags -> IO DynFlags
617 initDynFlags dflags = do
618 -- someday these will be dynamic flags
619 ways <- readIORef v_Ways
620 refFilesToClean <- newIORef []
621 refDirsToClean <- newIORef Map.empty
622 return dflags{
623 ways = ways,
624 buildTag = mkBuildTag (filter (not . wayRTSOnly) ways),
625 rtsBuildTag = mkBuildTag ways,
626 filesToClean = refFilesToClean,
627 dirsToClean = refDirsToClean
628 }
629
630 -- | The normal 'DynFlags'. Note that they is not suitable for use in this form
631 -- and must be fully initialized by 'GHC.newSession' first.
632 defaultDynFlags :: DynFlags
633 defaultDynFlags =
634 DynFlags {
635 ghcMode = CompManager,
636 ghcLink = LinkBinary,
637 hscTarget = defaultHscTarget,
638 hscOutName = "",
639 extCoreName = "",
640 verbosity = 0,
641 optLevel = 0,
642 simplPhases = 2,
643 maxSimplIterations = 4,
644 shouldDumpSimplPhase = Nothing,
645 ruleCheck = Nothing,
646 specConstrThreshold = Just 200,
647 specConstrCount = Just 3,
648 liberateCaseThreshold = Just 200,
649 strictnessBefore = [],
650
651 #ifndef OMIT_NATIVE_CODEGEN
652 targetPlatform = defaultTargetPlatform,
653 #endif
654 stolen_x86_regs = 4,
655 cmdlineHcIncludes = [],
656 importPaths = ["."],
657 mainModIs = mAIN,
658 mainFunIs = Nothing,
659 ctxtStkDepth = mAX_CONTEXT_REDUCTION_DEPTH,
660
661 dphBackend = DPHPar,
662
663 thisPackage = mainPackageId,
664
665 objectDir = Nothing,
666 dylibInstallName = Nothing,
667 hiDir = Nothing,
668 stubDir = Nothing,
669
670 objectSuf = phaseInputExt StopLn,
671 hcSuf = phaseInputExt HCc,
672 hiSuf = "hi",
673
674 outputFile = Nothing,
675 outputHi = Nothing,
676 dynLibLoader = SystemDependent,
677 dumpPrefix = Nothing,
678 dumpPrefixForce = Nothing,
679 includePaths = [],
680 libraryPaths = [],
681 frameworkPaths = [],
682 cmdlineFrameworks = [],
683 tmpDir = cDEFAULT_TMPDIR,
684 rtsOpts = Nothing,
685 rtsOptsEnabled = RtsOptsSafeOnly,
686
687 hpcDir = ".hpc",
688
689 opt_L = [],
690 opt_P = (if opt_PIC
691 then ["-D__PIC__", "-U __PIC__"] -- this list is reversed
692 else []),
693 opt_F = [],
694 opt_c = [],
695 opt_a = [],
696 opt_m = [],
697 opt_l = [],
698 opt_windres = [],
699 opt_lo = [],
700 opt_lc = [],
701
702 extraPkgConfs = [],
703 packageFlags = [],
704 pkgDatabase = Nothing,
705 pkgState = panic "no package state yet: call GHC.setSessionDynFlags",
706 ways = panic "defaultDynFlags: No ways",
707 buildTag = panic "defaultDynFlags: No buildTag",
708 rtsBuildTag = panic "defaultDynFlags: No rtsBuildTag",
709 splitInfo = Nothing,
710 -- initSysTools fills all these in
711 ghcUsagePath = panic "defaultDynFlags: No ghciUsagePath",
712 ghciUsagePath = panic "defaultDynFlags: No ghciUsagePath",
713 topDir = panic "defaultDynFlags: No topDir",
714 systemPackageConfig = panic "no systemPackageConfig: call GHC.setSessionDynFlags",
715 pgm_L = panic "defaultDynFlags: No pgm_L",
716 pgm_P = panic "defaultDynFlags: No pgm_P",
717 pgm_F = panic "defaultDynFlags: No pgm_F",
718 pgm_c = panic "defaultDynFlags: No pgm_c",
719 pgm_m = panic "defaultDynFlags: No pgm_m",
720 pgm_s = panic "defaultDynFlags: No pgm_s",
721 pgm_a = panic "defaultDynFlags: No pgm_a",
722 pgm_l = panic "defaultDynFlags: No pgm_l",
723 pgm_dll = panic "defaultDynFlags: No pgm_dll",
724 pgm_T = panic "defaultDynFlags: No pgm_T",
725 pgm_sysman = panic "defaultDynFlags: No pgm_sysman",
726 pgm_windres = panic "defaultDynFlags: No pgm_windres",
727 pgm_lo = panic "defaultDynFlags: No pgm_lo",
728 pgm_lc = panic "defaultDynFlags: No pgm_lc",
729 -- end of initSysTools values
730 -- ghc -M values
731 depMakefile = "Makefile",
732 depIncludePkgDeps = False,
733 depExcludeMods = [],
734 depSuffixes = [],
735 -- end of ghc -M values
736 filesToClean = panic "defaultDynFlags: No filesToClean",
737 dirsToClean = panic "defaultDynFlags: No dirsToClean",
738 haddockOptions = Nothing,
739 flags = defaultFlags,
740 language = Nothing,
741 extensionFlags = Left [],
742
743 log_action = \severity srcSpan style msg ->
744 case severity of
745 SevOutput -> printOutput (msg style)
746 SevInfo -> printErrs (msg style)
747 SevFatal -> printErrs (msg style)
748 _ -> do
749 hPutChar stderr '\n'
750 printErrs ((mkLocMessage srcSpan msg) style)
751 -- careful (#2302): printErrs prints in UTF-8, whereas
752 -- converting to string first and using hPutStr would
753 -- just emit the low 8 bits of each unicode char.
754 }
755
756 {-
757 Note [Verbosity levels]
758 ~~~~~~~~~~~~~~~~~~~~~~~
759 0 | print errors & warnings only
760 1 | minimal verbosity: print "compiling M ... done." for each module.
761 2 | equivalent to -dshow-passes
762 3 | equivalent to existing "ghc -v"
763 4 | "ghc -v -ddump-most"
764 5 | "ghc -v -ddump-all"
765 -}
766
767 data OnOff a = On a
768 | Off a
769
770 flattenExtensionFlags :: DynFlags -> DynFlags
771 flattenExtensionFlags dflags
772 = case extensionFlags dflags of
773 Left onoffs ->
774 dflags {
775 extensionFlags = Right $ flattenExtensionFlags' (language dflags) onoffs
776 }
777 Right _ ->
778 panic "Flattening already-flattened extension flags"
779
780 ensureFlattenedExtensionFlags :: DynFlags -> DynFlags
781 ensureFlattenedExtensionFlags dflags
782 = case extensionFlags dflags of
783 Left onoffs ->
784 dflags {
785 extensionFlags = Right $ flattenExtensionFlags' (language dflags) onoffs
786 }
787 Right _ ->
788 dflags
789
790 -- OnOffs accumulate in reverse order, so we use foldr in order to
791 -- process them in the right order
792 flattenExtensionFlags' :: Maybe Language -> [OnOff ExtensionFlag]
793 -> [ExtensionFlag]
794 flattenExtensionFlags' ml = foldr f defaultExtensionFlags
795 where f (On f) flags = f : delete f flags
796 f (Off f) flags = delete f flags
797 defaultExtensionFlags = languageExtensions ml
798
799 languageExtensions :: Maybe Language -> [ExtensionFlag]
800 languageExtensions Nothing
801 = Opt_MonoPatBinds -- Experimentally, I'm making this non-standard
802 -- behaviour the default, to see if anyone notices
803 -- SLPJ July 06
804 -- In due course I'd like Opt_MonoLocalBinds to be on by default
805 -- SLPJ September 2010
806 : languageExtensions (Just Haskell2010)
807 languageExtensions (Just Haskell98)
808 = [Opt_ImplicitPrelude,
809 Opt_MonomorphismRestriction,
810 Opt_NPlusKPatterns,
811 Opt_DatatypeContexts]
812 languageExtensions (Just Haskell2010)
813 = [Opt_ImplicitPrelude,
814 Opt_MonomorphismRestriction,
815 Opt_DatatypeContexts,
816 Opt_EmptyDataDecls,
817 Opt_ForeignFunctionInterface,
818 Opt_PatternGuards,
819 Opt_DoAndIfThenElse,
820 Opt_RelaxedPolyRec]
821
822 -- | Test whether a 'DynFlag' is set
823 dopt :: DynFlag -> DynFlags -> Bool
824 dopt f dflags = f `elem` (flags dflags)
825
826 -- | Set a 'DynFlag'
827 dopt_set :: DynFlags -> DynFlag -> DynFlags
828 dopt_set dfs f = dfs{ flags = f : flags dfs }
829
830 -- | Unset a 'DynFlag'
831 dopt_unset :: DynFlags -> DynFlag -> DynFlags
832 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
833
834 -- | Test whether a 'ExtensionFlag' is set
835 xopt :: ExtensionFlag -> DynFlags -> Bool
836 xopt f dflags = case extensionFlags dflags of
837 Left _ -> panic ("Testing for extension flag " ++ show f ++ " before flattening")
838 Right flags -> f `elem` flags
839
840 -- | Set a 'ExtensionFlag'
841 xopt_set :: DynFlags -> ExtensionFlag -> DynFlags
842 xopt_set dfs f = case extensionFlags dfs of
843 Left onoffs -> dfs { extensionFlags = Left (On f : onoffs) }
844 Right _ -> panic ("Setting extension flag " ++ show f ++ " after flattening")
845
846 -- | Set a 'ExtensionFlag'
847 xopt_set_flattened :: DynFlags -> ExtensionFlag -> DynFlags
848 xopt_set_flattened dfs f = case extensionFlags dfs of
849 Left _ ->
850 panic ("Setting extension flag " ++ show f ++ " before flattening, but expected flattened")
851 Right flags ->
852 dfs { extensionFlags = Right (f : delete f flags) }
853
854 -- | Unset a 'ExtensionFlag'
855 xopt_unset :: DynFlags -> ExtensionFlag -> DynFlags
856 xopt_unset dfs f = case extensionFlags dfs of
857 Left onoffs -> dfs { extensionFlags = Left (Off f : onoffs) }
858 Right _ -> panic ("Unsetting extension flag " ++ show f ++ " after flattening")
859
860 -- | Unset a 'ExtensionFlag'
861 xopt_unset_flattened :: DynFlags -> ExtensionFlag -> DynFlags
862 xopt_unset_flattened dfs f = case extensionFlags dfs of
863 Left _ ->
864 panic ("Unsetting extension flag " ++ show f ++ " before flattening, but expected flattened")
865 Right flags ->
866 dfs { extensionFlags = Right (delete f flags) }
867
868 -- | Retrieve the options corresponding to a particular @opt_*@ field in the correct order
869 getOpts :: DynFlags -- ^ 'DynFlags' to retrieve the options from
870 -> (DynFlags -> [a]) -- ^ Relevant record accessor: one of the @opt_*@ accessors
871 -> [a] -- ^ Correctly ordered extracted options
872 getOpts dflags opts = reverse (opts dflags)
873 -- We add to the options from the front, so we need to reverse the list
874
875 -- | Gets the verbosity flag for the current verbosity level. This is fed to
876 -- other tools, so GHC-specific verbosity flags like @-ddump-most@ are not included
877 getVerbFlag :: DynFlags -> String
878 getVerbFlag dflags
879 | verbosity dflags >= 3 = "-v"
880 | otherwise = ""
881
882 setObjectDir, setHiDir, setStubDir, setOutputDir, setDylibInstallName,
883 setObjectSuf, setHiSuf, setHcSuf, parseDynLibLoaderMode,
884 setPgmP, addOptl, addOptP,
885 addCmdlineFramework, addHaddockOpts
886 :: String -> DynFlags -> DynFlags
887 setOutputFile, setOutputHi, setDumpPrefixForce
888 :: Maybe String -> DynFlags -> DynFlags
889
890 setObjectDir f d = d{ objectDir = Just f}
891 setHiDir f d = d{ hiDir = Just f}
892 setStubDir f d = d{ stubDir = Just f, includePaths = f : includePaths d }
893 -- -stubdir D adds an implicit -I D, so that gcc can find the _stub.h file
894 -- \#included from the .hc file when compiling with -fvia-C.
895 setOutputDir f = setObjectDir f . setHiDir f . setStubDir f
896 setDylibInstallName f d = d{ dylibInstallName = Just f}
897
898 setObjectSuf f d = d{ objectSuf = f}
899 setHiSuf f d = d{ hiSuf = f}
900 setHcSuf f d = d{ hcSuf = f}
901
902 setOutputFile f d = d{ outputFile = f}
903 setOutputHi f d = d{ outputHi = f}
904
905 parseDynLibLoaderMode f d =
906 case splitAt 8 f of
907 ("deploy", "") -> d{ dynLibLoader = Deployable }
908 ("sysdep", "") -> d{ dynLibLoader = SystemDependent }
909 _ -> ghcError (CmdLineError ("Unknown dynlib loader: " ++ f))
910
911 setDumpPrefixForce f d = d { dumpPrefixForce = f}
912
913 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
914 -- Config.hs should really use Option.
915 setPgmP f d = let (pgm:args) = words f in d{ pgm_P = (pgm, map Option args)}
916 addOptl f d = d{ opt_l = f : opt_l d}
917 addOptP f d = d{ opt_P = f : opt_P d}
918
919
920 setDepMakefile :: FilePath -> DynFlags -> DynFlags
921 setDepMakefile f d = d { depMakefile = deOptDep f }
922
923 setDepIncludePkgDeps :: Bool -> DynFlags -> DynFlags
924 setDepIncludePkgDeps b d = d { depIncludePkgDeps = b }
925
926 addDepExcludeMod :: String -> DynFlags -> DynFlags
927 addDepExcludeMod m d
928 = d { depExcludeMods = mkModuleName (deOptDep m) : depExcludeMods d }
929
930 addDepSuffix :: FilePath -> DynFlags -> DynFlags
931 addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d }
932
933 -- XXX Legacy code:
934 -- We used to use "-optdep-flag -optdeparg", so for legacy applications
935 -- we need to strip the "-optdep" off of the arg
936 deOptDep :: String -> String
937 deOptDep x = case stripPrefix "-optdep" x of
938 Just rest -> rest
939 Nothing -> x
940
941 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
942
943 addHaddockOpts f d = d{ haddockOptions = Just f}
944
945 -- -----------------------------------------------------------------------------
946 -- Command-line options
947
948 -- | When invoking external tools as part of the compilation pipeline, we
949 -- pass these a sequence of options on the command-line. Rather than
950 -- just using a list of Strings, we use a type that allows us to distinguish
951 -- between filepaths and 'other stuff'. The reason for this is that
952 -- this type gives us a handle on transforming filenames, and filenames only,
953 -- to whatever format they're expected to be on a particular platform.
954 data Option
955 = FileOption -- an entry that _contains_ filename(s) / filepaths.
956 String -- a non-filepath prefix that shouldn't be
957 -- transformed (e.g., "/out=")
958 String -- the filepath/filename portion
959 | Option String
960
961 showOpt :: Option -> String
962 showOpt (FileOption pre f) = pre ++ f
963 showOpt (Option s) = s
964
965 -----------------------------------------------------------------------------
966 -- Setting the optimisation level
967
968 updOptLevel :: Int -> DynFlags -> DynFlags
969 -- ^ Sets the 'DynFlags' to be appropriate to the optimisation level
970 updOptLevel n dfs
971 = dfs2{ optLevel = final_n }
972 where
973 final_n = max 0 (min 2 n) -- Clamp to 0 <= n <= 2
974 dfs1 = foldr (flip dopt_unset) dfs remove_dopts
975 dfs2 = foldr (flip dopt_set) dfs1 extra_dopts
976
977 extra_dopts = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
978 remove_dopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
979
980 -- -----------------------------------------------------------------------------
981 -- StgToDo: abstraction of stg-to-stg passes to run.
982
983 data StgToDo
984 = StgDoMassageForProfiling -- should be (next to) last
985 -- There's also setStgVarInfo, but its absolute "lastness"
986 -- is so critical that it is hardwired in (no flag).
987 | D_stg_stats
988
989 getStgToDo :: DynFlags -> [StgToDo]
990 getStgToDo dflags
991 = todo2
992 where
993 stg_stats = dopt Opt_StgStats dflags
994
995 todo1 = if stg_stats then [D_stg_stats] else []
996
997 todo2 | WayProf `elem` wayNames dflags
998 = StgDoMassageForProfiling : todo1
999 | otherwise
1000 = todo1
1001
1002 {- **********************************************************************
1003 %* *
1004 DynFlags parser
1005 %* *
1006 %********************************************************************* -}
1007
1008 -- -----------------------------------------------------------------------------
1009 -- Parsing the dynamic flags.
1010
1011 -- | Parse dynamic flags from a list of command line arguments. Returns the
1012 -- the parsed 'DynFlags', the left-over arguments, and a list of warnings.
1013 -- Throws a 'UsageError' if errors occurred during parsing (such as unknown
1014 -- flags or missing arguments).
1015 parseDynamicFlags :: Monad m =>
1016 DynFlags -> [Located String]
1017 -> m (DynFlags, [Located String], [Located String])
1018 -- ^ Updated 'DynFlags', left-over arguments, and
1019 -- list of warnings.
1020 parseDynamicFlags dflags args = parseDynamicFlags_ dflags args True
1021
1022 -- | Like 'parseDynamicFlags' but does not allow the package flags (-package,
1023 -- -hide-package, -ignore-package, -hide-all-packages, -package-conf).
1024 parseDynamicNoPackageFlags :: Monad m =>
1025 DynFlags -> [Located String]
1026 -> m (DynFlags, [Located String], [Located String])
1027 -- ^ Updated 'DynFlags', left-over arguments, and
1028 -- list of warnings.
1029 parseDynamicNoPackageFlags dflags args = parseDynamicFlags_ dflags args False
1030
1031 parseDynamicFlags_ :: Monad m =>
1032 DynFlags -> [Located String] -> Bool
1033 -> m (DynFlags, [Located String], [Located String])
1034 parseDynamicFlags_ dflags0 args pkg_flags = do
1035 -- XXX Legacy support code
1036 -- We used to accept things like
1037 -- optdep-f -optdepdepend
1038 -- optdep-f -optdep depend
1039 -- optdep -f -optdepdepend
1040 -- optdep -f -optdep depend
1041 -- but the spaces trip up proper argument handling. So get rid of them.
1042 let f (L p "-optdep" : L _ x : xs) = (L p ("-optdep" ++ x)) : f xs
1043 f (x : xs) = x : f xs
1044 f xs = xs
1045 args' = f args
1046
1047 -- Note: -ignore-package (package_flags) must precede -i* (dynamic_flags)
1048 flag_spec | pkg_flags = package_flags ++ dynamic_flags
1049 | otherwise = dynamic_flags
1050
1051 let ((leftover, errs, warns), dflags1)
1052 = runCmdLine (processArgs flag_spec args') dflags0
1053 when (not (null errs)) $ ghcError $ errorsToGhcException errs
1054
1055 -- Cannot use -fPIC with registerised -fvia-C, because the mangler
1056 -- isn't up to the job. We know that if hscTarget == HscC, then the
1057 -- user has explicitly used -fvia-C, because -fasm is the default,
1058 -- unless there is no NCG on this platform. The latter case is
1059 -- checked when the -fPIC flag is parsed.
1060 --
1061 let (pic_warns, dflags2)
1062 | opt_PIC && hscTarget dflags1 == HscC && cGhcUnregisterised == "NO"
1063 = ([L noSrcSpan $ "Warning: -fvia-C is incompatible with -fPIC; ignoring -fvia-C"],
1064 dflags1{ hscTarget = HscAsm })
1065 #if !(x86_64_TARGET_ARCH && linux_TARGET_OS)
1066 | (not opt_Static || opt_PIC) && hscTarget dflags1 == HscLlvm
1067 = ([L noSrcSpan $ "Warning: -fllvm is incompatible with -fPIC and -"
1068 ++ "dynamic on this platform;\n ignoring -fllvm"],
1069 dflags1{ hscTarget = HscAsm })
1070 #endif
1071 | otherwise = ([], dflags1)
1072
1073 return (dflags2, leftover, pic_warns ++ warns)
1074
1075
1076 {- **********************************************************************
1077 %* *
1078 DynFlags specifications
1079 %* *
1080 %********************************************************************* -}
1081
1082 allFlags :: [String]
1083 allFlags = map ('-':) $
1084 [ flagName flag | flag <- dynamic_flags, ok (flagOptKind flag) ] ++
1085 map ("fno-"++) flags ++
1086 map ("f"++) flags ++
1087 map ("f"++) flags' ++
1088 map ("X"++) supportedExtensions
1089 where ok (PrefixPred _ _) = False
1090 ok _ = True
1091 flags = [ name | (name, _, _) <- fFlags ]
1092 flags' = [ name | (name, _, _) <- fLangFlags ]
1093
1094 --------------- The main flags themselves ------------------
1095 dynamic_flags :: [Flag (CmdLineP DynFlags)]
1096 dynamic_flags = [
1097 Flag "n" (NoArg (setDynFlag Opt_DryRun))
1098 , Flag "cpp" (NoArg (setExtensionFlag Opt_Cpp))
1099 , Flag "F" (NoArg (setDynFlag Opt_Pp))
1100 , Flag "#include"
1101 (HasArg (\s -> do { addCmdlineHCInclude s
1102 ; addWarn "-#include and INCLUDE pragmas are deprecated: They no longer have any effect" }))
1103 , Flag "v" (OptIntSuffix setVerbosity)
1104
1105 ------- Specific phases --------------------------------------------
1106 -- need to appear before -pgmL to be parsed as LLVM flags.
1107 , Flag "pgmlo" (hasArg (\f d -> d{ pgm_lo = (f,[])}))
1108 , Flag "pgmlc" (hasArg (\f d -> d{ pgm_lc = (f,[])}))
1109 , Flag "pgmL" (hasArg (\f d -> d{ pgm_L = f}))
1110 , Flag "pgmP" (hasArg setPgmP)
1111 , Flag "pgmF" (hasArg (\f d -> d{ pgm_F = f}))
1112 , Flag "pgmc" (hasArg (\f d -> d{ pgm_c = (f,[])}))
1113 , Flag "pgmm" (hasArg (\f d -> d{ pgm_m = (f,[])}))
1114 , Flag "pgms" (hasArg (\f d -> d{ pgm_s = (f,[])}))
1115 , Flag "pgma" (hasArg (\f d -> d{ pgm_a = (f,[])}))
1116 , Flag "pgml" (hasArg (\f d -> d{ pgm_l = (f,[])}))
1117 , Flag "pgmdll" (hasArg (\f d -> d{ pgm_dll = (f,[])}))
1118 , Flag "pgmwindres" (hasArg (\f d -> d{ pgm_windres = f}))
1119
1120 -- need to appear before -optl/-opta to be parsed as LLVM flags.
1121 , Flag "optlo" (hasArg (\f d -> d{ opt_lo = f : opt_lo d}))
1122 , Flag "optlc" (hasArg (\f d -> d{ opt_lc = f : opt_lc d}))
1123 , Flag "optL" (hasArg (\f d -> d{ opt_L = f : opt_L d}))
1124 , Flag "optP" (hasArg addOptP)
1125 , Flag "optF" (hasArg (\f d -> d{ opt_F = f : opt_F d}))
1126 , Flag "optc" (hasArg (\f d -> d{ opt_c = f : opt_c d}))
1127 , Flag "optm" (hasArg (\f d -> d{ opt_m = f : opt_m d}))
1128 , Flag "opta" (hasArg (\f d -> d{ opt_a = f : opt_a d}))
1129 , Flag "optl" (hasArg addOptl)
1130 , Flag "optwindres" (hasArg (\f d -> d{ opt_windres = f : opt_windres d}))
1131
1132 , Flag "split-objs"
1133 (NoArg (if can_split
1134 then setDynFlag Opt_SplitObjs
1135 else addWarn "ignoring -fsplit-objs"))
1136
1137 -------- ghc -M -----------------------------------------------------
1138 , Flag "dep-suffix" (hasArg addDepSuffix)
1139 , Flag "optdep-s" (hasArgDF addDepSuffix "Use -dep-suffix instead")
1140 , Flag "dep-makefile" (hasArg setDepMakefile)
1141 , Flag "optdep-f" (hasArgDF setDepMakefile "Use -dep-makefile instead")
1142 , Flag "optdep-w" (NoArg (deprecate "doesn't do anything"))
1143 , Flag "include-pkg-deps" (noArg (setDepIncludePkgDeps True))
1144 , Flag "optdep--include-prelude" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
1145 , Flag "optdep--include-pkg-deps" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
1146 , Flag "exclude-module" (hasArg addDepExcludeMod)
1147 , Flag "optdep--exclude-module" (hasArgDF addDepExcludeMod "Use -exclude-module instead")
1148 , Flag "optdep-x" (hasArgDF addDepExcludeMod "Use -exclude-module instead")
1149
1150 -------- Linking ----------------------------------------------------
1151 , Flag "no-link" (noArg (\d -> d{ ghcLink=NoLink }))
1152 , Flag "shared" (noArg (\d -> d{ ghcLink=LinkDynLib }))
1153 , Flag "dynload" (hasArg parseDynLibLoaderMode)
1154 , Flag "dylib-install-name" (hasArg setDylibInstallName)
1155
1156 ------- Libraries ---------------------------------------------------
1157 , Flag "L" (Prefix addLibraryPath)
1158 , Flag "l" (AnySuffix (upd . addOptl))
1159
1160 ------- Frameworks --------------------------------------------------
1161 -- -framework-path should really be -F ...
1162 , Flag "framework-path" (HasArg addFrameworkPath)
1163 , Flag "framework" (hasArg addCmdlineFramework)
1164
1165 ------- Output Redirection ------------------------------------------
1166 , Flag "odir" (hasArg setObjectDir)
1167 , Flag "o" (SepArg (upd . setOutputFile . Just))
1168 , Flag "ohi" (hasArg (setOutputHi . Just ))
1169 , Flag "osuf" (hasArg setObjectSuf)
1170 , Flag "hcsuf" (hasArg setHcSuf)
1171 , Flag "hisuf" (hasArg setHiSuf)
1172 , Flag "hidir" (hasArg setHiDir)
1173 , Flag "tmpdir" (hasArg setTmpDir)
1174 , Flag "stubdir" (hasArg setStubDir)
1175 , Flag "outputdir" (hasArg setOutputDir)
1176 , Flag "ddump-file-prefix" (hasArg (setDumpPrefixForce . Just))
1177
1178 ------- Keeping temporary files -------------------------------------
1179 -- These can be singular (think ghc -c) or plural (think ghc --make)
1180 , Flag "keep-hc-file" (NoArg (setDynFlag Opt_KeepHcFiles))
1181 , Flag "keep-hc-files" (NoArg (setDynFlag Opt_KeepHcFiles))
1182 , Flag "keep-s-file" (NoArg (setDynFlag Opt_KeepSFiles))
1183 , Flag "keep-s-files" (NoArg (setDynFlag Opt_KeepSFiles))
1184 , Flag "keep-raw-s-file" (NoArg (setDynFlag Opt_KeepRawSFiles))
1185 , Flag "keep-raw-s-files" (NoArg (setDynFlag Opt_KeepRawSFiles))
1186 , Flag "keep-llvm-file" (NoArg (setDynFlag Opt_KeepLlvmFiles))
1187 , Flag "keep-llvm-files" (NoArg (setDynFlag Opt_KeepLlvmFiles))
1188 -- This only makes sense as plural
1189 , Flag "keep-tmp-files" (NoArg (setDynFlag Opt_KeepTmpFiles))
1190
1191 ------- Miscellaneous ----------------------------------------------
1192 , Flag "no-auto-link-packages" (NoArg (unSetDynFlag Opt_AutoLinkPackages))
1193 , Flag "no-hs-main" (NoArg (setDynFlag Opt_NoHsMain))
1194 , Flag "with-rtsopts" (HasArg setRtsOpts)
1195 , Flag "rtsopts" (NoArg (setRtsOptsEnabled RtsOptsAll))
1196 , Flag "rtsopts=all" (NoArg (setRtsOptsEnabled RtsOptsAll))
1197 , Flag "rtsopts=some" (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
1198 , Flag "rtsopts=none" (NoArg (setRtsOptsEnabled RtsOptsNone))
1199 , Flag "no-rtsopts" (NoArg (setRtsOptsEnabled RtsOptsNone))
1200 , Flag "main-is" (SepArg setMainIs)
1201 , Flag "haddock" (NoArg (setDynFlag Opt_Haddock))
1202 , Flag "haddock-opts" (hasArg addHaddockOpts)
1203 , Flag "hpcdir" (SepArg setOptHpcDir)
1204
1205 ------- recompilation checker --------------------------------------
1206 , Flag "recomp" (NoArg (do { unSetDynFlag Opt_ForceRecomp
1207 ; deprecate "Use -fno-force-recomp instead" }))
1208 , Flag "no-recomp" (NoArg (do { setDynFlag Opt_ForceRecomp
1209 ; deprecate "Use -fforce-recomp instead" }))
1210
1211 ------ HsCpp opts ---------------------------------------------------
1212 , Flag "D" (AnySuffix (upd . addOptP))
1213 , Flag "U" (AnySuffix (upd . addOptP))
1214
1215 ------- Include/Import Paths ----------------------------------------
1216 , Flag "I" (Prefix addIncludePath)
1217 , Flag "i" (OptPrefix addImportPath)
1218
1219 ------ Debugging ----------------------------------------------------
1220 , Flag "dstg-stats" (NoArg (setDynFlag Opt_StgStats))
1221
1222 , Flag "ddump-cmm" (setDumpFlag Opt_D_dump_cmm)
1223 , Flag "ddump-cmmz" (setDumpFlag Opt_D_dump_cmmz)
1224 , Flag "ddump-cmmz-pretty" (setDumpFlag Opt_D_dump_cmmz_pretty)
1225 , Flag "ddump-cps-cmm" (setDumpFlag Opt_D_dump_cps_cmm)
1226 , Flag "ddump-cvt-cmm" (setDumpFlag Opt_D_dump_cvt_cmm)
1227 , Flag "ddump-asm" (setDumpFlag Opt_D_dump_asm)
1228 , Flag "ddump-asm-native" (setDumpFlag Opt_D_dump_asm_native)
1229 , Flag "ddump-asm-liveness" (setDumpFlag Opt_D_dump_asm_liveness)
1230 , Flag "ddump-asm-coalesce" (setDumpFlag Opt_D_dump_asm_coalesce)
1231 , Flag "ddump-asm-regalloc" (setDumpFlag Opt_D_dump_asm_regalloc)
1232 , Flag "ddump-asm-conflicts" (setDumpFlag Opt_D_dump_asm_conflicts)
1233 , Flag "ddump-asm-regalloc-stages" (setDumpFlag Opt_D_dump_asm_regalloc_stages)
1234 , Flag "ddump-asm-stats" (setDumpFlag Opt_D_dump_asm_stats)
1235 , Flag "ddump-asm-expanded" (setDumpFlag Opt_D_dump_asm_expanded)
1236 , Flag "ddump-llvm" (NoArg (do { setObjTarget HscLlvm
1237 ; setDumpFlag' Opt_D_dump_llvm}))
1238 , Flag "ddump-cpranal" (setDumpFlag Opt_D_dump_cpranal)
1239 , Flag "ddump-deriv" (setDumpFlag Opt_D_dump_deriv)
1240 , Flag "ddump-ds" (setDumpFlag Opt_D_dump_ds)
1241 , Flag "ddump-flatC" (setDumpFlag Opt_D_dump_flatC)
1242 , Flag "ddump-foreign" (setDumpFlag Opt_D_dump_foreign)
1243 , Flag "ddump-inlinings" (setDumpFlag Opt_D_dump_inlinings)
1244 , Flag "ddump-rule-firings" (setDumpFlag Opt_D_dump_rule_firings)
1245 , Flag "ddump-occur-anal" (setDumpFlag Opt_D_dump_occur_anal)
1246 , Flag "ddump-parsed" (setDumpFlag Opt_D_dump_parsed)
1247 , Flag "ddump-rn" (setDumpFlag Opt_D_dump_rn)
1248 , Flag "ddump-simpl" (setDumpFlag Opt_D_dump_simpl)
1249 , Flag "ddump-simpl-iterations" (setDumpFlag Opt_D_dump_simpl_iterations)
1250 , Flag "ddump-simpl-phases" (OptPrefix setDumpSimplPhases)
1251 , Flag "ddump-spec" (setDumpFlag Opt_D_dump_spec)
1252 , Flag "ddump-prep" (setDumpFlag Opt_D_dump_prep)
1253 , Flag "ddump-stg" (setDumpFlag Opt_D_dump_stg)
1254 , Flag "ddump-stranal" (setDumpFlag Opt_D_dump_stranal)
1255 , Flag "ddump-tc" (setDumpFlag Opt_D_dump_tc)
1256 , Flag "ddump-types" (setDumpFlag Opt_D_dump_types)
1257 , Flag "ddump-rules" (setDumpFlag Opt_D_dump_rules)
1258 , Flag "ddump-cse" (setDumpFlag Opt_D_dump_cse)
1259 , Flag "ddump-worker-wrapper" (setDumpFlag Opt_D_dump_worker_wrapper)
1260 , Flag "ddump-rn-trace" (setDumpFlag Opt_D_dump_rn_trace)
1261 , Flag "ddump-if-trace" (setDumpFlag Opt_D_dump_if_trace)
1262 , Flag "ddump-tc-trace" (setDumpFlag Opt_D_dump_tc_trace)
1263 , Flag "ddump-splices" (setDumpFlag Opt_D_dump_splices)
1264 , Flag "ddump-rn-stats" (setDumpFlag Opt_D_dump_rn_stats)
1265 , Flag "ddump-opt-cmm" (setDumpFlag Opt_D_dump_opt_cmm)
1266 , Flag "ddump-simpl-stats" (setDumpFlag Opt_D_dump_simpl_stats)
1267 , Flag "ddump-bcos" (setDumpFlag Opt_D_dump_BCOs)
1268 , Flag "dsource-stats" (setDumpFlag Opt_D_source_stats)
1269 , Flag "dverbose-core2core" (NoArg (do { setVerbosity (Just 2)
1270 ; setVerboseCore2Core }))
1271 , Flag "dverbose-stg2stg" (setDumpFlag Opt_D_verbose_stg2stg)
1272 , Flag "ddump-hi" (setDumpFlag Opt_D_dump_hi)
1273 , Flag "ddump-minimal-imports" (setDumpFlag Opt_D_dump_minimal_imports)
1274 , Flag "ddump-vect" (setDumpFlag Opt_D_dump_vect)
1275 , Flag "ddump-hpc" (setDumpFlag Opt_D_dump_hpc)
1276 , Flag "ddump-mod-cycles" (setDumpFlag Opt_D_dump_mod_cycles)
1277 , Flag "ddump-view-pattern-commoning" (setDumpFlag Opt_D_dump_view_pattern_commoning)
1278 , Flag "ddump-to-file" (setDumpFlag Opt_DumpToFile)
1279 , Flag "ddump-hi-diffs" (setDumpFlag Opt_D_dump_hi_diffs)
1280 , Flag "ddump-rtti" (setDumpFlag Opt_D_dump_rtti)
1281 , Flag "dcore-lint" (NoArg (setDynFlag Opt_DoCoreLinting))
1282 , Flag "dstg-lint" (NoArg (setDynFlag Opt_DoStgLinting))
1283 , Flag "dcmm-lint" (NoArg (setDynFlag Opt_DoCmmLinting))
1284 , Flag "dasm-lint" (NoArg (setDynFlag Opt_DoAsmLinting))
1285 , Flag "dshow-passes" (NoArg (do forceRecompile
1286 setVerbosity (Just 2)))
1287 , Flag "dfaststring-stats" (NoArg (setDynFlag Opt_D_faststring_stats))
1288
1289 ------ Machine dependant (-m<blah>) stuff ---------------------------
1290
1291 , Flag "monly-2-regs" (noArg (\s -> s{stolen_x86_regs = 2}))
1292 , Flag "monly-3-regs" (noArg (\s -> s{stolen_x86_regs = 3}))
1293 , Flag "monly-4-regs" (noArg (\s -> s{stolen_x86_regs = 4}))
1294 , Flag "msse2" (NoArg (setDynFlag Opt_SSE2))
1295
1296 ------ Warning opts -------------------------------------------------
1297 , Flag "W" (NoArg (mapM_ setDynFlag minusWOpts))
1298 , Flag "Werror" (NoArg (setDynFlag Opt_WarnIsError))
1299 , Flag "Wwarn" (NoArg (unSetDynFlag Opt_WarnIsError))
1300 , Flag "Wall" (NoArg (mapM_ setDynFlag minusWallOpts))
1301 , Flag "Wnot" (NoArg (do { mapM_ unSetDynFlag minusWallOpts
1302 ; deprecate "Use -w instead" }))
1303 , Flag "w" (NoArg (mapM_ unSetDynFlag minuswRemovesOpts))
1304
1305 ------ Optimisation flags ------------------------------------------
1306 , Flag "O" (noArg (setOptLevel 1))
1307 , Flag "Onot" (noArgDF (setOptLevel 0) "Use -O0 instead")
1308 , Flag "Odph" (noArg setDPHOpt)
1309 , Flag "O" (OptIntSuffix (\mb_n -> upd (setOptLevel (mb_n `orElse` 1))))
1310 -- If the number is missing, use 1
1311
1312 , Flag "fsimplifier-phases" (intSuffix (\n d -> d{ simplPhases = n }))
1313 , Flag "fmax-simplifier-iterations" (intSuffix (\n d -> d{ maxSimplIterations = n }))
1314 , Flag "fspec-constr-threshold" (intSuffix (\n d -> d{ specConstrThreshold = Just n }))
1315 , Flag "fno-spec-constr-threshold" (noArg (\d -> d{ specConstrThreshold = Nothing }))
1316 , Flag "fspec-constr-count" (intSuffix (\n d -> d{ specConstrCount = Just n }))
1317 , Flag "fno-spec-constr-count" (noArg (\d -> d{ specConstrCount = Nothing }))
1318 , Flag "fliberate-case-threshold" (intSuffix (\n d -> d{ liberateCaseThreshold = Just n }))
1319 , Flag "fno-liberate-case-threshold" (noArg (\d -> d{ liberateCaseThreshold = Nothing }))
1320 , Flag "frule-check" (SepArg (\s -> upd (\d -> d{ ruleCheck = Just s })))
1321 , Flag "fcontext-stack" (intSuffix (\n d -> d{ ctxtStkDepth = n }))
1322 , Flag "fstrictness-before" (intSuffix (\n d -> d{ strictnessBefore = n : strictnessBefore d }))
1323
1324 ------ Profiling ----------------------------------------------------
1325
1326 -- XXX Should the -f* flags be deprecated?
1327 -- They don't seem to be documented
1328 , Flag "fauto-sccs-on-all-toplevs" (NoArg (setDynFlag Opt_AutoSccsOnAllToplevs))
1329 , Flag "auto-all" (NoArg (setDynFlag Opt_AutoSccsOnAllToplevs))
1330 , Flag "no-auto-all" (NoArg (unSetDynFlag Opt_AutoSccsOnAllToplevs))
1331 , Flag "fauto-sccs-on-exported-toplevs" (NoArg (setDynFlag Opt_AutoSccsOnExportedToplevs))
1332 , Flag "auto" (NoArg (setDynFlag Opt_AutoSccsOnExportedToplevs))
1333 , Flag "no-auto" (NoArg (unSetDynFlag Opt_AutoSccsOnExportedToplevs))
1334 , Flag "fauto-sccs-on-individual-cafs" (NoArg (setDynFlag Opt_AutoSccsOnIndividualCafs))
1335 , Flag "caf-all" (NoArg (setDynFlag Opt_AutoSccsOnIndividualCafs))
1336 , Flag "no-caf-all" (NoArg (unSetDynFlag Opt_AutoSccsOnIndividualCafs))
1337
1338 ------ DPH flags ----------------------------------------------------
1339
1340 , Flag "fdph-seq" (NoArg (setDPHBackend DPHSeq))
1341 , Flag "fdph-par" (NoArg (setDPHBackend DPHPar))
1342 , Flag "fdph-this" (NoArg (setDPHBackend DPHThis))
1343
1344 ------ Compiler flags -----------------------------------------------
1345
1346 , Flag "fasm" (NoArg (setObjTarget HscAsm))
1347 , Flag "fvia-c" (NoArg (setObjTarget HscC >>
1348 (addWarn "The -fvia-c flag will be removed in a future GHC release")))
1349 , Flag "fvia-C" (NoArg (setObjTarget HscC >>
1350 (addWarn "The -fvia-C flag will be removed in a future GHC release")))
1351 , Flag "fllvm" (NoArg (setObjTarget HscLlvm))
1352
1353 , Flag "fno-code" (NoArg (do upd $ \d -> d{ ghcLink=NoLink }
1354 setTarget HscNothing))
1355 , Flag "fbyte-code" (NoArg (setTarget HscInterpreted))
1356 , Flag "fobject-code" (NoArg (setTarget defaultHscTarget))
1357 , Flag "fglasgow-exts" (NoArg enableGlasgowExts)
1358 , Flag "fno-glasgow-exts" (NoArg disableGlasgowExts)
1359 ]
1360 ++ map (mkFlag True "f" setDynFlag ) fFlags
1361 ++ map (mkFlag False "fno-" unSetDynFlag) fFlags
1362 ++ map (mkFlag True "f" setExtensionFlag ) fLangFlags
1363 ++ map (mkFlag False "fno-" unSetExtensionFlag) fLangFlags
1364 ++ map (mkFlag True "X" setExtensionFlag ) xFlags
1365 ++ map (mkFlag False "XNo" unSetExtensionFlag) xFlags
1366 ++ map (mkFlag True "X" setLanguage) languageFlags
1367
1368 package_flags :: [Flag (CmdLineP DynFlags)]
1369 package_flags = [
1370 ------- Packages ----------------------------------------------------
1371 Flag "package-conf" (HasArg extraPkgConf_)
1372 , Flag "no-user-package-conf" (NoArg (unSetDynFlag Opt_ReadUserPackageConf))
1373 , Flag "package-name" (hasArg setPackageName)
1374 , Flag "package-id" (HasArg exposePackageId)
1375 , Flag "package" (HasArg exposePackage)
1376 , Flag "hide-package" (HasArg hidePackage)
1377 , Flag "hide-all-packages" (NoArg (setDynFlag Opt_HideAllPackages))
1378 , Flag "ignore-package" (HasArg ignorePackage)
1379 , Flag "syslib" (HasArg (\s -> do { exposePackage s
1380 ; deprecate "Use -package instead" }))
1381 ]
1382
1383 type FlagSpec flag
1384 = ( String -- Flag in string form
1385 , flag -- Flag in internal form
1386 , Bool -> DynP ()) -- Extra action to run when the flag is found
1387 -- Typically, emit a warning or error
1388 -- True <=> we are turning the flag on
1389 -- False <=> we are turning the flag off
1390
1391
1392 mkFlag :: Bool -- ^ True <=> it should be turned on
1393 -> String -- ^ The flag prefix
1394 -> (flag -> DynP ()) -- ^ What to do when the flag is found
1395 -> FlagSpec flag -- ^ Specification of this particular flag
1396 -> Flag (CmdLineP DynFlags)
1397 mkFlag turnOn flagPrefix f (name, flag, extra_action)
1398 = Flag (flagPrefix ++ name) (NoArg (f flag >> extra_action turnOn))
1399
1400 deprecatedForExtension :: String -> Bool -> DynP ()
1401 deprecatedForExtension lang turn_on
1402 = deprecate ("use -X" ++ flag ++ " or pragma {-# LANGUAGE " ++ flag ++ " #-} instead")
1403 where
1404 flag | turn_on = lang
1405 | otherwise = "No"++lang
1406
1407 useInstead :: String -> Bool -> DynP ()
1408 useInstead flag turn_on
1409 = deprecate ("Use -f" ++ no ++ flag ++ " instead")
1410 where
1411 no = if turn_on then "" else "no-"
1412
1413 nop :: Bool -> DynP ()
1414 nop _ = return ()
1415
1416 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
1417 fFlags :: [FlagSpec DynFlag]
1418 fFlags = [
1419 ( "warn-dodgy-foreign-imports", Opt_WarnDodgyForeignImports, nop ),
1420 ( "warn-dodgy-exports", Opt_WarnDodgyExports, nop ),
1421 ( "warn-dodgy-imports", Opt_WarnDodgyImports, nop ),
1422 ( "warn-duplicate-exports", Opt_WarnDuplicateExports, nop ),
1423 ( "warn-hi-shadowing", Opt_WarnHiShadows, nop ),
1424 ( "warn-implicit-prelude", Opt_WarnImplicitPrelude, nop ),
1425 ( "warn-incomplete-patterns", Opt_WarnIncompletePatterns, nop ),
1426 ( "warn-incomplete-record-updates", Opt_WarnIncompletePatternsRecUpd, nop ),
1427 ( "warn-missing-fields", Opt_WarnMissingFields, nop ),
1428 ( "warn-missing-import-lists", Opt_WarnMissingImportList, nop ),
1429 ( "warn-missing-methods", Opt_WarnMissingMethods, nop ),
1430 ( "warn-missing-signatures", Opt_WarnMissingSigs, nop ),
1431 ( "warn-name-shadowing", Opt_WarnNameShadowing, nop ),
1432 ( "warn-overlapping-patterns", Opt_WarnOverlappingPatterns, nop ),
1433 ( "warn-simple-patterns", Opt_WarnSimplePatterns, nop ),
1434 ( "warn-type-defaults", Opt_WarnTypeDefaults, nop ),
1435 ( "warn-monomorphism-restriction", Opt_WarnMonomorphism, nop ),
1436 ( "warn-unused-binds", Opt_WarnUnusedBinds, nop ),
1437 ( "warn-unused-imports", Opt_WarnUnusedImports, nop ),
1438 ( "warn-unused-matches", Opt_WarnUnusedMatches, nop ),
1439 ( "warn-warnings-deprecations", Opt_WarnWarningsDeprecations, nop ),
1440 ( "warn-deprecations", Opt_WarnWarningsDeprecations, nop ),
1441 ( "warn-deprecated-flags", Opt_WarnDeprecatedFlags, nop ),
1442 ( "warn-orphans", Opt_WarnOrphans, nop ),
1443 ( "warn-tabs", Opt_WarnTabs, nop ),
1444 ( "warn-unrecognised-pragmas", Opt_WarnUnrecognisedPragmas, nop ),
1445 ( "warn-lazy-unlifted-bindings", Opt_WarnLazyUnliftedBindings, nop),
1446 ( "warn-unused-do-bind", Opt_WarnUnusedDoBind, nop ),
1447 ( "warn-wrong-do-bind", Opt_WarnWrongDoBind, nop ),
1448 ( "warn-alternative-layout-rule-transitional", Opt_WarnAlternativeLayoutRuleTransitional, nop ),
1449 ( "print-explicit-foralls", Opt_PrintExplicitForalls, nop ),
1450 ( "strictness", Opt_Strictness, nop ),
1451 ( "specialise", Opt_Specialise, nop ),
1452 ( "float-in", Opt_FloatIn, nop ),
1453 ( "static-argument-transformation", Opt_StaticArgumentTransformation, nop ),
1454 ( "full-laziness", Opt_FullLaziness, nop ),
1455 ( "liberate-case", Opt_LiberateCase, nop ),
1456 ( "spec-constr", Opt_SpecConstr, nop ),
1457 ( "cse", Opt_CSE, nop ),
1458 ( "ignore-interface-pragmas", Opt_IgnoreInterfacePragmas, nop ),
1459 ( "omit-interface-pragmas", Opt_OmitInterfacePragmas, nop ),
1460 ( "expose-all-unfoldings", Opt_ExposeAllUnfoldings, nop ),
1461 ( "do-lambda-eta-expansion", Opt_DoLambdaEtaExpansion, nop ),
1462 ( "ignore-asserts", Opt_IgnoreAsserts, nop ),
1463 ( "do-eta-reduction", Opt_DoEtaReduction, nop ),
1464 ( "case-merge", Opt_CaseMerge, nop ),
1465 ( "unbox-strict-fields", Opt_UnboxStrictFields, nop ),
1466 ( "method-sharing", Opt_MethodSharing, nop ),
1467 ( "dicts-cheap", Opt_DictsCheap, nop ),
1468 ( "excess-precision", Opt_ExcessPrecision, nop ),
1469 ( "eager-blackholing", Opt_EagerBlackHoling, nop ),
1470 ( "asm-mangling", Opt_DoAsmMangling, nop ),
1471 ( "print-bind-result", Opt_PrintBindResult, nop ),
1472 ( "force-recomp", Opt_ForceRecomp, nop ),
1473 ( "hpc-no-auto", Opt_Hpc_No_Auto, nop ),
1474 ( "rewrite-rules", Opt_EnableRewriteRules, useInstead "enable-rewrite-rules" ),
1475 ( "enable-rewrite-rules", Opt_EnableRewriteRules, nop ),
1476 ( "break-on-exception", Opt_BreakOnException, nop ),
1477 ( "break-on-error", Opt_BreakOnError, nop ),
1478 ( "print-evld-with-show", Opt_PrintEvldWithShow, nop ),
1479 ( "print-bind-contents", Opt_PrintBindContents, nop ),
1480 ( "run-cps", Opt_RunCPS, nop ),
1481 ( "run-cpsz", Opt_RunCPSZ, nop ),
1482 ( "new-codegen", Opt_TryNewCodeGen, nop ),
1483 ( "convert-to-zipper-and-back", Opt_ConvertToZipCfgAndBack, nop ),
1484 ( "vectorise", Opt_Vectorise, nop ),
1485 ( "regs-graph", Opt_RegsGraph, nop ),
1486 ( "regs-iterative", Opt_RegsIterative, nop ),
1487 ( "gen-manifest", Opt_GenManifest, nop ),
1488 ( "embed-manifest", Opt_EmbedManifest, nop ),
1489 ( "ext-core", Opt_EmitExternalCore, nop ),
1490 ( "shared-implib", Opt_SharedImplib, nop ),
1491 ( "building-cabal-package", Opt_BuildingCabalPackage, nop ),
1492 ( "implicit-import-qualified", Opt_ImplicitImportQualified, nop )
1493 ]
1494
1495 -- | These @-f\<blah\>@ flags can all be reversed with @-fno-\<blah\>@
1496 fLangFlags :: [FlagSpec ExtensionFlag]
1497 fLangFlags = [
1498 ( "th", Opt_TemplateHaskell,
1499 deprecatedForExtension "TemplateHaskell" >> checkTemplateHaskellOk ),
1500 ( "fi", Opt_ForeignFunctionInterface,
1501 deprecatedForExtension "ForeignFunctionInterface" ),
1502 ( "ffi", Opt_ForeignFunctionInterface,
1503 deprecatedForExtension "ForeignFunctionInterface" ),
1504 ( "arrows", Opt_Arrows,
1505 deprecatedForExtension "Arrows" ),
1506 ( "generics", Opt_Generics,
1507 deprecatedForExtension "Generics" ),
1508 ( "implicit-prelude", Opt_ImplicitPrelude,
1509 deprecatedForExtension "ImplicitPrelude" ),
1510 ( "bang-patterns", Opt_BangPatterns,
1511 deprecatedForExtension "BangPatterns" ),
1512 ( "monomorphism-restriction", Opt_MonomorphismRestriction,
1513 deprecatedForExtension "MonomorphismRestriction" ),
1514 ( "mono-pat-binds", Opt_MonoPatBinds,
1515 deprecatedForExtension "MonoPatBinds" ),
1516 ( "extended-default-rules", Opt_ExtendedDefaultRules,
1517 deprecatedForExtension "ExtendedDefaultRules" ),
1518 ( "implicit-params", Opt_ImplicitParams,
1519 deprecatedForExtension "ImplicitParams" ),
1520 ( "scoped-type-variables", Opt_ScopedTypeVariables,
1521 deprecatedForExtension "ScopedTypeVariables" ),
1522 ( "parr", Opt_PArr,
1523 deprecatedForExtension "PArr" ),
1524 ( "allow-overlapping-instances", Opt_OverlappingInstances,
1525 deprecatedForExtension "OverlappingInstances" ),
1526 ( "allow-undecidable-instances", Opt_UndecidableInstances,
1527 deprecatedForExtension "UndecidableInstances" ),
1528 ( "allow-incoherent-instances", Opt_IncoherentInstances,
1529 deprecatedForExtension "IncoherentInstances" )
1530 ]
1531
1532 supportedLanguages :: [String]
1533 supportedLanguages = [ name | (name, _, _) <- languageFlags ]
1534
1535 supportedExtensions :: [String]
1536 supportedExtensions = [ name' | (name, _, _) <- xFlags, name' <- [name, "No" ++ name] ]
1537
1538 supportedLanguagesAndExtensions :: [String]
1539 supportedLanguagesAndExtensions = supportedLanguages ++ supportedExtensions
1540
1541 -- | These -X<blah> flags cannot be reversed with -XNo<blah>
1542 languageFlags :: [FlagSpec Language]
1543 languageFlags = [
1544 ( "Haskell98", Haskell98, nop ),
1545 ( "Haskell2010", Haskell2010, nop )
1546 ]
1547
1548 -- | These -X<blah> flags can all be reversed with -XNo<blah>
1549 xFlags :: [FlagSpec ExtensionFlag]
1550 xFlags = [
1551 ( "CPP", Opt_Cpp, nop ),
1552 ( "PostfixOperators", Opt_PostfixOperators, nop ),
1553 ( "TupleSections", Opt_TupleSections, nop ),
1554 ( "PatternGuards", Opt_PatternGuards, nop ),
1555 ( "UnicodeSyntax", Opt_UnicodeSyntax, nop ),
1556 ( "MagicHash", Opt_MagicHash, nop ),
1557 ( "PolymorphicComponents", Opt_PolymorphicComponents, nop ),
1558 ( "ExistentialQuantification", Opt_ExistentialQuantification, nop ),
1559 ( "KindSignatures", Opt_KindSignatures, nop ),
1560 ( "EmptyDataDecls", Opt_EmptyDataDecls, nop ),
1561 ( "ParallelListComp", Opt_ParallelListComp, nop ),
1562 ( "TransformListComp", Opt_TransformListComp, nop ),
1563 ( "ForeignFunctionInterface", Opt_ForeignFunctionInterface, nop ),
1564 ( "UnliftedFFITypes", Opt_UnliftedFFITypes, nop ),
1565 ( "GHCForeignImportPrim", Opt_GHCForeignImportPrim, nop ),
1566 ( "LiberalTypeSynonyms", Opt_LiberalTypeSynonyms, nop ),
1567 ( "Rank2Types", Opt_Rank2Types, nop ),
1568 ( "RankNTypes", Opt_RankNTypes, nop ),
1569 ( "ImpredicativeTypes", Opt_ImpredicativeTypes,
1570 \_ -> deprecate "impredicative polymorphism will be simplified or removed in GHC 6.14" ),
1571 ( "TypeOperators", Opt_TypeOperators, nop ),
1572 ( "RecursiveDo", Opt_RecursiveDo,
1573 deprecatedForExtension "DoRec"),
1574 ( "DoRec", Opt_DoRec, nop ),
1575 ( "Arrows", Opt_Arrows, nop ),
1576 ( "PArr", Opt_PArr, nop ),
1577 ( "TemplateHaskell", Opt_TemplateHaskell, checkTemplateHaskellOk ),
1578 ( "QuasiQuotes", Opt_QuasiQuotes, nop ),
1579 ( "Generics", Opt_Generics, nop ),
1580 ( "ImplicitPrelude", Opt_ImplicitPrelude, nop ),
1581 ( "RecordWildCards", Opt_RecordWildCards, nop ),
1582 ( "NamedFieldPuns", Opt_RecordPuns, nop ),
1583 ( "RecordPuns", Opt_RecordPuns,
1584 deprecatedForExtension "NamedFieldPuns" ),
1585 ( "DisambiguateRecordFields", Opt_DisambiguateRecordFields, nop ),
1586 ( "OverloadedStrings", Opt_OverloadedStrings, nop ),
1587 ( "GADTs", Opt_GADTs, nop ),
1588 ( "ViewPatterns", Opt_ViewPatterns, nop ),
1589 ( "TypeFamilies", Opt_TypeFamilies, nop ),
1590 ( "BangPatterns", Opt_BangPatterns, nop ),
1591 ( "MonomorphismRestriction", Opt_MonomorphismRestriction, nop ),
1592 ( "NPlusKPatterns", Opt_NPlusKPatterns, nop ),
1593 ( "DoAndIfThenElse", Opt_DoAndIfThenElse, nop ),
1594 ( "MonoPatBinds", Opt_MonoPatBinds, nop ),
1595 ( "ExplicitForAll", Opt_ExplicitForAll, nop ),
1596 ( "AlternativeLayoutRule", Opt_AlternativeLayoutRule, nop ),
1597 ( "AlternativeLayoutRuleTransitional",Opt_AlternativeLayoutRuleTransitional, nop ),
1598 ( "DatatypeContexts", Opt_DatatypeContexts, nop ),
1599 ( "MonoLocalBinds", Opt_MonoLocalBinds, nop ),
1600 ( "RelaxedPolyRec", Opt_RelaxedPolyRec,
1601 \ turn_on -> if not turn_on
1602 then deprecate "You can't turn off RelaxedPolyRec any more"
1603 else return () ),
1604 ( "ExtendedDefaultRules", Opt_ExtendedDefaultRules, nop ),
1605 ( "ImplicitParams", Opt_ImplicitParams, nop ),
1606 ( "ScopedTypeVariables", Opt_ScopedTypeVariables, nop ),
1607
1608 ( "PatternSignatures", Opt_ScopedTypeVariables,
1609 deprecatedForExtension "ScopedTypeVariables" ),
1610
1611 ( "UnboxedTuples", Opt_UnboxedTuples, nop ),
1612 ( "StandaloneDeriving", Opt_StandaloneDeriving, nop ),
1613 ( "DeriveDataTypeable", Opt_DeriveDataTypeable, nop ),
1614 ( "DeriveFunctor", Opt_DeriveFunctor, nop ),
1615 ( "DeriveTraversable", Opt_DeriveTraversable, nop ),
1616 ( "DeriveFoldable", Opt_DeriveFoldable, nop ),
1617 ( "TypeSynonymInstances", Opt_TypeSynonymInstances, nop ),
1618 ( "FlexibleContexts", Opt_FlexibleContexts, nop ),
1619 ( "FlexibleInstances", Opt_FlexibleInstances, nop ),
1620 ( "ConstrainedClassMethods", Opt_ConstrainedClassMethods, nop ),
1621 ( "MultiParamTypeClasses", Opt_MultiParamTypeClasses, nop ),
1622 ( "FunctionalDependencies", Opt_FunctionalDependencies, nop ),
1623 ( "GeneralizedNewtypeDeriving", Opt_GeneralizedNewtypeDeriving, nop ),
1624 ( "OverlappingInstances", Opt_OverlappingInstances, nop ),
1625 ( "UndecidableInstances", Opt_UndecidableInstances, nop ),
1626 ( "IncoherentInstances", Opt_IncoherentInstances, nop ),
1627 ( "PackageImports", Opt_PackageImports, nop ),
1628 ( "NewQualifiedOperators", Opt_NewQualifiedOperators,
1629 \_ -> deprecate "The new qualified operator syntax was rejected by Haskell'" )
1630 ]
1631
1632 defaultFlags :: [DynFlag]
1633 defaultFlags
1634 = [ Opt_AutoLinkPackages,
1635 Opt_ReadUserPackageConf,
1636
1637 Opt_MethodSharing,
1638
1639 Opt_DoAsmMangling,
1640
1641 Opt_SharedImplib,
1642
1643 Opt_GenManifest,
1644 Opt_EmbedManifest,
1645 Opt_PrintBindContents
1646 ]
1647
1648 ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
1649 -- The default -O0 options
1650
1651 ++ standardWarnings
1652
1653 impliedFlags :: [(ExtensionFlag, ExtensionFlag)]
1654 impliedFlags
1655 = [ (Opt_RankNTypes, Opt_ExplicitForAll)
1656 , (Opt_Rank2Types, Opt_ExplicitForAll)
1657 , (Opt_ScopedTypeVariables, Opt_ExplicitForAll)
1658 , (Opt_LiberalTypeSynonyms, Opt_ExplicitForAll)
1659 , (Opt_ExistentialQuantification, Opt_ExplicitForAll)
1660 , (Opt_PolymorphicComponents, Opt_ExplicitForAll)
1661
1662 , (Opt_GADTs, Opt_MonoLocalBinds)
1663 , (Opt_TypeFamilies, Opt_MonoLocalBinds)
1664 , (Opt_FunctionalDependencies, Opt_MonoLocalBinds)
1665
1666 , (Opt_TypeFamilies, Opt_KindSignatures) -- Type families use kind signatures
1667 -- all over the place
1668
1669 , (Opt_ImpredicativeTypes, Opt_RankNTypes)
1670
1671 -- Record wild-cards implies field disambiguation
1672 -- Otherwise if you write (C {..}) you may well get
1673 -- stuff like " 'a' not in scope ", which is a bit silly
1674 -- if the compiler has just filled in field 'a' of constructor 'C'
1675 , (Opt_RecordWildCards, Opt_DisambiguateRecordFields)
1676 ]
1677
1678 optLevelFlags :: [([Int], DynFlag)]
1679 optLevelFlags
1680 = [ ([0], Opt_IgnoreInterfacePragmas)
1681 , ([0], Opt_OmitInterfacePragmas)
1682
1683 , ([1,2], Opt_IgnoreAsserts)
1684 , ([1,2], Opt_EnableRewriteRules) -- Off for -O0; see Note [Scoping for Builtin rules]
1685 -- in PrelRules
1686 , ([1,2], Opt_DoEtaReduction)
1687 , ([1,2], Opt_CaseMerge)
1688 , ([1,2], Opt_Strictness)
1689 , ([1,2], Opt_CSE)
1690 , ([1,2], Opt_FullLaziness)
1691 , ([1,2], Opt_Specialise)
1692 , ([1,2], Opt_FloatIn)
1693
1694 , ([2], Opt_LiberateCase)
1695 , ([2], Opt_SpecConstr)
1696 , ([2], Opt_RegsGraph)
1697
1698 -- , ([2], Opt_StaticArgumentTransformation)
1699 -- Max writes: I think it's probably best not to enable SAT with -O2 for the
1700 -- 6.10 release. The version of SAT in HEAD at the moment doesn't incorporate
1701 -- several improvements to the heuristics, and I'm concerned that without
1702 -- those changes SAT will interfere with some attempts to write "high
1703 -- performance Haskell", as we saw in some posts on Haskell-Cafe earlier
1704 -- this year. In particular, the version in HEAD lacks the tail call
1705 -- criterion, so many things that look like reasonable loops will be
1706 -- turned into functions with extra (unneccesary) thunk creation.
1707
1708 , ([0,1,2], Opt_DoLambdaEtaExpansion)
1709 -- This one is important for a tiresome reason:
1710 -- we want to make sure that the bindings for data
1711 -- constructors are eta-expanded. This is probably
1712 -- a good thing anyway, but it seems fragile.
1713 ]
1714
1715 -- -----------------------------------------------------------------------------
1716 -- Standard sets of warning options
1717
1718 standardWarnings :: [DynFlag]
1719 standardWarnings
1720 = [ Opt_WarnWarningsDeprecations,
1721 Opt_WarnDeprecatedFlags,
1722 Opt_WarnUnrecognisedPragmas,
1723 Opt_WarnOverlappingPatterns,
1724 Opt_WarnMissingFields,
1725 Opt_WarnMissingMethods,
1726 Opt_WarnDuplicateExports,
1727 Opt_WarnLazyUnliftedBindings,
1728 Opt_WarnDodgyForeignImports,
1729 Opt_WarnWrongDoBind,
1730 Opt_WarnAlternativeLayoutRuleTransitional
1731 ]
1732
1733 minusWOpts :: [DynFlag]
1734 minusWOpts
1735 = standardWarnings ++
1736 [ Opt_WarnUnusedBinds,
1737 Opt_WarnUnusedMatches,
1738 Opt_WarnUnusedImports,
1739 Opt_WarnIncompletePatterns,
1740 Opt_WarnDodgyExports,
1741 Opt_WarnDodgyImports
1742 ]
1743
1744 minusWallOpts :: [DynFlag]
1745 minusWallOpts
1746 = minusWOpts ++
1747 [ Opt_WarnTypeDefaults,
1748 Opt_WarnNameShadowing,
1749 Opt_WarnMissingSigs,
1750 Opt_WarnHiShadows,
1751 Opt_WarnOrphans,
1752 Opt_WarnUnusedDoBind
1753 ]
1754
1755 -- minuswRemovesOpts should be every warning option
1756 minuswRemovesOpts :: [DynFlag]
1757 minuswRemovesOpts
1758 = minusWallOpts ++
1759 [Opt_WarnImplicitPrelude,
1760 Opt_WarnIncompletePatternsRecUpd,
1761 Opt_WarnSimplePatterns,
1762 Opt_WarnMonomorphism,
1763 Opt_WarnUnrecognisedPragmas,
1764 Opt_WarnTabs
1765 ]
1766
1767 enableGlasgowExts :: DynP ()
1768 enableGlasgowExts = do setDynFlag Opt_PrintExplicitForalls
1769 mapM_ setExtensionFlag glasgowExtsFlags
1770
1771 disableGlasgowExts :: DynP ()
1772 disableGlasgowExts = do unSetDynFlag Opt_PrintExplicitForalls
1773 mapM_ unSetExtensionFlag glasgowExtsFlags
1774
1775 glasgowExtsFlags :: [ExtensionFlag]
1776 glasgowExtsFlags = [
1777 Opt_ForeignFunctionInterface
1778 , Opt_UnliftedFFITypes
1779 , Opt_GADTs
1780 , Opt_ImplicitParams
1781 , Opt_ScopedTypeVariables
1782 , Opt_UnboxedTuples
1783 , Opt_TypeSynonymInstances
1784 , Opt_StandaloneDeriving
1785 , Opt_DeriveDataTypeable
1786 , Opt_DeriveFunctor
1787 , Opt_DeriveFoldable
1788 , Opt_DeriveTraversable
1789 , Opt_FlexibleContexts
1790 , Opt_FlexibleInstances
1791 , Opt_ConstrainedClassMethods
1792 , Opt_MultiParamTypeClasses
1793 , Opt_FunctionalDependencies
1794 , Opt_MagicHash
1795 , Opt_PolymorphicComponents
1796 , Opt_ExistentialQuantification
1797 , Opt_UnicodeSyntax
1798 , Opt_PostfixOperators
1799 , Opt_PatternGuards
1800 , Opt_LiberalTypeSynonyms
1801 , Opt_RankNTypes
1802 , Opt_TypeOperators
1803 , Opt_DoRec
1804 , Opt_ParallelListComp
1805 , Opt_EmptyDataDecls
1806 , Opt_KindSignatures
1807 , Opt_GeneralizedNewtypeDeriving
1808 , Opt_TypeFamilies ]
1809
1810 #ifdef GHCI
1811 -- Consult the RTS to find whether GHC itself has been built profiled
1812 -- If so, you can't use Template Haskell
1813 foreign import ccall unsafe "rts_isProfiled" rtsIsProfiledIO :: IO CInt
1814
1815 rtsIsProfiled :: Bool
1816 rtsIsProfiled = unsafePerformIO rtsIsProfiledIO /= 0
1817
1818 checkTemplateHaskellOk :: Bool -> DynP ()
1819 checkTemplateHaskellOk turn_on
1820 | turn_on && rtsIsProfiled
1821 = addErr "You can't use Template Haskell with a profiled compiler"
1822 | otherwise
1823 = return ()
1824 #else
1825 -- In stage 1 we don't know that the RTS has rts_isProfiled,
1826 -- so we simply say "ok". It doesn't matter because TH isn't
1827 -- available in stage 1 anyway.
1828 checkTemplateHaskellOk turn_on = return ()
1829 #endif
1830
1831 {- **********************************************************************
1832 %* *
1833 DynFlags constructors
1834 %* *
1835 %********************************************************************* -}
1836
1837 type DynP = EwM (CmdLineP DynFlags)
1838
1839 upd :: (DynFlags -> DynFlags) -> DynP ()
1840 upd f = liftEwM (do { dfs <- getCmdLineState
1841 ; putCmdLineState $! (f dfs) })
1842
1843 --------------- Constructor functions for OptKind -----------------
1844 noArg :: (DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
1845 noArg fn = NoArg (upd fn)
1846
1847 noArgDF :: (DynFlags -> DynFlags) -> String -> OptKind (CmdLineP DynFlags)
1848 noArgDF fn deprec = NoArg (upd fn >> deprecate deprec)
1849
1850 hasArg :: (String -> DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
1851 hasArg fn = HasArg (upd . fn)
1852
1853 hasArgDF :: (String -> DynFlags -> DynFlags) -> String -> OptKind (CmdLineP DynFlags)
1854 hasArgDF fn deprec = HasArg (\s -> do { upd (fn s)
1855 ; deprecate deprec })
1856
1857 intSuffix :: (Int -> DynFlags -> DynFlags) -> OptKind (CmdLineP DynFlags)
1858 intSuffix fn = IntSuffix (\n -> upd (fn n))
1859
1860 setDumpFlag :: DynFlag -> OptKind (CmdLineP DynFlags)
1861 setDumpFlag dump_flag = NoArg (setDumpFlag' dump_flag)
1862
1863 --------------------------
1864 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1865 setDynFlag f = upd (\dfs -> dopt_set dfs f)
1866 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1867
1868 --------------------------
1869 setLanguage :: Language -> DynP ()
1870 setLanguage l = upd (\dfs -> dfs { language = Just l })
1871
1872 --------------------------
1873 setExtensionFlag, unSetExtensionFlag :: ExtensionFlag -> DynP ()
1874 setExtensionFlag f = do { upd (\dfs -> xopt_set dfs f)
1875 ; mapM_ setExtensionFlag deps }
1876 where
1877 deps = [ d | (f', d) <- impliedFlags, f' == f ]
1878 -- When you set f, set the ones it implies
1879 -- NB: use setExtensionFlag recursively, in case the implied flags
1880 -- implies further flags
1881 -- When you un-set f, however, we don't un-set the things it implies
1882 -- (except for -fno-glasgow-exts, which is treated specially)
1883
1884 unSetExtensionFlag f = upd (\dfs -> xopt_unset dfs f)
1885
1886 --------------------------
1887 setDumpFlag' :: DynFlag -> DynP ()
1888 setDumpFlag' dump_flag
1889 = do { setDynFlag dump_flag
1890 ; when want_recomp forceRecompile }
1891 where
1892 -- Certain dumpy-things are really interested in what's going
1893 -- on during recompilation checking, so in those cases we
1894 -- don't want to turn it off.
1895 want_recomp = dump_flag `notElem` [Opt_D_dump_if_trace,
1896 Opt_D_dump_hi_diffs]
1897
1898 forceRecompile :: DynP ()
1899 -- Whenver we -ddump, force recompilation (by switching off the
1900 -- recompilation checker), else you don't see the dump! However,
1901 -- don't switch it off in --make mode, else *everything* gets
1902 -- recompiled which probably isn't what you want
1903 forceRecompile = do { dfs <- liftEwM getCmdLineState
1904 ; when (force_recomp dfs) (setDynFlag Opt_ForceRecomp) }
1905 where
1906 force_recomp dfs = isOneShot (ghcMode dfs)
1907
1908 setVerboseCore2Core :: DynP ()
1909 setVerboseCore2Core = do forceRecompile
1910 setDynFlag Opt_D_verbose_core2core
1911 upd (\dfs -> dfs { shouldDumpSimplPhase = Nothing })
1912
1913
1914 setDumpSimplPhases :: String -> DynP ()
1915 setDumpSimplPhases s = do forceRecompile
1916 upd (\dfs -> dfs { shouldDumpSimplPhase = Just spec })
1917 where
1918 spec = case s of { ('=' : s') -> s'; _ -> s }
1919
1920 setVerbosity :: Maybe Int -> DynP ()
1921 setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
1922
1923 addCmdlineHCInclude :: String -> DynP ()
1924 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes = a : cmdlineHcIncludes s})
1925
1926 extraPkgConf_ :: FilePath -> DynP ()
1927 extraPkgConf_ p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1928
1929 exposePackage, exposePackageId, hidePackage, ignorePackage :: String -> DynP ()
1930 exposePackage p =
1931 upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1932 exposePackageId p =
1933 upd (\s -> s{ packageFlags = ExposePackageId p : packageFlags s })
1934 hidePackage p =
1935 upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1936 ignorePackage p =
1937 upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1938
1939 setPackageName :: String -> DynFlags -> DynFlags
1940 setPackageName p s = s{ thisPackage = stringToPackageId p }
1941
1942 -- If we're linking a binary, then only targets that produce object
1943 -- code are allowed (requests for other target types are ignored).
1944 setTarget :: HscTarget -> DynP ()
1945 setTarget l = upd set
1946 where
1947 set dfs
1948 | ghcLink dfs /= LinkBinary || isObjectTarget l = dfs{ hscTarget = l }
1949 | otherwise = dfs
1950
1951 -- Changes the target only if we're compiling object code. This is
1952 -- used by -fasm and -fvia-C, which switch from one to the other, but
1953 -- not from bytecode to object-code. The idea is that -fasm/-fvia-C
1954 -- can be safely used in an OPTIONS_GHC pragma.
1955 setObjTarget :: HscTarget -> DynP ()
1956 setObjTarget l = upd set
1957 where
1958 set dfs
1959 | isObjectTarget (hscTarget dfs) = dfs { hscTarget = l }
1960 | otherwise = dfs
1961
1962 setOptLevel :: Int -> DynFlags -> DynFlags
1963 setOptLevel n dflags
1964 | hscTarget dflags == HscInterpreted && n > 0
1965 = dflags
1966 -- not in IO any more, oh well:
1967 -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1968 | otherwise
1969 = updOptLevel n dflags
1970
1971
1972 -- -Odph is equivalent to
1973 --
1974 -- -O2 optimise as much as possible
1975 -- -fno-method-sharing sharing specialisation defeats fusion
1976 -- sometimes
1977 -- -fdicts-cheap always inline dictionaries
1978 -- -fmax-simplifier-iterations20 this is necessary sometimes
1979 -- -fsimplifier-phases=3 we use an additional simplifier phase
1980 -- for fusion
1981 -- -fno-spec-constr-threshold run SpecConstr even for big loops
1982 -- -fno-spec-constr-count SpecConstr as much as possible
1983 -- -finline-enough-args hack to prevent excessive inlining
1984 --
1985 setDPHOpt :: DynFlags -> DynFlags
1986 setDPHOpt dflags = setOptLevel 2 (dflags { maxSimplIterations = 20
1987 , simplPhases = 3
1988 , specConstrThreshold = Nothing
1989 , specConstrCount = Nothing
1990 })
1991 `dopt_set` Opt_DictsCheap
1992 `dopt_unset` Opt_MethodSharing
1993
1994 data DPHBackend = DPHPar
1995 | DPHSeq
1996 | DPHThis
1997 deriving(Eq, Ord, Enum, Show)
1998
1999 setDPHBackend :: DPHBackend -> DynP ()
2000 setDPHBackend backend
2001 = do
2002 upd $ \dflags -> dflags { dphBackend = backend }
2003 mapM_ exposePackage (dph_packages backend)
2004 where
2005 dph_packages DPHThis = []
2006 dph_packages DPHPar = ["dph-prim-par", "dph-par"]
2007 dph_packages DPHSeq = ["dph-prim-seq", "dph-seq"]
2008
2009 dphPackage :: DynFlags -> PackageId
2010 dphPackage dflags = case dphBackend dflags of
2011 DPHPar -> dphParPackageId
2012 DPHSeq -> dphSeqPackageId
2013 DPHThis -> thisPackage dflags
2014
2015 setMainIs :: String -> DynP ()
2016 setMainIs arg
2017 | not (null main_fn) && isLower (head main_fn)
2018 -- The arg looked like "Foo.Bar.baz"
2019 = upd $ \d -> d{ mainFunIs = Just main_fn,
2020 mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
2021
2022 | isUpper (head arg) -- The arg looked like "Foo" or "Foo.Bar"
2023 = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName arg) }
2024
2025 | otherwise -- The arg looked like "baz"
2026 = upd $ \d -> d{ mainFunIs = Just arg }
2027 where
2028 (main_mod, main_fn) = splitLongestPrefix arg (== '.')
2029
2030 -----------------------------------------------------------------------------
2031 -- Paths & Libraries
2032
2033 addImportPath, addLibraryPath, addIncludePath, addFrameworkPath :: FilePath -> DynP ()
2034
2035 -- -i on its own deletes the import paths
2036 addImportPath "" = upd (\s -> s{importPaths = []})
2037 addImportPath p = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
2038
2039
2040 addLibraryPath p =
2041 upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
2042
2043 addIncludePath p =
2044 upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
2045
2046 addFrameworkPath p =
2047 upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
2048
2049 #ifndef mingw32_TARGET_OS
2050 split_marker :: Char
2051 split_marker = ':' -- not configurable (ToDo)
2052 #endif
2053
2054 splitPathList :: String -> [String]
2055 splitPathList s = filter notNull (splitUp s)
2056 -- empty paths are ignored: there might be a trailing
2057 -- ':' in the initial list, for example. Empty paths can
2058 -- cause confusion when they are translated into -I options
2059 -- for passing to gcc.
2060 where
2061 #ifndef mingw32_TARGET_OS
2062 splitUp xs = split split_marker xs
2063 #else
2064 -- Windows: 'hybrid' support for DOS-style paths in directory lists.
2065 --
2066 -- That is, if "foo:bar:baz" is used, this interpreted as
2067 -- consisting of three entries, 'foo', 'bar', 'baz'.
2068 -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
2069 -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
2070 --
2071 -- Notice that no attempt is made to fully replace the 'standard'
2072 -- split marker ':' with the Windows / DOS one, ';'. The reason being
2073 -- that this will cause too much breakage for users & ':' will
2074 -- work fine even with DOS paths, if you're not insisting on being silly.
2075 -- So, use either.
2076 splitUp [] = []
2077 splitUp (x:':':div:xs) | div `elem` dir_markers
2078 = ((x:':':div:p): splitUp rs)
2079 where
2080 (p,rs) = findNextPath xs
2081 -- we used to check for existence of the path here, but that
2082 -- required the IO monad to be threaded through the command-line
2083 -- parser which is quite inconvenient. The
2084 splitUp xs = cons p (splitUp rs)
2085 where
2086 (p,rs) = findNextPath xs
2087
2088 cons "" xs = xs
2089 cons x xs = x:xs
2090
2091 -- will be called either when we've consumed nought or the
2092 -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
2093 -- finding the next split marker.
2094 findNextPath xs =
2095 case break (`elem` split_markers) xs of
2096 (p, _:ds) -> (p, ds)
2097 (p, xs) -> (p, xs)
2098
2099 split_markers :: [Char]
2100 split_markers = [':', ';']
2101
2102 dir_markers :: [Char]
2103 dir_markers = ['/', '\\']
2104 #endif
2105
2106 -- -----------------------------------------------------------------------------
2107 -- tmpDir, where we store temporary files.
2108
2109 setTmpDir :: FilePath -> DynFlags -> DynFlags
2110 setTmpDir dir dflags = dflags{ tmpDir = normalise dir }
2111 -- we used to fix /cygdrive/c/.. on Windows, but this doesn't
2112 -- seem necessary now --SDM 7/2/2008
2113
2114 -----------------------------------------------------------------------------
2115 -- RTS opts
2116
2117 setRtsOpts :: String -> DynP ()
2118 setRtsOpts arg = upd $ \ d -> d {rtsOpts = Just arg}
2119
2120 setRtsOptsEnabled :: RtsOptsEnabled -> DynP ()
2121 setRtsOptsEnabled arg = upd $ \ d -> d {rtsOptsEnabled = arg}
2122
2123 -----------------------------------------------------------------------------
2124 -- Hpc stuff
2125
2126 setOptHpcDir :: String -> DynP ()
2127 setOptHpcDir arg = upd $ \ d -> d{hpcDir = arg}
2128
2129 -----------------------------------------------------------------------------
2130 -- Via-C compilation stuff
2131
2132 -- There are some options that we need to pass to gcc when compiling
2133 -- Haskell code via C, but are only supported by recent versions of
2134 -- gcc. The configure script decides which of these options we need,
2135 -- and puts them in the file "extra-gcc-opts" in $topdir, which is
2136 -- read before each via-C compilation. The advantage of having these
2137 -- in a separate file is that the file can be created at install-time
2138 -- depending on the available gcc version, and even re-generated later
2139 -- if gcc is upgraded.
2140 --
2141 -- The options below are not dependent on the version of gcc, only the
2142 -- platform.
2143
2144 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
2145 [String]) -- for registerised HC compilations
2146 machdepCCOpts dflags = let (flagsAll, flagsRegHc) = machdepCCOpts' dflags
2147 in (cCcOpts ++ flagsAll, flagsRegHc)
2148
2149 machdepCCOpts' :: DynFlags -> ([String], -- flags for all C compilations
2150 [String]) -- for registerised HC compilations
2151 machdepCCOpts' _dflags
2152 #if alpha_TARGET_ARCH
2153 = ( ["-w", "-mieee"
2154 #ifdef HAVE_THREADED_RTS_SUPPORT
2155 , "-D_REENTRANT"
2156 #endif
2157 ], [] )
2158 -- For now, to suppress the gcc warning "call-clobbered
2159 -- register used for global register variable", we simply
2160 -- disable all warnings altogether using the -w flag. Oh well.
2161
2162 #elif hppa_TARGET_ARCH
2163 -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
2164 -- (very nice, but too bad the HP /usr/include files don't agree.)
2165 = ( ["-D_HPUX_SOURCE"], [] )
2166
2167 #elif m68k_TARGET_ARCH
2168 -- -fno-defer-pop : for the .hc files, we want all the pushing/
2169 -- popping of args to routines to be explicit; if we let things
2170 -- be deferred 'til after an STGJUMP, imminent death is certain!
2171 --
2172 -- -fomit-frame-pointer : *don't*
2173 -- It's better to have a6 completely tied up being a frame pointer
2174 -- rather than let GCC pick random things to do with it.
2175 -- (If we want to steal a6, then we would try to do things
2176 -- as on iX86, where we *do* steal the frame pointer [%ebp].)
2177 = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
2178
2179 #elif i386_TARGET_ARCH
2180 -- -fno-defer-pop : basically the same game as for m68k
2181 --
2182 -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
2183 -- the fp (%ebp) for our register maps.
2184 = let n_regs = stolen_x86_regs _dflags
2185 in
2186 (
2187 [ if opt_Static then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
2188 ],
2189 [ "-fno-defer-pop",
2190 "-fomit-frame-pointer",
2191 -- we want -fno-builtin, because when gcc inlines
2192 -- built-in functions like memcpy() it tends to
2193 -- run out of registers, requiring -monly-n-regs
2194 "-fno-builtin",
2195 "-DSTOLEN_X86_REGS="++show n_regs ]
2196 )
2197
2198 #elif ia64_TARGET_ARCH
2199 = ( [], ["-fomit-frame-pointer", "-G0"] )
2200
2201 #elif x86_64_TARGET_ARCH
2202 = (
2203 [],
2204 ["-fomit-frame-pointer",
2205 "-fno-asynchronous-unwind-tables",
2206 -- the unwind tables are unnecessary for HC code,
2207 -- and get in the way of -split-objs. Another option
2208 -- would be to throw them away in the mangler, but this
2209 -- is easier.
2210 "-fno-builtin"
2211 -- calling builtins like strlen() using the FFI can
2212 -- cause gcc to run out of regs, so use the external
2213 -- version.
2214 ] )
2215
2216 #elif sparc_TARGET_ARCH
2217 = ( [], ["-w"] )
2218 -- For now, to suppress the gcc warning "call-clobbered
2219 -- register used for global register variable", we simply
2220 -- disable all warnings altogether using the -w flag. Oh well.
2221
2222 #elif powerpc_apple_darwin_TARGET
2223 -- -no-cpp-precomp:
2224 -- Disable Apple's precompiling preprocessor. It's a great thing
2225 -- for "normal" programs, but it doesn't support register variable
2226 -- declarations.
2227 = ( [], ["-no-cpp-precomp"] )
2228 #else
2229 = ( [], [] )
2230 #endif
2231
2232 picCCOpts :: DynFlags -> [String]
2233 picCCOpts _dflags
2234 #if darwin_TARGET_OS
2235 -- Apple prefers to do things the other way round.
2236 -- PIC is on by default.
2237 -- -mdynamic-no-pic:
2238 -- Turn off PIC code generation.
2239 -- -fno-common:
2240 -- Don't generate "common" symbols - these are unwanted
2241 -- in dynamic libraries.
2242
2243 | opt_PIC
2244 = ["-fno-common", "-U __PIC__","-D__PIC__"]
2245 | otherwise
2246 = ["-mdynamic-no-pic"]
2247 #elif mingw32_TARGET_OS
2248 -- no -fPIC for Windows
2249 | opt_PIC
2250 = ["-U __PIC__","-D__PIC__"]
2251 | otherwise
2252 = []
2253 #else
2254 -- we need -fPIC for C files when we are compiling with -dynamic,
2255 -- otherwise things like stub.c files don't get compiled
2256 -- correctly. They need to reference data in the Haskell
2257 -- objects, but can't without -fPIC. See
2258 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/PositionIndependentCode
2259 | opt_PIC || not opt_Static
2260 = ["-fPIC", "-U __PIC__", "-D__PIC__"]
2261 | otherwise
2262 = []
2263 #endif
2264
2265 -- -----------------------------------------------------------------------------
2266 -- Splitting
2267
2268 can_split :: Bool
2269 can_split = cSplitObjs == "YES"
2270
2271 -- -----------------------------------------------------------------------------
2272 -- Compiler Info
2273
2274 data Printable = String String
2275 | FromDynFlags (DynFlags -> String)
2276
2277 compilerInfo :: [(String, Printable)]
2278 compilerInfo = [("Project name", String cProjectName),
2279 ("Project version", String cProjectVersion),
2280 ("Booter version", String cBooterVersion),
2281 ("Stage", String cStage),
2282 ("Build platform", String cBuildPlatform),
2283 ("Host platform", String cHostPlatform),
2284 ("Target platform", String cTargetPlatform),
2285 ("Have interpreter", String cGhcWithInterpreter),
2286 ("Object splitting", String cSplitObjs),
2287 ("Have native code generator", String cGhcWithNativeCodeGen),
2288 ("Have llvm code generator", String cGhcWithLlvmCodeGen),
2289 ("Support SMP", String cGhcWithSMP),
2290 ("Unregisterised", String cGhcUnregisterised),
2291 ("Tables next to code", String cGhcEnableTablesNextToCode),
2292 ("RTS ways", String cGhcRTSWays),
2293 ("Leading underscore", String cLeadingUnderscore),
2294 ("Debug on", String (show debugIsOn)),
2295 ("LibDir", FromDynFlags topDir),
2296 ("Global Package DB", FromDynFlags systemPackageConfig)
2297 ]
2298