Add -XPatternSigs flag
[ghc-hetmet.git] / compiler / main / DynFlags.hs
1
2 {-# OPTIONS -fno-warn-missing-fields #-}
3 -----------------------------------------------------------------------------
4 --
5 -- Dynamic flags
6 --
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.
11 --
12 -- (c) The University of Glasgow 2005
13 --
14 -----------------------------------------------------------------------------
15
16 module DynFlags (
17         -- Dynamic flags
18         DynFlag(..),
19         DynFlags(..),
20         HscTarget(..), isObjectTarget, defaultObjectTarget,
21         GhcMode(..), isOneShot,
22         GhcLink(..), isNoLink,
23         PackageFlag(..),
24         Option(..),
25
26         -- Configuration of the core-to-core and stg-to-stg phases
27         CoreToDo(..),
28         StgToDo(..),
29         SimplifierSwitch(..), 
30         SimplifierMode(..), FloatOutSwitches(..),
31         getCoreToDo, getStgToDo,
32         
33         -- Manipulating DynFlags
34         defaultDynFlags,                -- DynFlags
35         initDynFlags,                   -- DynFlags -> IO DynFlags
36
37         dopt,                           -- DynFlag -> DynFlags -> Bool
38         dopt_set, dopt_unset,           -- DynFlags -> DynFlag -> DynFlags
39         getOpts,                        -- (DynFlags -> [a]) -> IO [a]
40         getVerbFlag,
41         updOptLevel,
42         setTmpDir,
43         setPackageName,
44         
45         -- parsing DynFlags
46         parseDynamicFlags,
47         allFlags,
48
49         -- misc stuff
50         machdepCCOpts, picCCOpts
51   ) where
52
53 #include "HsVersions.h"
54
55 import Module           ( Module, mkModuleName, mkModule )
56 import PackageConfig
57 import PrelNames        ( mAIN )
58 #ifdef i386_TARGET_ARCH
59 import StaticFlags      ( opt_Static )
60 #endif
61 import StaticFlags      ( opt_PIC, WayName(..), v_Ways, v_Build_tag,
62                           v_RTS_Build_tag )
63 import {-# SOURCE #-} Packages (PackageState)
64 import DriverPhases     ( Phase(..), phaseInputExt )
65 import Config
66 import CmdLineParser
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           ( orElse, fromJust )
72 import SrcLoc           ( SrcSpan )
73 import Outputable
74 import {-# SOURCE #-} ErrUtils ( Severity(..), Message, mkLocMessage )
75
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 )
81 #else
82 import Util             ( split )
83 #endif
84
85 import Data.Char        ( isUpper, toLower )
86 import System.IO        ( hPutStrLn, stderr )
87
88 -- -----------------------------------------------------------------------------
89 -- DynFlags
90
91 data DynFlag
92
93    -- debugging flags
94    = Opt_D_dump_cmm
95    | Opt_D_dump_cps_cmm
96    | Opt_D_dump_asm
97    | Opt_D_dump_cpranal
98    | Opt_D_dump_deriv
99    | Opt_D_dump_ds
100    | Opt_D_dump_flatC
101    | Opt_D_dump_foreign
102    | Opt_D_dump_inlinings
103    | Opt_D_dump_rule_firings
104    | Opt_D_dump_occur_anal
105    | Opt_D_dump_parsed
106    | Opt_D_dump_rn
107    | Opt_D_dump_simpl
108    | Opt_D_dump_simpl_iterations
109    | Opt_D_dump_spec
110    | Opt_D_dump_prep
111    | Opt_D_dump_stg
112    | Opt_D_dump_stranal
113    | Opt_D_dump_tc
114    | Opt_D_dump_types
115    | Opt_D_dump_rules
116    | Opt_D_dump_cse
117    | Opt_D_dump_worker_wrapper
118    | Opt_D_dump_rn_trace
119    | Opt_D_dump_rn_stats
120    | Opt_D_dump_opt_cmm
121    | Opt_D_dump_simpl_stats
122    | Opt_D_dump_tc_trace
123    | Opt_D_dump_if_trace
124    | Opt_D_dump_splices
125    | Opt_D_dump_BCOs
126    | Opt_D_dump_vect
127    | Opt_D_dump_hpc
128    | Opt_D_source_stats
129    | Opt_D_verbose_core2core
130    | Opt_D_verbose_stg2stg
131    | Opt_D_dump_hi
132    | Opt_D_dump_hi_diffs
133    | Opt_D_dump_minimal_imports
134    | Opt_D_dump_mod_cycles
135    | Opt_D_faststring_stats
136    | Opt_DoCoreLinting
137    | Opt_DoStgLinting
138    | Opt_DoCmmLinting
139
140    | Opt_WarnIsError            -- -Werror; makes warnings fatal
141    | Opt_WarnDuplicateExports
142    | Opt_WarnHiShadows
143    | Opt_WarnImplicitPrelude
144    | Opt_WarnIncompletePatterns
145    | Opt_WarnIncompletePatternsRecUpd
146    | Opt_WarnMissingFields
147    | Opt_WarnMissingMethods
148    | Opt_WarnMissingSigs
149    | Opt_WarnNameShadowing
150    | Opt_WarnOverlappingPatterns
151    | Opt_WarnSimplePatterns
152    | Opt_WarnTypeDefaults
153    | Opt_WarnMonomorphism
154    | Opt_WarnUnusedBinds
155    | Opt_WarnUnusedImports
156    | Opt_WarnUnusedMatches
157    | Opt_WarnDeprecations
158    | Opt_WarnDodgyImports
159    | Opt_WarnOrphans
160    | Opt_WarnTabs
161
162    -- language opts
163    | Opt_AllowOverlappingInstances
164    | Opt_AllowUndecidableInstances
165    | Opt_AllowIncoherentInstances
166    | Opt_MonomorphismRestriction
167    | Opt_MonoPatBinds
168    | Opt_ExtendedDefaultRules           -- Use GHC's extended rules for defaulting
169    | Opt_GlasgowExts
170    | Opt_FFI
171    | Opt_PArr                           -- Syntactic support for parallel arrays
172    | Opt_Arrows                         -- Arrow-notation syntax
173    | Opt_TH
174    | Opt_ImplicitParams
175    | Opt_Generics
176    | Opt_ImplicitPrelude 
177    | Opt_ScopedTypeVariables
178    | Opt_BangPatterns
179    | Opt_TypeFamilies
180    | Opt_OverloadedStrings
181    | Opt_DisambiguateRecordFields
182    | Opt_RecordWildCards
183    | Opt_RecordPuns
184    | Opt_GADTs
185    | Opt_RelaxedPolyRec                 -- -X=RelaxedPolyRec
186    | Opt_TypeSynonymInstances
187    | Opt_FlexibleContexts
188    | Opt_FlexibleInstances
189    | Opt_MultiParamTypeClasses
190    | Opt_FunctionalDependencies
191    | Opt_UnicodeSyntax
192    | Opt_PolymorphicComponents
193    | Opt_ExistentialQuantification
194    | Opt_MagicHash
195    | Opt_EmptyDataDecls
196    | Opt_KindSignatures
197    | Opt_PatternSignatures
198    | Opt_ParallelListComp
199    | Opt_GeneralizedNewtypeDeriving
200    | Opt_RecursiveDo
201    | Opt_PatternGuards
202    | Opt_Rank2Types
203    | Opt_RankNTypes
204    | Opt_TypeOperators
205
206    | Opt_PrintExplicitForalls
207
208    -- optimisation opts
209    | Opt_Strictness
210    | Opt_FullLaziness
211    | Opt_CSE
212    | Opt_LiberateCase
213    | Opt_SpecConstr
214    | Opt_IgnoreInterfacePragmas
215    | Opt_OmitInterfacePragmas
216    | Opt_DoLambdaEtaExpansion
217    | Opt_IgnoreAsserts
218    | Opt_IgnoreBreakpoints
219    | Opt_DoEtaReduction
220    | Opt_CaseMerge
221    | Opt_UnboxStrictFields
222    | Opt_DictsCheap
223    | Opt_RewriteRules
224    | Opt_Vectorise
225
226    -- misc opts
227    | Opt_Cpp
228    | Opt_Pp
229    | Opt_ForceRecomp
230    | Opt_DryRun
231    | Opt_DoAsmMangling
232    | Opt_ExcessPrecision
233    | Opt_ReadUserPackageConf
234    | Opt_NoHsMain
235    | Opt_SplitObjs
236    | Opt_StgStats
237    | Opt_HideAllPackages
238    | Opt_PrintBindResult
239    | Opt_Haddock
240    | Opt_Hpc_No_Auto
241    | Opt_BreakOnException
242
243    -- keeping stuff
244    | Opt_KeepHiDiffs
245    | Opt_KeepHcFiles
246    | Opt_KeepSFiles
247    | Opt_KeepRawSFiles
248    | Opt_KeepTmpFiles
249
250    deriving (Eq)
251  
252 data DynFlags = DynFlags {
253   ghcMode               :: GhcMode,
254   ghcLink               :: GhcLink,
255   coreToDo              :: Maybe [CoreToDo], -- reserved for -Ofile
256   stgToDo               :: Maybe [StgToDo],  -- similarly
257   hscTarget             :: HscTarget,
258   hscOutName            :: String,      -- name of the output file
259   extCoreName           :: String,      -- name of the .core output file
260   verbosity             :: Int,         -- verbosity level
261   optLevel              :: Int,         -- optimisation level
262   maxSimplIterations    :: Int,         -- max simplifier iterations
263   ruleCheck             :: Maybe String,
264
265   specThreshold         :: Int,         -- Threshold for function specialisation
266
267   stolen_x86_regs       :: Int,         
268   cmdlineHcIncludes     :: [String],    -- -#includes
269   importPaths           :: [FilePath],
270   mainModIs             :: Module,
271   mainFunIs             :: Maybe String,
272   ctxtStkDepth          :: Int,         -- Typechecker context stack depth
273
274   thisPackage           :: PackageId,
275
276   -- ways
277   wayNames              :: [WayName],   -- way flags from the cmd line
278   buildTag              :: String,      -- the global "way" (eg. "p" for prof)
279   rtsBuildTag           :: String,      -- the RTS "way"
280   
281   -- paths etc.
282   objectDir             :: Maybe String,
283   hiDir                 :: Maybe String,
284   stubDir               :: Maybe String,
285
286   objectSuf             :: String,
287   hcSuf                 :: String,
288   hiSuf                 :: String,
289
290   outputFile            :: Maybe String,
291   outputHi              :: Maybe String,
292
293   includePaths          :: [String],
294   libraryPaths          :: [String],
295   frameworkPaths        :: [String],    -- used on darwin only
296   cmdlineFrameworks     :: [String],    -- ditto
297   tmpDir                :: String,      -- no trailing '/'
298   
299   ghcUsagePath          :: FilePath,    -- Filled in by SysTools
300   ghciUsagePath         :: FilePath,    -- ditto
301
302   hpcDir                :: String,      -- ^ path to store the .mix files
303
304   -- options for particular phases
305   opt_L                 :: [String],
306   opt_P                 :: [String],
307   opt_F                 :: [String],
308   opt_c                 :: [String],
309   opt_m                 :: [String],
310   opt_a                 :: [String],
311   opt_l                 :: [String],
312   opt_dll               :: [String],
313   opt_dep               :: [String],
314
315   -- commands for particular phases
316   pgm_L                 :: String,
317   pgm_P                 :: (String,[Option]),
318   pgm_F                 :: String,
319   pgm_c                 :: (String,[Option]),
320   pgm_m                 :: (String,[Option]),
321   pgm_s                 :: (String,[Option]),
322   pgm_a                 :: (String,[Option]),
323   pgm_l                 :: (String,[Option]),
324   pgm_dll               :: (String,[Option]),
325   pgm_T                 :: String,
326   pgm_sysman            :: String,
327
328   --  Package flags
329   extraPkgConfs         :: [FilePath],
330   topDir                :: FilePath,    -- filled in by SysTools
331   systemPackageConfig   :: FilePath,    -- ditto
332         -- The -package-conf flags given on the command line, in the order
333         -- they appeared.
334
335   packageFlags          :: [PackageFlag],
336         -- The -package and -hide-package flags from the command-line
337
338   -- Package state
339   -- NB. do not modify this field, it is calculated by 
340   -- Packages.initPackages and Packages.updatePackages.
341   pkgDatabase           :: Maybe (UniqFM InstalledPackageInfo),
342   pkgState              :: PackageState,
343
344   -- hsc dynamic flags
345   flags                 :: [DynFlag],
346   
347   -- message output
348   log_action            :: Severity -> SrcSpan -> PprStyle -> Message -> IO ()
349  }
350
351 data HscTarget
352   = HscC
353   | HscAsm
354   | HscJava
355   | HscInterpreted
356   | HscNothing
357   deriving (Eq, Show)
358
359 -- | will this target result in an object file on the disk?
360 isObjectTarget :: HscTarget -> Bool
361 isObjectTarget HscC     = True
362 isObjectTarget HscAsm   = True
363 isObjectTarget _        = False
364
365 -- | The 'GhcMode' tells us whether we're doing multi-module
366 -- compilation (controlled via the "GHC" API) or one-shot
367 -- (single-module) compilation.  This makes a difference primarily to
368 -- the "Finder": in one-shot mode we look for interface files for
369 -- imported modules, but in multi-module mode we look for source files
370 -- in order to check whether they need to be recompiled.
371 data GhcMode
372   = CompManager         -- ^ --make, GHCi, etc.
373   | OneShot             -- ^ ghc -c Foo.hs
374   | MkDepend            -- ^ ghc -M, see Finder for why we need this
375   deriving Eq
376
377 isOneShot :: GhcMode -> Bool
378 isOneShot OneShot = True
379 isOneShot _other  = False
380
381 -- | What kind of linking to do.
382 data GhcLink    -- What to do in the link step, if there is one
383   = NoLink              -- Don't link at all
384   | LinkBinary          -- Link object code into a binary
385   | LinkInMemory        -- Use the in-memory dynamic linker
386   | LinkDynLib          -- Link objects into a dynamic lib (DLL on Windows, DSO on ELF platforms)
387   deriving Eq
388
389 isNoLink :: GhcLink -> Bool
390 isNoLink NoLink = True
391 isNoLink other  = False
392
393 data PackageFlag
394   = ExposePackage  String
395   | HidePackage    String
396   | IgnorePackage  String
397   deriving Eq
398
399 defaultHscTarget = defaultObjectTarget
400
401 -- | the 'HscTarget' value corresponding to the default way to create
402 -- object files on the current platform.
403 defaultObjectTarget
404   | cGhcWithNativeCodeGen == "YES"      =  HscAsm
405   | otherwise                           =  HscC
406
407 initDynFlags dflags = do
408  -- someday these will be dynamic flags
409  ways <- readIORef v_Ways
410  build_tag <- readIORef v_Build_tag
411  rts_build_tag <- readIORef v_RTS_Build_tag
412  return dflags{
413         wayNames        = ways,
414         buildTag        = build_tag,
415         rtsBuildTag     = rts_build_tag
416         }
417
418 defaultDynFlags =
419      DynFlags {
420         ghcMode                 = CompManager,
421         ghcLink                 = LinkBinary,
422         coreToDo                = Nothing,
423         stgToDo                 = Nothing, 
424         hscTarget               = defaultHscTarget, 
425         hscOutName              = "", 
426         extCoreName             = "",
427         verbosity               = 0, 
428         optLevel                = 0,
429         maxSimplIterations      = 4,
430         ruleCheck               = Nothing,
431         specThreshold           = 200,
432         stolen_x86_regs         = 4,
433         cmdlineHcIncludes       = [],
434         importPaths             = ["."],
435         mainModIs               = mAIN,
436         mainFunIs               = Nothing,
437         ctxtStkDepth            = mAX_CONTEXT_REDUCTION_DEPTH,
438
439         thisPackage             = mainPackageId,
440
441         objectDir               = Nothing,
442         hiDir                   = Nothing,
443         stubDir                 = Nothing,
444
445         objectSuf               = phaseInputExt StopLn,
446         hcSuf                   = phaseInputExt HCc,
447         hiSuf                   = "hi",
448
449         outputFile              = Nothing,
450         outputHi                = Nothing,
451         includePaths            = [],
452         libraryPaths            = [],
453         frameworkPaths          = [],
454         cmdlineFrameworks       = [],
455         tmpDir                  = cDEFAULT_TMPDIR,
456         
457         hpcDir                  = ".hpc",
458
459         opt_L                   = [],
460         opt_P                   = [],
461         opt_F                   = [],
462         opt_c                   = [],
463         opt_a                   = [],
464         opt_m                   = [],
465         opt_l                   = [],
466         opt_dll                 = [],
467         opt_dep                 = [],
468         
469         extraPkgConfs           = [],
470         packageFlags            = [],
471         pkgDatabase             = Nothing,
472         pkgState                = panic "no package state yet: call GHC.setSessionDynFlags",
473         flags = [ 
474             Opt_ReadUserPackageConf,
475     
476             Opt_MonoPatBinds,   -- Experimentally, I'm making this non-standard
477                                 -- behaviour the default, to see if anyone notices
478                                 -- SLPJ July 06
479
480             Opt_ImplicitPrelude,
481             Opt_MonomorphismRestriction,
482
483             Opt_DoAsmMangling,
484     
485             -- on by default:
486             Opt_PrintBindResult ]
487             ++ [f | (ns,f) <- optLevelFlags, 0 `elem` ns]
488                     -- The default -O0 options
489             ++ standardWarnings,
490                
491         log_action = \severity srcSpan style msg -> 
492                         case severity of
493                           SevInfo  -> hPutStrLn stderr (show (msg style))
494                           SevFatal -> hPutStrLn stderr (show (msg style))
495                           _        -> hPutStrLn stderr ('\n':show ((mkLocMessage srcSpan msg) style))
496       }
497
498 {- 
499     Verbosity levels:
500         
501     0   |   print errors & warnings only
502     1   |   minimal verbosity: print "compiling M ... done." for each module.
503     2   |   equivalent to -dshow-passes
504     3   |   equivalent to existing "ghc -v"
505     4   |   "ghc -v -ddump-most"
506     5   |   "ghc -v -ddump-all"
507 -}
508
509 dopt :: DynFlag -> DynFlags -> Bool
510 dopt f dflags  = f `elem` (flags dflags)
511
512 dopt_set :: DynFlags -> DynFlag -> DynFlags
513 dopt_set dfs f = dfs{ flags = f : flags dfs }
514
515 dopt_unset :: DynFlags -> DynFlag -> DynFlags
516 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
517
518 getOpts :: DynFlags -> (DynFlags -> [a]) -> [a]
519 getOpts dflags opts = reverse (opts dflags)
520         -- We add to the options from the front, so we need to reverse the list
521
522 getVerbFlag :: DynFlags -> String
523 getVerbFlag dflags 
524   | verbosity dflags >= 3  = "-v" 
525   | otherwise =  ""
526
527 setObjectDir  f d = d{ objectDir  = f}
528 setHiDir      f d = d{ hiDir      = f}
529 setStubDir    f d = d{ stubDir    = f}
530
531 setObjectSuf  f d = d{ objectSuf  = f}
532 setHiSuf      f d = d{ hiSuf      = f}
533 setHcSuf      f d = d{ hcSuf      = f}
534
535 setOutputFile f d = d{ outputFile = f}
536 setOutputHi   f d = d{ outputHi   = f}
537
538 -- XXX HACK: Prelude> words "'does not' work" ===> ["'does","not'","work"]
539 -- Config.hs should really use Option.
540 setPgmP   f d = let (pgm:args) = words f in d{ pgm_P   = (pgm, map Option args)}
541
542 setPgmL   f d = d{ pgm_L   = f}
543 setPgmF   f d = d{ pgm_F   = f}
544 setPgmc   f d = d{ pgm_c   = (f,[])}
545 setPgmm   f d = d{ pgm_m   = (f,[])}
546 setPgms   f d = d{ pgm_s   = (f,[])}
547 setPgma   f d = d{ pgm_a   = (f,[])}
548 setPgml   f d = d{ pgm_l   = (f,[])}
549 setPgmdll f d = d{ pgm_dll = (f,[])}
550
551 addOptL   f d = d{ opt_L   = f : opt_L d}
552 addOptP   f d = d{ opt_P   = f : opt_P d}
553 addOptF   f d = d{ opt_F   = f : opt_F d}
554 addOptc   f d = d{ opt_c   = f : opt_c d}
555 addOptm   f d = d{ opt_m   = f : opt_m d}
556 addOpta   f d = d{ opt_a   = f : opt_a d}
557 addOptl   f d = d{ opt_l   = f : opt_l d}
558 addOptdll f d = d{ opt_dll = f : opt_dll d}
559 addOptdep f d = d{ opt_dep = f : opt_dep d}
560
561 addCmdlineFramework f d = d{ cmdlineFrameworks = f : cmdlineFrameworks d}
562
563 -- -----------------------------------------------------------------------------
564 -- Command-line options
565
566 -- When invoking external tools as part of the compilation pipeline, we
567 -- pass these a sequence of options on the command-line. Rather than
568 -- just using a list of Strings, we use a type that allows us to distinguish
569 -- between filepaths and 'other stuff'. [The reason being, of course, that
570 -- this type gives us a handle on transforming filenames, and filenames only,
571 -- to whatever format they're expected to be on a particular platform.]
572
573 data Option
574  = FileOption -- an entry that _contains_ filename(s) / filepaths.
575               String  -- a non-filepath prefix that shouldn't be 
576                       -- transformed (e.g., "/out=")
577               String  -- the filepath/filename portion
578  | Option     String
579  
580 -----------------------------------------------------------------------------
581 -- Setting the optimisation level
582
583 updOptLevel :: Int -> DynFlags -> DynFlags
584 -- Set dynflags appropriate to the optimisation level
585 updOptLevel n dfs
586   = dfs2{ optLevel = final_n }
587   where
588    final_n = max 0 (min 2 n)    -- Clamp to 0 <= n <= 2
589    dfs1 = foldr (flip dopt_unset) dfs  remove_dopts
590    dfs2 = foldr (flip dopt_set)   dfs1 extra_dopts
591
592    extra_dopts  = [ f | (ns,f) <- optLevelFlags, final_n `elem` ns ]
593    remove_dopts = [ f | (ns,f) <- optLevelFlags, final_n `notElem` ns ]
594         
595 optLevelFlags :: [([Int], DynFlag)]
596 optLevelFlags
597   = [ ([0],     Opt_IgnoreInterfacePragmas)
598     , ([0],     Opt_OmitInterfacePragmas)
599
600     , ([1,2],   Opt_IgnoreAsserts)
601     , ([1,2],   Opt_RewriteRules)       -- Off for -O0; see Note [Scoping for Builtin rules]
602                                         --              in PrelRules
603     , ([1,2],   Opt_DoEtaReduction)
604     , ([1,2],   Opt_CaseMerge)
605     , ([1,2],   Opt_Strictness)
606     , ([1,2],   Opt_CSE)
607     , ([1,2],   Opt_FullLaziness)
608
609     , ([2],     Opt_LiberateCase)
610     , ([2],     Opt_SpecConstr)
611
612     , ([0,1,2], Opt_DoLambdaEtaExpansion)
613                 -- This one is important for a tiresome reason:
614                 -- we want to make sure that the bindings for data 
615                 -- constructors are eta-expanded.  This is probably
616                 -- a good thing anyway, but it seems fragile.
617     ]
618
619 -- -----------------------------------------------------------------------------
620 -- Standard sets of warning options
621
622 standardWarnings
623     = [ Opt_WarnDeprecations,
624         Opt_WarnOverlappingPatterns,
625         Opt_WarnMissingFields,
626         Opt_WarnMissingMethods,
627         Opt_WarnDuplicateExports
628       ]
629
630 minusWOpts
631     = standardWarnings ++ 
632       [ Opt_WarnUnusedBinds,
633         Opt_WarnUnusedMatches,
634         Opt_WarnUnusedImports,
635         Opt_WarnIncompletePatterns,
636         Opt_WarnDodgyImports
637       ]
638
639 minusWallOpts
640     = minusWOpts ++
641       [ Opt_WarnTypeDefaults,
642         Opt_WarnNameShadowing,
643         Opt_WarnMissingSigs,
644         Opt_WarnHiShadows,
645         Opt_WarnOrphans
646       ]
647
648 -- -----------------------------------------------------------------------------
649 -- CoreToDo:  abstraction of core-to-core passes to run.
650
651 data CoreToDo           -- These are diff core-to-core passes,
652                         -- which may be invoked in any order,
653                         -- as many times as you like.
654
655   = CoreDoSimplify      -- The core-to-core simplifier.
656         SimplifierMode
657         [SimplifierSwitch]
658                         -- Each run of the simplifier can take a different
659                         -- set of simplifier-specific flags.
660   | CoreDoFloatInwards
661   | CoreDoFloatOutwards FloatOutSwitches
662   | CoreLiberateCase
663   | CoreDoPrintCore
664   | CoreDoStaticArgs
665   | CoreDoStrictness
666   | CoreDoWorkerWrapper
667   | CoreDoSpecialising
668   | CoreDoSpecConstr
669   | CoreDoOldStrictness
670   | CoreDoGlomBinds
671   | CoreCSE
672   | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules 
673                                                 -- matching this string
674   | CoreDoNothing                -- Useful when building up 
675   | CoreDoPasses [CoreToDo]      -- lists of these things
676
677 data SimplifierMode             -- See comments in SimplMonad
678   = SimplGently
679   | SimplPhase Int
680
681 data SimplifierSwitch
682   = MaxSimplifierIterations Int
683   | NoCaseOfCase
684
685 data FloatOutSwitches
686   = FloatOutSw  Bool    -- True <=> float lambdas to top level
687                 Bool    -- True <=> float constants to top level,
688                         --          even if they do not escape a lambda
689
690
691 -- The core-to-core pass ordering is derived from the DynFlags:
692 runWhen :: Bool -> CoreToDo -> CoreToDo
693 runWhen True  do_this = do_this
694 runWhen False do_this = CoreDoNothing
695
696 getCoreToDo :: DynFlags -> [CoreToDo]
697 getCoreToDo dflags
698   | Just todo <- coreToDo dflags = todo -- set explicitly by user
699   | otherwise = core_todo
700   where
701     opt_level     = optLevel dflags
702     max_iter      = maxSimplIterations dflags
703     strictness    = dopt Opt_Strictness dflags
704     full_laziness = dopt Opt_FullLaziness dflags
705     cse           = dopt Opt_CSE dflags
706     spec_constr   = dopt Opt_SpecConstr dflags
707     liberate_case = dopt Opt_LiberateCase dflags
708     rule_check    = ruleCheck dflags
709
710     core_todo = 
711      if opt_level == 0 then
712       [
713         CoreDoSimplify (SimplPhase 0) [
714             MaxSimplifierIterations max_iter
715         ]
716       ]
717      else {- opt_level >= 1 -} [ 
718
719         -- initial simplify: mk specialiser happy: minimum effort please
720         CoreDoSimplify SimplGently [
721                         --      Simplify "gently"
722                         -- Don't inline anything till full laziness has bitten
723                         -- In particular, inlining wrappers inhibits floating
724                         -- e.g. ...(case f x of ...)...
725                         --  ==> ...(case (case x of I# x# -> fw x#) of ...)...
726                         --  ==> ...(case x of I# x# -> case fw x# of ...)...
727                         -- and now the redex (f x) isn't floatable any more
728                         -- Similarly, don't apply any rules until after full 
729                         -- laziness.  Notably, list fusion can prevent floating.
730
731             NoCaseOfCase,       -- Don't do case-of-case transformations.
732                                 -- This makes full laziness work better
733             MaxSimplifierIterations max_iter
734         ],
735
736         -- Specialisation is best done before full laziness
737         -- so that overloaded functions have all their dictionary lambdas manifest
738         CoreDoSpecialising,
739
740         runWhen full_laziness (CoreDoFloatOutwards (FloatOutSw False False)),
741
742         CoreDoFloatInwards,
743
744         CoreDoSimplify (SimplPhase 2) [
745                 -- Want to run with inline phase 2 after the specialiser to give
746                 -- maximum chance for fusion to work before we inline build/augment
747                 -- in phase 1.  This made a difference in 'ansi' where an 
748                 -- overloaded function wasn't inlined till too late.
749            MaxSimplifierIterations max_iter
750         ],
751         case rule_check of { Just pat -> CoreDoRuleCheck 2 pat; Nothing -> CoreDoNothing },
752
753         CoreDoSimplify (SimplPhase 1) [
754                 -- Need inline-phase2 here so that build/augment get 
755                 -- inlined.  I found that spectral/hartel/genfft lost some useful
756                 -- strictness in the function sumcode' if augment is not inlined
757                 -- before strictness analysis runs
758            MaxSimplifierIterations max_iter
759         ],
760         case rule_check of { Just pat -> CoreDoRuleCheck 1 pat; Nothing -> CoreDoNothing },
761
762         CoreDoSimplify (SimplPhase 0) [
763                 -- Phase 0: allow all Ids to be inlined now
764                 -- This gets foldr inlined before strictness analysis
765
766            MaxSimplifierIterations 3
767                 -- At least 3 iterations because otherwise we land up with
768                 -- huge dead expressions because of an infelicity in the 
769                 -- simpifier.   
770                 --      let k = BIG in foldr k z xs
771                 -- ==>  let k = BIG in letrec go = \xs -> ...(k x).... in go xs
772                 -- ==>  let k = BIG in letrec go = \xs -> ...(BIG x).... in go xs
773                 -- Don't stop now!
774
775         ],
776         case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
777
778 #ifdef OLD_STRICTNESS
779         CoreDoOldStrictness,
780 #endif
781         runWhen strictness (CoreDoPasses [
782                 CoreDoStrictness,
783                 CoreDoWorkerWrapper,
784                 CoreDoGlomBinds,
785                 CoreDoSimplify (SimplPhase 0) [
786                    MaxSimplifierIterations max_iter
787                 ]]),
788
789         runWhen full_laziness 
790           (CoreDoFloatOutwards (FloatOutSw False    -- Not lambdas
791                                            True)),  -- Float constants
792                 -- nofib/spectral/hartel/wang doubles in speed if you
793                 -- do full laziness late in the day.  It only happens
794                 -- after fusion and other stuff, so the early pass doesn't
795                 -- catch it.  For the record, the redex is 
796                 --        f_el22 (f_el21 r_midblock)
797
798
799         runWhen cse CoreCSE,
800                 -- We want CSE to follow the final full-laziness pass, because it may
801                 -- succeed in commoning up things floated out by full laziness.
802                 -- CSE used to rely on the no-shadowing invariant, but it doesn't any more
803
804         CoreDoFloatInwards,
805
806         case rule_check of { Just pat -> CoreDoRuleCheck 0 pat; Nothing -> CoreDoNothing },
807
808                 -- Case-liberation for -O2.  This should be after
809                 -- strictness analysis and the simplification which follows it.
810         runWhen liberate_case (CoreDoPasses [
811             CoreLiberateCase,
812             CoreDoSimplify (SimplPhase 0) [
813                   MaxSimplifierIterations max_iter
814             ] ]),       -- Run the simplifier after LiberateCase to vastly 
815                         -- reduce the possiblility of shadowing
816                         -- Reason: see Note [Shadowing] in SpecConstr.lhs
817
818         runWhen spec_constr CoreDoSpecConstr,
819
820         -- Final clean-up simplification:
821         CoreDoSimplify (SimplPhase 0) [
822           MaxSimplifierIterations max_iter
823         ]
824      ]
825
826 -- -----------------------------------------------------------------------------
827 -- StgToDo:  abstraction of stg-to-stg passes to run.
828
829 data StgToDo
830   = StgDoMassageForProfiling  -- should be (next to) last
831   -- There's also setStgVarInfo, but its absolute "lastness"
832   -- is so critical that it is hardwired in (no flag).
833   | D_stg_stats
834
835 getStgToDo :: DynFlags -> [StgToDo]
836 getStgToDo dflags
837   | Just todo <- stgToDo dflags = todo -- set explicitly by user
838   | otherwise = todo2
839   where
840         stg_stats = dopt Opt_StgStats dflags
841
842         todo1 = if stg_stats then [D_stg_stats] else []
843
844         todo2 | WayProf `elem` wayNames dflags
845               = StgDoMassageForProfiling : todo1
846               | otherwise
847               = todo1
848
849 -- -----------------------------------------------------------------------------
850 -- DynFlags parser
851
852 allFlags :: [String]
853 allFlags = map ('-':) $
854            [ name | (name, optkind) <- dynamic_flags, ok optkind ] ++
855            map ("fno-"++) flags ++
856            map ("f"++) flags
857     where ok (PrefixPred _ _) = False
858           ok _ = True
859           flags = map fst fFlags
860
861 dynamic_flags :: [(String, OptKind DynP)]
862 dynamic_flags = [
863      ( "n"              , NoArg  (setDynFlag Opt_DryRun) )
864   ,  ( "cpp"            , NoArg  (setDynFlag Opt_Cpp))
865   ,  ( "F"              , NoArg  (setDynFlag Opt_Pp))
866   ,  ( "#include"       , HasArg (addCmdlineHCInclude) )
867   ,  ( "v"              , OptIntSuffix setVerbosity )
868
869         ------- Specific phases  --------------------------------------------
870   ,  ( "pgmL"           , HasArg (upd . setPgmL) )  
871   ,  ( "pgmP"           , HasArg (upd . setPgmP) )  
872   ,  ( "pgmF"           , HasArg (upd . setPgmF) )  
873   ,  ( "pgmc"           , HasArg (upd . setPgmc) )  
874   ,  ( "pgmm"           , HasArg (upd . setPgmm) )  
875   ,  ( "pgms"           , HasArg (upd . setPgms) )  
876   ,  ( "pgma"           , HasArg (upd . setPgma) )  
877   ,  ( "pgml"           , HasArg (upd . setPgml) )  
878   ,  ( "pgmdll"         , HasArg (upd . setPgmdll) )
879
880   ,  ( "optL"           , HasArg (upd . addOptL) )  
881   ,  ( "optP"           , HasArg (upd . addOptP) )  
882   ,  ( "optF"           , HasArg (upd . addOptF) )  
883   ,  ( "optc"           , HasArg (upd . addOptc) )  
884   ,  ( "optm"           , HasArg (upd . addOptm) )  
885   ,  ( "opta"           , HasArg (upd . addOpta) )  
886   ,  ( "optl"           , HasArg (upd . addOptl) )  
887   ,  ( "optdll"         , HasArg (upd . addOptdll) )  
888   ,  ( "optdep"         , HasArg (upd . addOptdep) )
889
890   ,  ( "split-objs"     , NoArg (if can_split
891                                     then setDynFlag Opt_SplitObjs
892                                     else return ()) )
893
894         -------- Linking ----------------------------------------------------
895   ,  ( "c"              , NoArg (upd $ \d -> d{ ghcLink=NoLink } ))
896   ,  ( "no-link"        , NoArg (upd $ \d -> d{ ghcLink=NoLink } )) -- Dep.
897   ,  ( "shared"         , NoArg (upd $ \d -> d{ ghcLink=LinkDynLib } ))
898
899         ------- Libraries ---------------------------------------------------
900   ,  ( "L"              , Prefix addLibraryPath )
901   ,  ( "l"              , AnySuffix (\s -> do upd (addOptl s)
902                                               upd (addOptdll s)))
903
904         ------- Frameworks --------------------------------------------------
905         -- -framework-path should really be -F ...
906   ,  ( "framework-path" , HasArg addFrameworkPath )
907   ,  ( "framework"      , HasArg (upd . addCmdlineFramework) )
908
909         ------- Output Redirection ------------------------------------------
910   ,  ( "odir"           , HasArg (upd . setObjectDir  . Just))
911   ,  ( "o"              , SepArg (upd . setOutputFile . Just))
912   ,  ( "ohi"            , HasArg (upd . setOutputHi   . Just ))
913   ,  ( "osuf"           , HasArg (upd . setObjectSuf))
914   ,  ( "hcsuf"          , HasArg (upd . setHcSuf))
915   ,  ( "hisuf"          , HasArg (upd . setHiSuf))
916   ,  ( "hidir"          , HasArg (upd . setHiDir . Just))
917   ,  ( "tmpdir"         , HasArg (upd . setTmpDir))
918   ,  ( "stubdir"        , HasArg (upd . setStubDir . Just))
919
920         ------- Keeping temporary files -------------------------------------
921      -- These can be singular (think ghc -c) or plural (think ghc --make)
922   ,  ( "keep-hc-file"    , NoArg (setDynFlag Opt_KeepHcFiles))
923   ,  ( "keep-hc-files"   , NoArg (setDynFlag Opt_KeepHcFiles))
924   ,  ( "keep-s-file"     , NoArg (setDynFlag Opt_KeepSFiles))
925   ,  ( "keep-s-files"    , NoArg (setDynFlag Opt_KeepSFiles))
926   ,  ( "keep-raw-s-file" , NoArg (setDynFlag Opt_KeepRawSFiles))
927   ,  ( "keep-raw-s-files", NoArg (setDynFlag Opt_KeepRawSFiles))
928      -- This only makes sense as plural
929   ,  ( "keep-tmp-files"  , NoArg (setDynFlag Opt_KeepTmpFiles))
930
931         ------- Miscellaneous ----------------------------------------------
932   ,  ( "no-hs-main"     , NoArg (setDynFlag Opt_NoHsMain))
933   ,  ( "main-is"        , SepArg setMainIs )
934   ,  ( "haddock"        , NoArg (setDynFlag Opt_Haddock) )
935   ,  ( "hpcdir"         , SepArg setOptHpcDir )
936
937         ------- recompilation checker (DEPRECATED, use -fforce-recomp) -----
938   ,  ( "recomp"         , NoArg (unSetDynFlag Opt_ForceRecomp) )
939   ,  ( "no-recomp"      , NoArg (setDynFlag   Opt_ForceRecomp) )
940
941         ------- Packages ----------------------------------------------------
942   ,  ( "package-conf"   , HasArg extraPkgConf_ )
943   ,  ( "no-user-package-conf", NoArg (unSetDynFlag Opt_ReadUserPackageConf) )
944   ,  ( "package-name"   , HasArg (upd . setPackageName) )
945   ,  ( "package"        , HasArg exposePackage )
946   ,  ( "hide-package"   , HasArg hidePackage )
947   ,  ( "hide-all-packages", NoArg (setDynFlag Opt_HideAllPackages) )
948   ,  ( "ignore-package" , HasArg ignorePackage )
949   ,  ( "syslib"         , HasArg exposePackage )  -- for compatibility
950
951         ------ HsCpp opts ---------------------------------------------------
952   ,  ( "D",             AnySuffix (upd . addOptP) )
953   ,  ( "U",             AnySuffix (upd . addOptP) )
954
955         ------- Include/Import Paths ----------------------------------------
956   ,  ( "I"              , Prefix    addIncludePath)
957   ,  ( "i"              , OptPrefix addImportPath )
958
959         ------ Debugging ----------------------------------------------------
960   ,  ( "dstg-stats",    NoArg (setDynFlag Opt_StgStats))
961
962   ,  ( "ddump-cmm",              setDumpFlag Opt_D_dump_cmm)
963   ,  ( "ddump-cps-cmm",          setDumpFlag Opt_D_dump_cps_cmm)
964   ,  ( "ddump-asm",              setDumpFlag Opt_D_dump_asm)
965   ,  ( "ddump-cpranal",          setDumpFlag Opt_D_dump_cpranal)
966   ,  ( "ddump-deriv",            setDumpFlag Opt_D_dump_deriv)
967   ,  ( "ddump-ds",               setDumpFlag Opt_D_dump_ds)
968   ,  ( "ddump-flatC",            setDumpFlag Opt_D_dump_flatC)
969   ,  ( "ddump-foreign",          setDumpFlag Opt_D_dump_foreign)
970   ,  ( "ddump-inlinings",        setDumpFlag Opt_D_dump_inlinings)
971   ,  ( "ddump-rule-firings",     setDumpFlag Opt_D_dump_rule_firings)
972   ,  ( "ddump-occur-anal",       setDumpFlag Opt_D_dump_occur_anal)
973   ,  ( "ddump-parsed",           setDumpFlag Opt_D_dump_parsed)
974   ,  ( "ddump-rn",               setDumpFlag Opt_D_dump_rn)
975   ,  ( "ddump-simpl",            setDumpFlag Opt_D_dump_simpl)
976   ,  ( "ddump-simpl-iterations", setDumpFlag Opt_D_dump_simpl_iterations)
977   ,  ( "ddump-spec",             setDumpFlag Opt_D_dump_spec)
978   ,  ( "ddump-prep",             setDumpFlag Opt_D_dump_prep)
979   ,  ( "ddump-stg",              setDumpFlag Opt_D_dump_stg)
980   ,  ( "ddump-stranal",          setDumpFlag Opt_D_dump_stranal)
981   ,  ( "ddump-tc",               setDumpFlag Opt_D_dump_tc)
982   ,  ( "ddump-types",            setDumpFlag Opt_D_dump_types)
983   ,  ( "ddump-rules",            setDumpFlag Opt_D_dump_rules)
984   ,  ( "ddump-cse",              setDumpFlag Opt_D_dump_cse)
985   ,  ( "ddump-worker-wrapper",   setDumpFlag Opt_D_dump_worker_wrapper)
986   ,  ( "ddump-rn-trace",         setDumpFlag Opt_D_dump_rn_trace)
987   ,  ( "ddump-if-trace",         setDumpFlag Opt_D_dump_if_trace)
988   ,  ( "ddump-tc-trace",         setDumpFlag Opt_D_dump_tc_trace)
989   ,  ( "ddump-splices",          setDumpFlag Opt_D_dump_splices)
990   ,  ( "ddump-rn-stats",         setDumpFlag Opt_D_dump_rn_stats)
991   ,  ( "ddump-opt-cmm",          setDumpFlag Opt_D_dump_opt_cmm)
992   ,  ( "ddump-simpl-stats",      setDumpFlag Opt_D_dump_simpl_stats)
993   ,  ( "ddump-bcos",             setDumpFlag Opt_D_dump_BCOs)
994   ,  ( "dsource-stats",          setDumpFlag Opt_D_source_stats)
995   ,  ( "dverbose-core2core",     setDumpFlag Opt_D_verbose_core2core)
996   ,  ( "dverbose-stg2stg",       setDumpFlag Opt_D_verbose_stg2stg)
997   ,  ( "ddump-hi",               setDumpFlag Opt_D_dump_hi)
998   ,  ( "ddump-minimal-imports",  setDumpFlag Opt_D_dump_minimal_imports)
999   ,  ( "ddump-vect",             setDumpFlag Opt_D_dump_vect)
1000   ,  ( "ddump-hpc",              setDumpFlag Opt_D_dump_hpc)
1001   ,  ( "ddump-mod-cycles",       setDumpFlag Opt_D_dump_mod_cycles)
1002   
1003   ,  ( "ddump-hi-diffs",         NoArg (setDynFlag Opt_D_dump_hi_diffs))
1004   ,  ( "dcore-lint",             NoArg (setDynFlag Opt_DoCoreLinting))
1005   ,  ( "dstg-lint",              NoArg (setDynFlag Opt_DoStgLinting))
1006   ,  ( "dcmm-lint",              NoArg (setDynFlag Opt_DoCmmLinting))
1007   ,  ( "dshow-passes",           NoArg (do setDynFlag Opt_ForceRecomp
1008                                            setVerbosity (Just 2)) )
1009   ,  ( "dfaststring-stats",      NoArg (setDynFlag Opt_D_faststring_stats))
1010
1011         ------ Machine dependant (-m<blah>) stuff ---------------------------
1012
1013   ,  ( "monly-2-regs",  NoArg (upd (\s -> s{stolen_x86_regs = 2}) ))
1014   ,  ( "monly-3-regs",  NoArg (upd (\s -> s{stolen_x86_regs = 3}) ))
1015   ,  ( "monly-4-regs",  NoArg (upd (\s -> s{stolen_x86_regs = 4}) ))
1016
1017         ------ Warning opts -------------------------------------------------
1018   ,  ( "W"              , NoArg (mapM_ setDynFlag   minusWOpts)    )
1019   ,  ( "Werror"         , NoArg (setDynFlag         Opt_WarnIsError) )
1020   ,  ( "Wall"           , NoArg (mapM_ setDynFlag   minusWallOpts) )
1021   ,  ( "Wnot"           , NoArg (mapM_ unSetDynFlag minusWallOpts) ) /* DEPREC */
1022   ,  ( "w"              , NoArg (mapM_ unSetDynFlag minusWallOpts) )
1023
1024         ------ Optimisation flags ------------------------------------------
1025   ,  ( "O"      , NoArg (upd (setOptLevel 1)))
1026   ,  ( "Onot"   , NoArg (upd (setOptLevel 0)))
1027   ,  ( "O"      , OptIntSuffix (\mb_n -> upd (setOptLevel (mb_n `orElse` 1))))
1028                 -- If the number is missing, use 1
1029
1030   ,  ( "fmax-simplifier-iterations", IntSuffix (\n -> 
1031                 upd (\dfs -> dfs{ maxSimplIterations = n })) )
1032
1033         -- liberate-case-threshold is an old flag for '-fspec-threshold'
1034   ,  ( "fspec-threshold",          IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1035   ,  ( "fliberate-case-threshold", IntSuffix (\n -> upd (\dfs -> dfs{ specThreshold = n })))
1036
1037   ,  ( "frule-check", SepArg (\s -> upd (\dfs -> dfs{ ruleCheck = Just s })))
1038   ,  ( "fcontext-stack" , IntSuffix $ \n -> upd $ \dfs -> dfs{ ctxtStkDepth = n })
1039
1040         ------ Compiler flags -----------------------------------------------
1041
1042   ,  ( "fasm",          NoArg (setObjTarget HscAsm) )
1043   ,  ( "fvia-c",        NoArg (setObjTarget HscC) )
1044   ,  ( "fvia-C",        NoArg (setObjTarget HscC) )
1045
1046   ,  ( "fno-code",      NoArg (setTarget HscNothing))
1047   ,  ( "fbyte-code",    NoArg (setTarget HscInterpreted) )
1048   ,  ( "fobject-code",  NoArg (setTarget defaultHscTarget) )
1049
1050   ,  ( "fglasgow-exts",    NoArg (mapM_ setDynFlag   glasgowExtsFlags) )
1051   ,  ( "fno-glasgow-exts", NoArg (mapM_ unSetDynFlag glasgowExtsFlags) )
1052
1053         -- the rest of the -f* and -fno-* flags
1054   ,  ( "f",             PrefixPred (isFlag fFlags)   (\f -> setDynFlag   (getFlag fFlags f)) )
1055   ,  ( "f",             PrefixPred (isNoFlag fFlags) (\f -> unSetDynFlag (getNoFlag fFlags f)) )
1056
1057         -- For now, allow -X flags with -f; ToDo: report this as deprecated
1058   ,  ( "f",             PrefixPred (isFlag xFlags) (\f ->  setDynFlag (getFlag xFlags f)) )
1059   ,  ( "f",             PrefixPred (isNoFlag xFlags) (\f -> unSetDynFlag (getNoFlag xFlags f)) )
1060
1061         -- the rest of the -X* and -Xno-* flags
1062   ,  ( "X",             PrefixPred (isFlag xFlags)   (\f -> setDynFlag   (getFlag xFlags f)) )
1063   ,  ( "X",             PrefixPred (isNoFlag xFlags) (\f -> unSetDynFlag (getNoFlag xFlags f)) )
1064  ]
1065
1066 -- these -f<blah> flags can all be reversed with -fno-<blah>
1067
1068 fFlags = [
1069   ( "warn-duplicate-exports",           Opt_WarnDuplicateExports ),
1070   ( "warn-hi-shadowing",                Opt_WarnHiShadows ),
1071   ( "warn-implicit-prelude",            Opt_WarnImplicitPrelude ),
1072   ( "warn-incomplete-patterns",         Opt_WarnIncompletePatterns ),
1073   ( "warn-incomplete-record-updates",   Opt_WarnIncompletePatternsRecUpd ),
1074   ( "warn-missing-fields",              Opt_WarnMissingFields ),
1075   ( "warn-missing-methods",             Opt_WarnMissingMethods ),
1076   ( "warn-missing-signatures",          Opt_WarnMissingSigs ),
1077   ( "warn-name-shadowing",              Opt_WarnNameShadowing ),
1078   ( "warn-overlapping-patterns",        Opt_WarnOverlappingPatterns ),
1079   ( "warn-simple-patterns",             Opt_WarnSimplePatterns ),
1080   ( "warn-type-defaults",               Opt_WarnTypeDefaults ),
1081   ( "warn-monomorphism-restriction",    Opt_WarnMonomorphism ),
1082   ( "warn-unused-binds",                Opt_WarnUnusedBinds ),
1083   ( "warn-unused-imports",              Opt_WarnUnusedImports ),
1084   ( "warn-unused-matches",              Opt_WarnUnusedMatches ),
1085   ( "warn-deprecations",                Opt_WarnDeprecations ),
1086   ( "warn-orphans",                     Opt_WarnOrphans ),
1087   ( "warn-tabs",                        Opt_WarnTabs ),
1088   ( "print-explicit-foralls", Opt_PrintExplicitForalls ),
1089   ( "strictness",                       Opt_Strictness ),
1090   ( "full-laziness",                    Opt_FullLaziness ),
1091   ( "liberate-case",                    Opt_LiberateCase ),
1092   ( "spec-constr",                      Opt_SpecConstr ),
1093   ( "cse",                              Opt_CSE ),
1094   ( "ignore-interface-pragmas",         Opt_IgnoreInterfacePragmas ),
1095   ( "omit-interface-pragmas",           Opt_OmitInterfacePragmas ),
1096   ( "do-lambda-eta-expansion",          Opt_DoLambdaEtaExpansion ),
1097   ( "ignore-asserts",                   Opt_IgnoreAsserts ),
1098   ( "ignore-breakpoints",               Opt_IgnoreBreakpoints),
1099   ( "do-eta-reduction",                 Opt_DoEtaReduction ),
1100   ( "case-merge",                       Opt_CaseMerge ),
1101   ( "unbox-strict-fields",              Opt_UnboxStrictFields ),
1102   ( "dicts-cheap",                      Opt_DictsCheap ),
1103   ( "excess-precision",                 Opt_ExcessPrecision ),
1104   ( "asm-mangling",                     Opt_DoAsmMangling ),
1105   ( "print-bind-result",                Opt_PrintBindResult ),
1106   ( "force-recomp",                     Opt_ForceRecomp ),
1107   ( "hpc-no-auto",                      Opt_Hpc_No_Auto ),
1108   ( "rewrite-rules",                    Opt_RewriteRules ),
1109   ( "break-on-exception",               Opt_BreakOnException ),
1110   ( "vectorise",                        Opt_Vectorise )
1111   ]
1112
1113
1114 -- These -X<blah> flags can all be reversed with -Xno-<blah>
1115 xFlags :: [(String, DynFlag)]
1116 xFlags = [
1117   ( "CPP",                              Opt_Cpp ),
1118   ( "PatternGuards",                    Opt_PatternGuards ),
1119   ( "UnicodeSyntax",                    Opt_UnicodeSyntax ),
1120   ( "MagicHash",                        Opt_MagicHash ),
1121   ( "PolymorphicComponents",            Opt_PolymorphicComponents ),
1122   ( "ExistentialQuantification",        Opt_ExistentialQuantification ),
1123   ( "KindSignatures",                   Opt_KindSignatures ),
1124   ( "PatternSignatures",                Opt_PatternSignatures ),
1125   ( "EmptyDataDecls",                   Opt_EmptyDataDecls ),
1126   ( "ParallelListComp",                 Opt_ParallelListComp ),
1127   ( "FI",                               Opt_FFI ),  -- support `-ffi'...
1128   ( "FFI",                              Opt_FFI ),  -- ...and also `-fffi'
1129   ( "ForeignFunctionInterface",         Opt_FFI ),
1130
1131   ( "Rank2Types",                       Opt_Rank2Types ),
1132   ( "RankNTypes",                       Opt_RankNTypes ),
1133   ( "TypeOperators",                    Opt_TypeOperators ),
1134   ( "RecursiveDo",                      Opt_RecursiveDo ),
1135   ( "Arrows",                           Opt_Arrows ), -- arrow syntax
1136   ( "Parr",                             Opt_PArr ),
1137
1138   ( "TH",                               Opt_TH ), -- support -fth
1139   ( "TemplateHaskelll",                 Opt_TH ),
1140
1141   ( "Generics",                         Opt_Generics ),
1142
1143   ( "ImplicitPrelude",                  Opt_ImplicitPrelude ),  -- On by default
1144
1145   ( "RecordWildCards",                  Opt_RecordWildCards ),
1146   ( "RecordPuns",                       Opt_RecordPuns ),
1147   ( "DisambiguateRecordFields",         Opt_DisambiguateRecordFields ),
1148
1149   ( "OverloadedStrings",                Opt_OverloadedStrings ),
1150   ( "GADTs",                            Opt_GADTs ),
1151   ( "TypeFamilies",                     Opt_TypeFamilies ),
1152   ( "BangPatterns",                     Opt_BangPatterns ),
1153   ( "MonomorphismRestriction",          Opt_MonomorphismRestriction ),  -- On by default
1154   ( "MonoPatBinds",                     Opt_MonoPatBinds ),             -- On by default (which is not strictly H98)
1155   ( "RelaxedPolyRec",                   Opt_RelaxedPolyRec),
1156   ( "ExtendedDefaultRules",             Opt_ExtendedDefaultRules ),
1157   ( "ImplicitParams",                   Opt_ImplicitParams ),
1158   ( "ScopedTypeVariables",              Opt_ScopedTypeVariables ),
1159   ( "TypeSynonymInstances",         Opt_TypeSynonymInstances ),
1160   ( "FlexibleContexts",             Opt_FlexibleContexts ),
1161   ( "FlexibleInstances",            Opt_FlexibleInstances ),
1162   ( "MultiParamTypeClasses",        Opt_MultiParamTypeClasses ),
1163   ( "FunctionalDependencies",        Opt_FunctionalDependencies ),
1164   ( "GeneralizedNewtypeDeriving",   Opt_GeneralizedNewtypeDeriving ),
1165   ( "AllowOverlappingInstances",        Opt_AllowOverlappingInstances ),
1166   ( "AllowUndecidableInstances",        Opt_AllowUndecidableInstances ),
1167   ( "AllowIncoherentInstances",         Opt_AllowIncoherentInstances )
1168   ]
1169
1170 impliedFlags :: [(DynFlag, [DynFlag])]
1171 impliedFlags = [
1172   ( Opt_GADTs, [Opt_RelaxedPolyRec] )   -- We want type-sig variables to be completely rigid for GADTs
1173   ]
1174
1175 glasgowExtsFlags = [ Opt_GlasgowExts 
1176            , Opt_PrintExplicitForalls
1177                    , Opt_FFI 
1178                    , Opt_GADTs
1179                    , Opt_ImplicitParams 
1180                    , Opt_ScopedTypeVariables
1181            , Opt_TypeSynonymInstances
1182            , Opt_FlexibleContexts
1183            , Opt_FlexibleInstances
1184            , Opt_MultiParamTypeClasses
1185            , Opt_FunctionalDependencies
1186                    , Opt_MagicHash
1187            , Opt_PolymorphicComponents
1188            , Opt_ExistentialQuantification
1189            , Opt_UnicodeSyntax
1190            , Opt_PatternGuards
1191            , Opt_RankNTypes
1192            , Opt_TypeOperators
1193            , Opt_RecursiveDo
1194            , Opt_ParallelListComp
1195            , Opt_EmptyDataDecls
1196            , Opt_KindSignatures
1197            , Opt_PatternSignatures
1198            , Opt_GeneralizedNewtypeDeriving
1199                    , Opt_TypeFamilies ]
1200
1201 ------------------
1202 isNoFlag, isFlag :: [(String,a)] -> String -> Bool
1203
1204 isFlag flags f = is_flag flags (normaliseFlag f)
1205
1206 isNoFlag flags no_f
1207   | Just f <- noFlag_maybe (normaliseFlag no_f) = is_flag flags f
1208   | otherwise                                   = False
1209
1210 is_flag flags nf = any (\(ff,_) -> normaliseFlag ff == nf) flags
1211         -- nf is normalised alreadly
1212
1213 ------------------
1214 getFlag, getNoFlag :: [(String,a)] -> String -> a
1215
1216 getFlag flags f = get_flag flags (normaliseFlag f)
1217
1218 getNoFlag flags f = get_flag flags (fromJust (noFlag_maybe (normaliseFlag f)))
1219                         -- The flag should be a no-flag already
1220
1221 get_flag flags nf = case [ opt | (ff, opt) <- flags, normaliseFlag ff == nf] of
1222                         (o:os) -> o
1223                         []     -> panic ("get_flag " ++ nf)
1224
1225 ------------------
1226 noFlag_maybe :: String -> Maybe String
1227 -- The input is normalised already
1228 noFlag_maybe ('n' : 'o' : f) = Just f
1229 noFlag_maybe other           = Nothing
1230
1231 normaliseFlag :: String -> String
1232 -- Normalise a option flag by
1233 --      * map to lower case
1234 --      * removing hyphens
1235 -- Thus: -X=overloaded-strings or -XOverloadedStrings
1236 normaliseFlag []      = []
1237 normaliseFlag ('-':s) = normaliseFlag s
1238 normaliseFlag (c:s)   = toLower c : normaliseFlag s
1239
1240 -- -----------------------------------------------------------------------------
1241 -- Parsing the dynamic flags.
1242
1243 parseDynamicFlags :: DynFlags -> [String] -> IO (DynFlags,[String])
1244 parseDynamicFlags dflags args = do
1245   let ((leftover,errs),dflags') 
1246           = runCmdLine (processArgs dynamic_flags args) dflags
1247   when (not (null errs)) $ do
1248     throwDyn (UsageError (unlines errs))
1249   return (dflags', leftover)
1250
1251
1252 type DynP = CmdLineP DynFlags
1253
1254 upd :: (DynFlags -> DynFlags) -> DynP ()
1255 upd f = do 
1256    dfs <- getCmdLineState
1257    putCmdLineState $! (f dfs)
1258
1259 --------------------------
1260 setDynFlag, unSetDynFlag :: DynFlag -> DynP ()
1261 setDynFlag f = upd (\dfs -> foldl dopt_set (dopt_set dfs f) deps)
1262   where
1263     deps = [ d | (f', ds) <- impliedFlags, f' == f, d <- ds ]
1264         -- When you set f, set the ones it implies
1265         -- When you un-set f, however, we don't un-set the things it implies
1266         --      (except for -fno-glasgow-exts, which is treated specially)
1267
1268 unSetDynFlag f = upd (\dfs -> dopt_unset dfs f)
1269
1270 --------------------------
1271 setDumpFlag :: DynFlag -> OptKind DynP
1272 setDumpFlag dump_flag 
1273   = NoArg (setDynFlag Opt_ForceRecomp >> setDynFlag dump_flag)
1274         -- Whenver we -ddump, switch off the recompilation checker,
1275         -- else you don't see the dump!
1276
1277 setVerbosity :: Maybe Int -> DynP ()
1278 setVerbosity mb_n = upd (\dfs -> dfs{ verbosity = mb_n `orElse` 3 })
1279
1280 addCmdlineHCInclude a = upd (\s -> s{cmdlineHcIncludes =  a : cmdlineHcIncludes s})
1281
1282 extraPkgConf_  p = upd (\s -> s{ extraPkgConfs = p : extraPkgConfs s })
1283
1284 exposePackage p = 
1285   upd (\s -> s{ packageFlags = ExposePackage p : packageFlags s })
1286 hidePackage p = 
1287   upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
1288 ignorePackage p = 
1289   upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
1290
1291 setPackageName p
1292   | Nothing <- unpackPackageId pid
1293   = throwDyn (CmdLineError ("cannot parse \'" ++ p ++ "\' as a package identifier"))
1294   | otherwise
1295   = \s -> s{ thisPackage = pid }
1296   where
1297         pid = stringToPackageId p
1298
1299 -- If we're linking a binary, then only targets that produce object
1300 -- code are allowed (requests for other target types are ignored).
1301 setTarget l = upd set
1302   where 
1303    set dfs 
1304      | ghcLink dfs /= LinkBinary || isObjectTarget l  = dfs{ hscTarget = l }
1305      | otherwise = dfs
1306
1307 -- Changes the target only if we're compiling object code.  This is
1308 -- used by -fasm and -fvia-C, which switch from one to the other, but
1309 -- not from bytecode to object-code.  The idea is that -fasm/-fvia-C
1310 -- can be safely used in an OPTIONS_GHC pragma.
1311 setObjTarget l = upd set
1312   where 
1313    set dfs 
1314      | isObjectTarget (hscTarget dfs) = dfs { hscTarget = l }
1315      | otherwise = dfs
1316
1317 setOptLevel :: Int -> DynFlags -> DynFlags
1318 setOptLevel n dflags
1319    | hscTarget dflags == HscInterpreted && n > 0
1320         = dflags
1321             -- not in IO any more, oh well:
1322             -- putStr "warning: -O conflicts with --interactive; -O ignored.\n"
1323    | otherwise
1324         = updOptLevel n dflags
1325
1326
1327 setMainIs :: String -> DynP ()
1328 setMainIs arg
1329   | not (null main_fn)          -- The arg looked like "Foo.baz"
1330   = upd $ \d -> d{ mainFunIs = Just main_fn,
1331                    mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
1332
1333   | isUpper (head main_mod)     -- The arg looked like "Foo"
1334   = upd $ \d -> d{ mainModIs = mkModule mainPackageId (mkModuleName main_mod) }
1335   
1336   | otherwise                   -- The arg looked like "baz"
1337   = upd $ \d -> d{ mainFunIs = Just main_mod }
1338   where
1339     (main_mod, main_fn) = splitLongestPrefix arg (== '.')
1340
1341 -----------------------------------------------------------------------------
1342 -- Paths & Libraries
1343
1344 -- -i on its own deletes the import paths
1345 addImportPath "" = upd (\s -> s{importPaths = []})
1346 addImportPath p  = upd (\s -> s{importPaths = importPaths s ++ splitPathList p})
1347
1348
1349 addLibraryPath p = 
1350   upd (\s -> s{libraryPaths = libraryPaths s ++ splitPathList p})
1351
1352 addIncludePath p = 
1353   upd (\s -> s{includePaths = includePaths s ++ splitPathList p})
1354
1355 addFrameworkPath p = 
1356   upd (\s -> s{frameworkPaths = frameworkPaths s ++ splitPathList p})
1357
1358 split_marker = ':'   -- not configurable (ToDo)
1359
1360 splitPathList :: String -> [String]
1361 splitPathList s = filter notNull (splitUp s)
1362                 -- empty paths are ignored: there might be a trailing
1363                 -- ':' in the initial list, for example.  Empty paths can
1364                 -- cause confusion when they are translated into -I options
1365                 -- for passing to gcc.
1366   where
1367 #ifndef mingw32_TARGET_OS
1368     splitUp xs = split split_marker xs
1369 #else 
1370      -- Windows: 'hybrid' support for DOS-style paths in directory lists.
1371      -- 
1372      -- That is, if "foo:bar:baz" is used, this interpreted as
1373      -- consisting of three entries, 'foo', 'bar', 'baz'.
1374      -- However, with "c:/foo:c:\\foo;x:/bar", this is interpreted
1375      -- as 3 elts, "c:/foo", "c:\\foo", "x:/bar"
1376      --
1377      -- Notice that no attempt is made to fully replace the 'standard'
1378      -- split marker ':' with the Windows / DOS one, ';'. The reason being
1379      -- that this will cause too much breakage for users & ':' will
1380      -- work fine even with DOS paths, if you're not insisting on being silly.
1381      -- So, use either.
1382     splitUp []             = []
1383     splitUp (x:':':div:xs) | div `elem` dir_markers
1384                            = ((x:':':div:p): splitUp rs)
1385                            where
1386                               (p,rs) = findNextPath xs
1387           -- we used to check for existence of the path here, but that
1388           -- required the IO monad to be threaded through the command-line
1389           -- parser which is quite inconvenient.  The 
1390     splitUp xs = cons p (splitUp rs)
1391                where
1392                  (p,rs) = findNextPath xs
1393     
1394                  cons "" xs = xs
1395                  cons x  xs = x:xs
1396
1397     -- will be called either when we've consumed nought or the
1398     -- "<Drive>:/" part of a DOS path, so splitting is just a Q of
1399     -- finding the next split marker.
1400     findNextPath xs = 
1401         case break (`elem` split_markers) xs of
1402            (p, d:ds) -> (p, ds)
1403            (p, xs)   -> (p, xs)
1404
1405     split_markers :: [Char]
1406     split_markers = [':', ';']
1407
1408     dir_markers :: [Char]
1409     dir_markers = ['/', '\\']
1410 #endif
1411
1412 -- -----------------------------------------------------------------------------
1413 -- tmpDir, where we store temporary files.
1414
1415 setTmpDir :: FilePath -> DynFlags -> DynFlags
1416 setTmpDir dir dflags = dflags{ tmpDir = canonicalise dir }
1417   where
1418 #if !defined(mingw32_HOST_OS)
1419      canonicalise p = normalisePath p
1420 #else
1421         -- Canonicalisation of temp path under win32 is a bit more
1422         -- involved: (a) strip trailing slash, 
1423         --           (b) normalise slashes
1424         --           (c) just in case, if there is a prefix /cygdrive/x/, change to x:
1425         -- 
1426      canonicalise path = normalisePath (xltCygdrive (removeTrailingSlash path))
1427
1428         -- if we're operating under cygwin, and TMP/TEMP is of
1429         -- the form "/cygdrive/drive/path", translate this to
1430         -- "drive:/path" (as GHC isn't a cygwin app and doesn't
1431         -- understand /cygdrive paths.)
1432      xltCygdrive path
1433       | "/cygdrive/" `isPrefixOf` path = 
1434           case drop (length "/cygdrive/") path of
1435             drive:xs@('/':_) -> drive:':':xs
1436             _ -> path
1437       | otherwise = path
1438
1439         -- strip the trailing backslash (awful, but we only do this once).
1440      removeTrailingSlash path = 
1441        case last path of
1442          '/'  -> init path
1443          '\\' -> init path
1444          _    -> path
1445 #endif
1446
1447 -----------------------------------------------------------------------------
1448 -- Hpc stuff
1449
1450 setOptHpcDir :: String -> DynP ()
1451 setOptHpcDir arg  = upd $ \ d -> d{hpcDir = arg}
1452
1453 -----------------------------------------------------------------------------
1454 -- Via-C compilation stuff
1455
1456 machdepCCOpts :: DynFlags -> ([String], -- flags for all C compilations
1457                               [String]) -- for registerised HC compilations
1458 machdepCCOpts dflags
1459 #if alpha_TARGET_ARCH
1460         =       ( ["-w", "-mieee"
1461 #ifdef HAVE_THREADED_RTS_SUPPORT
1462                     , "-D_REENTRANT"
1463 #endif
1464                    ], [] )
1465         -- For now, to suppress the gcc warning "call-clobbered
1466         -- register used for global register variable", we simply
1467         -- disable all warnings altogether using the -w flag. Oh well.
1468
1469 #elif hppa_TARGET_ARCH
1470         -- ___HPUX_SOURCE, not _HPUX_SOURCE, is #defined if -ansi!
1471         -- (very nice, but too bad the HP /usr/include files don't agree.)
1472         = ( ["-D_HPUX_SOURCE"], [] )
1473
1474 #elif m68k_TARGET_ARCH
1475       -- -fno-defer-pop : for the .hc files, we want all the pushing/
1476       --    popping of args to routines to be explicit; if we let things
1477       --    be deferred 'til after an STGJUMP, imminent death is certain!
1478       --
1479       -- -fomit-frame-pointer : *don't*
1480       --     It's better to have a6 completely tied up being a frame pointer
1481       --     rather than let GCC pick random things to do with it.
1482       --     (If we want to steal a6, then we would try to do things
1483       --     as on iX86, where we *do* steal the frame pointer [%ebp].)
1484         = ( [], ["-fno-defer-pop", "-fno-omit-frame-pointer"] )
1485
1486 #elif i386_TARGET_ARCH
1487       -- -fno-defer-pop : basically the same game as for m68k
1488       --
1489       -- -fomit-frame-pointer : *must* in .hc files; because we're stealing
1490       --   the fp (%ebp) for our register maps.
1491         =  let n_regs = stolen_x86_regs dflags
1492                sta = opt_Static
1493            in
1494                     ( [ if sta then "-DDONT_WANT_WIN32_DLL_SUPPORT" else ""
1495 --                    , if "mingw32" `isSuffixOf` cTARGETPLATFORM then "-mno-cygwin" else "" 
1496                       ],
1497                       [ "-fno-defer-pop",
1498 #ifdef HAVE_GCC_MNO_OMIT_LFPTR
1499                         -- Some gccs are configured with
1500                         -- -momit-leaf-frame-pointer on by default, and it
1501                         -- apparently takes precedence over 
1502                         -- -fomit-frame-pointer, so we disable it first here.
1503                         "-mno-omit-leaf-frame-pointer",
1504 #endif
1505 #ifdef HAVE_GCC_HAS_NO_UNIT_AT_A_TIME
1506                         "-fno-unit-at-a-time",
1507                         -- unit-at-a-time doesn't do us any good, and screws
1508                         -- up -split-objs by moving the split markers around.
1509                         -- It's only turned on with -O2, but put it here just
1510                         -- in case someone uses -optc-O2.
1511 #endif
1512                         "-fomit-frame-pointer",
1513                         -- we want -fno-builtin, because when gcc inlines
1514                         -- built-in functions like memcpy() it tends to
1515                         -- run out of registers, requiring -monly-n-regs
1516                         "-fno-builtin",
1517                         "-DSTOLEN_X86_REGS="++show n_regs ]
1518                     )
1519
1520 #elif ia64_TARGET_ARCH
1521         = ( [], ["-fomit-frame-pointer", "-G0"] )
1522
1523 #elif x86_64_TARGET_ARCH
1524         = ( [], ["-fomit-frame-pointer",
1525                  "-fno-asynchronous-unwind-tables",
1526                         -- the unwind tables are unnecessary for HC code,
1527                         -- and get in the way of -split-objs.  Another option
1528                         -- would be to throw them away in the mangler, but this
1529                         -- is easier.
1530 #ifdef HAVE_GCC_HAS_NO_UNIT_AT_A_TIME
1531                  "-fno-unit-at-a-time",
1532                         -- unit-at-a-time doesn't do us any good, and screws
1533                         -- up -split-objs by moving the split markers around.
1534                         -- It's only turned on with -O2, but put it here just
1535                         -- in case someone uses -optc-O2.
1536 #endif
1537                  "-fno-builtin"
1538                         -- calling builtins like strlen() using the FFI can
1539                         -- cause gcc to run out of regs, so use the external
1540                         -- version.
1541                 ] )
1542
1543 #elif sparc_TARGET_ARCH
1544         = ( [], ["-w"] )
1545         -- For now, to suppress the gcc warning "call-clobbered
1546         -- register used for global register variable", we simply
1547         -- disable all warnings altogether using the -w flag. Oh well.
1548
1549 #elif powerpc_apple_darwin_TARGET
1550       -- -no-cpp-precomp:
1551       --     Disable Apple's precompiling preprocessor. It's a great thing
1552       --     for "normal" programs, but it doesn't support register variable
1553       --     declarations.
1554         = ( [], ["-no-cpp-precomp"] )
1555 #else
1556         = ( [], [] )
1557 #endif
1558
1559 picCCOpts :: DynFlags -> [String]
1560 picCCOpts dflags
1561 #if darwin_TARGET_OS
1562       -- Apple prefers to do things the other way round.
1563       -- PIC is on by default.
1564       -- -mdynamic-no-pic:
1565       --     Turn off PIC code generation.
1566       -- -fno-common:
1567       --     Don't generate "common" symbols - these are unwanted
1568       --     in dynamic libraries.
1569
1570     | opt_PIC
1571         = ["-fno-common"]
1572     | otherwise
1573         = ["-mdynamic-no-pic"]
1574 #elif mingw32_TARGET_OS
1575       -- no -fPIC for Windows
1576         = []
1577 #else
1578     | opt_PIC
1579         = ["-fPIC"]
1580     | otherwise
1581         = []
1582 #endif
1583
1584 -- -----------------------------------------------------------------------------
1585 -- Splitting
1586
1587 can_split :: Bool
1588 can_split =  
1589 #if    defined(i386_TARGET_ARCH)     \
1590     || defined(x86_64_TARGET_ARCH)   \
1591     || defined(alpha_TARGET_ARCH)    \
1592     || defined(hppa_TARGET_ARCH)     \
1593     || defined(m68k_TARGET_ARCH)     \
1594     || defined(mips_TARGET_ARCH)     \
1595     || defined(powerpc_TARGET_ARCH)  \
1596     || defined(rs6000_TARGET_ARCH)   \
1597     || defined(sparc_TARGET_ARCH) 
1598    True
1599 #else
1600    False
1601 #endif
1602