Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make goal_eval_unint handle Z n types. #1274

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions saw-core-what4/src/Verifier/SAW/Simulator/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ parseUninterpretedSAW sym st sc ref trm app ty =
VIntType
-> VInt <$> mkUninterpretedSAW sym st ref trm app BaseIntegerRepr

VIntModType n
-> VIntMod n <$> mkUninterpretedSAW sym st ref (ArgTermFromIntMod n trm) app BaseIntegerRepr

-- 0 width bitvector is a constant
VVecType 0 VBoolType
-> return $ VWord ZBV
Expand Down Expand Up @@ -1247,6 +1250,8 @@ mkUninterpretedSAW sym st ref trm (UnintApp nm args tys) ret =
data ArgTerm
= ArgTermVar
| ArgTermBVZero -- ^ scBvNat 0 0
| ArgTermToIntMod Natural ArgTerm -- ^ toIntMod n x
| ArgTermFromIntMod Natural ArgTerm -- ^ fromIntMod n x
| ArgTermVector Term [ArgTerm] -- ^ element type, elements
| ArgTermUnit
| ArgTermPair ArgTerm ArgTerm
Expand Down Expand Up @@ -1278,6 +1283,16 @@ reconstructArgTerm atrm sc ts =
do z <- scNat sc 0
x <- scBvNat sc z z
return (x, ts0)
ArgTermToIntMod n at1 ->
do n' <- scNat sc n
(x1, ts1) <- parse at1 ts0
x <- scToIntMod sc n' x1
pure (x, ts1)
ArgTermFromIntMod n at1 ->
do n' <- scNat sc n
(x1, ts1) <- parse at1 ts0
x <- scFromIntMod sc n' x1
pure (x, ts1)
ArgTermVector ty ats ->
do (xs, ts1) <- parseList ats ts0
x <- scVector sc ty xs
Expand Down Expand Up @@ -1336,6 +1351,7 @@ mkArgTerm sc ty val =
(_, VWord ZBV) -> return ArgTermBVZero -- 0-width bitvector is a constant
(_, VWord (DBV _)) -> return ArgTermVar
(VUnitType, VUnit) -> return ArgTermUnit
(VIntModType n, VIntMod _ _) -> pure (ArgTermToIntMod n ArgTermVar)

(VVecType _ ety, VVector vv) ->
do vs <- traverse force (V.toList vv)
Expand Down
7 changes: 7 additions & 0 deletions saw-core/src/Verifier/SAW/SharedTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ module Verifier.SAW.SharedTerm
-- *** IntMod
, scIntModType
, scToIntMod
, scFromIntMod
-- *** Vectors
, scAppend
, scJoin
Expand Down Expand Up @@ -1829,6 +1830,12 @@ scIntModType sc n = scGlobalApply sc "Prelude.IntMod" [n]
scToIntMod :: SharedContext -> Term -> Term -> IO Term
scToIntMod sc n x = scGlobalApply sc "Prelude.toIntMod" [n, x]

-- | Convert an integer mod n to an integer.
--
-- > fromIntMod : (n : Nat) -> IntMod n -> Integer;
scFromIntMod :: SharedContext -> Term -> Term -> IO Term
scFromIntMod sc n x = scGlobalApply sc "Prelude.fromIntMod" [n, x]


-- Primitive operations on bitvectors

Expand Down