Skip to content

Commit

Permalink
Merge pull request #1274 from GaloisInc/issue1120
Browse files Browse the repository at this point in the history
Make `goal_eval_unint` handle `Z n` types.
  • Loading branch information
brianhuffman authored May 6, 2021
2 parents 1fb5f4e + 4a471b6 commit 2d92f2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 2d92f2a

Please sign in to comment.