@@ -2,6 +2,7 @@ module Main (main) where
22
33import Prelude.Kore
44
5+ import qualified Control.Lens as Lens
56import Control.Monad.Catch
67 ( MonadMask
78 , SomeException
@@ -10,11 +11,13 @@ import Control.Monad.Catch
1011 , throwM
1112 )
1213import Control.Monad.Extra as Monad
13- import qualified Data.Char as Char
1414import Data.Default
1515 ( def
1616 )
1717import qualified Data.Foldable as Foldable
18+ import Data.Generics.Product
19+ ( field
20+ )
1821import Data.Limit
1922 ( Limit (.. )
2023 , maybeLimit
@@ -35,6 +38,7 @@ import qualified Data.Text.IO as Text
3538 ( putStrLn
3639 , readFile
3740 )
41+ import qualified GHC.Generics as GHC
3842import Options.Applicative
3943 ( InfoMod
4044 , Parser
@@ -160,6 +164,14 @@ import qualified Kore.Syntax.Definition as Definition.DoNotUse
160164import Kore.Unparser
161165 ( unparse
162166 )
167+ import Options.SMT
168+ ( KoreSolverOptions (.. )
169+ , Solver (.. )
170+ , ensureSmtPreludeExists
171+ , parseKoreSolverOptions
172+ , unparseKoreSolverOptions
173+ , writeKoreSolverFiles
174+ )
163175import Pretty
164176 ( Doc
165177 , Pretty (.. )
@@ -172,7 +184,6 @@ import Prof
172184 )
173185import SMT
174186 ( MonadSMT
175- , TimeOut (.. )
176187 )
177188import qualified SMT
178189import Stats
@@ -192,7 +203,7 @@ data KoreSearchOptions =
192203 -- ^ The maximum bound on the number of search matches
193204 , searchType :: ! SearchType
194205 -- ^ The type of search to perform
195- }
206+ } deriving ( GHC.Generic )
196207
197208parseKoreSearchOptions :: Parser KoreSearchOptions
198209parseKoreSearchOptions =
@@ -262,23 +273,6 @@ applyKoreSearchOptions koreSearchOptions@(Just koreSearchOpts) koreExecOpts =
262273 ONE -> Limit 1
263274 _ -> Unlimited
264275
265- -- | Available SMT solvers
266- data Solver = Z3 | None
267- deriving (Eq , Ord , Show )
268- deriving (Enum , Bounded )
269-
270- parseSolver :: Parser Solver
271- parseSolver =
272- option (snd <$> readSum longName options)
273- $ metavar " SOLVER"
274- <> long longName
275- <> help (" SMT solver for checking constraints: " <> knownOptions)
276- <> value Z3
277- where
278- longName = " smt"
279- knownOptions = intercalate " , " (map fst options)
280- options = [ (map Char. toLower $ show s, s) | s <- [minBound .. maxBound ] ]
281-
282276-- | Main options record
283277data KoreExecOptions = KoreExecOptions
284278 { definitionFileName :: ! FilePath
@@ -289,19 +283,17 @@ data KoreExecOptions = KoreExecOptions
289283 -- ^ Name for file to contain the output pattern
290284 , mainModuleName :: ! ModuleName
291285 -- ^ The name of the main module in the definition
292- , smtTimeOut :: ! SMT. TimeOut
293- , smtPrelude :: ! (Maybe FilePath )
294- , smtSolver :: ! Solver
295286 , breadthLimit :: ! (Limit Natural )
296287 , depthLimit :: ! (Limit Natural )
297288 , strategy :: ! (String , [RewriteRule RewritingVariableName ] -> Strategy (Prim (RewriteRule RewritingVariableName )))
289+ , koreSolverOptions :: ! KoreSolverOptions
298290 , koreLogOptions :: ! KoreLogOptions
299291 , koreSearchOptions :: ! (Maybe KoreSearchOptions )
300292 , koreProveOptions :: ! (Maybe KoreProveOptions )
301293 , koreMergeOptions :: ! (Maybe KoreMergeOptions )
302294 , rtsStatistics :: ! (Maybe FilePath )
303295 , bugReport :: ! BugReport
304- }
296+ } deriving ( GHC.Generic )
305297
306298-- | Command Line Argument Parser
307299parseKoreExecOptions :: TimeSpec -> Parser KoreExecOptions
@@ -332,35 +324,17 @@ parseKoreExecOptions startTime =
332324 )
333325 )
334326 <*> parseMainModuleName
335- <*> option readSMTTimeOut
336- ( metavar " SMT_TIMEOUT"
337- <> long " smt-timeout"
338- <> help " Timeout for calls to the SMT solver, in milliseconds"
339- <> value defaultTimeOut
340- )
341- <*> optional
342- ( strOption
343- ( metavar " SMT_PRELUDE"
344- <> long " smt-prelude"
345- <> help " Path to the SMT prelude file"
346- )
347- )
348- <*> parseSolver
349327 <*> parseBreadthLimit
350328 <*> parseDepthLimit
351329 <*> parseStrategy
330+ <*> parseKoreSolverOptions
352331 <*> parseKoreLogOptions (ExeName " kore-exec" ) startTime
353332 <*> pure Nothing
354333 <*> optional parseKoreProveOptions
355334 <*> optional parseKoreMergeOptions
356335 <*> optional parseRtsStatistics
357336 <*> parseBugReport
358- SMT. Config { timeOut = defaultTimeOut } = SMT. defaultConfig
359- readSMTTimeOut = do
360- i <- auto
361- if i <= 0
362- then readerError " smt-timeout must be a positive integer."
363- else return $ SMT. TimeOut $ Limit i
337+
364338 parseBreadthLimit = Limit <$> breadth <|> pure Unlimited
365339 parseDepthLimit = Limit <$> depth <|> pure Unlimited
366340 parseStrategy =
@@ -375,6 +349,7 @@ parseKoreExecOptions startTime =
375349 [ (" any" , priorityAnyStrategy)
376350 , (" all" , priorityAllStrategy)
377351 ]
352+
378353 breadth =
379354 option auto
380355 ( metavar " BREADTH"
@@ -387,6 +362,7 @@ parseKoreExecOptions startTime =
387362 <> long " depth"
388363 <> help " Execute up to DEPTH steps."
389364 )
365+
390366 parseMainModuleName =
391367 GlobalMain. parseModuleName
392368 " MODULE"
@@ -446,12 +422,10 @@ koreExecSh
446422 patternFileName
447423 outputFileName
448424 mainModuleName
449- (TimeOut timeout)
450- smtPrelude
451- smtSolver
452425 breadthLimit
453426 depthLimit
454427 strategy
428+ koreSolverOptions
455429 koreLogOptions
456430 koreSearchOptions
457431 koreProveOptions
@@ -474,10 +448,6 @@ koreExecSh
474448 , patternFileName $> " --pattern pgm.kore"
475449 , outputFileName $> " --output result.kore"
476450 , pure $ " --module " <> unpack (getModuleName mainModuleName)
477- , (\ limit -> unwords [" --smt-timeout" , show limit])
478- <$> maybeLimit Nothing Just timeout
479- , smtPrelude $> unwords [" --smt-prelude" , defaultSmtPreludeFilePath]
480- , pure $ " --smt " <> fmap Char. toLower (show smtSolver)
481451 , (\ limit -> unwords [" --breadth" , show limit])
482452 <$> maybeLimit Nothing Just breadthLimit
483453 , (\ limit -> unwords [" --depth" , show limit])
@@ -486,6 +456,7 @@ koreExecSh
486456 , rtsStatistics $>
487457 unwords [" --rts-statistics" , defaultRtsStatisticsFilePath]
488458 ]
459+ , unparseKoreSolverOptions koreSolverOptions
489460 , unparseKoreLogOptions koreLogOptions
490461 , maybe mempty unparseKoreSearchOptions koreSearchOptions
491462 , maybe mempty unparseKoreProveOptions koreProveOptions
@@ -497,9 +468,6 @@ defaultDefinitionFilePath KoreExecOptions { koreProveOptions }
497468 | isJust koreProveOptions = " vdefinition.kore"
498469 | otherwise = " definition.kore"
499470
500- defaultSmtPreludeFilePath :: FilePath
501- defaultSmtPreludeFilePath = " prelude.smt2"
502-
503471defaultRtsStatisticsFilePath :: FilePath
504472defaultRtsStatisticsFilePath = " rts-statistics.json"
505473
@@ -527,7 +495,7 @@ writeOptionsAndKoreFiles
527495 opts@ KoreExecOptions
528496 { definitionFileName
529497 , patternFileName
530- , smtPrelude
498+ , koreSolverOptions
531499 , koreSearchOptions
532500 , koreProveOptions
533501 , koreMergeOptions
@@ -545,8 +513,7 @@ writeOptionsAndKoreFiles
545513 (reportDirectory </> defaultDefinitionFilePath opts)
546514 Foldable. for_ patternFileName
547515 $ flip copyFile (reportDirectory </> " pgm.kore" )
548- Foldable. for_ smtPrelude
549- $ flip copyFile (reportDirectory </> defaultSmtPreludeFilePath)
516+ writeKoreSolverFiles koreSolverOptions reportDirectory
550517 Foldable. for_ koreSearchOptions
551518 (writeKoreSearchFiles reportDirectory)
552519 Foldable. for_ koreMergeOptions
@@ -569,18 +536,10 @@ main = do
569536 parserInfoModifiers
570537 Foldable. for_ (localOptions options) mainWithOptions
571538
572- -- | Ensure that the SMT prelude file exists, if specified.
573- ensureSmtPreludeExists :: Maybe FilePath -> IO ()
574- ensureSmtPreludeExists =
575- Foldable. traverse_ $ \ filePath ->
576- Monad. whenM
577- (not <$> doesFileExist filePath)
578- (error $ " SMT prelude file does not exist: " <> filePath)
579-
580539mainWithOptions :: KoreExecOptions -> IO ()
581540mainWithOptions execOptions = do
582- let KoreExecOptions { koreLogOptions, bugReport, smtPrelude } = execOptions
583- ensureSmtPreludeExists smtPrelude
541+ let KoreExecOptions { koreLogOptions, koreSolverOptions, bugReport } = execOptions
542+ ensureSmtPreludeExists koreSolverOptions
584543 exitCode <-
585544 withBugReport Main. exeName bugReport $ \ tmpDir -> do
586545 writeOptionsAndKoreFiles tmpDir execOptions
@@ -841,7 +800,7 @@ execute
841800 -> Main r
842801execute options mainModule worker =
843802 clockSomethingIO " Executing"
844- $ case smtSolver of
803+ $ case solver of
845804 Z3 -> withZ3
846805 None -> withoutSMT
847806 where
@@ -854,11 +813,13 @@ execute options mainModule worker =
854813 )
855814 worker
856815 withoutSMT = SMT. runNoSMT worker
857- KoreExecOptions { smtTimeOut, smtPrelude, smtSolver } = options
816+ KoreSolverOptions { timeOut, resetInterval, prelude, solver } =
817+ Lens. view (field @ " koreSolverOptions" ) options
858818 config =
859819 SMT. defaultConfig
860- { SMT. timeOut = smtTimeOut
861- , SMT. preludeFile = smtPrelude
820+ { SMT. timeOut = timeOut
821+ , SMT. resetInterval = resetInterval
822+ , SMT. prelude = prelude
862823 }
863824
864825loadPattern :: LoadedModule -> Maybe FilePath -> Main (TermLike VariableName )
0 commit comments