2 % (c) The AQUA Project, Glasgow University, 1996-98
4 \section[CmdLineOpts]{Things to do with command-line options}
29 dopt_D_dump_inlinings,
30 dopt_D_dump_occur_anal,
36 dopt_D_dump_simpl_iterations,
37 dopt_D_dump_simpl_stats,
44 dopt_D_dump_worker_wrapper,
49 dopt_D_dump_minimal_imports,
51 dopt_D_verbose_core2core,
52 dopt_D_verbose_stg2stg,
61 -- other dynamic flags
66 opt_WarnDuplicateExports,
68 opt_WarnIncompletePatterns,
69 opt_WarnMissingFields,
70 opt_WarnMissingMethods,
72 opt_WarnNameShadowing,
73 opt_WarnOverlappingPatterns,
74 opt_WarnSimplePatterns,
77 opt_WarnUnusedImports,
78 opt_WarnUnusedMatches,
82 opt_AutoSccsOnAllToplevs,
83 opt_AutoSccsOnExportedToplevs,
84 opt_AutoSccsOnIndividualCafs,
92 opt_MaxContextReductionDepth,
93 dopt_AllowOverlappingInstances,
94 dopt_AllowUndecidableInstances,
97 opt_IrrefutableTuples,
105 opt_LiberateCaseThreshold,
106 opt_StgDoLetNoEscapes,
109 opt_UnboxStrictFields,
110 opt_SimplNoPreInlining,
111 opt_SimplDoEtaReduction,
112 opt_SimplDoLambdaEtaExpansion,
115 opt_SimplPedanticBottoms,
116 opt_SimplExcessPrecision,
119 opt_UF_HiFileThreshold,
120 opt_UF_CreationThreshold,
122 opt_UF_FunAppDiscount,
123 opt_UF_KeenessFactor,
124 opt_UF_UpdateInPlace,
130 opt_EmitCExternDecls,
131 opt_EnsureSplittableC,
136 opt_IgnoreIfacePragmas,
138 opt_NoImplicitPrelude,
140 opt_OmitInterfacePragmas,
155 #include "HsVersions.h"
157 import Array ( array, (//) )
160 import Constants -- Default values for some flags
162 import Maybes ( firstJust )
163 import Panic ( panic )
165 #if __GLASGOW_HASKELL__ < 301
166 import ArrBase ( Array(..) )
168 import PrelArr ( Array(..) )
172 %************************************************************************
174 \subsection{Command-line options}
176 %************************************************************************
178 The hsc command-line options are split into two categories:
183 Static flags are represented by top-level values of type Bool or Int,
184 for example. They therefore have the same value throughout the
187 Dynamic flags are represented by a function:
189 checkDynFlag :: DynFlag -> SwitchResult
191 which is passed into hsc by the compilation manager for every
192 compilation. Dynamic flags are those that change on a per-compilation
193 basis, perhaps because they may be present in the OPTIONS pragma at
196 Other flag-related blurb:
198 A list of {\em ToDo}s is things to be done in a particular part of
199 processing. A (fictitious) example for the Core-to-Core simplifier
200 might be: run the simplifier, then run the strictness analyser, then
201 run the simplifier again (three ``todos'').
203 There are three ``to-do processing centers'' at the moment. In the
204 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
205 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
206 (\tr{simplStg/SimplStg.lhs}).
208 %************************************************************************
210 \subsection{Datatypes associated with command-line options}
212 %************************************************************************
216 = SwBool Bool -- on/off
217 | SwString FAST_STRING -- nothing or a String
218 | SwInt Int -- nothing or an Int
222 data CoreToDo -- These are diff core-to-core passes,
223 -- which may be invoked in any order,
224 -- as many times as you like.
226 = CoreDoSimplify -- The core-to-core simplifier.
227 (SimplifierSwitch -> SwitchResult)
228 -- Each run of the simplifier can take a different
229 -- set of simplifier-specific flags.
231 | CoreDoFloatOutwards Bool -- True <=> float lambdas to top level
236 | CoreDoWorkerWrapper
248 | StgDoMassageForProfiling -- should be (next to) last
249 -- There's also setStgVarInfo, but its absolute "lastness"
250 -- is so critical that it is hardwired in (no flag).
255 data SimplifierSwitch
256 = MaxSimplifierIterations Int
257 | SimplInlinePhase Int
263 %************************************************************************
265 \subsection{Dynamic command-line options}
267 %************************************************************************
282 | Opt_D_dump_inlinings
283 | Opt_D_dump_occur_anal
288 | Opt_D_dump_simpl_iterations
297 | Opt_D_dump_worker_wrapper
299 | Opt_D_dump_rn_trace
300 | Opt_D_dump_rn_stats
302 | Opt_D_dump_simpl_stats
304 | Opt_D_verbose_core2core
305 | Opt_D_verbose_stg2stg
306 | Opt_D_dump_hi_diffs
307 | Opt_D_dump_minimal_imports
313 | Opt_AllowOverlappingInstances
314 | Opt_AllowUndecidableInstances
318 data DynFlags = DynFlags {
319 coreToDo :: CoreToDo,
322 flags :: [(DynFlag, SwitchResult)]
325 boolOpt :: DynFlag -> DynFlags -> Bool
327 = case lookup f (flags dflags) of
332 dopt_D_dump_all = boolOpt Opt_D_dump_all
333 dopt_D_dump_most = boolOpt Opt_D_dump_most
334 dopt_D_dump_absC = boolOpt Opt_D_dump_absC
335 dopt_D_dump_asm = boolOpt Opt_D_dump_asm
336 dopt_D_dump_cpranal = boolOpt Opt_D_dump_cpranal
337 dopt_D_dump_deriv = boolOpt Opt_D_dump_deriv
338 dopt_D_dump_ds = boolOpt Opt_D_dump_ds
339 dopt_D_dump_flatC = boolOpt Opt_D_dump_flatC
340 dopt_D_dump_foreign = boolOpt Opt_D_dump_foreign
341 dopt_D_dump_inlinings = boolOpt Opt_D_dump_inlinings
342 dopt_D_dump_occur_anal = boolOpt Opt_D_dump_occur_anal
343 dopt_D_dump_parsed = boolOpt Opt_D_dump_parsed
344 dopt_D_dump_realC = boolOpt Opt_D_dump_realC
345 dopt_D_dump_rn = boolOpt Opt_D_dump_rn
346 dopt_D_dump_simpl = boolOpt Opt_D_dump_simpl
347 dopt_D_dump_simpl_iterations = boolOpt Opt_D_dump_simpl_iterations
348 dopt_D_dump_spec = boolOpt Opt_D_dump_spec
349 dopt_D_dump_stg = boolOpt Opt_D_dump_stg
350 dopt_D_dump_stranal = boolOpt Opt_D_dump_stranal
351 dopt_D_dump_tc = boolOpt Opt_D_dump_tc
352 dopt_D_dump_types = boolOpt Opt_D_dump_types
353 dopt_D_dump_rules = boolOpt Opt_D_dump_rules
354 dopt_D_dump_usagesp = boolOpt Opt_D_dump_usagesp
355 dopt_D_dump_cse = boolOpt Opt_D_dump_cse
356 dopt_D_dump_worker_wrapper = boolOpt Opt_D_dump_worker_wrapper
357 dopt_D_show_passes = boolOpt Opt_D_show_passes
358 dopt_D_dump_rn_trace = boolOpt Opt_D_dump_rn_trace
359 dopt_D_dump_rn_stats = boolOpt Opt_D_dump_rn_stats
360 dopt_D_dump_stix = boolOpt Opt_D_dump_stix
361 dopt_D_dump_simpl_stats = boolOpt Opt_D_dump_simpl_stats
362 dopt_D_source_stats = boolOpt Opt_D_source_stats
363 dopt_D_verbose_core2core = boolOpt Opt_D_verbose_core2core
364 dopt_D_verbose_stg2stg = boolOpt Opt_D_verbose_stg2stg
365 dopt_D_dump_hi_diffs = boolOpt Opt_D_dump_hi_diffs
366 dopt_D_dump_minimal_imports = boolOpt Opt_D_dump_minimal_imports
367 dopt_DoCoreLinting = boolOpt Opt_DoCoreLinting
368 dopt_DoStgLinting = boolOpt Opt_DoStgLinting
369 dopt_DoUSPLinting = boolOpt Opt_DoUSPLinting
371 dopt_AllowOverlappingInstances = boolOpt Opt_AllowOverlappingInstances
372 dopt_AllowUndecidableInstances = boolOpt Opt_AllowUndecidableInstances
373 dopt_GlasgowExts = boolOpt Opt_GlasgowExts
375 dopt_CoreToDo :: DynFlags -> CoreToDo
376 dopt_CoreToDo = coreToDo
378 dopt_StgToDo :: DynFlags -> StgToDo
379 dopt_StgToDo = stgToDo
387 dopt_HscLang :: DynFlags -> HscLang
388 dopt_HscLang = hscLang
391 %************************************************************************
393 \subsection{Classifying command-line options}
395 %************************************************************************
398 lookUp :: FAST_STRING -> Bool
399 lookup_int :: String -> Maybe Int
400 lookup_def_int :: String -> Int -> Int
401 lookup_def_float :: String -> Float -> Float
402 lookup_str :: String -> Maybe String
404 lookUp sw = sw `elem` argv
406 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
408 lookup_int sw = case (lookup_str sw) of
410 Just xx -> Just (read xx)
412 lookup_def_int sw def = case (lookup_str sw) of
413 Nothing -> def -- Use default
416 lookup_def_char sw def = case (lookup_str sw) of
418 _ -> def -- Use default
420 lookup_def_float sw def = case (lookup_str sw) of
421 Nothing -> def -- Use default
424 unpacked_opts = map _UNPK_ argv
427 Putting the compiler options into temporary at-files
428 may turn out to be necessary later on if we turn hsc into
429 a pure Win32 application where I think there's a command-line
430 length limit of 255. unpacked_opts understands the @ option.
432 unpacked_opts :: [String]
438 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
443 %************************************************************************
445 \subsection{Static options}
447 %************************************************************************
451 opt_PprStyle_NoPrags = lookUp SLIT("-dppr-noprags")
452 opt_PprStyle_Debug = lookUp SLIT("-dppr-debug")
453 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
456 opt_WarnDuplicateExports = lookUp SLIT("-fwarn-duplicate-exports")
457 opt_WarnHiShadows = lookUp SLIT("-fwarn-hi-shadowing")
458 opt_WarnIncompletePatterns = lookUp SLIT("-fwarn-incomplete-patterns")
459 opt_WarnMissingFields = lookUp SLIT("-fwarn-missing-fields")
460 opt_WarnMissingMethods = lookUp SLIT("-fwarn-missing-methods")
461 opt_WarnMissingSigs = lookUp SLIT("-fwarn-missing-signatures")
462 opt_WarnNameShadowing = lookUp SLIT("-fwarn-name-shadowing")
463 opt_WarnOverlappingPatterns = lookUp SLIT("-fwarn-overlapping-patterns")
464 opt_WarnSimplePatterns = lookUp SLIT("-fwarn-simple-patterns")
465 opt_WarnTypeDefaults = lookUp SLIT("-fwarn-type-defaults")
466 opt_WarnUnusedBinds = lookUp SLIT("-fwarn-unused-binds")
467 opt_WarnUnusedImports = lookUp SLIT("-fwarn-unused-imports")
468 opt_WarnUnusedMatches = lookUp SLIT("-fwarn-unused-matches")
469 opt_WarnDeprecations = lookUp SLIT("-fwarn-deprecations")
472 opt_AutoSccsOnAllToplevs = lookUp SLIT("-fauto-sccs-on-all-toplevs")
473 opt_AutoSccsOnExportedToplevs = lookUp SLIT("-fauto-sccs-on-exported-toplevs")
474 opt_AutoSccsOnIndividualCafs = lookUp SLIT("-fauto-sccs-on-individual-cafs")
475 opt_AutoSccsOnDicts = lookUp SLIT("-fauto-sccs-on-dicts")
476 opt_SccProfilingOn = lookUp SLIT("-fscc-profiling")
477 opt_DoTickyProfiling = lookUp SLIT("-fticky-ticky")
480 opt_AllStrict = lookUp SLIT("-fall-strict")
481 opt_DictsStrict = lookUp SLIT("-fdicts-strict")
482 opt_Generics = lookUp SLIT("-fgenerics")
483 opt_IrrefutableTuples = lookUp SLIT("-firrefutable-tuples")
484 opt_MaxContextReductionDepth = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
485 opt_NumbersStrict = lookUp SLIT("-fnumbers-strict")
486 opt_Parallel = lookUp SLIT("-fparallel")
487 opt_SMP = lookUp SLIT("-fsmp")
490 opt_DoSemiTagging = lookUp SLIT("-fsemi-tagging")
491 opt_FoldrBuildOn = lookUp SLIT("-ffoldr-build-on")
492 opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" (10::Int)
493 opt_StgDoLetNoEscapes = lookUp SLIT("-flet-no-escape")
494 opt_UnfoldCasms = lookUp SLIT("-funfold-casms-in-hi-file")
495 opt_UsageSPOn = lookUp SLIT("-fusagesp-on")
496 opt_UnboxStrictFields = lookUp SLIT("-funbox-strict-fields")
499 The optional '-inpackage=P' flag tells what package
500 we are compiling this module for.
501 The Prelude, for example is compiled with '-package prelude'
503 opt_InPackage = case lookup_str "-inpackage=" of
505 Nothing -> SLIT("Main") -- The package name if none is specified
507 opt_EmitCExternDecls = lookUp SLIT("-femit-extern-decls")
508 opt_EnsureSplittableC = lookUp SLIT("-fglobalise-toplev-names")
509 opt_GranMacros = lookUp SLIT("-fgransim")
510 opt_HiVersion = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
511 opt_HistorySize = lookup_def_int "-fhistory-size" 20
512 opt_IgnoreAsserts = lookUp SLIT("-fignore-asserts")
513 opt_IgnoreIfacePragmas = lookUp SLIT("-fignore-interface-pragmas")
514 opt_NoHiCheck = lookUp SLIT("-fno-hi-version-check")
515 opt_NoImplicitPrelude = lookUp SLIT("-fno-implicit-prelude")
516 opt_OmitBlackHoling = lookUp SLIT("-dno-black-holing")
517 opt_OmitInterfacePragmas = lookUp SLIT("-fomit-interface-pragmas")
519 -- Simplifier switches
520 opt_SimplNoPreInlining = lookUp SLIT("-fno-pre-inlining")
521 -- NoPreInlining is there just to see how bad things
522 -- get if you don't do it!
523 opt_SimplDoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
524 opt_SimplDoLambdaEtaExpansion = lookUp SLIT("-fdo-lambda-eta-expansion")
525 opt_SimplCaseOfCase = lookUp SLIT("-fcase-of-case")
526 opt_SimplCaseMerge = lookUp SLIT("-fcase-merge")
527 opt_SimplPedanticBottoms = lookUp SLIT("-fpedantic-bottoms")
528 opt_SimplExcessPrecision = lookUp SLIT("-fexcess-precision")
531 opt_UF_HiFileThreshold = lookup_def_int "-funfolding-interface-threshold" (45::Int)
532 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
533 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (8::Int) -- Discounts can be big
534 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
535 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
536 opt_UF_UpdateInPlace = lookUp SLIT("-funfolding-update-in-place")
538 opt_UF_CheapOp = ( 1 :: Int) -- Only one instruction; and the args are charged for
539 opt_UF_DearOp = ( 4 :: Int)
541 opt_ReportCompile = lookUp SLIT("-freport-compile")
542 opt_NoPruneDecls = lookUp SLIT("-fno-prune-decls")
543 opt_NoPruneTyDecls = lookUp SLIT("-fno-prune-tydecls")
544 opt_Static = lookUp SLIT("-static")
545 opt_Unregisterised = lookUp SLIT("-funregisterised")
546 opt_Verbose = lookUp SLIT("-v")
548 opt_UseVanillaRegs | opt_Unregisterised = 0
549 | otherwise = mAX_Real_Vanilla_REG
550 opt_UseFloatRegs | opt_Unregisterised = 0
551 | otherwise = mAX_Real_Float_REG
552 opt_UseDoubleRegs | opt_Unregisterised = 0
553 | otherwise = mAX_Real_Double_REG
554 opt_UseLongRegs | opt_Unregisterised = 0
555 | otherwise = mAX_Real_Long_REG
559 classifyOpts :: ([CoreToDo], -- Core-to-Core processing spec
560 [StgToDo]) -- STG-to-STG processing spec
562 classifyOpts = sep argv [] [] -- accumulators...
564 sep :: [FAST_STRING] -- cmd-line opts (input)
565 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
566 -> ([CoreToDo], [StgToDo]) -- result
568 sep [] core_td stg_td -- all done!
569 = (reverse core_td, reverse stg_td)
571 # define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
572 # define STG_TD(to_do) sep opts core_td (to_do:stg_td)
574 sep (opt1:opts) core_td stg_td
575 = case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
576 ',' : _ -> sep opts core_td stg_td -- it is for the parser
578 "-fsimplify" -> -- gather up SimplifierSwitches specially...
579 simpl_sep opts defaultSimplSwitches core_td stg_td
581 "-ffloat-inwards" -> CORE_TD(CoreDoFloatInwards)
582 "-ffloat-outwards" -> CORE_TD(CoreDoFloatOutwards False)
583 "-ffloat-outwards-full" -> CORE_TD(CoreDoFloatOutwards True)
584 "-fliberate-case" -> CORE_TD(CoreLiberateCase)
585 "-fcse" -> CORE_TD(CoreCSE)
586 "-fglom-binds" -> CORE_TD(CoreDoGlomBinds)
587 "-fprint-core" -> CORE_TD(CoreDoPrintCore)
588 "-fstatic-args" -> CORE_TD(CoreDoStaticArgs)
589 "-fstrictness" -> CORE_TD(CoreDoStrictness)
590 "-fworker-wrapper" -> CORE_TD(CoreDoWorkerWrapper)
591 "-fspecialise" -> CORE_TD(CoreDoSpecialising)
592 "-fusagesp" -> CORE_TD(CoreDoUSPInf)
593 "-fcpr-analyse" -> CORE_TD(CoreDoCPResult)
595 "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
596 "-dstg-stats" -> STG_TD(D_stg_stats)
597 "-flambda-lift" -> STG_TD(StgDoLambdaLift)
598 "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
600 _ -> -- NB: the driver is really supposed to handle bad options
601 sep opts core_td stg_td
605 simpl_sep :: [FAST_STRING] -- cmd-line opts (input)
606 -> [SimplifierSwitch] -- simplifier-switch accumulator
607 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
608 -> ([CoreToDo], [StgToDo]) -- result
610 -- "simpl_sep" tailcalls "sep" once it's seen one set
611 -- of SimplifierSwitches for a CoreDoSimplify.
614 simpl_sep input@[] simpl_sw core_td stg_td
615 = panic "simpl_sep []"
618 -- The SimplifierSwitches should be delimited by "[" and "]".
620 simpl_sep (opt1:opts) simpl_sw core_td stg_td
621 = case (_UNPK_ opt1) of
622 "[" -> simpl_sep opts simpl_sw core_td stg_td
624 this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
626 sep opts (this_simpl : core_td) stg_td
628 opt -> case matchSimplSw opt of
629 Just sw -> simpl_sep opts (sw:simpl_sw) core_td stg_td
630 Nothing -> simpl_sep opts simpl_sw core_td stg_td
633 = firstJust [ matchSwInt opt "-fmax-simplifier-iterations" MaxSimplifierIterations
634 , matchSwInt opt "-finline-phase" SimplInlinePhase
635 , matchSwBool opt "-fno-rules" DontApplyRules
636 , matchSwBool opt "-fno-case-of-case" NoCaseOfCase
637 , matchSwBool opt "-flet-to-case" SimplLetToCase
640 matchSwBool :: String -> String -> a -> Maybe a
641 matchSwBool opt str sw | opt == str = Just sw
642 | otherwise = Nothing
644 matchSwInt :: String -> String -> (Int -> a) -> Maybe a
645 matchSwInt opt str sw = case startsWith str opt of
646 Just opt_left -> Just (sw (read opt_left))
650 %************************************************************************
652 \subsection{Switch ordering}
654 %************************************************************************
656 In spite of the @Produce*@ constructor, these things behave just like
660 instance Eq SimplifierSwitch where
661 a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
663 instance Ord SimplifierSwitch where
664 a < b = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
665 a <= b = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
668 tagOf_SimplSwitch (SimplInlinePhase _) = ILIT(1)
669 tagOf_SimplSwitch (MaxSimplifierIterations _) = ILIT(2)
670 tagOf_SimplSwitch DontApplyRules = ILIT(3)
671 tagOf_SimplSwitch SimplLetToCase = ILIT(4)
672 tagOf_SimplSwitch NoCaseOfCase = ILIT(5)
674 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
676 lAST_SIMPL_SWITCH_TAG = 5
679 %************************************************************************
681 \subsection{Switch lookup}
683 %************************************************************************
686 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
688 isAmongSimpl on_switches -- Switches mentioned later occur *earlier*
689 -- in the list; defaults right at the end.
691 tidied_on_switches = foldl rm_dups [] on_switches
692 -- The fold*l* ensures that we keep the latest switches;
693 -- ie the ones that occur earliest in the list.
695 sw_tbl :: Array Int SwitchResult
696 sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
700 all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
702 defined_elems = map mk_assoc_elem tidied_on_switches
704 -- (avoid some unboxing, bounds checking, and other horrible things:)
705 #if __GLASGOW_HASKELL__ < 405
706 case sw_tbl of { Array bounds_who_needs_'em stuff ->
708 case sw_tbl of { Array _ _ stuff ->
711 case (indexArray# stuff (tagOf_SimplSwitch switch)) of
712 #if __GLASGOW_HASKELL__ < 400
714 #elif __GLASGOW_HASKELL__ < 403
721 mk_assoc_elem k@(MaxSimplifierIterations lvl) = (IBOX(tagOf_SimplSwitch k), SwInt lvl)
722 mk_assoc_elem k@(SimplInlinePhase n) = (IBOX(tagOf_SimplSwitch k), SwInt n)
723 mk_assoc_elem k = (IBOX(tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
725 -- cannot have duplicates if we are going to use the array thing
726 rm_dups switches_so_far switch
727 = if switch `is_elem` switches_so_far
729 else switch : switches_so_far
731 sw `is_elem` [] = False
732 sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
736 Default settings for simplifier switches
739 defaultSimplSwitches = [MaxSimplifierIterations 1]
742 %************************************************************************
744 \subsection{Misc functions for command-line options}
746 %************************************************************************
750 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
752 switchIsOn lookup_fn switch
753 = case (lookup_fn switch) of
754 SwBool False -> False
757 intSwitchSet :: (switch -> SwitchResult)
761 intSwitchSet lookup_fn switch
762 = case (lookup_fn (switch (panic "intSwitchSet"))) of
763 SwInt int -> Just int
768 startsWith :: String -> String -> Maybe String
769 -- startsWith pfx (pfx++rest) = Just rest
771 startsWith [] str = Just str
772 startsWith (c:cs) (s:ss)
773 = if c /= s then Nothing else startsWith cs ss
774 startsWith _ [] = Nothing
776 endsWith :: String -> String -> Maybe String
778 = case (startsWith (reverse cs) (reverse ss)) of
780 Just rs -> Just (reverse rs)