Skip to content

Commit

Permalink
Implement llvm_assert and jvm_assert.
Browse files Browse the repository at this point in the history
Fixes #1644
  • Loading branch information
robdockins committed May 20, 2022
1 parent 31fa250 commit bf5dd74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/SAWScript/Crucible/JVM/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module SAWScript.Crucible.JVM.Builtins
, jvm_execute_func
, jvm_postcond
, jvm_precond
, jvm_assert
, jvm_modifies_field
, jvm_modifies_static_field
, jvm_modifies_elem
Expand Down Expand Up @@ -1255,6 +1256,11 @@ generic_array_is ptr mval =
X.throwM $ JVMArrayModifyPrestate ptr'
Setup.addPointsTo pt

jvm_assert :: TypedTerm -> JVMSetupM ()
jvm_assert term = JVMSetupM $ do
loc <- SS.toW4Loc "jvm_assert" <$> lift getPosition
Setup.addCondition (MS.SetupCond_Pred loc term)

jvm_precond :: TypedTerm -> JVMSetupM ()
jvm_precond term = JVMSetupM $ do
loc <- SS.toW4Loc "jvm_precond" <$> lift getPosition
Expand Down
7 changes: 7 additions & 0 deletions src/SAWScript/Crucible/LLVM/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module SAWScript.Crucible.LLVM.Builtins
, llvm_return
, llvm_precond
, llvm_postcond
, llvm_assert
, llvm_cfg
, llvm_extract
, llvm_compositional_extract
Expand Down Expand Up @@ -1732,6 +1733,12 @@ checkMemTypeCompatibility loc t1 t2 =
--------------------------------------------------------------------------------
-- Setup builtins

llvm_assert :: TypedTerm -> LLVMCrucibleSetupM ()
llvm_assert term =
LLVMCrucibleSetupM $
do loc <- getW4Position "llvm_assert"
Setup.addCondition (MS.SetupCond_Pred loc term)

llvm_precond :: TypedTerm -> LLVMCrucibleSetupM ()
llvm_precond term =
LLVMCrucibleSetupM $
Expand Down
16 changes: 16 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,14 @@ primitives = Map.fromList
Current
[ "Legacy alternative name for `llvm_precond`." ]

, prim "llvm_assert" "Term -> LLVMSetup ()"
(pureVal llvm_assert)
Current
[ "State that the given predicate must hold. Acts as `llvm_precond`"
, "or `llvm_postcond` depending on the phase of specification in which"
, "it appears (i.e., before or after `llvm_execute_func`."
]

, prim "llvm_postcond" "Term -> LLVMSetup ()"
(pureVal llvm_postcond)
Current
Expand Down Expand Up @@ -3145,6 +3153,14 @@ primitives = Map.fromList
, "method being verified."
]

, prim "jvm_assert" "Term -> JVMSetup ()"
(pureVal jvm_assert)
Current
[ "State that the given predicate must hold. Acts as `jvm_precond`"
, "or `jvm_postcond` depending on the phase of specification in which"
, "it appears (i.e., before or after `jvm_execute_func`."
]

, prim "jvm_postcond" "Term -> JVMSetup ()"
(pureVal jvm_postcond)
Current
Expand Down

0 comments on commit bf5dd74

Please sign in to comment.