Skip to content
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

cli: Allow client libraries to use IO to create ExtensionImpl #1239

Merged
merged 3 commits into from
Aug 20, 2024
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
2 changes: 1 addition & 1 deletion crucible-cli/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import qualified Lang.Crucible.CLI.Options as Opts
main :: IO ()
main =
do let ?parserHooks = defaultParserHooks
Opts.main "crucible" (\_ -> emptyExtensionImpl) simulationHooks
Opts.main "crucible" (\_ -> pure emptyExtensionImpl) simulationHooks
where
simulationHooks =
defaultSimulateProgramHooks
Expand Down
10 changes: 6 additions & 4 deletions crucible-cli/src/Lang/Crucible/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ defaultSimulateProgramHooks = SimulateProgramHooks

simulateProgramWithExtension
:: (IsSyntaxExtension ext, ?parserHooks :: ParserHooks ext)
=> (forall sym. IsSymInterface sym => sym -> ExtensionImpl () sym ext)
=> (forall sym bak t st fs. (IsSymBackend sym bak, sym ~ ExprBuilder t st fs) =>
bak -> IO (ExtensionImpl () sym ext))
-> FilePath -- ^ The name of the input (appears in source locations)
-> Text -- ^ The contents of the input
-> Handle -- ^ A handle that will receive the output
Expand Down Expand Up @@ -159,7 +160,7 @@ simulateProgramWithExtension mkExt fn theInput outh profh opts hooks =
(UseCFG ssa (postdomInfo ssa))
m)
fwdDecFnBindings cs
let ext = mkExt sym
ext <- mkExt bak
let simCtx = initSimContext bak emptyIntrinsicTypes ha outh fns ext ()
let simSt = InitialState simCtx gst defaultAbortHandler retType $
runOverrideSim retType $
Expand Down Expand Up @@ -215,7 +216,7 @@ simulateProgram
-> IO ()
simulateProgram fn theInput outh profh opts hooks = do
let ?parserHooks = defaultParserHooks
let ext = const emptyExtensionImpl
let ext = const (pure emptyExtensionImpl)
simulateProgramWithExtension ext fn theInput outh profh opts hooks

repl ::
Expand Down Expand Up @@ -257,7 +258,8 @@ data Command
-- line), and this function takes care of the rest.
execCommand ::
(IsSyntaxExtension ext, ?parserHooks :: ParserHooks ext) =>
(forall sym. IsSymInterface sym => sym -> ExtensionImpl () sym ext) ->
(forall sym bak t st fs. (IsSymBackend sym bak, sym ~ ExprBuilder t st fs) =>
bak -> IO (ExtensionImpl () sym ext)) ->
SimulateProgramHooks ext ->
Command ->
IO ()
Expand Down
7 changes: 5 additions & 2 deletions crucible-cli/src/Lang/Crucible/CLI/Options.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}

module Lang.Crucible.CLI.Options (main) where

import Lang.Crucible.Backend (IsSymInterface)
import Lang.Crucible.Backend (IsSymBackend)
import Lang.Crucible.CFG.Extension (IsSyntaxExtension)
import Lang.Crucible.Simulator.ExecutionTree (ExtensionImpl)

Expand All @@ -14,6 +15,8 @@ import Options.Applicative ( (<**>) )

import Lang.Crucible.CLI

import What4.Expr (ExprBuilder)

file :: String -> Opt.Parser FilePath
file which = Opt.strArgument (Opt.metavar "FILE" <> Opt.help ("The " <> which <> " file"))

Expand Down Expand Up @@ -53,7 +56,7 @@ parseCheck =
main ::
(?parserHooks :: ParserHooks ext, IsSyntaxExtension ext) =>
String ->
(forall sym. IsSymInterface sym => sym -> ExtensionImpl () sym ext) ->
(forall sym bak t st fs. (IsSymBackend sym bak, sym ~ ExprBuilder t st fs) => bak -> IO (ExtensionImpl () sym ext)) ->
SimulateProgramHooks ext ->
IO ()
main name ext simulationHooks =
Expand Down
6 changes: 3 additions & 3 deletions crucible-llvm-cli/src/Lang/Crucible/LLVM/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import qualified Data.Map as Map

import Data.Parameterized.NatRepr (knownNat)

import Lang.Crucible.Backend (IsSymInterface)
import Lang.Crucible.Backend (IsSymBackend)
import Lang.Crucible.FunctionHandle (newHandleAllocator)
import Lang.Crucible.Simulator.ExecutionTree (ExtensionImpl)
import Lang.Crucible.Simulator.OverrideSim (writeGlobal)
Expand Down Expand Up @@ -43,7 +43,7 @@ import Lang.Crucible.LLVM.Syntax.TypeAlias (typeAliasParserHooks, x86_64LinuxTyp
withLlvmHooks ::
(forall w.
(HasPtrWidth w, ?parserHooks :: ParserHooks LLVM) =>
(forall sym. IsSymInterface sym => sym -> ExtensionImpl () sym LLVM) ->
(forall sym bak. IsSymBackend sym bak => bak -> IO (ExtensionImpl () sym LLVM)) ->
SimulateProgramHooks LLVM ->
IO a) ->
IO a
Expand Down Expand Up @@ -80,5 +80,5 @@ withLlvmHooks k = do
, setupOverridesHook = setupOverrides
}
let ext _ = let ?recordLLVMAnnotation = \_ _ _ -> pure ()
in llvmExtensionImpl Mem.defaultMemOptions
in pure (llvmExtensionImpl Mem.defaultMemOptions)
k ext simulationHooks
Loading