@@ -63,7 +63,6 @@ import Control.Lens.Fold
63
63
import Control.Lens.Getter
64
64
import Control.Lens.Lens
65
65
import Control.Lens.Setter
66
- import Control.Lens.TH
67
66
import Control.Exception as X
68
67
import Control.Monad (filterM , foldM , forM , forM_ , when , zipWithM )
69
68
import Control.Monad.Except (runExcept )
@@ -76,13 +75,11 @@ import Data.IORef (IORef, modifyIORef)
76
75
import Data.Map (Map )
77
76
import qualified Data.Map as Map
78
77
import Data.Maybe
79
- import Data.Proxy
80
78
import Data.Set (Set )
81
79
import qualified Data.Set as Set
82
80
import Data.Text (Text , pack )
83
81
import qualified Data.Vector as V
84
82
import Data.Void (absurd )
85
- import GHC.Generics (Generic )
86
83
import Numeric.Natural
87
84
import qualified Prettyprinter as PP
88
85
@@ -93,7 +90,6 @@ import qualified Cryptol.Eval.Type as Cryptol (TValue(..), evalType)
93
90
import qualified Cryptol.Utils.PP as Cryptol (pp )
94
91
95
92
import qualified Lang.Crucible.Backend as Crucible
96
- import qualified Lang.Crucible.Backend.Online as Crucible
97
93
import qualified Lang.Crucible.CFG.Core as Crucible (TypeRepr (UnitRepr ))
98
94
import qualified Lang.Crucible.FunctionHandle as Crucible
99
95
import qualified Lang.Crucible.LLVM.Bytes as Crucible
@@ -141,20 +137,7 @@ import SAWScript.Options
141
137
import SAWScript.Panic
142
138
import SAWScript.Utils (bullets , handleException )
143
139
144
- type LabeledPred sym = W4. LabeledPred (W4. Pred sym ) Crucible. SimError
145
-
146
- -- | An override packaged together with its preconditions, labeled with some
147
- -- human-readable info about each condition.
148
- data OverrideWithPreconditions arch =
149
- OverrideWithPreconditions
150
- { _owpPreconditions :: [(MS. ConditionMetadata , LabeledPred Sym )]
151
- -- ^ c.f. '_osAsserts'
152
- , _owpMethodSpec :: MS. CrucibleMethodSpecIR (LLVM arch )
153
- , owpState :: OverrideState (LLVM arch )
154
- }
155
- deriving (Generic )
156
-
157
- makeLenses ''OverrideWithPreconditions
140
+ type instance Pointer' (LLVM arch ) Sym = LLVMPtr (Crucible. ArchWidth arch )
158
141
159
142
------------------------------------------------------------------------
160
143
-- Translating SAW values to Crucible values for good error messages
@@ -260,89 +243,12 @@ notEqual cond opts loc cc sc spec expected actual = do
260
243
261
244
------------------------------------------------------------------------
262
245
263
- -- | Partition into three groups:
264
- -- * Preconditions concretely succeed
265
- -- * Preconditions concretely fail
266
- -- * Preconditions are symbolic
267
- partitionOWPsConcrete :: forall arch .
268
- Sym ->
269
- [OverrideWithPreconditions arch ] ->
270
- IO ([OverrideWithPreconditions arch ], [OverrideWithPreconditions arch ], [OverrideWithPreconditions arch ])
271
- partitionOWPsConcrete sym =
272
- let traversal = owpPreconditions . each . _2 . W4. labeledPred
273
- in W4. partitionByPredsM (Just sym) $
274
- foldlMOf traversal (W4. andPred sym) (W4. truePred sym)
275
-
276
- -- | Like 'W4.partitionByPreds', but partitions on solver responses, not just
277
- -- concretized values.
278
- partitionBySymbolicPreds ::
279
- (OnlineSolver solver , Foldable t ) =>
280
- Backend solver {- ^ solver connection -} ->
281
- (a -> W4. Pred Sym ) {- ^ how to extract predicates -} ->
282
- t a ->
283
- IO (Map Crucible. BranchResult [a ])
284
- partitionBySymbolicPreds sym getPred =
285
- let step mp a =
286
- Crucible. considerSatisfiability sym Nothing (getPred a) <&> \ k ->
287
- Map. insertWith (++) k [a] mp
288
- in foldM step Map. empty
289
-
290
- -- | Find individual preconditions that are symbolically false
291
- --
292
- -- We should probably be using unsat cores for this.
293
- findFalsePreconditions ::
294
- OnlineSolver solver =>
295
- Backend solver ->
296
- OverrideWithPreconditions arch ->
297
- IO [(MS. ConditionMetadata , LabeledPred Sym )]
298
- findFalsePreconditions bak owp =
299
- fromMaybe [] . Map. lookup (Crucible. NoBranch False ) <$>
300
- partitionBySymbolicPreds bak (view (_2 . W4. labeledPred)) (owp ^. owpPreconditions)
301
-
302
- -- | Is this group of predicates collectively unsatisfiable?
303
- unsatPreconditions ::
304
- OnlineSolver solver =>
305
- Backend solver {- ^ solver connection -} ->
306
- Fold s (W4. Pred Sym ) {- ^ how to extract predicates -} ->
307
- s {- ^ a container full of predicates -} ->
308
- IO Bool
309
- unsatPreconditions bak container getPreds = do
310
- let sym = backendGetSym bak
311
- conj <- W4. andAllOf sym container getPreds
312
- Crucible. considerSatisfiability bak Nothing conj >>=
313
- \ case
314
- Crucible. NoBranch False -> pure True
315
- _ -> pure False
316
-
317
- -- | Print a message about failure of an override's preconditions
318
- ppFailure ::
319
- OverrideWithPreconditions arch ->
320
- [LabeledPred Sym ] ->
321
- PP. Doc ann
322
- ppFailure owp false =
323
- PP. vcat
324
- [ MS. ppMethodSpec (owp ^. owpMethodSpec)
325
- -- TODO: remove viaShow when crucible switches to prettyprinter
326
- , bullets ' *' (map (PP. viaShow . Crucible. ppSimError)
327
- (false ^.. traverse . W4. labeledPredMsg))
328
- ]
329
-
330
- -- | Print a message about concrete failure of an override's preconditions
331
- --
332
- -- Assumes that the override it's being passed does have concretely failing
333
- -- preconditions. Otherwise, the error won't make much sense.
334
- ppConcreteFailure :: OverrideWithPreconditions arch -> PP. Doc ann
335
- ppConcreteFailure owp =
336
- let (_, false, _) =
337
- W4. partitionLabeledPreds (Proxy :: Proxy Sym ) (map snd (owp ^. owpPreconditions))
338
- in ppFailure owp false
339
-
340
246
-- | Print a message about symbolic failure of an override's preconditions
341
247
--
342
248
-- TODO: Needs additional testing. Are these messages useful?
343
249
{-
344
250
ppSymbolicFailure ::
345
- (OverrideWithPreconditions arch, [LabeledPred Sym]) ->
251
+ (OverrideWithPreconditions (LLVM arch) , [LabeledPred Sym]) ->
346
252
PP.Doc
347
253
ppSymbolicFailure = uncurry ppFailure
348
254
-}
@@ -489,7 +395,7 @@ handleSingleOverrideBranch :: forall arch rtp args ret.
489
395
W4. ProgramLoc {- ^ Location of the call site for error reporting-} ->
490
396
IORef MetadataMap ->
491
397
Crucible. FnHandle args ret {- ^ the handle for this function -} ->
492
- OverrideWithPreconditions arch ->
398
+ OverrideWithPreconditions ( LLVM arch ) ->
493
399
Crucible. OverrideSim (SAWCruciblePersonality Sym ) Sym Crucible. LLVM rtp args ret
494
400
(Crucible. RegValue Sym ret )
495
401
handleSingleOverrideBranch opts sc cc call_loc mdMap h (OverrideWithPreconditions preconds cs st) =
@@ -548,8 +454,8 @@ handleOverrideBranches :: forall arch rtp args ret.
548
454
NE. NonEmpty (MS. CrucibleMethodSpecIR (LLVM arch ))
549
455
{- ^ specification for current function override -} ->
550
456
Crucible. FnHandle args ret {- ^ the handle for this function -} ->
551
- [OverrideWithPreconditions arch ] ->
552
- ([OverrideWithPreconditions arch ],[OverrideWithPreconditions arch ],[OverrideWithPreconditions arch ]) ->
457
+ [OverrideWithPreconditions ( LLVM arch ) ] ->
458
+ ([OverrideWithPreconditions ( LLVM arch ) ],[OverrideWithPreconditions ( LLVM arch ) ],[OverrideWithPreconditions ( LLVM arch ) ]) ->
553
459
Crucible. OverrideSim (SAWCruciblePersonality Sym ) Sym Crucible. LLVM rtp args ret
554
460
(Crucible. RegValue Sym ret )
555
461
@@ -834,21 +740,6 @@ executeCond opts sc cc cs ss = do
834
740
(ss ^. MS. csPointsTos)
835
741
traverse_ (executeSetupCondition opts sc cc cs) (ss ^. MS. csConditions)
836
742
837
- -- | Allocate fresh variables for all of the "fresh" vars
838
- -- used in this phase and add them to the term substitution.
839
- refreshTerms ::
840
- SharedContext {- ^ shared context -} ->
841
- MS. StateSpec (LLVM arch ) {- ^ current phase spec -} ->
842
- OverrideMatcher (LLVM arch ) md ()
843
- refreshTerms sc ss =
844
- do extension <- Map. fromList <$> traverse freshenTerm (view MS. csFreshVars ss)
845
- OM (termSub %= Map. union extension)
846
- where
847
- freshenTerm (TypedExtCns _cty ec) =
848
- do ec' <- liftIO $ scFreshEC sc (toShortName (ecName ec)) (ecType ec)
849
- new <- liftIO $ scExtCns sc ec'
850
- return (ecVarIndex ec, new)
851
-
852
743
------------------------------------------------------------------------
853
744
854
745
-- | Generate assertions that all of the memory regions matched by an
0 commit comments