|
5 | 5 | module Main (main) where
|
6 | 6 |
|
7 | 7 | import Control.Concurrent.MVar
|
| 8 | +import Control.Monad.Catch |
| 9 | + ( SomeException |
| 10 | + , fromException |
| 11 | + , handle |
| 12 | + , throwM |
| 13 | + ) |
8 | 14 | import Data.Reflection
|
9 | 15 | import GlobalMain
|
10 | 16 | import Kore.BugReport
|
11 |
| -import Kore.Exec ( |
12 |
| - proveWithRepl, |
13 |
| - ) |
14 |
| -import qualified Kore.IndexedModule.MetadataToolsBuilder as MetadataTools ( |
15 |
| - build, |
16 |
| - ) |
17 |
| -import Kore.Log ( |
18 |
| - KoreLogOptions (..), |
19 |
| - runLoggerT, |
20 |
| - swappableLogger, |
21 |
| - withLogger, |
22 |
| - ) |
23 |
| -import Kore.Log.KoreLogOptions ( |
24 |
| - parseKoreLogOptions, |
25 |
| - ) |
26 |
| -import Kore.Log.WarnIfLowProductivity ( |
27 |
| - warnIfLowProductivity, |
28 |
| - ) |
| 17 | +import Kore.Exec |
| 18 | + ( proveWithRepl |
| 19 | + ) |
| 20 | +import qualified Kore.IndexedModule.MetadataToolsBuilder as MetadataTools |
| 21 | + ( build |
| 22 | + ) |
| 23 | +import Kore.Log |
| 24 | + ( KoreLogOptions (..) |
| 25 | + , SomeEntry (..) |
| 26 | + , logEntry |
| 27 | + , runLoggerT |
| 28 | + , swappableLogger |
| 29 | + , withLogger |
| 30 | + ) |
| 31 | +import Kore.Log.ErrorException |
| 32 | + ( errorException |
| 33 | + ) |
| 34 | +import Kore.Log.KoreLogOptions |
| 35 | + ( parseKoreLogOptions |
| 36 | + ) |
| 37 | +import Kore.Log.WarnIfLowProductivity |
| 38 | + ( warnIfLowProductivity |
| 39 | + ) |
| 40 | +import qualified Kore.Reachability.Claim as Claim |
29 | 41 | import Kore.Repl.Data
|
30 | 42 | import Kore.Step.SMT.Lemma
|
31 |
| -import Kore.Syntax.Module ( |
32 |
| - ModuleName (..), |
33 |
| - ) |
34 |
| -import Options.Applicative ( |
35 |
| - InfoMod, |
36 |
| - Parser, |
37 |
| - argument, |
38 |
| - flag, |
39 |
| - fullDesc, |
40 |
| - header, |
41 |
| - help, |
42 |
| - long, |
43 |
| - metavar, |
44 |
| - progDesc, |
45 |
| - short, |
46 |
| - str, |
47 |
| - strOption, |
48 |
| - ) |
49 |
| -import Options.SMT ( |
50 |
| - KoreSolverOptions (..), |
51 |
| - parseKoreSolverOptions, |
52 |
| - ) |
| 43 | +import Kore.Syntax.Module |
| 44 | + ( ModuleName (..) |
| 45 | + ) |
| 46 | +import Kore.Unparser |
| 47 | + ( unparseToString |
| 48 | + ) |
| 49 | +import Options.Applicative |
| 50 | + ( InfoMod |
| 51 | + , Parser |
| 52 | + , argument |
| 53 | + , flag |
| 54 | + , fullDesc |
| 55 | + , header |
| 56 | + , help |
| 57 | + , long |
| 58 | + , metavar |
| 59 | + , progDesc |
| 60 | + , short |
| 61 | + , str |
| 62 | + , strOption |
| 63 | + ) |
| 64 | +import Options.SMT |
| 65 | + ( KoreSolverOptions (..) |
| 66 | + , parseKoreSolverOptions |
| 67 | + ) |
53 | 68 | import Prelude.Kore
|
54 | 69 | import qualified SMT
|
55 |
| -import System.Clock ( |
56 |
| - Clock (Monotonic), |
57 |
| - TimeSpec, |
58 |
| - getTime, |
59 |
| - ) |
60 |
| -import System.Exit ( |
61 |
| - exitFailure, |
62 |
| - exitWith, |
63 |
| - ) |
64 |
| -import System.IO ( |
65 |
| - hPutStrLn, |
66 |
| - stderr, |
67 |
| - ) |
| 70 | +import System.Clock |
| 71 | + ( Clock (Monotonic) |
| 72 | + , TimeSpec |
| 73 | + , getTime |
| 74 | + ) |
| 75 | +import System.Exit |
| 76 | + ( exitFailure |
| 77 | + , exitWith |
| 78 | + ) |
| 79 | +import System.IO |
| 80 | + ( hPutStrLn |
| 81 | + , stderr |
| 82 | + ) |
68 | 83 |
|
69 | 84 | -- | Represents a file name along with its module name passed.
|
70 | 85 | data KoreModule = KoreModule
|
@@ -198,7 +213,7 @@ mainWithOptions
|
198 | 213 | withLogger tempDirectory koreLogOptions $ \actualLogAction -> do
|
199 | 214 | mvarLogAction <- newMVar actualLogAction
|
200 | 215 | let swapLogAction = swappableLogger mvarLogAction
|
201 |
| - flip runLoggerT swapLogAction $ do |
| 216 | + flip runLoggerT swapLogAction $ runExceptionHandlers $ do |
202 | 217 | definition <- loadDefinitions [definitionFileName, specFile]
|
203 | 218 | indexedModule <- loadModule mainModuleName definition
|
204 | 219 | specDefIndexedModule <- loadModule specModule definition
|
@@ -254,6 +269,32 @@ mainWithOptions
|
254 | 269 | pure ExitSuccess
|
255 | 270 | exitWith exitCode
|
256 | 271 | where
|
| 272 | + runExceptionHandlers action = |
| 273 | + action |
| 274 | + & handle exitReplHandler |
| 275 | + & handle withConfigurationHandler |
| 276 | + & handle someExceptionHandler |
| 277 | + |
| 278 | + exitReplHandler :: ExitCode -> Main ExitCode |
| 279 | + exitReplHandler = pure |
| 280 | + |
| 281 | + someExceptionHandler :: SomeException -> Main ExitCode |
| 282 | + someExceptionHandler someException = do |
| 283 | + case fromException someException of |
| 284 | + Just (SomeEntry entry) -> logEntry entry |
| 285 | + Nothing -> errorException someException |
| 286 | + throwM someException |
| 287 | + |
| 288 | + withConfigurationHandler :: Claim.WithConfiguration -> Main ExitCode |
| 289 | + withConfigurationHandler |
| 290 | + (Claim.WithConfiguration lastConfiguration someException) = |
| 291 | + do |
| 292 | + liftIO $ |
| 293 | + hPutStrLn |
| 294 | + stderr |
| 295 | + ("// Last configuration:\n" <> unparseToString lastConfiguration) |
| 296 | + throwM someException |
| 297 | + |
257 | 298 | mainModuleName :: ModuleName
|
258 | 299 | mainModuleName = moduleName definitionModule
|
259 | 300 |
|
|
0 commit comments