@@ -29,7 +29,7 @@ module SAWScript.Crucible.LLVM.X86
29
29
import Control.Lens.TH (makeLenses )
30
30
31
31
import System.IO (stdout )
32
- import Control.Exception (catch , throw )
32
+ import Control.Exception (throw )
33
33
import Control.Lens (view , use , (&) , (^.) , (.~) , (.=) )
34
34
import Control.Monad.ST (stToIO )
35
35
import Control.Monad.State
@@ -54,11 +54,12 @@ import Data.Parameterized.NatRepr
54
54
import Data.Parameterized.Context hiding (view )
55
55
import Data.Parameterized.Nonce
56
56
57
+ import Verifier.SAW.FiniteValue
57
58
import Verifier.SAW.Recognizer
58
59
import Verifier.SAW.Term.Functor
59
60
import Verifier.SAW.TypedTerm
60
61
61
- import SAWScript.Prover.SBV
62
+ import SAWScript.Proof
62
63
import SAWScript.Prover.SolverStats
63
64
import SAWScript.TopLevel
64
65
import SAWScript.Value
@@ -187,8 +188,9 @@ crucible_llvm_verify_x86 ::
187
188
[(String , Integer )] {- ^ Global variable symbol names and sizes (in bytes) -} ->
188
189
Bool {-^ Whether to enable path satisfiability checking (currently ignored) -} ->
189
190
LLVMCrucibleSetupM () {- ^ Specification to verify against -} ->
191
+ ProofScript SatResult {- ^ Tactic used to use when discharging goals -} ->
190
192
TopLevel (SomeLLVM MS. CrucibleMethodSpecIR )
191
- crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x )) path nm globsyms _checkSat setup
193
+ crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x )) path nm globsyms _checkSat setup tactic
192
194
| Just Refl <- testEquality (C.LLVM. X86Repr $ knownNat @ 64 ) . C.LLVM. llvmArch
193
195
$ modTrans llvmModule ^. C.LLVM. transContext = do
194
196
let ? ptrWidth = knownNat @ 64
@@ -278,7 +280,7 @@ crucible_llvm_verify_x86 bic opts (Some (llvmModule :: LLVMModule x)) path nm gl
278
280
C. AbortedResult {} -> printOutLn opts Warn " Warning: function never returns"
279
281
C. TimeoutResult {} -> fail " Execution timed out"
280
282
281
- liftIO . void $ runX86Sim preState checkGoals
283
+ checkGoals sym opts sc tactic
282
284
283
285
pure $ SomeLLVM methodSpec
284
286
| otherwise = fail " LLVM module must be 64-bit"
@@ -700,29 +702,35 @@ assertPointsTo env tyenv nameEnv (LLVMPointsTo _ cond tptr texpected) = do
700
702
701
703
-- | Gather and run the solver on goals from the simulator.
702
704
checkGoals ::
703
- X86Sim ()
704
- checkGoals = do
705
- sym <- use x86Sym
706
- opts <- use x86Options
707
- sc <- use x86SharedContext
705
+ Sym ->
706
+ Options ->
707
+ SharedContext ->
708
+ ProofScript SatResult ->
709
+ TopLevel ()
710
+ checkGoals sym opts sc tactic = do
708
711
gs <- liftIO $ getGoals sym
709
712
liftIO . printOutLn opts Info $ mconcat
710
713
[ " Simulation finished, running solver on "
711
714
, show $ length gs
712
715
, " goals"
713
716
]
714
- liftIO . forM_ gs $ \ g ->
715
- do
716
- term <- gGoal sc g
717
- (mb, stats) <- proveUnintSBV z3 [] Nothing sc term
718
- printOutLn opts Info $ ppStats stats
719
- case mb of
720
- Nothing -> printOutLn opts Info " Goal succeeded"
721
- Just ex -> do
722
- fail $ mconcat
723
- [" Failure (" , show $ gLoc g
724
- , " ): " , show $ gMessage g
725
- , " \n Counterexample: " <> show ex
726
- ]
727
- `catch` \ (X86Error e) -> fail $ " Failure, error: " <> e
717
+ forM_ (zip [0 .. ] gs) $ \ (n, g) -> do
718
+ term <- liftIO $ gGoal sc g
719
+ let proofgoal = ProofGoal n " vc" (show $ gMessage g) term
720
+ r <- evalStateT tactic $ startProof proofgoal
721
+ case r of
722
+ Unsat stats -> do
723
+ liftIO . printOutLn opts Info $ ppStats stats
724
+ SatMulti stats vals -> do
725
+ printOutLnTop Info $ unwords [" Subgoal failed:" , show $ gMessage g]
726
+ printOutLnTop Info (show stats)
727
+ printOutLnTop OnlyCounterExamples " ----------Counterexample----------"
728
+ ppOpts <- sawPPOpts . rwPPOpts <$> getTopLevelRW
729
+ case vals of
730
+ [] -> printOutLnTop OnlyCounterExamples " <<All settings of the symbolic variables constitute a counterexample>>"
731
+ _ -> let showAssignment (name, val) =
732
+ mconcat [ " " , name, " : " , show $ ppFirstOrderValue ppOpts val ]
733
+ in mapM_ (printOutLnTop OnlyCounterExamples . showAssignment) vals
734
+ printOutLnTop OnlyCounterExamples " ----------------------------------"
735
+ throwTopLevel " Proof failed."
728
736
liftIO $ printOutLn opts Info " All goals succeeded"
0 commit comments