Skip to content

Commit

Permalink
Merge pull request #1191 from GaloisInc/dholland-cast
Browse files Browse the repository at this point in the history
Implement byte-to-char casts for crucible-mir.
  • Loading branch information
sauclovian-g authored Aug 1, 2024
2 parents af11dc2 + 4dbb659 commit 5b4d945
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crucible-mir/src/Mir/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,15 @@ evalCast' ck ty1 e ty2 = do
-> baseSizeToNatCont bsz $ \w ->
return $ MirExp (C.BVRepr w) (R.App $ E.BVIte e0 w (R.App $ eBVLit w 1) (R.App $ eBVLit w 0))

-- char to uint
-- char to usize
(M.Misc, M.TyChar, M.TyUint M.USize)
| MirExp (C.BVRepr sz) e0 <- e
-> return $ MirExp UsizeRepr (bvToUsize sz R.App e0)
-- char to other uint
(M.Misc, M.TyChar, M.TyUint s) -> baseSizeToNatCont s $ extendUnsignedBV e

-- byte to char
(M.Misc, M.TyUint B8, M.TyChar) -> baseSizeToNatCont M.B32 $ extendUnsignedBV e



Expand Down
10 changes: 10 additions & 0 deletions crux-mir/test/conc_eval/num/byte_to_char.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub fn b() -> u8 {
97
}

#[cfg_attr(crux, crux::test)]
pub fn crux_test() -> char {
b() as char
}

pub fn main() { println!("{:?}", crux_test()); }

0 comments on commit 5b4d945

Please sign in to comment.