-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.hs
More file actions
63 lines (54 loc) · 2.35 KB
/
Copy pathIO.hs
File metadata and controls
63 lines (54 loc) · 2.35 KB
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
module IO where
import Data.Set (Set(..))
import qualified Data.Set as Set
import Data.ByteString.Lazy (ByteString(..))
import qualified Data.ByteString.Lazy as BS
import Control.Monad
import System.Directory
import System.FilePath
import Transform.Pexpr
import Transform.Normalize
import SMV.Syntax
import SMV.Typing
import SMV.Pretty hiding (SmvMode(..))
import qualified SMV.Pretty as SMV
import SMV.Packed
import SMV.Parser
import SMV.Trace as SMV
import Utils.Error
import Utils.Misc
import Utils.Pretty
import qualified Utils.Location as L
writeSMV :: Bool -> FilePath -> PackedPmodule -> IO ()
writeSMV isDebug f smv = do
writeFile f $ prettyprint smv
when isDebug $ putStrLn $ "Wrote SMV file " ++ f
withTempSMV :: Bool -> Bool -> PackedPmodule -> (FilePath -> IO a) -> IO a
withTempSMV doRemoveTemps isDebug smv go = withSystemTempUnlessError doRemoveTemps isDebug "out.smv" $ \f -> do
writeSMV isDebug f smv
go f
withTempSMVs :: Bool -> Bool -> [PackedPmodule] -> ([FilePath] -> IO a) -> IO a
withTempSMVs doRemoveTemps isDebug [] go = go []
withTempSMVs doRemoveTemps isDebug (smv:smvs) go = withSystemTempUnlessError doRemoveTemps isDebug "out.smv" $ \f -> do
writeSMV isDebug f smv
withTempSMVs doRemoveTemps isDebug smvs (go . (f:))
writeFormula :: Bool -> FilePath -> Pformula -> IO ()
writeFormula isDebug fn formula = do
writeFile fn $ prettyprint $ normalizeFormula formula
when isDebug $ putStrLn $ "Wrote formula file " ++ fn
withTempFormula :: Bool -> Bool -> Pformula -> (FilePath -> IO a) -> IO a
withTempFormula doRemoveTemps isDebug formula go = withSystemTempUnlessError doRemoveTemps isDebug "formula" $ \f -> do
writeFormula isDebug f formula
go f
readFormula :: Bool -> FilePath -> [PackedPtypes] -> IO Pformula
readFormula isDebug fn tys = do
txt <- BS.readFile fn
f <- ioErrorM $ runFormulaParser fn txt >>= return . L.unloc
let qs = quantsPformula f
when (length qs /= length tys) $ exitWithErrorMessage "Please provide same number of models and formula quantifiers"
return $ addFormulaTypes tys f
writeTraces :: Bool -> [(String,Quant)] -> [Maybe SMV.Trace] -> IO ()
writeTraces isDebug qs traces = forM_ (zip qs traces) $ \((dim,_),mbtrace) -> forM_ mbtrace $ \trace -> do
let f = addExtension dim "witness"
writeFile f $ prettyprint trace
when isDebug $ putStrLn $ "Wrote witness file " ++ f