module Hsmtlib.Solvers.Boolector(startBoolector) 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)
boolectorConfigOnline :: SolverConfig
boolectorConfigOnline =
Config { path = "boolector"
, args = ["--smt2", "-d2", "-o STDOUT"]
}
boolectorConfigScript :: SolverConfig
boolectorConfigScript =
Config { path = "boolector"
, args = ["--smt2", "-d2", "-o STDOUT"]
}
boolectorConfigBatch :: SolverConfig
boolectorConfigBatch =
Config { path = "boolector"
, args = ["--smt2", "-d2", "-o STDOUT"]
}
startBoolector :: Mode
-> String
-> Maybe SolverConfig
-> Maybe FilePath
-> IO Solver
startBoolector Slv.Batch logic sConf _ = startBoolectorBatch logic sConf
startBoolector Slv.Online logic sConf _ = startBoolectorOnline logic sConf
startBoolector Slv.Script logic sConf scriptFilePath =
startBoolectorScript logic sConf scriptFilePath
startBoolectorOnline :: String -> Maybe SolverConfig -> IO Solver
startBoolectorOnline logic Nothing = startBoolectorOnline' logic boolectorConfigOnline
startBoolectorOnline logic (Just conf) = startBoolectorOnline' logic conf
startBoolectorOnline' :: String -> SolverConfig -> IO Solver
startBoolectorOnline' logic conf = do
process <- beginProcess (path conf) (args conf)
onlineSetLogic process (N logic)
return $ onlineSolver process
startBoolectorScript :: String -> Maybe SolverConfig -> Maybe FilePath -> IO Solver
startBoolectorScript logic Nothing Nothing =
startBoolectorScript' logic boolectorConfigScript "temp.smt2"
startBoolectorScript logic (Just conf) Nothing =
startBoolectorScript' logic conf "temp.smt2"
startBoolectorScript logic Nothing (Just scriptFilePath) =
startBoolectorScript' logic boolectorConfigScript scriptFilePath
startBoolectorScript logic (Just conf) (Just scriptFilePath) =
startBoolectorScript' logic conf scriptFilePath
startBoolectorScript' :: String -> SolverConfig -> FilePath -> IO Solver
startBoolectorScript' 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
}
startBoolectorBatch :: String -> Maybe SolverConfig -> IO Solver
startBoolectorBatch logic Nothing =
startBoolectorBatch' logic boolectorConfigBatch
startBoolectorBatch logic (Just conf) = startBoolectorBatch' logic conf
startBoolectorBatch' :: String -> SolverConfig -> IO Solver
startBoolectorBatch' 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}