[project @ 1996-07-15 11:32:34 by partain]
[ghc-hetmet.git] / ghc / compiler / main / CmdLineOpts.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1996
3 %
4 \section[CmdLineOpts]{Things to do with command-line options}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module CmdLineOpts (
10         CoreToDo(..),
11         SimplifierSwitch(..),
12         StgToDo(..),
13         SwitchResult(..),
14         classifyOpts,
15
16         intSwitchSet,
17         switchIsOn,
18
19         maybe_CompilingGhcInternals,
20         opt_AllDemanded,
21         opt_AllStrict,
22         opt_AutoSccsOnAllToplevs,
23         opt_AutoSccsOnExportedToplevs,
24         opt_AutoSccsOnIndividualCafs,
25         opt_CompilingGhcInternals,
26         opt_UsingGhcInternals,
27         opt_D_dump_absC,
28         opt_D_dump_asm,
29         opt_D_dump_deforest,
30         opt_D_dump_deriv,
31         opt_D_dump_ds,
32         opt_D_dump_flatC,
33         opt_D_dump_occur_anal,
34         opt_D_dump_rdr,
35         opt_D_dump_realC,
36         opt_D_dump_rn,
37         opt_D_dump_simpl,
38         opt_D_dump_spec,
39         opt_D_dump_stg,
40         opt_D_dump_stranal,
41         opt_D_dump_tc,
42         opt_D_show_passes,
43         opt_D_simplifier_stats,
44         opt_D_source_stats,
45         opt_D_verbose_core2core,
46         opt_D_verbose_stg2stg,
47         opt_DoCoreLinting,
48         opt_DoSemiTagging,
49         opt_DoTickyProfiling,
50         opt_EnsureSplittableC,
51         opt_FoldrBuildOn,
52         opt_FoldrBuildTrace,
53         opt_ForConcurrent,
54         opt_GlasgowExts,
55         opt_GranMacros,
56         opt_Haskell_1_3,
57         opt_HiMap,
58         opt_IgnoreIfacePragmas,
59         opt_IgnoreStrictnessPragmas,
60         opt_IrrefutableEverything,
61         opt_IrrefutableTuples,
62         opt_NoImplicitPrelude,
63         opt_NumbersStrict,
64         opt_OmitBlackHoling,
65         opt_OmitDefaultInstanceMethods,
66         opt_OmitInterfacePragmas,
67         opt_PprStyle_All,
68         opt_PprStyle_Debug,
69         opt_PprStyle_User,
70         opt_ProduceC,
71         opt_ProduceHi,
72         opt_ProduceS,
73         opt_ReportWhyUnfoldingsDisallowed,
74         opt_ReturnInRegsThreshold,
75         opt_SccGroup,
76         opt_SccProfilingOn,
77         opt_ShowImportSpecs,
78         opt_ShowPragmaNameErrs,
79         opt_SigsRequired,
80         opt_SpecialiseAll,
81         opt_SpecialiseImports,
82         opt_SpecialiseOverloaded,
83         opt_SpecialiseTrace,
84         opt_SpecialiseUnboxed,
85         opt_StgDoLetNoEscapes,
86         opt_UnfoldingCreationThreshold,
87         opt_UnfoldingOverrideThreshold,
88         opt_UnfoldingUseThreshold,
89         opt_Verbose,
90         opt_WarnNameShadowing
91     ) where
92
93 IMPORT_1_3(Array(array, (//)))
94 import PreludeGlaST     -- bad bad bad boy, Will (_Array internals)
95 import Argv
96
97 CHK_Ubiq() -- debugging consistency check
98
99 import Maybes           ( assocMaybe, firstJust, maybeToBool )
100 import Util             ( startsWith, panic, panic#, assertPanic )
101 \end{code}
102
103 A command-line {\em switch} is (generally) either on or off; e.g., the
104 ``verbose'' (-v) switch is either on or off.  (The \tr{-G<group>}
105 switch is an exception; it's set to a string, or nothing.)
106
107 A list of {\em ToDo}s is things to be done in a particular part of
108 processing.  A (fictitious) example for the Core-to-Core simplifier
109 might be: run the simplifier, then run the strictness analyser, then
110 run the simplifier again (three ``todos'').
111
112 There are three ``to-do processing centers'' at the moment.  In the
113 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
114 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
115 (\tr{simplStg/SimplStg.lhs}).
116
117 %************************************************************************
118 %*                                                                      *
119 \subsection{Datatypes associated with command-line options}
120 %*                                                                      *
121 %************************************************************************
122
123 \begin{code}
124 data SwitchResult
125   = SwBool      Bool            -- on/off
126   | SwString    FAST_STRING     -- nothing or a String
127   | SwInt       Int             -- nothing or an Int
128 \end{code}
129
130 \begin{code}
131 data CoreToDo           -- These are diff core-to-core passes,
132                         -- which may be invoked in any order,
133                         -- as many times as you like.
134
135   = CoreDoSimplify      -- The core-to-core simplifier.
136         (SimplifierSwitch -> SwitchResult)
137                         -- Each run of the simplifier can take a different
138                         -- set of simplifier-specific flags.
139   | CoreDoCalcInlinings1
140   | CoreDoCalcInlinings2
141   | CoreDoFloatInwards
142   | CoreDoFullLaziness
143   | CoreLiberateCase
144   | CoreDoPrintCore
145   | CoreDoStaticArgs
146   | CoreDoStrictness
147   | CoreDoSpecialising
148   | CoreDoDeforest
149   | CoreDoFoldrBuildWorkerWrapper
150   | CoreDoFoldrBuildWWAnal
151 \end{code}
152
153 \begin{code}
154 data StgToDo
155   = StgDoStaticArgs
156   | StgDoUpdateAnalysis
157   | StgDoLambdaLift
158   | StgDoMassageForProfiling  -- should be (next to) last
159   -- There's also setStgVarInfo, but its absolute "lastness"
160   -- is so critical that it is hardwired in (no flag).
161   | D_stg_stats
162 \end{code}
163
164 \begin{code}
165 data SimplifierSwitch
166   = SimplOkToDupCode
167   | SimplFloatLetsExposingWHNF
168   | SimplOkToFloatPrimOps
169   | SimplAlwaysFloatLetsFromLets
170   | SimplDoCaseElim
171   | SimplReuseCon
172   | SimplCaseOfCase
173   | SimplLetToCase
174   | SimplMayDeleteConjurableIds
175   | SimplPedanticBottoms -- see Simplifier for an explanation
176   | SimplDoArityExpand   -- expand arity of bindings
177   | SimplDoFoldrBuild    -- This is the per-simplification flag;
178                          -- see also FoldrBuildOn, used elsewhere
179                          -- in the compiler.
180   | SimplDoInlineFoldrBuild
181                          -- inline foldr/build (*after* f/b rule is used)
182
183   | IgnoreINLINEPragma
184   | SimplDoLambdaEtaExpansion
185   | SimplDoEtaReduction
186
187   | EssentialUnfoldingsOnly -- never mind the thresholds, only
188                             -- do unfoldings that *must* be done
189                             -- (to saturate constructors and primitives)
190
191   | ShowSimplifierProgress  -- report counts on every interation
192
193   | MaxSimplifierIterations Int
194
195   | SimplUnfoldingUseThreshold      Int -- per-simplification variants
196   | SimplUnfoldingCreationThreshold Int
197
198   | KeepSpecPragmaIds       -- We normally *toss* Ids we can do without
199   | KeepUnusedBindings
200
201   | SimplNoLetFromCase      -- used when turning off floating entirely
202   | SimplNoLetFromApp       -- (for experimentation only) WDP 95/10
203   | SimplNoLetFromStrictLet
204
205   | SimplDontFoldBackAppend
206                         -- we fold `foldr (:)' back into flip (++),
207                         -- but we *don't* want to do it when compiling
208                         -- List.hs, otherwise
209                         -- xs ++ ys = foldr (:) ys xs
210                         -- {- via our loopback -}
211                         -- xs ++ ys = xs ++ ys
212                         -- Oops!
213                         -- So only use this flag inside List.hs
214                         -- (Sigh, what a HACK, Andy.  WDP 96/01)
215 \end{code}
216
217 %************************************************************************
218 %*                                                                      *
219 \subsection{Classifying command-line options}
220 %*                                                                      *
221 %************************************************************************
222
223 \begin{code}
224 lookUp     :: FAST_STRING -> Bool
225 lookup_int :: String -> Maybe Int
226 lookup_str :: String -> Maybe String
227
228 lookUp     sw = maybeToBool (assoc_opts sw)
229         
230 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
231
232 lookup_int sw = case (lookup_str sw) of
233                   Nothing -> Nothing
234                   Just xx -> Just (read xx)
235
236 assoc_opts    = assocMaybe [ (a, True) | a <- argv ]
237 unpacked_opts = map _UNPK_ argv
238 \end{code}
239
240 \begin{code}
241 opt_AllDemanded                 = lookUp  SLIT("-fall-demanded")
242 opt_AllStrict                   = lookUp  SLIT("-fall-strict")
243 opt_AutoSccsOnAllToplevs        = lookUp  SLIT("-fauto-sccs-on-all-toplevs")
244 opt_AutoSccsOnExportedToplevs   = lookUp  SLIT("-fauto-sccs-on-exported-toplevs")
245 opt_AutoSccsOnIndividualCafs    = lookUp  SLIT("-fauto-sccs-on-individual-cafs")
246 opt_D_dump_absC                 = lookUp  SLIT("-ddump-absC")
247 opt_D_dump_asm                  = lookUp  SLIT("-ddump-asm")
248 opt_D_dump_deforest             = lookUp  SLIT("-ddump-deforest")
249 opt_D_dump_deriv                = lookUp  SLIT("-ddump-deriv")
250 opt_D_dump_ds                   = lookUp  SLIT("-ddump-ds")
251 opt_D_dump_flatC                = lookUp  SLIT("-ddump-flatC")
252 opt_D_dump_occur_anal           = lookUp  SLIT("-ddump-occur-anal")
253 opt_D_dump_rdr                  = lookUp  SLIT("-ddump-rdr")
254 opt_D_dump_realC                = lookUp  SLIT("-ddump-realC")
255 opt_D_dump_rn                   = lookUp  SLIT("-ddump-rn")
256 opt_D_dump_simpl                = lookUp  SLIT("-ddump-simpl")
257 opt_D_dump_spec                 = lookUp  SLIT("-ddump-spec")
258 opt_D_dump_stg                  = lookUp  SLIT("-ddump-stg")
259 opt_D_dump_stranal              = lookUp  SLIT("-ddump-stranal")
260 opt_D_dump_tc                   = lookUp  SLIT("-ddump-tc")
261 opt_D_show_passes               = lookUp  SLIT("-dshow-passes")
262 opt_D_simplifier_stats          = lookUp  SLIT("-dsimplifier-stats")
263 opt_D_source_stats              = lookUp  SLIT("-dsource-stats")
264 opt_D_verbose_core2core         = lookUp  SLIT("-dverbose-simpl")
265 opt_D_verbose_stg2stg           = lookUp  SLIT("-dverbose-stg")
266 opt_DoCoreLinting               = lookUp  SLIT("-dcore-lint")
267 opt_DoSemiTagging               = lookUp  SLIT("-fsemi-tagging")
268 opt_DoTickyProfiling            = lookUp  SLIT("-fticky-ticky")
269 opt_FoldrBuildOn                = lookUp  SLIT("-ffoldr-build-on")
270 opt_FoldrBuildTrace             = lookUp  SLIT("-ffoldr-build-trace")
271 opt_ForConcurrent               = lookUp  SLIT("-fconcurrent")
272 opt_GranMacros                  = lookUp  SLIT("-fgransim")
273 opt_GlasgowExts                 = lookUp  SLIT("-fglasgow-exts")
274 opt_Haskell_1_3                 = lookUp  SLIT("-fhaskell-1.3")
275 opt_IgnoreStrictnessPragmas     = lookUp  SLIT("-fignore-strictness-pragmas")
276 opt_IrrefutableEverything       = lookUp  SLIT("-firrefutable-everything")
277 opt_IrrefutableTuples           = lookUp  SLIT("-firrefutable-tuples")
278 opt_WarnNameShadowing           = lookUp  SLIT("-fwarn-name-shadowing")
279 opt_NumbersStrict               = lookUp  SLIT("-fnumbers-strict")
280 opt_OmitBlackHoling             = lookUp  SLIT("-dno-black-holing")
281 opt_OmitDefaultInstanceMethods  = lookUp  SLIT("-fomit-default-instance-methods")
282 opt_OmitInterfacePragmas        = lookUp  SLIT("-fomit-interface-pragmas")
283 opt_PprStyle_All                = lookUp  SLIT("-dppr-all")
284 opt_PprStyle_Debug              = lookUp  SLIT("-dppr-debug")
285 opt_PprStyle_User               = lookUp  SLIT("-dppr-user")
286 opt_ReportWhyUnfoldingsDisallowed= lookUp SLIT("-freport-disallowed-unfoldings")
287 opt_SccProfilingOn              = lookUp  SLIT("-fscc-profiling")
288 opt_ShowImportSpecs             = lookUp  SLIT("-fshow-import-specs")
289 opt_ShowPragmaNameErrs          = lookUp  SLIT("-fshow-pragma-name-errs")
290 opt_SigsRequired                = lookUp  SLIT("-fsignatures-required")
291 opt_SpecialiseAll               = lookUp  SLIT("-fspecialise-all")
292 opt_SpecialiseImports           = lookUp  SLIT("-fspecialise-imports")
293 opt_SpecialiseOverloaded        = lookUp  SLIT("-fspecialise-overloaded")
294 opt_SpecialiseTrace             = lookUp  SLIT("-ftrace-specialisation")
295 opt_SpecialiseUnboxed           = lookUp  SLIT("-fspecialise-unboxed")
296 opt_StgDoLetNoEscapes           = lookUp  SLIT("-flet-no-escape")
297 opt_Verbose                     = lookUp  SLIT("-v")
298 opt_UsingGhcInternals           = lookUp  SLIT("-fusing-ghc-internals")
299 opt_CompilingGhcInternals       = maybeToBool maybe_CompilingGhcInternals
300 maybe_CompilingGhcInternals     = lookup_str "-fcompiling-ghc-internals="
301 opt_SccGroup                    = lookup_str "-G="
302 opt_ProduceC                    = lookup_str "-C="
303 opt_ProduceS                    = lookup_str "-S="
304 opt_ProduceHi                   = lookup_str "-hifile=" -- the one to produce this time 
305 opt_HiMap                       = lookup_str "-himap="  -- file saying where to look for .hi files
306 opt_EnsureSplittableC           = lookup_str "-fglobalise-toplev-names="
307 opt_UnfoldingUseThreshold       = lookup_int "-funfolding-use-threshold"
308 opt_UnfoldingCreationThreshold  = lookup_int "-funfolding-creation-threshold"
309 opt_UnfoldingOverrideThreshold  = lookup_int "-funfolding-override-threshold"
310 opt_ReturnInRegsThreshold       = lookup_int "-freturn-in-regs-threshold"
311
312 opt_NoImplicitPrelude           = lookUp  SLIT("-fno-implicit-prelude")
313 opt_IgnoreIfacePragmas          = lookUp  SLIT("-fignore-interface-pragmas")
314 \end{code}
315
316 \begin{code}
317 classifyOpts :: ([CoreToDo],    -- Core-to-Core processing spec
318                  [StgToDo])     -- STG-to-STG   processing spec
319
320 classifyOpts = sep argv [] [] -- accumulators...
321   where
322     sep :: [FAST_STRING]                         -- cmd-line opts (input)
323         -> [CoreToDo] -> [StgToDo]       -- to_do accumulators
324         -> ([CoreToDo], [StgToDo])       -- result
325
326     sep [] core_td stg_td -- all done!
327       = (reverse core_td, reverse stg_td)
328
329 #       define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
330 #       define STG_TD(to_do)  sep opts core_td (to_do:stg_td)
331 #       define IGNORE_ARG()   sep opts core_td stg_td
332
333     sep (opt1:opts) core_td stg_td
334       =
335         case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
336
337           ',' : _       -> IGNORE_ARG() -- it is for the parser
338
339           "-fsimplify"  -> -- gather up SimplifierSwitches specially...
340                            simpl_sep opts [] core_td stg_td
341
342           "-fcalc-inlinings1"-> CORE_TD(CoreDoCalcInlinings1)
343           "-fcalc-inlinings2"-> CORE_TD(CoreDoCalcInlinings2)
344           "-ffloat-inwards"  -> CORE_TD(CoreDoFloatInwards)
345           "-ffull-laziness"  -> CORE_TD(CoreDoFullLaziness)
346           "-fliberate-case"  -> CORE_TD(CoreLiberateCase)
347           "-fprint-core"     -> CORE_TD(CoreDoPrintCore)
348           "-fstatic-args"    -> CORE_TD(CoreDoStaticArgs)
349           "-fstrictness"     -> CORE_TD(CoreDoStrictness)
350           "-fspecialise"     -> CORE_TD(CoreDoSpecialising)
351           "-fdeforest"       -> CORE_TD(CoreDoDeforest)
352           "-ffoldr-build-worker-wrapper"  -> CORE_TD(CoreDoFoldrBuildWorkerWrapper)
353           "-ffoldr-build-ww-anal"  -> CORE_TD(CoreDoFoldrBuildWWAnal)
354
355           "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
356           "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
357           "-dstg-stats"       -> STG_TD(D_stg_stats)
358           "-flambda-lift"     -> STG_TD(StgDoLambdaLift)
359           "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
360
361           _ -> -- NB: the driver is really supposed to handle bad options
362                IGNORE_ARG()
363
364     ----------------
365
366     simpl_sep :: [FAST_STRING]      -- cmd-line opts (input)
367         -> [SimplifierSwitch]       -- simplifier-switch accumulator
368         -> [CoreToDo] -> [StgToDo]  -- to_do accumulators
369         -> ([CoreToDo], [StgToDo])  -- result
370
371         -- "simpl_sep" tailcalls "sep" once it's seen one set
372         -- of SimplifierSwitches for a CoreDoSimplify.
373
374 #ifdef DEBUG
375     simpl_sep input@[] simpl_sw core_td stg_td
376       = panic "simpl_sep []"
377 #endif
378
379         -- The SimplifierSwitches should be delimited by "(" and ")".
380
381     simpl_sep (opt1:opts) simpl_sw core_td stg_td
382       = case (_UNPK_ opt1) of
383           "(" -> ASSERT (null simpl_sw)
384                  simpl_sep opts [] core_td stg_td
385           ")" -> let
386                     this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
387                  in
388                  sep opts (this_simpl : core_td) stg_td
389
390 #         define SIMPL_SW(sw) simpl_sep opts (sw:simpl_sw) core_td stg_td
391
392           -- the non-"just match a string" options are at the end...
393           "-fshow-simplifier-progress"      -> SIMPL_SW(ShowSimplifierProgress)
394           "-fcode-duplication-ok"           -> SIMPL_SW(SimplOkToDupCode)
395           "-ffloat-lets-exposing-whnf"      -> SIMPL_SW(SimplFloatLetsExposingWHNF)
396           "-ffloat-primops-ok"              -> SIMPL_SW(SimplOkToFloatPrimOps)
397           "-falways-float-lets-from-lets"   -> SIMPL_SW(SimplAlwaysFloatLetsFromLets)
398           "-fdo-case-elim"                  -> SIMPL_SW(SimplDoCaseElim)
399           "-fdo-eta-reduction"              -> SIMPL_SW(SimplDoEtaReduction)
400           "-fdo-lambda-eta-expansion"       -> SIMPL_SW(SimplDoLambdaEtaExpansion)
401           "-fdo-foldr-build"                -> SIMPL_SW(SimplDoFoldrBuild)
402           "-fdo-not-fold-back-append"       -> SIMPL_SW(SimplDontFoldBackAppend)
403           "-fdo-arity-expand"               -> SIMPL_SW(SimplDoArityExpand)
404           "-fdo-inline-foldr-build"         -> SIMPL_SW(SimplDoInlineFoldrBuild)
405           "-freuse-con"                     -> SIMPL_SW(SimplReuseCon)
406           "-fcase-of-case"                  -> SIMPL_SW(SimplCaseOfCase)
407           "-flet-to-case"                   -> SIMPL_SW(SimplLetToCase)
408           "-fpedantic-bottoms"              -> SIMPL_SW(SimplPedanticBottoms)
409           "-fkeep-spec-pragma-ids"          -> SIMPL_SW(KeepSpecPragmaIds)
410           "-fkeep-unused-bindings"          -> SIMPL_SW(KeepUnusedBindings)
411           "-fmay-delete-conjurable-ids"     -> SIMPL_SW(SimplMayDeleteConjurableIds)
412           "-fessential-unfoldings-only"     -> SIMPL_SW(EssentialUnfoldingsOnly)
413           "-fignore-inline-pragma"          -> SIMPL_SW(IgnoreINLINEPragma)
414           "-fno-let-from-case"              -> SIMPL_SW(SimplNoLetFromCase)
415           "-fno-let-from-app"               -> SIMPL_SW(SimplNoLetFromApp)
416           "-fno-let-from-strict-let"        -> SIMPL_SW(SimplNoLetFromStrictLet)
417
418           o | starts_with_msi  -> SIMPL_SW(MaxSimplifierIterations (read after_msi))
419             | starts_with_suut -> SIMPL_SW(SimplUnfoldingUseThreshold (read after_suut))
420             | starts_with_suct -> SIMPL_SW(SimplUnfoldingCreationThreshold (read after_suct))
421            where
422             maybe_suut          = startsWith "-fsimpl-uf-use-threshold"      o
423             maybe_suct          = startsWith "-fsimpl-uf-creation-threshold" o
424             maybe_msi           = startsWith "-fmax-simplifier-iterations"   o
425             starts_with_suut    = maybeToBool maybe_suut
426             starts_with_suct    = maybeToBool maybe_suct
427             starts_with_msi     = maybeToBool maybe_msi
428             (Just after_suut)   = maybe_suut
429             (Just after_suct)   = maybe_suct
430             (Just after_msi)    = maybe_msi
431
432           _ -> -- NB: the driver is really supposed to handle bad options
433                simpl_sep opts simpl_sw core_td stg_td
434 \end{code}
435
436 %************************************************************************
437 %*                                                                      *
438 \subsection{Switch ordering}
439 %*                                                                      *
440 %************************************************************************
441
442 In spite of the @Produce*@ and @SccGroup@ constructors, these things
443 behave just like enumeration types.
444
445 \begin{code}
446 instance Eq SimplifierSwitch where
447     a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
448
449 instance Ord SimplifierSwitch where
450     a <  b  = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
451     a <= b  = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
452
453 tagOf_SimplSwitch SimplOkToDupCode              =(ILIT(0) :: FAST_INT)
454 tagOf_SimplSwitch SimplFloatLetsExposingWHNF    = ILIT(1)
455 tagOf_SimplSwitch SimplOkToFloatPrimOps         = ILIT(2)
456 tagOf_SimplSwitch SimplAlwaysFloatLetsFromLets  = ILIT(3)
457 tagOf_SimplSwitch SimplDoCaseElim               = ILIT(4)
458 tagOf_SimplSwitch SimplReuseCon                 = ILIT(5)
459 tagOf_SimplSwitch SimplCaseOfCase               = ILIT(6)
460 tagOf_SimplSwitch SimplLetToCase                = ILIT(7)
461 tagOf_SimplSwitch SimplMayDeleteConjurableIds   = ILIT(9)
462 tagOf_SimplSwitch SimplPedanticBottoms          = ILIT(10)
463 tagOf_SimplSwitch SimplDoArityExpand            = ILIT(11)
464 tagOf_SimplSwitch SimplDoFoldrBuild             = ILIT(12)
465 tagOf_SimplSwitch SimplDoInlineFoldrBuild       = ILIT(14)
466 tagOf_SimplSwitch IgnoreINLINEPragma            = ILIT(15)
467 tagOf_SimplSwitch SimplDoLambdaEtaExpansion     = ILIT(16)
468 tagOf_SimplSwitch SimplDoEtaReduction           = ILIT(18)
469 tagOf_SimplSwitch EssentialUnfoldingsOnly       = ILIT(19)
470 tagOf_SimplSwitch ShowSimplifierProgress        = ILIT(20)
471 tagOf_SimplSwitch (MaxSimplifierIterations _)   = ILIT(21)
472 tagOf_SimplSwitch (SimplUnfoldingUseThreshold _)      = ILIT(22)
473 tagOf_SimplSwitch (SimplUnfoldingCreationThreshold _) = ILIT(23)
474 tagOf_SimplSwitch KeepSpecPragmaIds             = ILIT(24)
475 tagOf_SimplSwitch KeepUnusedBindings            = ILIT(25)
476 tagOf_SimplSwitch SimplNoLetFromCase            = ILIT(26)
477 tagOf_SimplSwitch SimplNoLetFromApp             = ILIT(27)
478 tagOf_SimplSwitch SimplNoLetFromStrictLet       = ILIT(28)
479 tagOf_SimplSwitch SimplDontFoldBackAppend       = ILIT(29)
480 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
481
482 tagOf_SimplSwitch _ = panic# "tagOf_SimplSwitch"
483
484 lAST_SIMPL_SWITCH_TAG = IBOX(tagOf_SimplSwitch SimplDontFoldBackAppend)
485 \end{code}
486
487 %************************************************************************
488 %*                                                                      *
489 \subsection{Switch lookup}
490 %*                                                                      *
491 %************************************************************************
492
493 \begin{code}
494 #if __GLASGOW_HASKELL__ >= 200
495 # define ARRAY      Array
496 # define LIFT       GHCbase.Lift
497 # define SET_TO     =:
498 (=:) a b = (a,b)
499 #else
500 # define ARRAY      _Array
501 # define LIFT       _Lift
502 # define SET_TO     :=
503 #endif
504
505 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
506
507 isAmongSimpl on_switches
508   = let
509         tidied_on_switches = foldl rm_dups [] on_switches
510
511         sw_tbl :: Array Int SwitchResult
512
513         sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
514                         all_undefined)
515                  // defined_elems
516
517         all_undefined = [ i SET_TO SwBool False | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
518
519         defined_elems = map mk_assoc_elem tidied_on_switches
520     in
521     -- (avoid some unboxing, bounds checking, and other horrible things:)
522     case sw_tbl of { ARRAY bounds_who_needs_'em stuff ->
523     \ switch ->
524         case (indexArray# stuff (tagOf_SimplSwitch switch)) of
525           LIFT v -> v
526     }
527   where
528     mk_assoc_elem k@(MaxSimplifierIterations lvl)       = IBOX(tagOf_SimplSwitch k) SET_TO SwInt lvl
529     mk_assoc_elem k@(SimplUnfoldingUseThreshold      i) = IBOX(tagOf_SimplSwitch k) SET_TO SwInt i
530     mk_assoc_elem k@(SimplUnfoldingCreationThreshold i) = IBOX(tagOf_SimplSwitch k) SET_TO SwInt i
531
532     mk_assoc_elem k = IBOX(tagOf_SimplSwitch k) SET_TO SwBool   True -- I'm here, Mom!
533
534     -- cannot have duplicates if we are going to use the array thing
535
536     rm_dups switches_so_far switch
537       = if switch `is_elem` switches_so_far
538         then switches_so_far
539         else switch : switches_so_far
540       where
541         sw `is_elem` []     = False
542         sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
543                             || sw `is_elem` ss
544 \end{code}
545
546 %************************************************************************
547 %*                                                                      *
548 \subsection{Misc functions for command-line options}
549 %*                                                                      *
550 %************************************************************************
551
552
553 \begin{code}
554 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
555
556 switchIsOn lookup_fn switch
557   = case (lookup_fn switch) of
558       SwBool False -> False
559       _            -> True
560
561 stringSwitchSet :: (switch -> SwitchResult)
562                 -> (FAST_STRING -> switch)
563                 -> Maybe FAST_STRING
564
565 stringSwitchSet lookup_fn switch
566   = case (lookup_fn (switch (panic "stringSwitchSet"))) of
567       SwString str -> Just str
568       _            -> Nothing
569
570 intSwitchSet :: (switch -> SwitchResult)
571              -> (Int -> switch)
572              -> Maybe Int
573
574 intSwitchSet lookup_fn switch
575   = case (lookup_fn (switch (panic "intSwitchSet"))) of
576       SwInt int -> Just int
577       _         -> Nothing
578 \end{code}