{-# LANGUAGE NamedFieldPuns #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Data.SBV.SMT.SMTLib (
SMTLibPgm
, toSMTLib
, toIncSMTLib
) where
import qualified Data.Set as Set (member, toList)
import Data.SBV.Core.Data
import Data.SBV.SMT.Utils
import qualified Data.SBV.SMT.SMTLib2 as SMT2
toSMTLib :: SMTConfig -> SMTLibConverter SMTLibPgm
toSMTLib :: SMTConfig -> SMTLibConverter SMTLibPgm
toSMTLib SMTConfig{SMTLibVersion
smtLibVersion :: SMTConfig -> SMTLibVersion
smtLibVersion :: SMTLibVersion
smtLibVersion} = case SMTLibVersion
smtLibVersion of
SMTLibVersion
SMTLib2 -> SMTLibConverter SMTLibPgm
toSMTLib2
toIncSMTLib :: SMTConfig -> SMTLibIncConverter [String]
toIncSMTLib :: SMTConfig -> SMTLibIncConverter [String]
toIncSMTLib SMTConfig{SMTLibVersion
smtLibVersion :: SMTLibVersion
smtLibVersion :: SMTConfig -> SMTLibVersion
smtLibVersion} = case SMTLibVersion
smtLibVersion of
SMTLibVersion
SMTLib2 -> SMTLibIncConverter [String]
toIncSMTLib2
toSMTLib2 :: SMTLibConverter SMTLibPgm
toSMTLib2 :: SMTLibConverter SMTLibPgm
toSMTLib2 = SMTLibVersion -> SMTLibConverter SMTLibPgm
cvt SMTLibVersion
SMTLib2
where cvt :: SMTLibVersion -> SMTLibConverter SMTLibPgm
cvt SMTLibVersion
v QueryContext
ctx Set Kind
kindInfo Bool
isSat [String]
comments ([(Quantifier, NamedSymVar)], [NamedSymVar])
qinps [Either SV (SV, [SV])]
skolemMap (CnstMap, [(SV, CV)])
consts [((Int, Kind, Kind), [SV])]
tbls [(Int, ArrayInfo)]
arrs [(String, SBVType)]
uis [(Bool, String, [String])]
axs SBVPgm
asgnsSeq Seq (Bool, [(String, String)], SV)
cstrs SV
out SMTConfig
config
| Kind
KUnbounded forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Kind
kindInfo Bool -> Bool -> Bool
&& Bool -> Bool
not (SolverCapabilities -> Bool
supportsUnboundedInts SolverCapabilities
solverCaps)
= forall {a}. String -> a
unsupported String
"unbounded integers"
| Kind
KReal forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Kind
kindInfo Bool -> Bool -> Bool
&& Bool -> Bool
not (SolverCapabilities -> Bool
supportsReals SolverCapabilities
solverCaps)
= forall {a}. String -> a
unsupported String
"algebraic reals"
| (Bool
needsFloats Bool -> Bool -> Bool
|| Bool
needsDoubles) Bool -> Bool -> Bool
&& Bool -> Bool
not (SolverCapabilities -> Bool
supportsIEEE754 SolverCapabilities
solverCaps)
= forall {a}. String -> a
unsupported String
"floating-point numbers"
| Bool
needsQuantifiers Bool -> Bool -> Bool
&& Bool -> Bool
not (SolverCapabilities -> Bool
supportsQuantifiers SolverCapabilities
solverCaps)
= forall {a}. String -> a
unsupported String
"quantifiers"
| Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
sorts) Bool -> Bool -> Bool
&& Bool -> Bool
not (SolverCapabilities -> Bool
supportsUninterpretedSorts SolverCapabilities
solverCaps)
= forall {a}. String -> a
unsupported String
"uninterpreted sorts"
| Bool
True
= SMTLibVersion -> [String] -> SMTLibPgm
SMTLibPgm SMTLibVersion
v [String]
pgm
where sorts :: [String]
sorts = [String
s | KUserSort String
s Maybe [String]
_ <- forall a. Set a -> [a]
Set.toList Set Kind
kindInfo]
solverCaps :: SolverCapabilities
solverCaps = SMTSolver -> SolverCapabilities
capabilities (SMTConfig -> SMTSolver
solver SMTConfig
config)
unsupported :: String -> a
unsupported String
w = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ [String] -> String
unlines [ String
"SBV: Given problem needs " forall a. [a] -> [a] -> [a]
++ String
w
, String
"*** Which is not supported by SBV for the chosen solver: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (SMTSolver -> Solver
name (SMTConfig -> SMTSolver
solver SMTConfig
config))
]
converter :: SMTLibConverter [String]
converter = case SMTLibVersion
v of
SMTLibVersion
SMTLib2 -> SMTLibConverter [String]
SMT2.cvt
pgm :: [String]
pgm = SMTLibConverter [String]
converter QueryContext
ctx Set Kind
kindInfo Bool
isSat [String]
comments ([(Quantifier, NamedSymVar)], [NamedSymVar])
qinps [Either SV (SV, [SV])]
skolemMap (CnstMap, [(SV, CV)])
consts [((Int, Kind, Kind), [SV])]
tbls [(Int, ArrayInfo)]
arrs [(String, SBVType)]
uis [(Bool, String, [String])]
axs SBVPgm
asgnsSeq Seq (Bool, [(String, String)], SV)
cstrs SV
out SMTConfig
config
needsFloats :: Bool
needsFloats = Kind
KFloat forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Kind
kindInfo
needsDoubles :: Bool
needsDoubles = Kind
KDouble forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Kind
kindInfo
needsQuantifiers :: Bool
needsQuantifiers
| Bool
isSat = Quantifier
ALL forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Quantifier]
quantifiers
| Bool
True = Quantifier
EX forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Quantifier]
quantifiers
where quantifiers :: [Quantifier]
quantifiers = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (forall a b. (a, b) -> a
fst ([(Quantifier, NamedSymVar)], [NamedSymVar])
qinps)
toIncSMTLib2 :: SMTLibIncConverter [String]
toIncSMTLib2 :: SMTLibIncConverter [String]
toIncSMTLib2 = SMTLibVersion -> SMTLibIncConverter [String]
cvt SMTLibVersion
SMTLib2
where cvt :: SMTLibVersion -> SMTLibIncConverter [String]
cvt SMTLibVersion
SMTLib2 = SMTLibIncConverter [String]
SMT2.cvtInc