6de5b11666543ba5d9c2b113ca707cc50e90846b
[ghc-hetmet.git] / ghc / compiler / main / CmdLineOpts.lhs
1
2 % (c) The University of Glasgow, 1996-2000
3 %
4 \section[CmdLineOpts]{Things to do with command-line options}
5
6 \begin{code}
7
8 module CmdLineOpts (
9         CoreToDo(..), StgToDo(..),
10         SimplifierSwitch(..), 
11         SimplifierMode(..), FloatOutSwitches(..),
12
13         HscLang(..),
14         DynFlag(..),    -- needed non-abstractly by DriverFlags
15         DynFlags(..),
16
17         v_Static_hsc_opts,
18
19         isStaticHscFlag,
20
21         -- Manipulating DynFlags
22         defaultDynFlags,                -- DynFlags
23         defaultHscLang,                 -- HscLang
24         dopt,                           -- DynFlag -> DynFlags -> Bool
25         dopt_set, dopt_unset,           -- DynFlags -> DynFlag -> DynFlags
26         dopt_CoreToDo,                  -- DynFlags -> [CoreToDo]
27         dopt_StgToDo,                   -- DynFlags -> [StgToDo]
28         dopt_HscLang,                   -- DynFlags -> HscLang
29         dopt_OutName,                   -- DynFlags -> String
30         getOpts,                        -- (DynFlags -> [a]) -> IO [a]
31         setLang,
32         getVerbFlag,
33
34         -- Manipulating the DynFlags state
35         getDynFlags,                    -- IO DynFlags
36         setDynFlags,                    -- DynFlags -> IO ()
37         updDynFlags,                    -- (DynFlags -> DynFlags) -> IO ()
38         dynFlag,                        -- (DynFlags -> a) -> IO a
39         setDynFlag, unSetDynFlag,       -- DynFlag -> IO ()
40         saveDynFlags,                   -- IO ()
41         restoreDynFlags,                -- IO DynFlags
42
43         -- sets of warning opts
44         standardWarnings,
45         minusWOpts,
46         minusWallOpts,
47
48         -- Output style options
49         opt_PprStyle_NoPrags,
50         opt_PprStyle_RawTypes,
51         opt_PprUserLength,
52         opt_PprStyle_Debug,
53
54         -- profiling opts
55         opt_AutoSccsOnAllToplevs,
56         opt_AutoSccsOnExportedToplevs,
57         opt_AutoSccsOnIndividualCafs,
58         opt_AutoSccsOnDicts,
59         opt_SccProfilingOn,
60         opt_DoTickyProfiling,
61
62         -- language opts
63         opt_AllStrict,
64         opt_DictsStrict,
65         opt_MaxContextReductionDepth,
66         opt_IrrefutableTuples,
67         opt_NumbersStrict,
68         opt_Parallel,
69         opt_SMP,
70         opt_RuntimeTypes,
71         opt_Flatten,
72
73         -- optimisation opts
74         opt_NoMethodSharing,
75         opt_DoSemiTagging,
76         opt_LiberateCaseThreshold,
77         opt_StgDoLetNoEscapes,
78         opt_CprOff,
79         opt_RulesOff,
80         opt_UnboxStrictFields,
81         opt_SimplNoPreInlining,
82         opt_SimplDoEtaReduction,
83         opt_SimplDoLambdaEtaExpansion,
84         opt_SimplCaseMerge,
85         opt_SimplExcessPrecision,
86         opt_MaxWorkerArgs,
87
88         -- Unfolding control
89         opt_UF_CreationThreshold,
90         opt_UF_UseThreshold,
91         opt_UF_FunAppDiscount,
92         opt_UF_KeenessFactor,
93         opt_UF_UpdateInPlace,
94         opt_UF_CheapOp,
95         opt_UF_DearOp,
96
97         -- misc opts
98         opt_InPackage,
99         opt_EmitCExternDecls,
100         opt_EnsureSplittableC,
101         opt_GranMacros,
102         opt_HiVersion,
103         opt_HistorySize,
104         opt_IgnoreAsserts,
105         opt_IgnoreIfacePragmas,
106         opt_NoHiCheck,
107         opt_OmitBlackHoling,
108         opt_OmitInterfacePragmas,
109         opt_NoPruneDecls,
110         opt_Static,
111         opt_Unregisterised,
112         opt_EmitExternalCore
113     ) where
114
115 #include "HsVersions.h"
116
117 import Constants        -- Default values for some flags
118 import Util
119 import FastString       ( FastString, mkFastString )
120 import Config
121 import Maybes           ( firstJust )
122
123 import GLAEXTS
124 import DATA_IOREF       ( IORef, readIORef, writeIORef )
125 import UNSAFE_IO        ( unsafePerformIO )
126 \end{code}
127
128 %************************************************************************
129 %*                                                                      *
130 \subsection{Command-line options}
131 %*                                                                      *
132 %************************************************************************
133
134 The hsc command-line options are split into two categories:
135
136   - static flags
137   - dynamic flags
138
139 Static flags are represented by top-level values of type Bool or Int,
140 for example.  They therefore have the same value throughout the
141 invocation of hsc.
142
143 Dynamic flags are represented by an abstract type, DynFlags, which is
144 passed into hsc by the compilation manager for every compilation.
145 Dynamic flags are those that change on a per-compilation basis,
146 perhaps because they may be present in the OPTIONS pragma at the top
147 of a module.
148
149 Other flag-related blurb:
150
151 A list of {\em ToDo}s is things to be done in a particular part of
152 processing.  A (fictitious) example for the Core-to-Core simplifier
153 might be: run the simplifier, then run the strictness analyser, then
154 run the simplifier again (three ``todos'').
155
156 There are three ``to-do processing centers'' at the moment.  In the
157 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
158 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
159 (\tr{simplStg/SimplStg.lhs}).
160
161 %************************************************************************
162 %*                                                                      *
163 \subsection{Datatypes associated with command-line options}
164 %*                                                                      *
165 %************************************************************************
166
167 \begin{code}
168 data CoreToDo           -- These are diff core-to-core passes,
169                         -- which may be invoked in any order,
170                         -- as many times as you like.
171
172   = CoreDoSimplify      -- The core-to-core simplifier.
173         SimplifierMode
174         [SimplifierSwitch]
175                         -- Each run of the simplifier can take a different
176                         -- set of simplifier-specific flags.
177   | CoreDoFloatInwards
178   | CoreDoFloatOutwards FloatOutSwitches
179   | CoreLiberateCase
180   | CoreDoPrintCore
181   | CoreDoStaticArgs
182   | CoreDoStrictness
183   | CoreDoWorkerWrapper
184   | CoreDoSpecialising
185   | CoreDoSpecConstr
186   | CoreDoOldStrictness
187   | CoreDoGlomBinds
188   | CoreCSE
189   | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules 
190                                                 -- matching this string
191
192   | CoreDoNothing        -- useful when building up lists of these things
193 \end{code}
194
195 \begin{code}
196 data StgToDo
197   = StgDoMassageForProfiling  -- should be (next to) last
198   -- There's also setStgVarInfo, but its absolute "lastness"
199   -- is so critical that it is hardwired in (no flag).
200   | D_stg_stats
201 \end{code}
202
203 \begin{code}
204 data SimplifierMode             -- See comments in SimplMonad
205   = SimplGently
206   | SimplPhase Int
207
208 data SimplifierSwitch
209   = MaxSimplifierIterations Int
210   | NoCaseOfCase
211
212 data FloatOutSwitches
213   = FloatOutSw  Bool    -- True <=> float lambdas to top level
214                 Bool    -- True <=> float constants to top level,
215                         --          even if they do not escape a lambda
216 \end{code}
217
218 %************************************************************************
219 %*                                                                      *
220 \subsection{Dynamic command-line options}
221 %*                                                                      *
222 %************************************************************************
223
224 \begin{code}
225 data DynFlag
226
227    -- debugging flags
228    = Opt_D_dump_absC
229    | Opt_D_dump_asm
230    | Opt_D_dump_cpranal
231    | Opt_D_dump_deriv
232    | Opt_D_dump_ds
233    | Opt_D_dump_flatC
234    | Opt_D_dump_foreign
235    | Opt_D_dump_inlinings
236    | Opt_D_dump_occur_anal
237    | Opt_D_dump_parsed
238    | Opt_D_dump_realC
239    | Opt_D_dump_rn
240    | Opt_D_dump_simpl
241    | Opt_D_dump_simpl_iterations
242    | Opt_D_dump_spec
243    | Opt_D_dump_prep
244    | Opt_D_dump_stg
245    | Opt_D_dump_stranal
246    | Opt_D_dump_tc
247    | Opt_D_dump_types
248    | Opt_D_dump_rules
249    | Opt_D_dump_cse
250    | Opt_D_dump_worker_wrapper
251    | Opt_D_dump_rn_trace
252    | Opt_D_dump_rn_stats
253    | Opt_D_dump_stix
254    | Opt_D_dump_simpl_stats
255    | Opt_D_dump_tc_trace
256    | Opt_D_dump_splices
257    | Opt_D_dump_BCOs
258    | Opt_D_dump_vect
259    | Opt_D_source_stats
260    | Opt_D_verbose_core2core
261    | Opt_D_verbose_stg2stg
262    | Opt_D_dump_hi
263    | Opt_D_dump_hi_diffs
264    | Opt_D_dump_minimal_imports
265    | Opt_DoCoreLinting
266    | Opt_DoStgLinting
267
268    | Opt_WarnIsError            -- -Werror; makes warnings fatal
269    | Opt_WarnDuplicateExports
270    | Opt_WarnHiShadows
271    | Opt_WarnIncompletePatterns
272    | Opt_WarnMissingFields
273    | Opt_WarnMissingMethods
274    | Opt_WarnMissingSigs
275    | Opt_WarnNameShadowing
276    | Opt_WarnOverlappingPatterns
277    | Opt_WarnSimplePatterns
278    | Opt_WarnTypeDefaults
279    | Opt_WarnUnusedBinds
280    | Opt_WarnUnusedImports
281    | Opt_WarnUnusedMatches
282    | Opt_WarnDeprecations
283    | Opt_WarnMisc
284
285    -- language opts
286    | Opt_AllowOverlappingInstances
287    | Opt_AllowUndecidableInstances
288    | Opt_AllowIncoherentInstances
289    | Opt_NoMonomorphismRestriction
290    | Opt_GlasgowExts
291    | Opt_FFI
292    | Opt_PArr                          -- syntactic support for parallel arrays
293    | Opt_With                          -- deprecated keyword for implicit parms
294    | Opt_Arrows                        -- Arrow-notation syntax
295    | Opt_TH
296    | Opt_ImplicitParams
297    | Opt_Generics
298    | Opt_NoImplicitPrelude 
299
300    deriving (Eq)
301
302 data DynFlags = DynFlags {
303   coreToDo              :: [CoreToDo],
304   stgToDo               :: [StgToDo],
305   hscLang               :: HscLang,
306   hscOutName            :: String,      -- name of the output file
307   hscStubHOutName       :: String,      -- name of the .stub_h output file
308   hscStubCOutName       :: String,      -- name of the .stub_c output file
309   extCoreName           :: String,      -- name of the .core output file
310   verbosity             :: Int,         -- verbosity level
311   cppFlag               :: Bool,        -- preprocess with cpp?
312   ppFlag                :: Bool,        -- preprocess with a Haskell Pp?
313   stolen_x86_regs       :: Int,         
314   cmdlineHcIncludes     :: [String],    -- -#includes
315
316   -- options for particular phases
317   opt_L                 :: [String],
318   opt_P                 :: [String],
319   opt_F                 :: [String],
320   opt_c                 :: [String],
321   opt_a                 :: [String],
322   opt_m                 :: [String],
323 #ifdef ILX                         
324   opt_I                 :: [String],
325   opt_i                 :: [String],
326 #endif
327
328   -- hsc dynamic flags
329   flags                 :: [DynFlag]
330  }
331
332 data HscLang
333   = HscC
334   | HscAsm
335   | HscJava
336   | HscILX
337   | HscInterpreted
338   | HscNothing
339     deriving (Eq, Show)
340
341 defaultHscLang
342   | cGhcWithNativeCodeGen == "YES" && 
343         (prefixMatch "i386" cTARGETPLATFORM ||
344          prefixMatch "sparc" cTARGETPLATFORM ||
345          prefixMatch "powerpc" cTARGETPLATFORM)   =  HscAsm
346   | otherwise                                   =  HscC
347
348 defaultDynFlags = DynFlags {
349   coreToDo = [], stgToDo = [], 
350   hscLang = defaultHscLang, 
351   hscOutName = "", 
352   hscStubHOutName = "", hscStubCOutName = "",
353   extCoreName = "",
354   verbosity = 0, 
355   cppFlag               = False,
356   ppFlag                = False,
357   stolen_x86_regs       = 4,
358   cmdlineHcIncludes     = [],
359   opt_L                 = [],
360   opt_P                 = [],
361   opt_F                 = [],
362   opt_c                 = [],
363   opt_a                 = [],
364   opt_m                 = [],
365 #ifdef ILX
366   opt_I                 = [],
367   opt_i                 = [],
368 #endif
369   flags = [Opt_Generics] ++ standardWarnings,
370         -- Generating the helper-functions for
371         -- generics is now on by default
372   }
373
374 {- 
375     Verbosity levels:
376         
377     0   |   print errors & warnings only
378     1   |   minimal verbosity: print "compiling M ... done." for each module.
379     2   |   equivalent to -dshow-passes
380     3   |   equivalent to existing "ghc -v"
381     4   |   "ghc -v -ddump-most"
382     5   |   "ghc -v -ddump-all"
383 -}
384
385 dopt :: DynFlag -> DynFlags -> Bool
386 dopt f dflags  = f `elem` (flags dflags)
387
388 dopt_CoreToDo :: DynFlags -> [CoreToDo]
389 dopt_CoreToDo = coreToDo
390
391 dopt_StgToDo :: DynFlags -> [StgToDo]
392 dopt_StgToDo = stgToDo
393
394 dopt_OutName :: DynFlags -> String
395 dopt_OutName = hscOutName
396
397 dopt_HscLang :: DynFlags -> HscLang
398 dopt_HscLang = hscLang
399
400 dopt_set :: DynFlags -> DynFlag -> DynFlags
401 dopt_set dfs f = dfs{ flags = f : flags dfs }
402
403 dopt_unset :: DynFlags -> DynFlag -> DynFlags
404 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
405
406 getOpts :: (DynFlags -> [a]) -> IO [a]
407         -- We add to the options from the front, so we need to reverse the list
408 getOpts opts = dynFlag opts >>= return . reverse
409
410 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags 
411 -- (-fvia-C, -fasm, -filx respectively).
412 setLang l = updDynFlags (\ dfs -> case hscLang dfs of
413                                         HscC   -> dfs{ hscLang = l }
414                                         HscAsm -> dfs{ hscLang = l }
415                                         HscILX -> dfs{ hscLang = l }
416                                         _      -> dfs)
417
418 getVerbFlag = do
419    verb <- dynFlag verbosity
420    if verb >= 3  then return  "-v" else return ""
421 \end{code}
422
423 -----------------------------------------------------------------------------
424 -- Mess about with the mutable variables holding the dynamic arguments
425
426 -- v_InitDynFlags 
427 --      is the "baseline" dynamic flags, initialised from
428 --      the defaults and command line options, and updated by the
429 --      ':s' command in GHCi.
430 --
431 -- v_DynFlags
432 --      is the dynamic flags for the current compilation.  It is reset
433 --      to the value of v_InitDynFlags before each compilation, then
434 --      updated by reading any OPTIONS pragma in the current module.
435
436 \begin{code}
437 GLOBAL_VAR(v_InitDynFlags, defaultDynFlags, DynFlags)
438 GLOBAL_VAR(v_DynFlags,     defaultDynFlags, DynFlags)
439
440 setDynFlags :: DynFlags -> IO ()
441 setDynFlags dfs = writeIORef v_DynFlags dfs
442
443 saveDynFlags :: IO ()
444 saveDynFlags = do dfs <- readIORef v_DynFlags
445                   writeIORef v_InitDynFlags dfs
446
447 restoreDynFlags :: IO DynFlags
448 restoreDynFlags = do dfs <- readIORef v_InitDynFlags
449                      writeIORef v_DynFlags dfs
450                      return dfs
451
452 getDynFlags :: IO DynFlags
453 getDynFlags = readIORef v_DynFlags
454
455 updDynFlags :: (DynFlags -> DynFlags) -> IO ()
456 updDynFlags f = do dfs <- readIORef v_DynFlags
457                    writeIORef v_DynFlags (f dfs)
458
459 dynFlag :: (DynFlags -> a) -> IO a
460 dynFlag f = do dflags <- readIORef v_DynFlags; return (f dflags)
461
462 setDynFlag, unSetDynFlag :: DynFlag -> IO ()
463 setDynFlag f   = updDynFlags (\dfs -> dopt_set dfs f)
464 unSetDynFlag f = updDynFlags (\dfs -> dopt_unset dfs f)
465 \end{code}
466
467
468 %************************************************************************
469 %*                                                                      *
470 \subsection{Warnings}
471 %*                                                                      *
472 %************************************************************************
473
474 \begin{code}
475 standardWarnings
476     = [ Opt_WarnDeprecations,
477         Opt_WarnOverlappingPatterns,
478         Opt_WarnMissingFields,
479         Opt_WarnMissingMethods,
480         Opt_WarnDuplicateExports
481       ]
482
483 minusWOpts
484     = standardWarnings ++ 
485       [ Opt_WarnUnusedBinds,
486         Opt_WarnUnusedMatches,
487         Opt_WarnUnusedImports,
488         Opt_WarnIncompletePatterns,
489         Opt_WarnMisc
490       ]
491
492 minusWallOpts
493     = minusWOpts ++
494       [ Opt_WarnTypeDefaults,
495         Opt_WarnNameShadowing,
496         Opt_WarnMissingSigs,
497         Opt_WarnHiShadows
498       ]
499 \end{code}
500
501 %************************************************************************
502 %*                                                                      *
503 \subsection{Classifying command-line options}
504 %*                                                                      *
505 %************************************************************************
506
507 \begin{code}
508 -- v_Statis_hsc_opts is here to avoid a circular dependency with
509 -- main/DriverState.
510 GLOBAL_VAR(v_Static_hsc_opts, [], [String])
511
512 lookUp           :: FastString -> Bool
513 lookup_int       :: String -> Maybe Int
514 lookup_def_int   :: String -> Int -> Int
515 lookup_def_float :: String -> Float -> Float
516 lookup_str       :: String -> Maybe String
517
518 unpacked_static_opts = unsafePerformIO (readIORef v_Static_hsc_opts)
519 packed_static_opts   = map mkFastString unpacked_static_opts
520
521 lookUp     sw = sw `elem` packed_static_opts
522         
523 lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
524
525 lookup_int sw = case (lookup_str sw) of
526                   Nothing -> Nothing
527                   Just xx -> Just (read xx)
528
529 lookup_def_int sw def = case (lookup_str sw) of
530                             Nothing -> def              -- Use default
531                             Just xx -> read xx
532
533 lookup_def_float sw def = case (lookup_str sw) of
534                             Nothing -> def              -- Use default
535                             Just xx -> read xx
536
537
538 {-
539  Putting the compiler options into temporary at-files
540  may turn out to be necessary later on if we turn hsc into
541  a pure Win32 application where I think there's a command-line
542  length limit of 255. unpacked_opts understands the @ option.
543
544 unpacked_opts :: [String]
545 unpacked_opts =
546   concat $
547   map (expandAts) $
548   map unpackFS argv  -- NOT ARGV any more: v_Static_hsc_opts
549   where
550    expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
551    expandAts l = [l]
552 -}
553 \end{code}
554
555 %************************************************************************
556 %*                                                                      *
557 \subsection{Static options}
558 %*                                                                      *
559 %************************************************************************
560
561 \begin{code}
562 -- debugging opts
563 opt_PprStyle_NoPrags            = lookUp  FSLIT("-dppr-noprags")
564 opt_PprStyle_Debug              = lookUp  FSLIT("-dppr-debug")
565 opt_PprStyle_RawTypes           = lookUp  FSLIT("-dppr-rawtypes")
566 opt_PprUserLength               = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
567
568 -- profiling opts
569 opt_AutoSccsOnAllToplevs        = lookUp  FSLIT("-fauto-sccs-on-all-toplevs")
570 opt_AutoSccsOnExportedToplevs   = lookUp  FSLIT("-fauto-sccs-on-exported-toplevs")
571 opt_AutoSccsOnIndividualCafs    = lookUp  FSLIT("-fauto-sccs-on-individual-cafs")
572 opt_AutoSccsOnDicts             = lookUp  FSLIT("-fauto-sccs-on-dicts")
573 opt_SccProfilingOn              = lookUp  FSLIT("-fscc-profiling")
574 opt_DoTickyProfiling            = lookUp  FSLIT("-fticky-ticky")
575
576 -- language opts
577 opt_AllStrict                   = lookUp  FSLIT("-fall-strict")
578 opt_DictsStrict                 = lookUp  FSLIT("-fdicts-strict")
579 opt_IrrefutableTuples           = lookUp  FSLIT("-firrefutable-tuples")
580 opt_MaxContextReductionDepth    = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
581 opt_NumbersStrict               = lookUp  FSLIT("-fnumbers-strict")
582 opt_Parallel                    = lookUp  FSLIT("-fparallel")
583 opt_SMP                         = lookUp  FSLIT("-fsmp")
584 opt_Flatten                     = lookUp  FSLIT("-fflatten")
585
586 -- optimisation opts
587 opt_NoMethodSharing             = lookUp  FSLIT("-fno-method-sharing")
588 opt_DoSemiTagging               = lookUp  FSLIT("-fsemi-tagging")
589 opt_CprOff                      = lookUp  FSLIT("-fcpr-off")
590 opt_RulesOff                    = lookUp  FSLIT("-frules-off")
591         -- Switch off CPR analysis in the new demand analyser
592 opt_LiberateCaseThreshold       = lookup_def_int "-fliberate-case-threshold" (10::Int)
593 opt_StgDoLetNoEscapes           = lookUp  FSLIT("-flet-no-escape")
594 opt_UnboxStrictFields           = lookUp  FSLIT("-funbox-strict-fields")
595 opt_MaxWorkerArgs               = lookup_def_int "-fmax-worker-args" (10::Int)
596
597 {-
598    The optional '-inpackage=P' flag tells what package
599    we are compiling this module for.
600    The Prelude, for example is compiled with '-inpackage std'
601 -}
602 opt_InPackage                   = case lookup_str "-inpackage=" of
603                                     Just p  -> mkFastString p
604                                     Nothing -> FSLIT("Main")    -- The package name if none is specified
605
606 opt_EmitCExternDecls            = lookUp  FSLIT("-femit-extern-decls")
607 opt_EnsureSplittableC           = lookUp  FSLIT("-fglobalise-toplev-names")
608 opt_GranMacros                  = lookUp  FSLIT("-fgransim")
609 opt_HiVersion                   = read (cProjectVersionInt ++ cProjectPatchLevel) :: Int
610 opt_HistorySize                 = lookup_def_int "-fhistory-size" 20
611 opt_IgnoreAsserts               = lookUp  FSLIT("-fignore-asserts")
612 opt_IgnoreIfacePragmas          = lookUp  FSLIT("-fignore-interface-pragmas")
613 opt_NoHiCheck                   = lookUp  FSLIT("-fno-hi-version-check")
614 opt_OmitBlackHoling             = lookUp  FSLIT("-dno-black-holing")
615 opt_OmitInterfacePragmas        = lookUp  FSLIT("-fomit-interface-pragmas")
616 opt_RuntimeTypes                = lookUp  FSLIT("-fruntime-types")
617
618 -- Simplifier switches
619 opt_SimplNoPreInlining          = lookUp  FSLIT("-fno-pre-inlining")
620         -- NoPreInlining is there just to see how bad things
621         -- get if you don't do it!
622 opt_SimplDoEtaReduction         = lookUp  FSLIT("-fdo-eta-reduction")
623 opt_SimplDoLambdaEtaExpansion   = lookUp  FSLIT("-fdo-lambda-eta-expansion")
624 opt_SimplCaseMerge              = lookUp  FSLIT("-fcase-merge")
625 opt_SimplExcessPrecision        = lookUp  FSLIT("-fexcess-precision")
626
627 -- Unfolding control
628 opt_UF_CreationThreshold        = lookup_def_int "-funfolding-creation-threshold"  (45::Int)
629 opt_UF_UseThreshold             = lookup_def_int "-funfolding-use-threshold"       (8::Int)     -- Discounts can be big
630 opt_UF_FunAppDiscount           = lookup_def_int "-funfolding-fun-discount"        (6::Int)     -- It's great to inline a fn
631 opt_UF_KeenessFactor            = lookup_def_float "-funfolding-keeness-factor"    (1.5::Float)
632 opt_UF_UpdateInPlace            = lookUp  FSLIT("-funfolding-update-in-place")
633
634 opt_UF_CheapOp  = ( 1 :: Int)   -- Only one instruction; and the args are charged for
635 opt_UF_DearOp   = ( 4 :: Int)
636                         
637 opt_NoPruneDecls                = lookUp  FSLIT("-fno-prune-decls")
638 opt_Static                      = lookUp  FSLIT("-static")
639 opt_Unregisterised              = lookUp  FSLIT("-funregisterised")
640 opt_EmitExternalCore            = lookUp  FSLIT("-fext-core")
641 \end{code}
642
643 %************************************************************************
644 %*                                                                      *
645 \subsection{List of static hsc flags}
646 %*                                                                      *
647 %************************************************************************
648
649 \begin{code}
650 isStaticHscFlag f =
651   f `elem` [
652         "fauto-sccs-on-all-toplevs",
653         "fauto-sccs-on-exported-toplevs",
654         "fauto-sccs-on-individual-cafs",
655         "fauto-sccs-on-dicts",
656         "fscc-profiling",
657         "fticky-ticky",
658         "fall-strict",
659         "fdicts-strict",
660         "firrefutable-tuples",
661         "fnumbers-strict",
662         "fparallel",
663         "fsmp",
664         "fflatten",
665         "fsemi-tagging",
666         "flet-no-escape",
667         "funbox-strict-fields",
668         "femit-extern-decls",
669         "fglobalise-toplev-names",
670         "fgransim",
671         "fignore-asserts",
672         "fignore-interface-pragmas",
673         "fno-hi-version-check",
674         "dno-black-holing",
675         "fno-method-sharing",
676         "fomit-interface-pragmas",
677         "fruntime-types",
678         "fno-pre-inlining",
679         "fdo-eta-reduction",
680         "fdo-lambda-eta-expansion",
681         "fcase-merge",
682         "fexcess-precision",
683         "funfolding-update-in-place",
684         "fno-prune-decls",
685         "static",
686         "funregisterised",
687         "fext-core",
688         "frule-check",
689         "frules-off",
690         "fcpr-off"
691         ]
692   || any (flip prefixMatch f) [
693         "fcontext-stack",
694         "fliberate-case-threshold",
695         "fmax-worker-args",
696         "fhistory-size",
697         "funfolding-creation-threshold",
698         "funfolding-use-threshold",
699         "funfolding-fun-discount",
700         "funfolding-keeness-factor"
701      ]
702 \end{code}
703
704 %************************************************************************
705 %*                                                                      *
706 \subsection{Misc functions for command-line options}
707 %*                                                                      *
708 %************************************************************************
709
710
711
712 \begin{code}
713 startsWith :: String -> String -> Maybe String
714 -- startsWith pfx (pfx++rest) = Just rest
715
716 startsWith []     str = Just str
717 startsWith (c:cs) (s:ss)
718   = if c /= s then Nothing else startsWith cs ss
719 startsWith  _     []  = Nothing
720
721 endsWith  :: String -> String -> Maybe String
722 endsWith cs ss
723   = case (startsWith (reverse cs) (reverse ss)) of
724       Nothing -> Nothing
725       Just rs -> Just (reverse rs)
726 \end{code}