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