{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module Language.Fixpoint.Types.Config (
Config (..)
, defConfig
, withPragmas
, getOpts
, SMTSolver (..)
, Eliminate (..)
, useElim
, defaultMinPartSize
, defaultMaxPartSize
, multicore
, queryFile
) where
import Data.Serialize (Serialize (..))
import Control.Monad
import GHC.Generics
import System.Console.CmdArgs
import System.Console.CmdArgs.Explicit
import System.Environment
import Language.Fixpoint.Utils.Files
withPragmas :: Config -> [String] -> IO Config
withPragmas = foldM withPragma
withPragma :: Config -> String -> IO Config
withPragma c s = withArgs [s] $ cmdArgsRun
config { modeValue = (modeValue config) { cmdArgsValue = c } }
defaultMinPartSize :: Int
defaultMinPartSize = 500
defaultMaxPartSize :: Int
defaultMaxPartSize = 700
data Config = Config
{ srcFile :: FilePath
, cores :: Maybe Int
, minPartSize :: Int
, maxPartSize :: Int
, solver :: SMTSolver
, linear :: Bool
, stringTheory :: Bool
, defunction :: Bool
, allowHO :: Bool
, allowHOqs :: Bool
, eliminate :: Eliminate
, elimBound :: Maybe Int
, smtTimeout :: Maybe Int
, elimStats :: Bool
, solverStats :: Bool
, metadata :: Bool
, stats :: Bool
, parts :: Bool
, save :: Bool
, minimize :: Bool
, minimizeQs :: Bool
, minimizeKs :: Bool
, minimalSol :: Bool
, etaElim :: Bool
, gradual :: Bool
, ginteractive :: Bool
, autoKuts :: Bool
, nonLinCuts :: Bool
, noslice :: Bool
, rewriteAxioms :: Bool
, oldPLE :: Bool
, noIncrPle :: Bool
, checkCstr :: [Integer]
, extensionality :: Bool
, maxRWOrderingConstraints :: Maybe Int
, rwTerminationCheck :: Bool
} deriving (Eq,Data,Typeable,Show,Generic)
instance Default Config where
def = defConfig
data SMTSolver = Z3 | Cvc4 | Mathsat
deriving (Eq, Data, Typeable, Generic)
instance Default SMTSolver where
def = Z3
instance Show SMTSolver where
show Z3 = "z3"
show Cvc4 = "cvc4"
show Mathsat = "mathsat"
data Eliminate
= None
| Some
| All
| Horn
| Existentials
deriving (Eq, Data, Typeable, Generic)
instance Serialize Eliminate
instance Default Eliminate where
def = None
instance Show Eliminate where
show None = "none"
show Some = "some"
show All = "all"
show Horn = "horn"
show Existentials = "existentials"
useElim :: Config -> Bool
useElim cfg = eliminate cfg /= None
defConfig :: Config
defConfig = Config {
srcFile = "out" &= args &= typFile
, defunction = False &= help "Allow higher order binders into fixpoint environment"
, solver = def &= help "Name of SMT Solver"
, linear = False &= help "Use uninterpreted integer multiplication and division"
, stringTheory = False &= help "Interpretation of String Theory by SMT"
, allowHO = False &= help "Allow higher order binders into fixpoint environment"
, allowHOqs = False &= help "Allow higher order qualifiers"
, eliminate = None &= help "Eliminate KVars [none = quals for all-kvars, cuts = quals for cut-kvars, all = eliminate all-kvars (TRUE for cuts)]"
, elimBound = Nothing &= name "elimBound" &= help "(alpha) Maximum eliminate-chain depth"
, smtTimeout = Nothing &= name "smtTimeout" &= help "smt timeout in msec"
, elimStats = False &= help "(alpha) Print eliminate stats"
, solverStats = False &= help "Print solver stats"
, save = False &= help "Save Query as .fq and .bfq files"
, metadata = False &= help "Print meta-data associated with constraints"
, stats = False &= help "Compute constraint statistics"
, etaElim = False &= help "eta elimination in function definition"
, parts = False &= help "Partition constraints into indepdendent .fq files"
, cores = def &= help "(numeric) Number of threads to use"
, minPartSize = defaultMinPartSize &= help "(numeric) Minimum partition size when solving in parallel"
, maxPartSize = defaultMaxPartSize &= help "(numeric) Maximum partiton size when solving in parallel."
, minimize = False &= help "Delta debug to minimize fq file (unsat with min constraints)"
, minimizeQs = False &= help "Delta debug to minimize fq file (sat with min qualifiers)"
, minimizeKs = False &= help "Delta debug to minimize fq file (sat with max kvars replaced by True)"
, minimalSol = False &= help "Shrink fixpoint by removing implied qualifiers"
, gradual = False &= help "Solve gradual-refinement typing constraints"
, ginteractive = False &= help "Interactive Gradual Solving"
, autoKuts = False &= help "Ignore given Kut vars, compute from scratch"
, nonLinCuts = False &= help "Treat non-linear kvars as cuts"
, noslice = False &= help "Disable non-concrete KVar slicing"
, rewriteAxioms = False &= help "allow axiom instantiation via rewriting"
, oldPLE = False &= help "Use old version of PLE"
, noIncrPle = False &= help "Don't use incremental PLE"
, checkCstr = [] &= help "Only check these specific constraint-ids"
, extensionality = False &= help "Allow extensional interpretation of extensionality"
, maxRWOrderingConstraints = Nothing &= help "Maximum number of functions to consider in rewrite orderings"
, rwTerminationCheck = False &= help "Disable rewrite divergence checker"
}
&= verbosity
&= program "fixpoint"
&= help "Predicate Abstraction Based Horn-Clause Solver"
&= summary "fixpoint Copyright 2009-15 Regents of the University of California."
&= details [ "Predicate Abstraction Based Horn-Clause Solver"
, ""
, "To check a file foo.fq type:"
, " fixpoint foo.fq"
]
config :: Mode (CmdArgs Config)
config = cmdArgsMode defConfig
getOpts :: IO Config
getOpts = do md <- cmdArgs defConfig
putStrLn banner
return md
banner :: String
banner = "\n\nLiquid-Fixpoint Copyright 2013-15 Regents of the University of California.\n"
++ "All Rights Reserved.\n"
multicore :: Config -> Bool
multicore cfg = cores cfg /= Just 1
queryFile :: Ext -> Config -> FilePath
queryFile e = extFileName e . srcFile