module Hsmtlib.Solvers.Altergo(startAltErgo) 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)
altErgoConfigOnline :: SolverConfig
altErgoConfigOnline =
Config { path = "altergo"
, args = ["-v"]
}
altErgoConfigScript :: SolverConfig
altErgoConfigScript =
Config { path = "altergo"
, args = ["-v"]
}
altErgoConfigBatch :: SolverConfig
altErgoConfigBatch =
Config { path = "altergo"
, args = ["-v"]
}
startAltErgo :: Mode
-> String
-> Maybe SolverConfig
-> Maybe FilePath
-> IO Solver
startAltErgo Slv.Batch logic sConf _ = startAltErgoBatch logic sConf
startAltErgo Slv.Online logic sConf _ = startAltErgoOnline logic sConf
startAltErgo Slv.Script logic sConf scriptFilePath =
startAltErgoScript logic sConf scriptFilePath
startAltErgoOnline :: String -> Maybe SolverConfig -> IO Solver
startAltErgoOnline logic Nothing =
startAltErgoOnline' logic altErgoConfigOnline
startAltErgoOnline logic (Just conf) = startAltErgoOnline' logic conf
startAltErgoOnline' :: String -> SolverConfig -> IO Solver
startAltErgoOnline' logic conf = do
process <- beginProcess (path conf) (args conf)
onlineSetOption process (OptPrintSuccess True)
onlineSetLogic process (N logic)
return $ onlineSolver process
startAltErgoScript :: String -> Maybe SolverConfig -> Maybe FilePath -> IO Solver
startAltErgoScript logic Nothing Nothing =
startAltErgoScript' logic altErgoConfigScript "temp.smt2"
startAltErgoScript logic (Just conf) Nothing =
startAltErgoScript' logic conf "temp.smt2"
startAltErgoScript logic Nothing (Just scriptFilePath) =
startAltErgoScript' logic altErgoConfigScript scriptFilePath
startAltErgoScript logic (Just conf) (Just scriptFilePath) =
startAltErgoScript' logic conf scriptFilePath
startAltErgoScript' :: String -> SolverConfig -> FilePath -> IO Solver
startAltErgoScript' 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
}
startAltErgoBatch :: String -> Maybe SolverConfig -> IO Solver
startAltErgoBatch logic Nothing = startAltErgoBatch' logic altErgoConfigBatch
startAltErgoBatch logic (Just conf) = startAltErgoBatch' logic conf
startAltErgoBatch' :: String -> SolverConfig -> IO Solver
startAltErgoBatch' logic config = return $ batchSolver logic config
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}