Skip to content

Add {enable_disable}_debug_intrinsics #1424

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

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions saw-remote-api/src/SAWServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ initialState readFileFn =
, rwCrucibleAssertThenAssume = False
, rwLaxArith = False
, rwLaxPointerOrdering = False
, rwDebugIntrinsics = True
, rwWhat4HashConsing = False
, rwWhat4HashConsingX86 = False
, rwStackBaseAlign = defaultStackBaseAlign
Expand Down
11 changes: 9 additions & 2 deletions saw-remote-api/src/SAWServer/LLVMCrucibleSetup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ import SAWScript.Crucible.LLVM.Builtins
, llvm_return
, llvm_precond
, llvm_postcond )
import qualified SAWScript.Crucible.LLVM.CrucibleLLVM as CL
import qualified SAWScript.Crucible.LLVM.MethodSpecIR as CMS
import qualified SAWScript.Crucible.Common.MethodSpec as CMS (GhostGlobal)
import SAWScript.Value (BuiltinContext, LLVMCrucibleSetupM(..), biSharedContext)
import SAWScript.Value
( BuiltinContext, LLVMCrucibleSetupM(..), TopLevelRW(..), biSharedContext )
import qualified Verifier.SAW.CryptolEnv as CEnv
import Verifier.SAW.CryptolEnv (CryptolEnv)
import Verifier.SAW.TypedTerm (TypedTerm)
Expand All @@ -57,6 +59,7 @@ import SAWServer as Server
SAWState,
CrucibleSetupVal(..),
sawTask,
sawTopLevelRW,
getHandleAlloc,
setServerVal )
import SAWServer.Data.Contract
Expand Down Expand Up @@ -209,7 +212,11 @@ llvmLoadModule (LLVMLoadModuleParams serverName fileName) =
case tasks of
(_:_) -> Argo.raise $ notAtTopLevel $ map fst tasks
[] ->
do let ?laxArith = False -- TODO read from config
do rw <- view sawTopLevelRW <$> Argo.getState
let ?transOpts = CL.defaultTranslationOptions
{ CL.laxArith = rwLaxArith rw
, CL.debugIntrinsics = rwDebugIntrinsics rw
}
halloc <- getHandleAlloc
loaded <- liftIO (CMS.loadLLVMModule fileName halloc)
case loaded of
Expand Down
5 changes: 5 additions & 0 deletions saw-remote-api/src/SAWServer/SetOption.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ setOption opt =
updateRW rw { rwLaxArith = enabled }
EnableLaxPointerOrdering enabled ->
updateRW rw { rwLaxPointerOrdering = enabled }
EnableDebugIntrinsics enabled ->
updateRW rw { rwDebugIntrinsics = enabled }
EnableSMTArrayMemoryModel enabled ->
updateRW rw { rwSMTArrayMemoryModel = enabled }
EnableWhat4HashConsing enabled ->
Expand All @@ -42,6 +44,7 @@ setOption opt =
data SetOptionParams
= EnableLaxArithmetic Bool
| EnableLaxPointerOrdering Bool
| EnableDebugIntrinsics Bool
| EnableSMTArrayMemoryModel Bool
| EnableWhat4HashConsing Bool

Expand All @@ -50,6 +53,7 @@ parseOption o name =
case name of
"lax arithmetic" -> EnableLaxArithmetic <$> o .: "value"
"lax pointer ordering" -> EnableLaxPointerOrdering <$> o .: "value"
"debug intrinsics" -> EnableDebugIntrinsics <$> o .: "value"
"SMT array memory model" -> EnableSMTArrayMemoryModel <$> o .: "value"
"What4 hash consing" -> EnableWhat4HashConsing <$> o .: "value"
_ -> empty
Expand All @@ -65,6 +69,7 @@ instance Doc.DescribedMethod SetOptionParams OK where
Doc.Paragraph [Doc.Text "The option to set and its accompanying value (i.e., true or false); one of the following:"
, Doc.Literal "lax arithmetic", Doc.Text ", "
, Doc.Literal "lax pointer ordering", Doc.Text ", "
, Doc.Literal "debug intrinsics", Doc.Text ", "
, Doc.Literal "SMT array memory model", Doc.Text ", or "
, Doc.Literal "What4 hash consing"
])
Expand Down
5 changes: 4 additions & 1 deletion src/SAWScript/Crucible/LLVM/CrucibleLLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ module SAWScript.Crucible.LLVM.CrucibleLLVM
, LLVMContext
, translateModule
, llvmDeclToFunHandleRepr'
, TranslationOptions(..)
, defaultTranslationOptions
-- * Re-exports from "Lang.Crucible.LLVM.MemModel"
, doResolveGlobal
, Mem
Expand Down Expand Up @@ -166,7 +168,8 @@ import Lang.Crucible.LLVM.Globals

import Lang.Crucible.LLVM.Translation
(llvmMemVar, cfgMap, transContext, llvmPtrWidth, llvmTypeCtx,
ModuleTranslation, LLVMContext, translateModule, llvmDeclToFunHandleRepr')
ModuleTranslation, LLVMContext, translateModule, llvmDeclToFunHandleRepr',
TranslationOptions(..), defaultTranslationOptions)

import Lang.Crucible.LLVM.MemModel
(Mem, MemImpl, doResolveGlobal, storeRaw, storeConstRaw, mallocRaw, mallocConstRaw,
Expand Down
5 changes: 2 additions & 3 deletions src/SAWScript/Crucible/LLVM/MethodSpecIR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ modTrans = _modTrans
-- | Load an LLVM module from the given bitcode file, then parse and
-- translate to Crucible.
loadLLVMModule ::
(?laxArith :: Bool) =>
(?transOpts :: CL.TranslationOptions) =>
FilePath ->
Crucible.HandleAllocator ->
IO (Either LLVM.Error (Some LLVMModule))
Expand All @@ -257,8 +257,7 @@ loadLLVMModule file halloc =
case parseResult of
Left err -> return (Left err)
Right llvm_mod ->
do let ?optLoopMerge = False
memVar <- CL.mkMemVar (Text.pack "saw:llvm_memory") halloc
do memVar <- CL.mkMemVar (Text.pack "saw:llvm_memory") halloc
Some mtrans <- CL.translateModule halloc memVar llvm_mod
return (Right (Some (LLVMModule file llvm_mod mtrans)))

Expand Down
21 changes: 21 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ buildTopLevelEnv proxy opts =
, rwProfilingFile = Nothing
, rwLaxArith = False
, rwLaxPointerOrdering = False
, rwDebugIntrinsics = True
, rwWhat4HashConsing = False
, rwWhat4HashConsingX86 = False
, rwPreservedRegs = []
Expand Down Expand Up @@ -564,6 +565,16 @@ disable_lax_pointer_ordering = do
rw <- getTopLevelRW
putTopLevelRW rw { rwLaxPointerOrdering = False }

enable_debug_intrinsics :: TopLevel ()
enable_debug_intrinsics = do
rw <- getTopLevelRW
putTopLevelRW rw { rwDebugIntrinsics = True }

disable_debug_intrinsics :: TopLevel ()
disable_debug_intrinsics = do
rw <- getTopLevelRW
putTopLevelRW rw { rwDebugIntrinsics = False }

enable_what4_hash_consing :: TopLevel ()
enable_what4_hash_consing = do
rw <- getTopLevelRW
Expand Down Expand Up @@ -805,6 +816,16 @@ primitives = Map.fromList
Current
[ "Disable lax rules for pointer ordering comparisons in Crucible." ]

, prim "enable_debug_intrinsics" "TopLevel ()"
(pureVal enable_debug_intrinsics)
Current
[ "Enable translating statements using certain llvm.dbg intrinsic functions in Crucible." ]

, prim "disable_debug_intrinsics" "TopLevel ()"
(pureVal disable_debug_intrinsics)
Current
[ "Disable translating statements using certain llvm.dbg intrinsic functions in Crucible." ]

, prim "enable_what4_hash_consing" "TopLevel ()"
(pureVal enable_what4_hash_consing)
Current
Expand Down
7 changes: 6 additions & 1 deletion src/SAWScript/LLVMBuiltins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ import qualified Text.LLVM.Parser as LLVM (parseType)

import SAWScript.Value as SV

import qualified SAWScript.Crucible.LLVM.CrucibleLLVM as CL
import qualified SAWScript.Crucible.LLVM.MethodSpecIR as CMS (LLVMModule, loadLLVMModule)

llvm_load_module :: FilePath -> TopLevel (Some CMS.LLVMModule)
llvm_load_module file =
do laxArith <- gets rwLaxArith
let ?laxArith = laxArith
debugIntrinsics <- gets rwDebugIntrinsics
let ?transOpts = CL.defaultTranslationOptions
{ CL.laxArith = laxArith
, CL.debugIntrinsics = debugIntrinsics
}
halloc <- getHandleAlloc
io (CMS.loadLLVMModule file halloc) >>= \case
Left err -> fail (LLVM.formatError err)
Expand Down
1 change: 1 addition & 0 deletions src/SAWScript/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ data TopLevelRW =
, rwProfilingFile :: Maybe FilePath
, rwLaxArith :: Bool
, rwLaxPointerOrdering :: Bool
, rwDebugIntrinsics :: Bool

-- FIXME: These might be better split into "simulator hash-consing" and "tactic hash-consing"
, rwWhat4HashConsing :: Bool
Expand Down