22-- backends.
33{-# Language DataKinds, TypeOperators, GADTs, TypeApplications #-}
44{-# Language ImplicitParams #-}
5- module SAWCentral.Crucible.Common.ResolveSetupValue (
5+ module SAWCentral.Crucible.Common.ResolveSetupValue (
66 resolveBoolTerm , resolveBoolTerm' ,
77 resolveBitvectorTerm , resolveBitvectorTerm' ,
88 ResolveRewrite (.. ),
99 ) where
1010
11- import qualified Data.Map as Map
1211import Data.Set (Set )
1312import qualified Data.BitVector.Sized as BV
1413import Data.Parameterized.Some (Some (.. ))
@@ -19,7 +18,6 @@ import qualified What4.Interface as W4
1918
2019
2120import SAWCore.SharedTerm
22- import SAWCore.Name
2321import qualified SAWCore.Prim as Prim
2422
2523import qualified SAWCore.Simulator.Concrete as Concrete
@@ -32,7 +30,6 @@ import SAWCentral.Crucible.Common
3230
3331import SAWCentral.Proof (TheoremNonce )
3432import SAWCore.Rewriter (Simpset , rewriteSharedTerm )
35- import qualified CryptolSAWCore.Simpset as Cryptol
3633import SAWCoreWhat4.What4 (w4EvalAny , valueToSymExpr )
3734
3835import Cryptol.TypeCheck.Type (tIsBit , tIsSeq , tIsNum )
@@ -82,21 +79,13 @@ resolveTerm sym unint bt rr tm =
8279 _ -> fail " resolveTerm: expected `Bool` or bit-vector"
8380
8481 | rrWhat4Eval rr ->
85- do -- Try to use rewrites to simplify the term
86- cryptol_ss <- Cryptol. mkCryptolSimpset @ TheoremNonce sc
87- tm'' <- snd <$> rewriteSharedTerm sc cryptol_ss tm'
88- tm''' <- basicRewrite sc tm''
89- if all isPreludeName (Map. elems (getConstantSet tm''')) then
90- do
91- (_, _, _, p) <- w4EvalAny sym st sc mempty unint tm'''
92- case valueToSymExpr p of
93- Just (Some y)
94- | Just Refl <- testEquality bt ty -> pure y
95- | otherwise -> typeError (show ty)
96- where ty = W4. exprType y
97- _ -> fail (" resolveTerm: unexpected w4Eval result " ++ show p)
98- else
99- bindSAWTerm sym st bt tm'''
82+ do (_, _, _, p) <- w4EvalAny sym st sc mempty unint tm'
83+ case valueToSymExpr p of
84+ Just (Some y)
85+ | Just Refl <- testEquality bt ty -> pure y
86+ | otherwise -> typeError (show ty)
87+ where ty = W4. exprType y
88+ _ -> fail (" resolveTerm: unexpected w4Eval result " ++ show p)
10089
10190 -- Just bind the term
10291 | otherwise -> bindSAWTerm sym st bt tm'
@@ -107,11 +96,6 @@ resolveTerm sym unint bt rr tm =
10796 Nothing -> pure
10897 Just ss -> \ t -> snd <$> rewriteSharedTerm sc ss t
10998
110- isPreludeName nm =
111- case nm of
112- ModuleIdentifier ident -> identModule ident == preludeName
113- _ -> False
114-
11599 checkType sc =
116100 do
117101 schema <- ttType <$> mkTypedTerm sc tm
@@ -146,9 +130,8 @@ resolveBoolTerm sym unint = resolveBoolTerm' sym unint noResolveRewrite
146130resolveBitvectorTerm' ::
147131 (1 W4. <= w ) => Sym -> Set VarIndex -> W4. NatRepr w -> ResolveRewrite -> Term -> IO (W4. SymBV Sym w )
148132resolveBitvectorTerm' sym unint w = resolveTerm sym unint (W4. BaseBVRepr w)
149-
133+
150134-- 'resolveTerm' specialized to bit-vectors, without rewriting.
151- resolveBitvectorTerm ::
135+ resolveBitvectorTerm ::
152136 (1 W4. <= w ) => Sym -> Set VarIndex -> W4. NatRepr w -> Term -> IO (W4. SymBV Sym w )
153137resolveBitvectorTerm sym unint w = resolveBitvectorTerm' sym unint w noResolveRewrite
154-
0 commit comments