-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathCommon.hs
101 lines (84 loc) · 3.54 KB
/
Common.hs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{- |
Module : SAWScript.Crucible.Common
Description : Crucible-related material that is not specific to a given language
License : BSD3
Maintainer : langston
Stability : provisional
-}
{-# LANGUAGE RankNTypes #-}
module SAWScript.Crucible.Common
( ppAbortedResult
, Sym
, setupProfiling
, SAWCruciblePersonality(..)
, newSAWCoreBackend
, sawCoreState
) where
import Lang.Crucible.Simulator (GenericExecutionFeature)
import Lang.Crucible.Simulator.ExecutionTree (AbortedResult(..), GlobalPair)
import Lang.Crucible.Simulator.CallFrame (SimFrame)
import Lang.Crucible.Simulator.Profiling
import Lang.Crucible.Backend (AbortExecReason(..), ppAbortExecReason, IsSymInterface)
import Lang.Crucible.Backend.Online
import qualified Data.Parameterized.Nonce as Nonce
import qualified What4.Solver.Yices as Yices
import qualified What4.Config as W4
import qualified What4.Expr as W4
import qualified What4.Interface as W4
import qualified What4.Expr.Builder as W4
import qualified What4.ProgramLoc as W4 (plSourceLoc)
import System.Directory (createDirectoryIfMissing)
import System.FilePath ((</>))
import qualified Prettyprinter as PP
import Verifier.SAW.SharedTerm as SC
import Verifier.SAW.Simulator.What4.ReturnTrip (SAWCoreState, newSAWCoreState)
-- | The symbolic backend we use for SAW verification
type Sym = OnlineBackendUserSt Nonce.GlobalNonceGenerator Yices.Connection SAWCoreState (W4.Flags W4.FloatReal)
data SAWCruciblePersonality sym = SAWCruciblePersonality
newSAWCoreBackend :: SC.SharedContext -> IO Sym
newSAWCoreBackend sc =
do st <- newSAWCoreState sc
sym <- newOnlineBackend W4.FloatRealRepr Nonce.globalNonceGenerator Yices.yicesDefaultFeatures st
W4.extendConfig Yices.yicesOptions (W4.getConfiguration sym)
return sym
sawCoreState :: Sym -> IO (SAWCoreState Nonce.GlobalNonceGenerator)
sawCoreState sym = pure (onlineUserState (W4.sbUserState sym))
ppAbortedResult :: (forall l args. GlobalPair Sym (SimFrame Sym ext l args) -> PP.Doc ann)
-> AbortedResult Sym ext
-> PP.Doc ann
ppAbortedResult _ (AbortedExec InfeasibleBranch{} _) =
PP.pretty "Infeasible branch"
ppAbortedResult ppGP (AbortedExec abt gp) = do
PP.vcat
[ ppAbortExecReason abt
, ppGP gp
]
ppAbortedResult ppGP (AbortedBranch loc _predicate trueBranch falseBranch) =
PP.vcat
[ PP.pretty "Both branches aborted after a symbolic branch."
, PP.pretty "Location of control-flow branching:"
, PP.indent 2 (PP.pretty (W4.plSourceLoc loc))
, PP.pretty "Message from the true branch:"
, PP.indent 2 (ppAbortedResult ppGP trueBranch)
, PP.pretty "Message from the false branch:"
, PP.indent 2 (ppAbortedResult ppGP falseBranch)
]
ppAbortedResult _ (AbortedExit ec) =
PP.pretty "Branch exited:" PP.<+> PP.viaShow ec
setupProfiling ::
IsSymInterface sym =>
sym -> String -> Maybe FilePath ->
IO (IO (), [GenericExecutionFeature sym])
setupProfiling _ _ Nothing = return (return (), [])
setupProfiling sym profSource (Just dir) =
do tbl <- newProfilingTable
createDirectoryIfMissing True dir
startRecordingSolverEvents sym tbl
let profOutFile = dir </> "report_data.js"
saveProf = writeProfileReport profOutFile "Crucible profile" profSource
profOpts = ProfilingOptions
{ periodicProfileInterval = 5
, periodicProfileAction = saveProf
}
pfs <- profilingFeature tbl profilingEventFilter (Just profOpts)
return (saveProf tbl, [pfs])