hsmt-0.1.0.0: src/HSMT/Backend.hs
-- | The solvers behind the API and the SMT-LIB runner: the Haskell engine
-- ('HSMT.SMT.Engine') or an external solver process
-- ('HSMT.Backend.External'), with one check interface.
module HSMT.Backend
( Backend (..)
, ExternalSolver (..)
, Dialect (..)
, z3Backend
, solverFromCommand
, BackendSession
, newBackendSession
, closeBackendSession
, checkBackend
) where
import HSMT.Backend.External
import HSMT.Core.Expr (Expr)
import HSMT.SMT.Engine
-- | Which solver decides the formulas.
data Backend
= Native
-- ^ The Haskell engine of hsmt.
| External ExternalSolver
-- ^ An external solver process, such as 'z3Backend'.
deriving (Eq, Show)
-- | An incremental session of either backend.
data BackendSession
= NativeSession Session
| ExternalBackendSession ExternalSession
-- | A session with no checks yet; external solvers start on the first
-- check.
newBackendSession :: Backend -> IO BackendSession
newBackendSession = \case
Native -> NativeSession <$> newSession
External s -> ExternalBackendSession <$> newExternalSession s
-- | Release the session; an external solver process is stopped.
closeBackendSession :: BackendSession -> IO ()
closeBackendSession = \case
NativeSession _ -> pure ()
ExternalBackendSession s -> closeExternalSession s
-- | Decide the conjunction of assertion levels (outermost first, each in
-- assertion order) and assumptions. An 'EUnsat' answer carries positions
-- in the concatenated levels followed by the assumptions.
checkBackend :: BackendSession -> CheckOptions -> [[Expr]] -> [Expr] -> IO EngineResult
checkBackend sess opts levels assumed = case sess of
NativeSession s -> checkSession s opts (concat levels <> assumed)
ExternalBackendSession s -> checkExternal s opts levels assumed