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

Change saw-core tuple representation. #1612

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4a961b3
Change saw-core tuple representation.
Mar 16, 2022
8e5b70c
Reinstate pair-related functions to Verifier/SAW/OpenTerm.hs
Mar 16, 2022
1e00330
Adapt heapster-saw to changed tuple representation.
Mar 16, 2022
7a1f95f
Adapt saw-core-coq to changed tuple representation.
Mar 16, 2022
4854f0d
Adapt saw-script to changed tuple representation.
Mar 16, 2022
453cdb0
Adapt crux-mir-comp to changed tuple representation.
Mar 16, 2022
84e0573
Fix definition of `ensureTupleType` in SCTypeCheck.hs.
Mar 17, 2022
0b43f8f
Remove saw-core parenthesized tuple selector syntax "x.(1)".
Mar 18, 2022
aec37ef
Rewrite CompM combinators in Prelude.sawcore to use new tuple types.
Mar 18, 2022
454b0da
Update saw-core tuple syntax in heapster-saw/examples.
Mar 18, 2022
e29f98f
Restore special cases to tuple operations in Heapster/SAWTranslation.
Mar 18, 2022
75b639c
Change saw-core tuple representation.
Mar 16, 2022
016cdbc
Reinstate pair-related functions to Verifier/SAW/OpenTerm.hs
Mar 16, 2022
65966e7
Adapt heapster-saw to changed tuple representation.
Mar 16, 2022
3051800
Adapt saw-core-coq to changed tuple representation.
Mar 16, 2022
46a0c6d
Adapt saw-script to changed tuple representation.
Mar 16, 2022
b6f308a
Adapt crux-mir-comp to changed tuple representation.
Mar 16, 2022
7ce2fce
Fix definition of `ensureTupleType` in SCTypeCheck.hs.
Mar 17, 2022
4af3cbf
Remove saw-core parenthesized tuple selector syntax "x.(1)".
Mar 18, 2022
b1fad07
Rewrite CompM combinators in Prelude.sawcore to use new tuple types.
Mar 18, 2022
5c93c78
Update saw-core tuple syntax in heapster-saw/examples.
Mar 18, 2022
2edef5f
Restore special cases to tuple operations in Heapster/SAWTranslation.
Mar 18, 2022
aa624a8
Export typeListOpenTerm from OpenTerm library.
Mar 18, 2022
6d50ea7
Add Coq definitions for `Tuple` and `{head,tail,cons}Tuple` functions.
Mar 18, 2022
d601299
fixed a bug in translateBlockMapBodies, which was iteratively buildin…
Mar 18, 2022
e311d74
Merge branch 'saw-tuples' of github.com:GaloisInc/saw-script into saw…
Mar 18, 2022
c59371b
added saw-core-coq translations for all the tuple-related definitions
Mar 18, 2022
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
24 changes: 5 additions & 19 deletions crux-mir-comp/src/Mir/Compositional/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ termToReg sym sc varMap term shp = do
where
go :: forall tp'. TypeShape tp' -> SValue sym -> IO (RegValue sym tp')
go shp sv = case (shp, sv) of
(UnitShape _, SAW.VUnit) -> return ()
(UnitShape _, SAW.VTuple ts) | V.null ts -> return ()
(PrimShape _ BaseBoolRepr, SAW.VBool b) -> return b
(PrimShape _ (BaseBVRepr w), SAW.VWord (W4.DBV e))
| Just Refl <- testEquality (W4.exprType e) (BaseBVRepr w) -> return e
Expand All @@ -326,9 +326,9 @@ termToReg sym sc varMap term shp = do
_ -> fail $ "termToReg: type error: need to produce " ++ show (shapeType shp) ++
", but simulator returned a vector containing " ++ show x
buildBitVector w bits
(TupleShape _ _ flds, _) -> do
svs <- tupleToListRev (Ctx.sizeInt $ Ctx.size flds) [] sv
goTuple flds svs
(TupleShape _ _ flds, SAW.VTuple ts) -> do
svs <- traverse SAW.force ts
goTuple flds (reverse (V.toList svs))
(ArrayShape (M.TyArray _ n) _ shp, SAW.VVector thunks) -> do
svs <- mapM SAW.force $ toList thunks
when (length svs /= n) $ fail $
Expand All @@ -350,21 +350,7 @@ termToReg sym sc varMap term shp = do
_ -> error $ "termToReg: type error: need to produce " ++ show (shapeType shp) ++
", but simulator returned " ++ show sv

-- | Convert an `SValue` tuple (built from nested `VPair`s) into a list of
-- the inner `SValue`s, in reverse order.
tupleToListRev :: Int -> [SValue sym] -> SValue sym -> IO [SValue sym]
tupleToListRev 2 acc (SAW.VPair x y) = do
x' <- SAW.force x
y' <- SAW.force y
return $ y' : x' : acc
tupleToListRev n acc (SAW.VPair x xs) | n > 2 = do
x' <- SAW.force x
xs' <- SAW.force xs
tupleToListRev (n - 1) (x' : acc) xs'
tupleToListRev n _ _ | n < 2 = error $ "bad tuple size " ++ show n
tupleToListRev n _ v = error $ "termToReg: expected tuple of " ++ show n ++
" elements, but got " ++ show v

-- `SValue`s expected in reverse order.
goTuple :: forall ctx.
Assignment FieldShape ctx ->
[SValue sym] ->
Expand Down
Loading