Skip to content

Commit 5c3ee39

Browse files
committed
Change saw-core tuple representation.
We now have an explicit AST constructor for arbitrary-size tuple values. Tuple types are formalized as a type constructor that takes a list of types as an argument: data TypeList : sort 1 where { TypeNil : TypeList; TypeCons : sort 0 -> TypeList -> TypeList; } primitive Tuple : TypeList -> sort 0; Additional primitives allow constructing and deconstructing tuples in a nested fashion: primitive headTuple : (t : sort 0) -> (ts : TypeList) -> Tuple (TypeCons t ts) -> t; primitive tailTuple : (t : sort 0) -> (ts : TypeList) -> Tuple (TypeCons t ts) -> Tuple ts; primitive consTuple : (t : sort 0) -> (ts : TypeList) -> t -> Tuple ts -> Tuple (TypeCons t ts);
1 parent 68d6efc commit 5c3ee39

File tree

55 files changed

+844
-990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+844
-990
lines changed

crucible-mir-comp/src/Mir/Compositional/Convert.hs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ termToReg sym varMap term shp0 = do
156156
where
157157
go :: forall tp'. TypeShape tp' -> SValue sym -> IO (RegValue sym tp')
158158
go shp sv = case (shp, sv) of
159-
(UnitShape _, SAW.VUnit) -> return ()
159+
-- (UnitShape _, SAW.VUnit) -> return ()
160160
(PrimShape _ BaseBoolRepr, SAW.VBool b) -> return b
161161
(PrimShape _ (BaseBVRepr w), SAW.VWord (W4.DBV e))
162162
| Just Refl <- testEquality (W4.exprType e) (BaseBVRepr w) -> return e
@@ -167,8 +167,9 @@ termToReg sym varMap term shp0 = do
167167
_ -> fail $ "termToReg: type error: need to produce " ++ show (shapeType shp) ++
168168
", but simulator returned a vector containing " ++ show x
169169
buildBitVector w bits
170-
(TupleShape _ elems, _) -> do
171-
svs <- reverse <$> tupleToListRev (length elems) [] sv
170+
(TupleShape _ elems, SAW.VTuple thunks) -> do
171+
svs <- mapM SAW.force $ toList thunks
172+
-- svs <- reverse <$> tupleToListRev (length elems) [] sv
172173
buildMirAggregate sym elems svs $ \_ _ shp' sv' -> go shp' sv'
173174
(ArrayShape (M.TyArray _ n) _ shp', SAW.VVector thunks) -> do
174175
svs <- mapM SAW.force $ toList thunks
@@ -191,20 +192,20 @@ termToReg sym varMap term shp0 = do
191192
_ -> error $ "termToReg: type error: need to produce " ++ show (shapeType shp) ++
192193
", but simulator returned " ++ show sv
193194

194-
-- | Convert an `SValue` tuple (built from nested `VPair`s) into a list of
195-
-- the inner `SValue`s, in reverse order.
196-
tupleToListRev :: Int -> [SValue sym] -> SValue sym -> IO [SValue sym]
197-
tupleToListRev 2 acc (SAW.VPair x y) = do
198-
x' <- SAW.force x
199-
y' <- SAW.force y
200-
return $ y' : x' : acc
201-
tupleToListRev n acc (SAW.VPair x xs) | n > 2 = do
202-
x' <- SAW.force x
203-
xs' <- SAW.force xs
204-
tupleToListRev (n - 1) (x' : acc) xs'
205-
tupleToListRev n _ _ | n < 2 = error $ "bad tuple size " ++ show n
206-
tupleToListRev n _ v = error $ "termToReg: expected tuple of " ++ show n ++
207-
" elements, but got " ++ show v
195+
-- -- | Convert an `SValue` tuple (built from nested `VPair`s) into a list of
196+
-- -- the inner `SValue`s, in reverse order.
197+
-- tupleToListRev :: Int -> [SValue sym] -> SValue sym -> IO [SValue sym]
198+
-- tupleToListRev 2 acc (SAW.VPair x y) = do
199+
-- x' <- SAW.force x
200+
-- y' <- SAW.force y
201+
-- return $ y' : x' : acc
202+
-- tupleToListRev n acc (SAW.VPair x xs) | n > 2 = do
203+
-- x' <- SAW.force x
204+
-- xs' <- SAW.force xs
205+
-- tupleToListRev (n - 1) (x' : acc) xs'
206+
-- tupleToListRev n _ _ | n < 2 = error $ "bad tuple size " ++ show n
207+
-- tupleToListRev n _ v = error $ "termToReg: expected tuple of " ++ show n ++
208+
-- " elements, but got " ++ show v
208209

209210
-- | Build a bitvector from a vector of bits. The length of the vector is
210211
-- required to match `tw`.

0 commit comments

Comments
 (0)