@@ -41,6 +41,7 @@ import Control.Monad.Catch (MonadThrow)
41
41
42
42
import qualified Data.BitVector.Sized as BV
43
43
import Data.Foldable (foldlM )
44
+ import Data.IORef
44
45
import qualified Data.List.NonEmpty as NE
45
46
import qualified Data.Vector as Vector
46
47
import qualified Data.Text as Text
@@ -79,6 +80,7 @@ import SAWScript.Options
79
80
import SAWScript.X86 hiding (Options )
80
81
import SAWScript.X86Spec
81
82
import SAWScript.Crucible.Common
83
+ import SAWScript.Crucible.Common.Override (MetadataMap )
82
84
83
85
import qualified SAWScript.Crucible.Common as Common
84
86
import qualified SAWScript.Crucible.Common.MethodSpec as MS
@@ -350,6 +352,7 @@ llvm_verify_x86_common (Some (llvmModule :: LLVMModule x)) path nm globsyms chec
350
352
basic_ss <- getBasicSS
351
353
rw <- getTopLevelRW
352
354
sym <- liftIO $ newSAWCoreExprBuilder sc
355
+ mdMap <- liftIO $ newIORef mempty
353
356
SomeOnlineBackend bak <- liftIO $
354
357
newSAWCoreBackendWithTimeout pathSatSolver sym $ rwCrucibleTimeout rw
355
358
cacheTermsSetting <- liftIO $ W4. getOptionSetting W4.B. cacheTerms $ W4. getConfiguration sym
@@ -487,7 +490,8 @@ llvm_verify_x86_common (Some (llvmModule :: LLVMModule x)) path nm globsyms chec
487
490
}
488
491
liftIO $ printOutLn opts Info
489
492
" Examining specification to determine postconditions"
490
- liftIO . void . runX86Sim finalState $ assertPost globals' env (preState ^. x86Mem) (preState ^. x86Regs)
493
+ liftIO . void . runX86Sim finalState $
494
+ assertPost globals' env (preState ^. x86Mem) (preState ^. x86Regs) mdMap
491
495
pure $ C. regValue r
492
496
493
497
liftIO $ printOutLn opts Info " Simulating function"
@@ -521,7 +525,7 @@ llvm_verify_x86_common (Some (llvmModule :: LLVMModule x)) path nm globsyms chec
521
525
ar
522
526
C. TimeoutResult {} -> fail " Execution timed out"
523
527
524
- (stats,thms) <- checkGoals bak opts nm sc tactic
528
+ (stats,thms) <- checkGoals bak opts nm sc tactic mdMap
525
529
526
530
end <- io getCurrentTime
527
531
let diff = diffUTCTime end start
@@ -1020,8 +1024,9 @@ assertPost ::
1020
1024
Map MS. AllocIndex Ptr ->
1021
1025
Mem {- ^ The state of memory before simulation -} ->
1022
1026
Regs {- ^ The state of the registers before simulation -} ->
1027
+ IORef MetadataMap {- ^ metadata map -} ->
1023
1028
X86Sim ()
1024
- assertPost globals env premem preregs = do
1029
+ assertPost globals env premem preregs mdMap = do
1025
1030
SomeOnlineBackend bak <- use x86Backend
1026
1031
sym <- use x86Sym
1027
1032
opts <- use x86Options
@@ -1109,9 +1114,10 @@ assertPost globals env premem preregs = do
1109
1114
Right (_, st) -> pure st
1110
1115
liftIO . forM_ (view O. osAssumes st) $ \ (_md, asum) ->
1111
1116
C. addAssumption bak $ C. GenericAssumption (st ^. O. osLocation) " precondition" asum
1112
- liftIO . forM_ (view LO. osAsserts st) $ \ (_md, W4. LabeledPred p r) ->
1113
- -- TODO, use assertion metadata
1114
- C. addAssertion bak $ C. LabeledPred p r
1117
+ liftIO . forM_ (view LO. osAsserts st) $ \ (md, W4. LabeledPred p r) ->
1118
+ do (ann,p') <- W4. annotateTerm sym p
1119
+ modifyIORef mdMap (Map. insert ann md)
1120
+ C. addAssertion bak (W4. LabeledPred p' r)
1115
1121
1116
1122
-- | Assert that a points-to postcondition holds.
1117
1123
assertPointsTo ::
@@ -1160,9 +1166,10 @@ checkGoals ::
1160
1166
String ->
1161
1167
SharedContext ->
1162
1168
ProofScript () ->
1169
+ IORef MetadataMap {- ^ metadata map -} ->
1163
1170
TopLevel (SolverStats , Set TheoremNonce )
1164
- checkGoals bak opts nm sc tactic = do
1165
- gs <- liftIO $ getGoals (SomeBackend bak)
1171
+ checkGoals bak opts nm sc tactic mdMap = do
1172
+ gs <- liftIO $ getGoals (SomeBackend bak) mdMap
1166
1173
liftIO . printOutLn opts Info $ mconcat
1167
1174
[ " Simulation finished, running solver on "
1168
1175
, show $ length gs
@@ -1172,12 +1179,12 @@ checkGoals bak opts nm sc tactic = do
1172
1179
term <- liftIO $ gGoal sc g
1173
1180
let proofgoal = ProofGoal
1174
1181
{ goalNum = n
1175
- , goalType = " vc "
1182
+ , goalType = MS. conditionType (gMd g)
1176
1183
, goalName = nm
1177
- , goalLoc = show $ gLoc g
1184
+ , goalLoc = show $ MS. conditionLoc (gMd g)
1178
1185
, goalDesc = show $ gMessage g
1179
1186
, goalProp = term
1180
- , goalTags = mempty -- TODO! propagate tags
1187
+ , goalTags = MS. conditionTags (gMd g)
1181
1188
}
1182
1189
res <- runProofScript tactic proofgoal (Just (gLoc g)) $ Text. unwords
1183
1190
[" X86 verification condition" , Text. pack (show n), Text. pack (show (gMessage g))]
0 commit comments