[project @ 2002-02-11 08:20:38 by chak]
[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 Config
124
125 import Maybes           ( firstJust )
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   | CoreDoUSPInf
187   | CoreDoCPResult
188   | CoreDoGlomBinds
189   | CoreCSE
190   | CoreDoRuleCheck Int{-CompilerPhase-} String -- Check for non-application of rules 
191                                                 -- matching this string
192
193   | CoreDoNothing        -- useful when building up lists of these things
194 \end{code}
195
196 \begin{code}
197 data StgToDo
198   = StgDoMassageForProfiling  -- should be (next to) last
199   -- There's also setStgVarInfo, but its absolute "lastness"
200   -- is so critical that it is hardwired in (no flag).
201   | D_stg_stats
202 \end{code}
203
204 \begin{code}
205 data SimplifierMode             -- See comments in SimplMonad
206   = SimplGently
207   | SimplPhase Int
208
209 data SimplifierSwitch
210   = MaxSimplifierIterations Int
211   | NoCaseOfCase
212
213 data FloatOutSwitches
214   = FloatOutSw  Bool    -- True <=> float lambdas to top level
215                 Bool    -- True <=> float constants to top level,
216                         --          even if they do not escape a lambda
217 \end{code}
218
219 %************************************************************************
220 %*                                                                      *
221 \subsection{Dynamic command-line options}
222 %*                                                                      *
223 %************************************************************************
224
225 \begin{code}
226 data DynFlag
227
228    -- debugging flags
229    = Opt_D_dump_absC
230    | Opt_D_dump_asm
231    | Opt_D_dump_cpranal
232    | Opt_D_dump_deriv
233    | Opt_D_dump_ds
234    | Opt_D_dump_flatC
235    | Opt_D_dump_foreign
236    | Opt_D_dump_inlinings
237    | Opt_D_dump_occur_anal
238    | Opt_D_dump_parsed
239    | Opt_D_dump_realC
240    | Opt_D_dump_rn
241    | Opt_D_dump_simpl
242    | Opt_D_dump_simpl_iterations
243    | Opt_D_dump_spec
244    | Opt_D_dump_prep
245    | Opt_D_dump_stg
246    | Opt_D_dump_stranal
247    | Opt_D_dump_tc
248    | Opt_D_dump_types
249    | Opt_D_dump_rules
250    | Opt_D_dump_usagesp
251    | Opt_D_dump_cse
252    | Opt_D_dump_worker_wrapper
253    | Opt_D_dump_rn_trace
254    | Opt_D_dump_rn_stats
255    | Opt_D_dump_stix
256    | Opt_D_dump_simpl_stats
257    | Opt_D_dump_tc_trace
258    | Opt_D_dump_BCOs
259    | Opt_D_dump_vect
260    | Opt_D_source_stats
261    | Opt_D_verbose_core2core
262    | Opt_D_verbose_stg2stg
263    | Opt_D_dump_hi
264    | Opt_D_dump_hi_diffs
265    | Opt_D_dump_minimal_imports
266    | Opt_DoCoreLinting
267    | Opt_DoStgLinting
268    | Opt_DoUSPLinting
269
270    | Opt_WarnDuplicateExports
271    | Opt_WarnHiShadows
272    | Opt_WarnIncompletePatterns
273    | Opt_WarnMissingFields
274    | Opt_WarnMissingMethods
275    | Opt_WarnMissingSigs
276    | Opt_WarnNameShadowing
277    | Opt_WarnOverlappingPatterns
278    | Opt_WarnSimplePatterns
279    | Opt_WarnTypeDefaults
280    | Opt_WarnUnusedBinds
281    | Opt_WarnUnusedImports
282    | Opt_WarnUnusedMatches
283    | Opt_WarnDeprecations
284    | Opt_WarnMisc
285
286    -- language opts
287    | Opt_AllowOverlappingInstances
288    | Opt_AllowUndecidableInstances
289    | Opt_AllowIncoherentInstances
290    | Opt_NoMonomorphismRestriction
291    | Opt_GlasgowExts
292    | Opt_PArr                          -- syntactic support for parallel arrays
293    | Opt_Generics
294    | Opt_NoImplicitPrelude 
295
296    deriving (Eq)
297
298 data DynFlags = DynFlags {
299   coreToDo              :: [CoreToDo],
300   stgToDo               :: [StgToDo],
301   hscLang               :: HscLang,
302   hscOutName            :: String,      -- name of the output file
303   hscStubHOutName       :: String,      -- name of the .stub_h output file
304   hscStubCOutName       :: String,      -- name of the .stub_c output file
305   extCoreName           :: String,      -- name of the .core output file
306   verbosity             :: Int,         -- verbosity level
307   cppFlag               :: Bool,        -- preprocess with cpp?
308   ppFlag                :: Bool,        -- preprocess with a Haskell Pp?
309   stolen_x86_regs       :: Int,         
310   cmdlineHcIncludes     :: [String],    -- -#includes
311
312   -- options for particular phases
313   opt_L                 :: [String],
314   opt_P                 :: [String],
315   opt_F                 :: [String],
316   opt_c                 :: [String],
317   opt_a                 :: [String],
318   opt_m                 :: [String],
319 #ifdef ILX                         
320   opt_I                 :: [String],
321   opt_i                 :: [String],
322 #endif
323
324   -- hsc dynamic flags
325   flags                 :: [DynFlag]
326  }
327
328 data HscLang
329   = HscC
330   | HscAsm
331   | HscJava
332   | HscILX
333   | HscInterpreted
334   | HscNothing
335     deriving (Eq, Show)
336
337 defaultDynFlags = DynFlags {
338   coreToDo = [], stgToDo = [], 
339   hscLang = HscC, 
340   hscOutName = "", 
341   hscStubHOutName = "", hscStubCOutName = "",
342   extCoreName = "",
343   verbosity = 0, 
344   cppFlag               = False,
345   ppFlag                = False,
346   stolen_x86_regs       = 4,
347   cmdlineHcIncludes     = [],
348   opt_L                 = [],
349   opt_P                 = [],
350   opt_F                 = [],
351   opt_c                 = [],
352   opt_a                 = [],
353   opt_m                 = [],
354 #ifdef ILX
355   opt_I                 = [],
356   opt_i                 = [],
357 #endif
358   flags = standardWarnings,
359   }
360
361 {- 
362     Verbosity levels:
363         
364     0   |   print errors & warnings only
365     1   |   minimal verbosity: print "compiling M ... done." for each module.
366     2   |   equivalent to -dshow-passes
367     3   |   equivalent to existing "ghc -v"
368     4   |   "ghc -v -ddump-most"
369     5   |   "ghc -v -ddump-all"
370 -}
371
372 dopt :: DynFlag -> DynFlags -> Bool
373 dopt f dflags  = f `elem` (flags dflags)
374
375 dopt_CoreToDo :: DynFlags -> [CoreToDo]
376 dopt_CoreToDo = coreToDo
377
378 dopt_StgToDo :: DynFlags -> [StgToDo]
379 dopt_StgToDo = stgToDo
380
381 dopt_OutName :: DynFlags -> String
382 dopt_OutName = hscOutName
383
384 dopt_HscLang :: DynFlags -> HscLang
385 dopt_HscLang = hscLang
386
387 dopt_set :: DynFlags -> DynFlag -> DynFlags
388 dopt_set dfs f = dfs{ flags = f : flags dfs }
389
390 dopt_unset :: DynFlags -> DynFlag -> DynFlags
391 dopt_unset dfs f = dfs{ flags = filter (/= f) (flags dfs) }
392
393 getOpts :: (DynFlags -> [a]) -> IO [a]
394         -- We add to the options from the front, so we need to reverse the list
395 getOpts opts = dynFlag opts >>= return . reverse
396
397 -- we can only switch between HscC, HscAsmm, and HscILX with dynamic flags 
398 -- (-fvia-C, -fasm, -filx respectively).
399 setLang l = updDynFlags (\ dfs -> case hscLang dfs of
400                                         HscC   -> dfs{ hscLang = l }
401                                         HscAsm -> dfs{ hscLang = l }
402                                         HscILX -> dfs{ hscLang = l }
403                                         _      -> dfs)
404
405 getVerbFlag = do
406    verb <- dynFlag verbosity
407    if verb >= 3  then return  "-v" else return ""
408 \end{code}
409
410 -----------------------------------------------------------------------------
411 -- Mess about with the mutable variables holding the dynamic arguments
412
413 -- v_InitDynFlags 
414 --      is the "baseline" dynamic flags, initialised from
415 --      the defaults and command line options, and updated by the
416 --      ':s' command in GHCi.
417 --
418 -- v_DynFlags
419 --      is the dynamic flags for the current compilation.  It is reset
420 --      to the value of v_InitDynFlags before each compilation, then
421 --      updated by reading any OPTIONS pragma in the current module.
422
423 \begin{code}
424 GLOBAL_VAR(v_InitDynFlags, defaultDynFlags, DynFlags)
425 GLOBAL_VAR(v_DynFlags,     defaultDynFlags, DynFlags)
426
427 setDynFlags :: DynFlags -> IO ()
428 setDynFlags dfs = writeIORef v_DynFlags dfs
429
430 saveDynFlags :: IO ()
431 saveDynFlags = do dfs <- readIORef v_DynFlags
432                   writeIORef v_InitDynFlags dfs
433
434 restoreDynFlags :: IO DynFlags
435 restoreDynFlags = do dfs <- readIORef v_InitDynFlags
436                      writeIORef v_DynFlags dfs
437                      return dfs
438
439 getDynFlags :: IO DynFlags
440 getDynFlags = readIORef v_DynFlags
441
442 updDynFlags :: (DynFlags -> DynFlags) -> IO ()
443 updDynFlags f = do dfs <- readIORef v_DynFlags
444                    writeIORef v_DynFlags (f dfs)
445
446 dynFlag :: (DynFlags -> a) -> IO a
447 dynFlag f = do dflags <- readIORef v_DynFlags; return (f dflags)
448
449 setDynFlag, unSetDynFlag :: DynFlag -> IO ()
450 setDynFlag f   = updDynFlags (\dfs -> dopt_set dfs f)
451 unSetDynFlag f = updDynFlags (\dfs -> dopt_unset dfs f)
452 \end{code}
453
454
455 %************************************************************************
456 %*                                                                      *
457 \subsection{Warnings}
458 %*                                                                      *
459 %************************************************************************
460
461 \begin{code}
462 standardWarnings
463     = [ Opt_WarnDeprecations,
464         Opt_WarnOverlappingPatterns,
465         Opt_WarnMissingFields,
466         Opt_WarnMissingMethods,
467         Opt_WarnDuplicateExports
468       ]
469
470 minusWOpts
471     = standardWarnings ++ 
472       [ Opt_WarnUnusedBinds,
473         Opt_WarnUnusedMatches,
474         Opt_WarnUnusedImports,
475         Opt_WarnIncompletePatterns,
476         Opt_WarnMisc
477       ]
478
479 minusWallOpts
480     = minusWOpts ++
481       [ Opt_WarnTypeDefaults,
482         Opt_WarnNameShadowing,
483         Opt_WarnMissingSigs,
484         Opt_WarnHiShadows
485       ]
486 \end{code}
487
488 %************************************************************************
489 %*                                                                      *
490 \subsection{Classifying command-line options}
491 %*                                                                      *
492 %************************************************************************
493
494 \begin{code}
495 -- v_Statis_hsc_opts is here to avoid a circular dependency with
496 -- main/DriverState.
497 GLOBAL_VAR(v_Static_hsc_opts, [], [String])
498
499 lookUp           :: FAST_STRING -> Bool
500 lookup_int       :: String -> Maybe Int
501 lookup_def_int   :: String -> Int -> Int
502 lookup_def_float :: String -> Float -> Float
503 lookup_str       :: String -> Maybe String
504
505 unpacked_static_opts = unsafePerformIO (readIORef v_Static_hsc_opts)
506 packed_static_opts   = map _PK_ unpacked_static_opts
507
508 lookUp     sw = sw `elem` packed_static_opts
509         
510 lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
511
512 lookup_int sw = case (lookup_str sw) of
513                   Nothing -> Nothing
514                   Just xx -> Just (read xx)
515
516 lookup_def_int sw def = case (lookup_str sw) of
517                             Nothing -> def              -- Use default
518                             Just xx -> read xx
519
520 lookup_def_float sw def = case (lookup_str sw) of
521                             Nothing -> def              -- Use default
522                             Just xx -> read xx
523
524
525 {-
526  Putting the compiler options into temporary at-files
527  may turn out to be necessary later on if we turn hsc into
528  a pure Win32 application where I think there's a command-line
529  length limit of 255. unpacked_opts understands the @ option.
530
531 unpacked_opts :: [String]
532 unpacked_opts =
533   concat $
534   map (expandAts) $
535   map _UNPK_ argv  -- NOT ARGV any more: v_Static_hsc_opts
536   where
537    expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
538    expandAts l = [l]
539 -}
540 \end{code}
541
542 %************************************************************************
543 %*                                                                      *
544 \subsection{Static options}
545 %*                                                                      *
546 %************************************************************************
547
548 \begin{code}
549 -- debugging opts
550 opt_PprStyle_NoPrags            = lookUp  SLIT("-dppr-noprags")
551 opt_PprStyle_Debug              = lookUp  SLIT("-dppr-debug")
552 opt_PprStyle_RawTypes           = lookUp  SLIT("-dppr-rawtypes")
553 opt_PprUserLength               = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
554
555 -- profiling opts
556 opt_AutoSccsOnAllToplevs        = lookUp  SLIT("-fauto-sccs-on-all-toplevs")
557 opt_AutoSccsOnExportedToplevs   = lookUp  SLIT("-fauto-sccs-on-exported-toplevs")
558 opt_AutoSccsOnIndividualCafs    = lookUp  SLIT("-fauto-sccs-on-individual-cafs")
559 opt_AutoSccsOnDicts             = lookUp  SLIT("-fauto-sccs-on-dicts")
560 opt_SccProfilingOn              = lookUp  SLIT("-fscc-profiling")
561 opt_DoTickyProfiling            = lookUp  SLIT("-fticky-ticky")
562
563 -- language opts
564 opt_AllStrict                   = lookUp  SLIT("-fall-strict")
565 opt_DictsStrict                 = lookUp  SLIT("-fdicts-strict")
566 opt_IrrefutableTuples           = lookUp  SLIT("-firrefutable-tuples")
567 opt_MaxContextReductionDepth    = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
568 opt_NumbersStrict               = lookUp  SLIT("-fnumbers-strict")
569 opt_Parallel                    = lookUp  SLIT("-fparallel")
570 opt_SMP                         = lookUp  SLIT("-fsmp")
571 opt_Flatten                     = lookUp  SLIT("-fflatten")
572
573 -- optimisation opts
574 opt_NoMethodSharing             = lookUp  SLIT("-fno-method-sharing")
575 opt_DoSemiTagging               = lookUp  SLIT("-fsemi-tagging")
576 opt_FoldrBuildOn                = lookUp  SLIT("-ffoldr-build-on")
577 opt_LiberateCaseThreshold       = lookup_def_int "-fliberate-case-threshold" (10::Int)
578 opt_StgDoLetNoEscapes           = lookUp  SLIT("-flet-no-escape")
579 opt_UnfoldCasms                 = lookUp  SLIT("-funfold-casms-in-hi-file")
580 opt_UsageSPOn                   = lookUp  SLIT("-fusagesp-on")
581 opt_UnboxStrictFields           = lookUp  SLIT("-funbox-strict-fields")
582 opt_MaxWorkerArgs               = lookup_def_int "-fmax-worker-args" (10::Int)
583
584 {-
585    The optional '-inpackage=P' flag tells what package
586    we are compiling this module for.
587    The Prelude, for example is compiled with '-inpackage std'
588 -}
589 opt_InPackage                   = case lookup_str "-inpackage=" of
590                                     Just p  -> _PK_ p
591                                     Nothing -> SLIT("Main")     -- The package name if none is specified
592
593 opt_EmitCExternDecls            = lookUp  SLIT("-femit-extern-decls")
594 opt_EnsureSplittableC           = lookUp  SLIT("-fglobalise-toplev-names")
595 opt_GranMacros                  = lookUp  SLIT("-fgransim")
596 opt_HiVersion                   = read (cProjectVersionInt ++ cProjectPatchLevel) :: Int
597 opt_HistorySize                 = lookup_def_int "-fhistory-size" 20
598 opt_IgnoreAsserts               = lookUp  SLIT("-fignore-asserts")
599 opt_IgnoreIfacePragmas          = lookUp  SLIT("-fignore-interface-pragmas")
600 opt_NoHiCheck                   = lookUp  SLIT("-fno-hi-version-check")
601 opt_OmitBlackHoling             = lookUp  SLIT("-dno-black-holing")
602 opt_OmitInterfacePragmas        = lookUp  SLIT("-fomit-interface-pragmas")
603 opt_RuntimeTypes                = lookUp  SLIT("-fruntime-types")
604
605 -- Simplifier switches
606 opt_SimplNoPreInlining          = lookUp  SLIT("-fno-pre-inlining")
607         -- NoPreInlining is there just to see how bad things
608         -- get if you don't do it!
609 opt_SimplDoEtaReduction         = lookUp  SLIT("-fdo-eta-reduction")
610 opt_SimplDoLambdaEtaExpansion   = lookUp  SLIT("-fdo-lambda-eta-expansion")
611 opt_SimplCaseMerge              = lookUp  SLIT("-fcase-merge")
612 opt_SimplExcessPrecision        = lookUp  SLIT("-fexcess-precision")
613
614 -- Unfolding control
615 opt_UF_CreationThreshold        = lookup_def_int "-funfolding-creation-threshold"  (45::Int)
616 opt_UF_UseThreshold             = lookup_def_int "-funfolding-use-threshold"       (8::Int)     -- Discounts can be big
617 opt_UF_FunAppDiscount           = lookup_def_int "-funfolding-fun-discount"        (6::Int)     -- It's great to inline a fn
618 opt_UF_KeenessFactor            = lookup_def_float "-funfolding-keeness-factor"    (1.5::Float)
619 opt_UF_UpdateInPlace            = lookUp  SLIT("-funfolding-update-in-place")
620
621 opt_UF_CheapOp  = ( 1 :: Int)   -- Only one instruction; and the args are charged for
622 opt_UF_DearOp   = ( 4 :: Int)
623                         
624 opt_NoPruneDecls                = lookUp  SLIT("-fno-prune-decls")
625 opt_NoPruneTyDecls              = lookUp  SLIT("-fno-prune-tydecls")
626 opt_Static                      = lookUp  SLIT("-static")
627 opt_Unregisterised              = lookUp  SLIT("-funregisterised")
628 opt_EmitExternalCore            = lookUp  SLIT("-fext-core")
629 \end{code}
630
631 %************************************************************************
632 %*                                                                      *
633 \subsection{List of static hsc flags}
634 %*                                                                      *
635 %************************************************************************
636
637 \begin{code}
638 isStaticHscFlag f =
639   f `elem` [
640         "fauto-sccs-on-all-toplevs",
641         "fauto-sccs-on-exported-toplevs",
642         "fauto-sccs-on-individual-cafs",
643         "fauto-sccs-on-dicts",
644         "fscc-profiling",
645         "fticky-ticky",
646         "fall-strict",
647         "fdicts-strict",
648         "firrefutable-tuples",
649         "fnumbers-strict",
650         "fparallel",
651         "fsmp",
652         "fflatten",
653         "fsemi-tagging",
654         "ffoldr-build-on",
655         "flet-no-escape",
656         "funfold-casms-in-hi-file",
657         "fusagesp-on",
658         "funbox-strict-fields",
659         "femit-extern-decls",
660         "fglobalise-toplev-names",
661         "fgransim",
662         "fignore-asserts",
663         "fignore-interface-pragmas",
664         "fno-hi-version-check",
665         "dno-black-holing",
666         "fno-method-sharing",
667         "fno-monomorphism-restriction",
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}