module Hsmtlib.Solvers.Cvc4(startCvc4) where
import Hsmtlib.Solver as Slv
import Hsmtlib.Solvers.Cmd.BatchCmd as B (executeBatch)
import Hsmtlib.Solvers.Cmd.OnlineCmd
import Hsmtlib.Solvers.Cmd.ProcCom.Process
import Hsmtlib.Solvers.Cmd.ScriptCmd
import SMTLib2
import System.IO (Handle,
IOMode (WriteMode),
openFile)
cvc4ConfigOnline :: SolverConfig
cvc4ConfigOnline =
Config { path = "cvc4"
, args = ["--interactive", "--lang=smt2", "--quiet"]
}
cvc4ConfigScript :: SolverConfig
cvc4ConfigScript =
Config { path = "cvc4"
, args = ["--lang=smt2"]
}
cvc4ConfigBatch :: SolverConfig
cvc4ConfigBatch =
Config { path = "cvc4"
, args = ["--lang=smt2"]
}
startCvc4 :: Mode -> String -> Maybe SolverConfig -> Maybe FilePath -> IO Solver
startCvc4 Slv.Batch logic sConf _ = startCvc4Batch logic sConf
startCvc4 Slv.Online logic sConf _ = startCvc4Online logic sConf
startCvc4 Slv.Script logic sConf scriptFilePath =
startCvc4Script logic sConf scriptFilePath
startCvc4Online :: String -> Maybe SolverConfig -> IO Solver
startCvc4Online logic Nothing = startCvc4Online' logic cvc4ConfigOnline
startCvc4Online logic (Just conf) = startCvc4Online' logic conf
startCvc4Online':: String -> SolverConfig -> IO Solver
startCvc4Online' logic conf = do
process <- beginProcess (path conf) (args conf)
onlineSetOption process (OptPrintSuccess True)
onlineSetLogic process (N logic)
return $ onlineSolver process
startCvc4Script :: String -> Maybe SolverConfig -> Maybe FilePath -> IO Solver
startCvc4Script logic Nothing Nothing =
startCvc4Script' logic cvc4ConfigScript "temp.smt2"
startCvc4Script logic (Just conf) Nothing =
startCvc4Script' logic conf "temp.smt2"
startCvc4Script logic Nothing (Just scriptFilePath) =
startCvc4Script' logic cvc4ConfigScript scriptFilePath
startCvc4Script logic (Just conf) (Just scriptFilePath) =
startCvc4Script' logic conf scriptFilePath
startCvc4Script' :: String -> SolverConfig -> FilePath -> IO Solver
startCvc4Script' logic conf scriptFilePath = do
scriptHandle <- openFile scriptFilePath WriteMode
let srcmd = newScriptArgs conf scriptHandle scriptFilePath
scriptSetOption srcmd (OptPrintSuccess True)
scriptSetLogic srcmd (N logic)
return $ scriptSolver srcmd
newScriptArgs :: SolverConfig -> Handle -> FilePath -> ScriptConf
newScriptArgs solverConfig nHandle scriptFilePath =
ScriptConf { sHandle = nHandle
, sCmdPath = path solverConfig
, sArgs = args solverConfig
, sFilePath = scriptFilePath
}
startCvc4Batch :: String -> Maybe SolverConfig -> IO Solver
startCvc4Batch logic Nothing = startCvc4Batch' logic cvc4ConfigBatch
startCvc4Batch logic (Just conf) = startCvc4Batch' logic conf
startCvc4Batch' :: String -> SolverConfig -> IO Solver
startCvc4Batch' logic conf = return $ batchSolver logic conf
onlineSolver :: Process -> Solver
onlineSolver process =
Solver { setLogic = onlineSetLogic process
, setOption = onlineSetOption process
, setInfo = onlineSetInfo process
, declareType = onlineDeclareType process
, defineType = onlineDefineType process
, declareFun = onlineDeclareFun process
, defineFun = onlineDefineFun process
, push = onlinePush process
, pop = onlinePop process
, assert = onlineAssert process
, checkSat = onlineCheckSat process
, getAssertions = onlineGetAssertions process
, getValue = onlineGetValue process
, getProof = onlineGetProof process
, getUnsatCore = onlineGetUnsatCore process
, getInfo = onlineGetInfo process
, getOption = onlineGetOption process
, exit = onlineExit process
}
scriptSolver :: ScriptConf -> Solver
scriptSolver srcmd =
Solver { setLogic = scriptSetLogic srcmd
, setOption = scriptSetOption srcmd
, setInfo = scriptSetInfo srcmd
, declareType = scriptDeclareType srcmd
, defineType = scriptDefineType srcmd
, declareFun = scriptDeclareFun srcmd
, defineFun = scriptDefineFun srcmd
, push = scriptPush srcmd
, pop = scriptPop srcmd
, assert = scriptAssert srcmd
, checkSat = scriptCheckSat srcmd
, getAssertions = scriptGetAssertions srcmd
, getValue = scriptGetValue srcmd
, getProof = scriptGetProof srcmd
, getUnsatCore = scriptGetUnsatCore srcmd
, getInfo = scriptGetInfo srcmd
, getOption = scriptGetOption srcmd
, exit = scriptExit srcmd
}
batchSolver :: String -> SolverConfig -> Solver
batchSolver logic config =
BSolver { Slv.executeBatch = B.executeBatch (path config) (args config) logic}