Skip to content

Commit

Permalink
Bring SAW variables of type Bool into Cryptol expressions
Browse files Browse the repository at this point in the history
Fixes #1404.
  • Loading branch information
RyanGlScott committed Aug 4, 2021
1 parent 65d764b commit 799b36b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ A new `enable_lax_pointer_ordering` function exists, which relaxes the
restrictions that Crucible imposes on comparisons between pointers from
different allocation blocks.

A SAW value of type `Bool` can now be brought into scope in Cryptol expressions
as a value of type `Bit`.

## Changes

* The linked-in version of ABC (based on the Haskell `abcBridge`
Expand Down
2 changes: 2 additions & 0 deletions intTests/test1404/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let b = true;
print {{ b }};
3 changes: 3 additions & 0 deletions intTests/test1404/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set -e

$SAW test.saw
11 changes: 10 additions & 1 deletion src/SAWScript/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ extendEnv sc x mt md v rw =
VString s ->
do tt <- typedTermOfString sc (unpack s)
pure $ CEnv.bindTypedTerm (ident, tt) ce
VBool b ->
do tt <- typedTermOfBool sc b
pure $ CEnv.bindTypedTerm (ident, tt) ce
_ ->
pure ce
pure $
Expand All @@ -590,7 +593,7 @@ extendEnv sc x mt md v rw =

typedTermOfString :: SharedContext -> String -> IO TypedTerm
typedTermOfString sc str =
do let schema = Cryptol.Forall [] [] (Cryptol.tString (length str))
do let schema = Cryptol.tMono (Cryptol.tString (length str))
bvNat <- scGlobalDef sc "Prelude.bvNat"
bvNat8 <- scApply sc bvNat =<< scNat sc 8
byteT <- scBitvector sc 8
Expand All @@ -599,6 +602,12 @@ typedTermOfString sc str =
trm <- scVector sc byteT ts
pure (TypedTerm (TypedTermSchema schema) trm)

typedTermOfBool :: SharedContext -> Bool -> IO TypedTerm
typedTermOfBool sc b =
do let schema = Cryptol.tMono Cryptol.tBit
trm <- scBool sc b
pure (TypedTerm (TypedTermSchema schema) trm)


-- Other SAWScript Monads ------------------------------------------------------

Expand Down

0 comments on commit 799b36b

Please sign in to comment.