Options.hs 11.5 KB
Newer Older
Philipp Meyer's avatar
Philipp Meyer committed
1
2
3
{-# LANGUAGE TupleSections #-}

module Options
4
    (InputFormat(..),OutputFormat(..),NetTransformation(..),RefinementType(..),
Philipp Meyer's avatar
Philipp Meyer committed
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
     ImplicitProperty(..),Options(..),startOptions,options,parseArgs,
     usageInformation)
where

import Control.Applicative ((<$>))
import System.Console.GetOpt
import System.Environment (getArgs)

data InputFormat = PNET | LOLA | TPN | MIST deriving (Show,Read)
data OutputFormat = OutLOLA | OutSARA | OutSPEC | OutDOT deriving (Read)

instance Show OutputFormat where
        show OutLOLA = "LOLA"
        show OutSARA = "SARA"
        show OutSPEC = "SPEC"
        show OutDOT = "DOT"

data NetTransformation = TerminationByReachability
                       | ValidateIdentifiers

data ImplicitProperty = Termination
                      | DeadlockFree | DeadlockFreeUnlessFinal
                      | FinalStateUnreachable
                      | ProperTermination
                      | Safe | Bounded Integer
                      | StructFreeChoice
                      | StructParallel
                      | StructFinalPlace
                      | StructCommunicationFree
34
                      | TerminalMarkingsUniqueConsensus
35
                      | NonConsensusState
36
                      | TerminalMarkingReachable
Philipp Meyer's avatar
Philipp Meyer committed
37
38
                      deriving (Show,Read)

39
data RefinementType = TrapRefinement | SComponentRefinement | SComponentWithCutRefinement
40
41
                    deriving (Show,Read)

Philipp Meyer's avatar
Philipp Meyer committed
42
43
44
45
46
47
data Options = Options { inputFormat :: InputFormat
                       , optVerbosity :: Int
                       , optShowHelp :: Bool
                       , optShowVersion :: Bool
                       , optProperties :: [ImplicitProperty]
                       , optTransformations :: [NetTransformation]
48
                       , optSimpMethod :: Int
49
                       , optRefinementType :: Maybe RefinementType
50
                       , optMinimizeRefinement :: Int
51
                       , optAuto :: Bool
Philipp Meyer's avatar
Philipp Meyer committed
52
                       , optInvariant :: Bool
53
                       , optBoolConst :: Bool
Philipp Meyer's avatar
Philipp Meyer committed
54
55
56
57
58
59
60
61
62
63
64
65
66
                       , optOutput :: Maybe String
                       , outputFormat :: OutputFormat
                       , optUseProperties :: Bool
                       , optPrintStructure :: Bool
                       }

startOptions :: Options
startOptions = Options { inputFormat = PNET
                       , optVerbosity = 1
                       , optShowHelp = False
                       , optShowVersion = False
                       , optProperties = []
                       , optTransformations = []
67
                       , optSimpMethod = 1
68
                       , optRefinementType = Just SComponentWithCutRefinement
69
                       , optMinimizeRefinement = 0
70
                       , optAuto = False
Philipp Meyer's avatar
Philipp Meyer committed
71
                       , optInvariant = False
72
                       , optBoolConst = False
Philipp Meyer's avatar
Philipp Meyer committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
                       , optOutput = Nothing
                       , outputFormat = OutLOLA
                       , optUseProperties = True
                       , optPrintStructure = False
                       }

options :: [ OptDescr (Options -> Either String Options) ]
options =
        [ Option "" ["pnet"]
        (NoArg (\opt -> Right opt { inputFormat = PNET }))
        "Use the pnet input format"

        , Option "" ["lola"]
        (NoArg (\opt -> Right opt { inputFormat = LOLA }))
        "Use the lola input format"

        , Option "" ["tpn"]
        (NoArg (\opt -> Right opt { inputFormat = TPN }))
        "Use the tpn input format"

        , Option "" ["spec"]
        (NoArg (\opt -> Right opt { inputFormat = MIST }))
        "Use the mist input format"

97
        , Option "" ["structure"]
Philipp Meyer's avatar
Philipp Meyer committed
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
123
124
125
126
127
128
129
130
131
132
133
134
135
        (NoArg (\opt -> Right opt { optPrintStructure = True }))
        "Print structural information"

        , Option "" ["validate-identifiers"]
        (NoArg (\opt -> Right opt {
            optTransformations = ValidateIdentifiers : optTransformations opt
          }))
        "Make identifiers valid for lola"

        , Option "" ["termination-by-reachability"]
        (NoArg (\opt -> Right opt {
            optTransformations = TerminationByReachability : optTransformations opt
          }))
        "Prove termination by reducing it to reachability"

        , Option "" ["termination"]
        (NoArg (\opt -> Right opt {
                   optProperties = Termination : optProperties opt
               }))
        "Prove that the net is terminating"

        , Option "" ["proper-termination"]
        (NoArg (\opt -> Right opt {
                   optProperties = ProperTermination : optProperties opt
               }))
        "Prove termination in the final marking"

        , Option "" ["deadlock-free"]
        (NoArg (\opt -> Right opt {
                   optProperties = DeadlockFree : optProperties opt
               }))
        "Prove that the net is deadlock-free"

        , Option "" ["deadlock-free-unless-final"]
        (NoArg (\opt -> Right opt {
                   optProperties = DeadlockFreeUnlessFinal : optProperties opt
               }))
        ("Prove that the net is deadlock-free\n" ++
136
         "  unless it is in the final marking")
Philipp Meyer's avatar
Philipp Meyer committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

        , Option "" ["final-state-unreachable"]
        (NoArg (\opt -> Right opt {
                   optProperties = FinalStateUnreachable : optProperties opt
               }))
        "Prove that the final state is unreachable"

        , Option "" ["safe"]
        (NoArg (\opt -> Right opt {
                   optProperties = Safe : optProperties opt
               }))
        "Prove that the net is safe, i.e. 1-bounded"

        , Option "" ["bounded"]
        (ReqArg (\arg opt -> case reads arg of
                    [(k, "")] -> Right opt {
                           optProperties = Bounded k : optProperties opt }
                    _ -> Left ("invalid argument for k-bounded option: " ++ arg)
                )
                "K")
        "Prove that the net is K-bounded"

        , Option "" ["free-choice"]
        (NoArg (\opt -> Right opt {
                   optProperties = StructFreeChoice : optProperties opt
               }))
        "Prove that the net is free-choice"

        , Option "" ["parallel"]
        (NoArg (\opt -> Right opt {
                   optProperties = StructParallel : optProperties opt
               }))
        "Prove that the net has non-trivial parallellism"

        , Option "" ["final-place"]
        (NoArg (\opt -> Right opt {
                   optProperties = StructFinalPlace : optProperties opt
               }))
        "Prove that there is only one needed final place"

        , Option "" ["communication-free"]
        (NoArg (\opt -> Right opt {
                   optProperties = StructCommunicationFree : optProperties opt
               }))
        "Prove that the net is communication-free"

183
        , Option "" ["terminal-markings-unique-consensus"]
184
        (NoArg (\opt -> Right opt {
185
                   optProperties = TerminalMarkingsUniqueConsensus : optProperties opt
186
               }))
187
        "Prove that terminal markings have a unique consensus"
188

189
190
191
192
193
194
        , Option "" ["non-consensus-state"]
        (NoArg (\opt -> Right opt {
                   optProperties = NonConsensusState : optProperties opt
               }))
        "Prove that no non-consensus terminal state is reachable from an initial marking"

195
196
197
198
199
200
        , Option "" ["terminal-marking-reachable"]
        (NoArg (\opt -> Right opt {
                   optProperties = TerminalMarkingReachable : optProperties opt
               }))
        "Prove that a terminal marking is reachable"

201
202
203
204
        , Option "i" ["invariant"]
        (NoArg (\opt -> Right opt { optInvariant = True }))
        "Generate an invariant"

205
206
207
208
209
        , Option "" ["bool-const"]
        (NoArg (\opt -> Right opt { optBoolConst = True }))
        ("Use boolean constraints instead of integer ones\n" ++
         "  for transition invariant")

210
211
212
213
214
215
216
217
218
219
220
        , Option "r" ["refinement"]
        (ReqArg (\arg opt -> case reads arg :: [(Int, String)] of
                    [(0, "")] -> Right opt { optRefinementType = Nothing }
                    [(1, "")] -> Right opt { optRefinementType = Just SComponentWithCutRefinement }
                    [(2, "")] -> Right opt { optRefinementType = Just SComponentRefinement }
                    [(3, "")] -> Right opt { optRefinementType = Just TrapRefinement }
                    _ -> Left ("invalid argument for refinement method: " ++ arg)
                )
                "METHOD")
        ("Refine with METHOD (0=none, 1=SCompCut+Traps,\n" ++
         "  2=SComp+Traps, 3=Traps)")
Philipp Meyer's avatar
Philipp Meyer committed
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

        , Option "o" ["output"]
        (ReqArg (\arg opt -> Right opt {
                        optOutput = Just arg
                })
                "FILE")
        "Write net and properties to FILE"

        , Option "" ["out-lola"]
        (NoArg (\opt -> Right opt { outputFormat = OutLOLA }))
        "Use the lola output format"

        , Option "" ["out-sara"]
        (NoArg (\opt -> Right opt { outputFormat = OutSARA }))
        "Use the sara output format"

        , Option "" ["out-spec"]
        (NoArg (\opt -> Right opt { outputFormat = OutSPEC }))
        "Use the spec output format"

        , Option "" ["out-dot"]
        (NoArg (\opt -> Right opt { outputFormat = OutDOT }))
        "Use the dot output format"

        , Option "" ["no-given-properties"]
        (NoArg (\opt -> Right opt {
                   optUseProperties = False
               }))
        "Do not use the properties given in the input file"

251
        , Option "s" ["simp"]
252
253
254
        (ReqArg (\arg opt -> case reads arg of
                    [(i, "")] -> Right opt { optSimpMethod = i }
                    _ -> Left ("invalid argument for simplification method: " ++ arg)
255
                )
256
                "METHOD")
257
        "Simply formula with method METHOD (0-2)"
258

259
260
        , Option "" ["simp-1"]
        (NoArg (\opt -> Right opt {
261
                   optSimpMethod = 1
262
263
264
265
266
               }))
        "Use simplification level 1 for invariant generation"

        , Option "" ["simp-2"]
        (NoArg (\opt -> Right opt {
267
                   optSimpMethod = 2
268
269
270
               }))
        "Use simplification level 2 for invariant generation"

271
        , Option "m" ["minimize"]
272
273
274
        (ReqArg (\arg opt -> case reads arg of
                        [(i, "")] -> Right opt { optMinimizeRefinement = i }
                        _ -> Left ("invalid argument for minimization method: " ++ arg)
275
276
                )
                "METHOD")
277
278
279
280
281
        "Minimize size of refinement structure by method METHOD (1-4)"

        , Option "" ["auto"]
        (NoArg (\opt -> Right opt { optAuto = True }))
        "Automatically find best refinement, minimization and simplification method"
282

Philipp Meyer's avatar
Philipp Meyer committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
        , Option "v" ["verbose"]
        (NoArg (\opt -> Right opt { optVerbosity = optVerbosity opt + 1 }))
        "Increase verbosity (may be specified more than once)"

        , Option "q" ["quiet"]
        (NoArg (\opt -> Right opt { optVerbosity = optVerbosity opt - 1 }))
        "Decrease verbosity (may be specified more than once)"

        , Option "V" ["version"]
        (NoArg (\opt -> Right opt { optShowVersion = True }))
        "Show version"

        , Option "h" ["help"]
        (NoArg (\opt -> Right opt { optShowHelp = True }))
        "Show help"
        ]

parseArgs :: IO (Either String (Options, [String]))
parseArgs = do
        args <- getArgs
        case getOpt Permute options args of
            (actions, files, []) ->
                return $ (,files) <$> foldl (>>=) (return startOptions) actions
            (_, _, errs) -> return $ Left $ concat errs

usageInformation :: String
usageInformation = usageInfo "SLAPnet" options