1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
module ToolOptions
( Options(..), defaultOptions, processOptions
, printWhenStatus, printWhenIntermediate, printWhenAll
)
where
import Control.Monad ( when, unless )
import Data.Char ( toUpper )
import System.Console.GetOpt
import Numeric ( readNat )
import System.Process ( exitWith )
import System.CurryPath ( stripCurrySuffix )
data Options = Options
{ optVerb :: Int
, optHelp :: Bool
, optName :: String
, optVerify :: Bool
, optFCY :: Bool
, optTAFCY :: Bool
, optStrict :: Bool
, optNoProof :: Bool
, optTimeout :: Int
}
defaultOptions :: Options
defaultOptions = Options 1 False "" True True False False False 4
processOptions :: String -> [String] -> IO (Options,[String])
processOptions banner argv = do
let (funopts, args, opterrors) = getOpt Permute options argv
opts = foldl (flip id) defaultOptions funopts
unless (null opterrors)
(putStr (unlines opterrors) >> printUsage >> exitWith 1)
when (optHelp opts) (printUsage >> exitWith 0)
return (opts, map stripCurrySuffix args)
where
printUsage = putStrLn (banner ++ "\n" ++ usageText)
usageText :: String
usageText = usageInfo ("Usage: curry-contracts [options] <module names>\n") options
options :: [OptDescr (Options -> Options)]
options =
[ Option "h?" ["help"] (NoArg (\opts -> opts { optHelp = True }))
"print help and exit"
, Option "q" ["quiet"] (NoArg (\opts -> opts { optVerb = 0 }))
"run quietly (no output, only exit code)"
, Option "v" ["verbosity"]
(OptArg (maybe (checkVerb 2) (safeReadNat checkVerb)) "<n>")
"verbosity level:\n0: quiet (same as `-q')\n1: show status messages (default)\n2: show intermediate results (same as `-v')\n3: show all intermediate results and more details"
, Option "a" ["add"] (NoArg (\opts -> opts { optVerify = False }))
"do not verify contracts, just add contract checks"
, Option "s" ["strict"] (NoArg (\opts -> opts { optStrict = True }))
"check contracts w.r.t. strict evaluation strategy"
, Option "t" ["target"]
(ReqArg checkTarget "<T>")
("target of the transformed program:\n" ++
"NONE : do not store transformed FlatCurry program\n" ++
"FCY : write FlatCurry program (default)\n" ++
"TAFCY: write type-annotated FlatCurry program")
, Option "" ["timeout"]
(ReqArg (safeReadNat (\n opts -> opts { optTimeout = n })) "<n>")
("timeout for SMT prover (default: " ++
show (optTimeout defaultOptions) ++ "s)")
, Option "" ["noproof"] (NoArg (\opts -> opts { optNoProof = True }))
"do not write scripts of successful proofs"
, Option "" ["name"]
(ReqArg (\s opts -> opts { optName = s }) "<f>")
"only show the names of pre- and postconditions\nfor function <f>"
]
where
safeReadNat opttrans s opts = case readNat s of
[(n,"")] -> opttrans n opts
_ -> error "Illegal number argument (try `-h' for help)"
checkVerb n opts = if n>=0 && n<4
then opts { optVerb = n }
else error "Illegal verbosity level (try `-h' for help)"
checkTarget t opts = case map toUpper t of
"NONE" -> opts { optFCY = False, optTAFCY = False }
"FCY" -> opts { optFCY = True, optTAFCY = False }
"TAFCY" -> opts { optFCY = False, optTAFCY = True }
_ -> error $ "Illegal target `" ++ t ++ "' (try `-h' for help)"
printWhenStatus :: Options -> String -> IO ()
printWhenStatus opts s =
when (optVerb opts > 0) (printCP s)
printWhenIntermediate :: Options -> String -> IO ()
printWhenIntermediate opts s =
when (optVerb opts > 1) (printCP s)
printWhenAll :: Options -> String -> IO ()
printWhenAll opts s =
when (optVerb opts > 2) (printCP s)
printCP :: String -> IO ()
printCP s = putStrLn $ "INFO: " ++ s
|