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