Skip to content

Commit

Permalink
Merge pull request #36 from GaloisInc/saw-script-issue445
Browse files Browse the repository at this point in the history
Make subNat support symbolic VToNat values.
  • Loading branch information
brianhuffman authored May 21, 2019
2 parents 332eebd + 9682421 commit 9e06f8b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Verifier/SAW/Simulator/Prims.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ constMap bp = Map.fromList
-- Nat
, ("Prelude.Succ", succOp)
, ("Prelude.addNat", addNatOp)
, ("Prelude.subNat", subNatOp)
, ("Prelude.subNat", subNatOp bp)
, ("Prelude.mulNat", mulNatOp)
, ("Prelude.minNat", minNatOp)
, ("Prelude.maxNat", maxNatOp)
Expand Down Expand Up @@ -442,11 +442,20 @@ addNatOp =
vNat (m + n)

-- subNat :: Nat -> Nat -> Nat;
subNatOp :: VMonad l => Value l
subNatOp =
natFun' "subNat1" $ \m -> return $
natFun' "subNat2" $ \n -> return $
vNat (if m < n then 0 else m - n)
subNatOp :: (VMonad l, Show (Extra l)) => BasePrims l -> Value l
subNatOp bp =
strictFun $ \x -> return $
strictFun $ \y -> g x y
where
g (VNat i) (VNat j) = return $ VNat (if i < j then 0 else i - j)
g v1 v2 =
do let w = max (natSize bp v1) (natSize bp v2)
x1 <- natToWord bp w v1
x2 <- natToWord bp w v2
lt <- bpBvult bp x1 x2
z <- bpBvLit bp w 0
d <- bpBvSub bp x1 x2
VToNat . VWord <$> bpMuxWord bp lt z d

-- mulNat :: Nat -> Nat -> Nat;
mulNatOp :: VMonad l => Value l
Expand Down

0 comments on commit 9e06f8b

Please sign in to comment.