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