@@ -7,6 +7,8 @@ module Booster.CLOptions (
7
7
CLOptions (.. ),
8
8
EquationOptions (.. ),
9
9
LogFormat (.. ),
10
+ LogOptions (.. ),
11
+ RewriteOptions (.. ),
10
12
TimestampFormat (.. ),
11
13
clOptionsParser ,
12
14
adjustLogLevels ,
@@ -25,6 +27,7 @@ import Data.Maybe (fromMaybe)
25
27
import Data.Text (Text , pack )
26
28
import Data.Text.Encoding (decodeASCII )
27
29
import Data.Version (Version (.. ), showVersion )
30
+ import Numeric.Natural (Natural )
28
31
import Options.Applicative
29
32
30
33
import Booster.GlobalState (EquationOptions (.. ))
@@ -41,18 +44,23 @@ data CLOptions = CLOptions
41
44
, mainModuleName :: Text
42
45
, llvmLibraryFile :: Maybe FilePath
43
46
, port :: Int
44
- , logLevels :: [LogLevel ]
47
+ , logOptions :: LogOptions
48
+ , smtOptions :: Maybe SMTOptions
49
+ , equationOptions :: EquationOptions
50
+ , rewriteOptions :: RewriteOptions
51
+ }
52
+ deriving stock (Show )
53
+
54
+ data LogOptions = LogOptions
55
+ { logLevels :: [LogLevel ]
45
56
, logTimeStamps :: Bool
46
57
, timeStampsFormat :: TimestampFormat
47
58
, logFormat :: LogFormat
48
59
, logContexts :: [ContextFilter ]
49
60
, logFile :: Maybe FilePath
50
- , smtOptions :: Maybe SMTOptions
51
- , equationOptions :: EquationOptions
52
- , indexCells :: [Text ]
53
61
, prettyPrintOptions :: [ModifierT ]
54
62
}
55
- deriving (Show )
63
+ deriving stock (Show )
56
64
57
65
data LogFormat
58
66
= Standard
@@ -76,6 +84,12 @@ instance Show TimestampFormat where
76
84
Pretty -> " pretty"
77
85
Nanoseconds -> " nanoseconds"
78
86
87
+ data RewriteOptions = RewriteOptions
88
+ { indexCells :: [Text ]
89
+ , interimSimplification :: Maybe Natural
90
+ }
91
+ deriving stock (Show , Eq )
92
+
79
93
clOptionsParser :: Parser CLOptions
80
94
clOptionsParser =
81
95
CLOptions
@@ -103,7 +117,15 @@ clOptionsParser =
103
117
<> help " Port for the RPC server to bind to"
104
118
<> showDefault
105
119
)
106
- <*> many
120
+ <*> parseLogOptions
121
+ <*> parseSMTOptions
122
+ <*> parseEquationOptions
123
+ <*> parseRewriteOptions
124
+
125
+ parseLogOptions :: Parser LogOptions
126
+ parseLogOptions =
127
+ LogOptions
128
+ <$> many
107
129
( option
108
130
(eitherReader readLogLevel)
109
131
( metavar " LEVEL"
@@ -154,15 +176,6 @@ clOptionsParser =
154
176
" Log file to output the logs into"
155
177
)
156
178
)
157
- <*> parseSMTOptions
158
- <*> parseEquationOptions
159
- <*> option
160
- (eitherReader $ mapM (readCellName . trim) . splitOn " ," )
161
- ( metavar " CELL-NAME[,CELL-NAME]"
162
- <> long " index-cells"
163
- <> help " Names of configuration cells to index rewrite rules with (default: 'k')"
164
- <> value []
165
- )
166
179
<*> option
167
180
(eitherReader $ mapM (readModifierT . trim) . splitOn " ," )
168
181
( metavar " PRETTY_PRINT"
@@ -202,18 +215,6 @@ clOptionsParser =
202
215
" nanoseconds" -> Right Nanoseconds
203
216
other -> Left $ other <> " : Unsupported timestamp format"
204
217
205
- readCellName :: String -> Either String Text
206
- readCellName input
207
- | null input =
208
- Left " Empty cell name"
209
- | all isAscii input
210
- , all isPrint input =
211
- Right $ " Lbl'-LT-'" <> enquote input <> " '-GT-'"
212
- | otherwise =
213
- Left $ " Illegal non-ascii characters in `" <> input <> " '"
214
-
215
- enquote = decodeASCII . encodeLabel . BS. pack
216
-
217
218
-- custom log levels that can be selected
218
219
allowedLogLevels :: [(String , String )]
219
220
allowedLogLevels =
@@ -364,13 +365,6 @@ parseSMTOptions =
364
365
where
365
366
smtDefaults = defaultSMTOptions
366
367
367
- nonnegativeInt :: ReadM Int
368
- nonnegativeInt =
369
- auto >>= \ case
370
- i
371
- | i < 0 -> readerError " must be a non-negative integer."
372
- | otherwise -> pure i
373
-
374
368
readTactic =
375
369
either (readerError . (" Invalid s-expression. " <> )) pure . SMT. parseSExpr . BS. pack =<< str
376
370
@@ -397,12 +391,46 @@ parseEquationOptions =
397
391
defaultMaxIterations = 100
398
392
defaultMaxRecursion = 5
399
393
400
- nonnegativeInt :: ReadM Int
401
- nonnegativeInt =
402
- auto >>= \ case
403
- i
404
- | i < 0 -> readerError " must be a non-negative integer."
405
- | otherwise -> pure i
394
+ parseRewriteOptions :: Parser RewriteOptions
395
+ parseRewriteOptions =
396
+ RewriteOptions
397
+ <$> option
398
+ (eitherReader $ mapM (readCellName . trim) . splitOn " ," )
399
+ ( metavar " CELL-NAME[,CELL-NAME]"
400
+ <> long " index-cells"
401
+ <> help " Names of configuration cells to index rewrite rules with (default: 'k')"
402
+ <> value []
403
+ )
404
+ <*> optional
405
+ ( option
406
+ (intWith (> 0 ))
407
+ ( metavar " DEPTH"
408
+ <> long " simplify-each"
409
+ <> help " If given: Simplify the term each time the given rewrite depth is reached"
410
+ )
411
+ )
412
+ where
413
+ readCellName :: String -> Either String Text
414
+ readCellName input
415
+ | null input =
416
+ Left " Empty cell name"
417
+ | all isAscii input
418
+ , all isPrint input =
419
+ Right $ " Lbl'-LT-'" <> enquote input <> " '-GT-'"
420
+ | otherwise =
421
+ Left $ " Illegal non-ascii characters in `" <> input <> " '"
422
+
423
+ enquote = decodeASCII . encodeLabel . BS. pack
424
+
425
+ intWith :: Integral i => (Integer -> Bool ) -> ReadM i
426
+ intWith p =
427
+ auto >>= \ case
428
+ i
429
+ | not (p i) -> readerError $ show i <> " : Invalid integer value."
430
+ | otherwise -> pure (fromIntegral i)
431
+
432
+ nonnegativeInt :: Integral i => ReadM i
433
+ nonnegativeInt = intWith (>= 0 )
406
434
407
435
versionInfoParser :: Parser (a -> a )
408
436
versionInfoParser =
0 commit comments