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