add Outputable instance for OccIfaceEq
[ghc-hetmet.git] / utils / nofib-analyse / CmdLine.hs
1 -----------------------------------------------------------------------------
2 -- CmdLine.hs
3
4 -- (c) Simon Marlow 2005
5 -----------------------------------------------------------------------------
6
7 module CmdLine
8     (
9     flags, other_args, cmdline_errors,
10     devs, nodevs, tooquick_threshold, reportTitle,
11     CLIFlags(..), usage,
12     )
13     where
14
15 import System.Console.GetOpt
16 import System.Environment       ( getArgs )
17 import System.IO.Unsafe         ( unsafePerformIO )
18
19 -----------------------------------------------------------------------------
20 -- Command line arguments
21
22 args :: [String]
23 args = unsafePerformIO getArgs
24
25 flags :: [CLIFlags]
26 other_args :: [String]
27 cmdline_errors :: [String]
28 (flags, other_args, cmdline_errors) = getOpt Permute argInfo args 
29
30 default_tooquick_threshold, tooquick_threshold :: Float
31 default_tooquick_threshold = 0.2 {- secs -}
32 tooquick_threshold
33  = case [ i | OptIgnoreSmallTimes i <- flags ] of
34         [] -> default_tooquick_threshold
35         (i:_) -> i
36
37 devs, nodevs :: Bool
38 devs   = OptDeviations   `elem` flags
39 nodevs = OptNoDeviations `elem` flags
40
41 default_title, reportTitle :: String
42 default_title = "NoFib Results"
43 reportTitle = case [ t | OptTitle t <- flags ] of
44         []    -> default_title
45         (t:_) -> t
46
47 data CLIFlags
48   = OptASCIIOutput
49   | OptLaTeXOutput
50   | OptHTMLOutput
51   | OptIgnoreSmallTimes Float
52   | OptDeviations
53   | OptNoDeviations
54   | OptTitle String
55   | OptColumns String
56   | OptRows String
57   | OptHelp
58   deriving Eq
59
60 usageHeader :: String
61 usageHeader = "usage: nofib-analyse [OPTION...] <logfile1> <logfile2> ..."
62
63 usage :: String
64 usage = usageInfo usageHeader argInfo
65
66 argInfo :: [ OptDescr CLIFlags ]
67 argInfo = 
68   [ Option ['?'] ["help"]    (NoArg OptHelp)        
69         "Display this message"
70   , Option ['a'] ["ascii"]   (NoArg OptASCIIOutput) 
71         "Produce ASCII output (default)"
72   , Option ['h'] ["html"]    (NoArg OptHTMLOutput)  
73         "Produce HTML output"
74   , Option ['i'] ["ignore"]  (ReqArg (OptIgnoreSmallTimes . read) "secs")
75         "Ignore runtimes smaller than <secs>"
76   , Option ['d'] ["deviations"] (NoArg OptDeviations)
77         "Display deviations (default)"
78   , Option ['l'] ["latex"]    (NoArg OptLaTeXOutput)  
79         "Produce LaTeX output"
80   , Option [] ["columns"] (ReqArg OptColumns "COLUMNS")
81         "Specify columns for summary table (comma separates)"
82   , Option [] ["rows"] (ReqArg OptRows "ROWS")
83         "Specify rows for summary table (comma separates)"
84   , Option ['n'] ["nodeviations"] (NoArg OptNoDeviations)
85         "Hide deviations"
86   , Option ['t'] ["title"] (ReqArg OptTitle "title")
87         "Specify report title"
88   ]
89