module Hsmtlib.Solvers.MathSAT(startMathSat) 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)
mathSatConfigOnline :: SolverConfig
mathSatConfigOnline =
Config { path = "mathsat"
, args = []
}
mathSatConfigScript :: SolverConfig
mathSatConfigScript =
Config { path = "mathsat"
, args = []
}
mathSatConfigBatch :: SolverConfig
mathSatConfigBatch =
Config { path = "mathsat"
, args = []
}
startMathSat :: Mode
-> String
-> Maybe SolverConfig
-> Maybe FilePath
-> IO Solver
startMathSat Slv.Batch logic sConf _ = startMathSatBatch logic sConf
startMathSat Slv.Online logic sConf _ = startMathSatOnline logic sConf
startMathSat Slv.Script logic sConf scriptFilePath =
startMathSatScript logic sConf scriptFilePath
startMathSatOnline :: String -> Maybe SolverConfig -> IO Solver
startMathSatOnline logic Nothing =
startMathSatOnline' logic mathSatConfigOnline
startMathSatOnline logic (Just conf) = startMathSatOnline' logic conf
startMathSatOnline' :: String -> SolverConfig -> IO Solver
startMathSatOnline' logic conf = do
process <- beginProcess (path conf) (args conf)
onlineSetOption process (OptPrintSuccess True)
onlineSetLogic process (N logic)
return $ onlineSolver process
startMathSatScript :: String -> Maybe SolverConfig -> Maybe FilePath -> IO Solver
startMathSatScript logic Nothing Nothing =
startMathSatScript' logic mathSatConfigScript "temp.smt2"
startMathSatScript logic (Just conf) Nothing =
startMathSatScript' logic conf "temp.smt2"
startMathSatScript logic Nothing (Just scriptFilePath) =
startMathSatScript' logic mathSatConfigScript scriptFilePath
startMathSatScript logic (Just conf) (Just scriptFilePath) =
startMathSatScript' logic conf scriptFilePath
startMathSatScript' :: String -> SolverConfig -> FilePath -> IO Solver
startMathSatScript' 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
}
startMathSatBatch :: String -> Maybe SolverConfig -> IO Solver
startMathSatBatch logic Nothing = startMathSatBatch' logic mathSatConfigBatch
startMathSatBatch logic (Just conf) = startMathSatBatch' logic conf
startMathSatBatch' :: String -> SolverConfig -> IO Solver
startMathSatBatch' 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}