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