sbv-7.3: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Copyright(c) Brian Huffman
LicenseBSD3
Maintainererkokl@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Data.SBV.Dynamic

Contents

Description

Dynamically typed low-level API to the SBV library, for users who want to generate symbolic values at run-time. Note that with this API it is possible to create terms that are not type correct; use at your own risk!

Synopsis

Programming with symbolic values

Symbolic types

Abstract symbolic value type

data SVal #

The Symbolic value. Either a constant (Left) or a symbolic value (Right Cached). Note that caching is essential for making sure sharing is preserved.

Instances

Eq SVal #

Equality constraint on SBV values. Not desirable since we can't really compare two symbolic values, but will do.

Methods

(==) :: SVal -> SVal -> Bool #

(/=) :: SVal -> SVal -> Bool #

Show SVal # 

Methods

showsPrec :: Int -> SVal -> ShowS #

show :: SVal -> String #

showList :: [SVal] -> ShowS #

NFData SVal # 

Methods

rnf :: SVal -> () #

HasKind SVal # 

class HasKind a where #

A class for capturing values that have a sign and a size (finite or infinite) minimal complete definition: kindOf. This class can be automatically derived for data-types that have a Data instance; this is useful for creating uninterpreted sorts.

Methods

kindOf :: a -> Kind #

hasSign :: a -> Bool #

intSizeOf :: a -> Int #

isBoolean :: a -> Bool #

isBounded :: a -> Bool #

isReal :: a -> Bool #

isFloat :: a -> Bool #

isDouble :: a -> Bool #

isInteger :: a -> Bool #

isUninterpreted :: a -> Bool #

showType :: a -> String #

kindOf :: (Read a, Data a) => a -> Kind #

Instances

HasKind Bool # 
HasKind Double # 
HasKind Float # 
HasKind Int8 # 
HasKind Int16 # 
HasKind Int32 # 
HasKind Int64 # 
HasKind Integer # 
HasKind Word8 # 
HasKind Word16 # 
HasKind Word32 # 
HasKind Word64 # 
HasKind AlgReal # 
HasKind Kind # 
HasKind ExtCW #

Kind instance for Extended CW

HasKind GeneralizedCW #

Kind instance for generalized CW

HasKind CW #

Kind instance for CW

HasKind RoundingMode #

RoundingMode kind

HasKind SVal # 
HasKind SW # 
HasKind E # 
HasKind Word4 #

HasKind instance; simply returning the underlying kind for the type

HasKind Color # 
HasKind Nationality # 
HasKind Beverage # 
HasKind Pet # 
HasKind Sport # 
HasKind U2Member # 
HasKind Location # 
HasKind Day # 
HasKind BinOp # 
HasKind UnOp # 
HasKind B # 
HasKind Q # 
HasKind L #

Similarly, HasKinds default implementation is sufficient.

HasKind (SBV a) # 

Methods

kindOf :: SBV a -> Kind #

hasSign :: SBV a -> Bool #

intSizeOf :: SBV a -> Int #

isBoolean :: SBV a -> Bool #

isBounded :: SBV a -> Bool #

isReal :: SBV a -> Bool #

isFloat :: SBV a -> Bool #

isDouble :: SBV a -> Bool #

isInteger :: SBV a -> Bool #

isUninterpreted :: SBV a -> Bool #

showType :: SBV a -> String #

data Kind #

Kind of symbolic value

Instances

Eq Kind #

We want to equate user-sorts only by name

Methods

(==) :: Kind -> Kind -> Bool #

(/=) :: Kind -> Kind -> Bool #

Ord Kind #

We want to order user-sorts only by name

Methods

compare :: Kind -> Kind -> Ordering #

(<) :: Kind -> Kind -> Bool #

(<=) :: Kind -> Kind -> Bool #

(>) :: Kind -> Kind -> Bool #

(>=) :: Kind -> Kind -> Bool #

max :: Kind -> Kind -> Kind #

min :: Kind -> Kind -> Kind #

Show Kind # 

Methods

showsPrec :: Int -> Kind -> ShowS #

show :: Kind -> String #

showList :: [Kind] -> ShowS #

HasKind Kind # 

data CW #

CW represents a concrete word of a fixed size: Endianness is mostly irrelevant (see the FromBits class). For signed words, the most significant digit is considered to be the sign.

Constructors

CW 

Fields

Instances

Eq CW # 

Methods

(==) :: CW -> CW -> Bool #

(/=) :: CW -> CW -> Bool #

Ord CW # 

Methods

compare :: CW -> CW -> Ordering #

(<) :: CW -> CW -> Bool #

(<=) :: CW -> CW -> Bool #

(>) :: CW -> CW -> Bool #

(>=) :: CW -> CW -> Bool #

max :: CW -> CW -> CW #

min :: CW -> CW -> CW #

Show CW #

Show instance for CW.

Methods

showsPrec :: Int -> CW -> ShowS #

show :: CW -> String #

showList :: [CW] -> ShowS #

HasKind CW #

Kind instance for CW

PrettyNum CW # 

Methods

hexS :: CW -> String #

binS :: CW -> String #

hex :: CW -> String #

bin :: CW -> String #

SatModel CW #

CW as extracted from a model; trivial definition

Methods

parseCWs :: [CW] -> Maybe (CW, [CW]) #

cvtModel :: (CW -> Maybe b) -> Maybe (CW, [CW]) -> Maybe (b, [CW]) #

SDivisible CW # 

Methods

sQuotRem :: CW -> CW -> (CW, CW) #

sDivMod :: CW -> CW -> (CW, CW) #

sQuot :: CW -> CW -> CW #

sRem :: CW -> CW -> CW #

sDiv :: CW -> CW -> CW #

sMod :: CW -> CW -> CW #

data CWVal #

A constant value

Constructors

CWAlgReal !AlgReal

algebraic real

CWInteger !Integer

bit-vector/unbounded integer

CWFloat !Float

float

CWDouble !Double

double

CWUserSort !(Maybe Int, String)

value of an uninterpreted/user kind. The Maybe Int shows index position for enumerations

Instances

Eq CWVal #

Eq instance for CWVal. Note that we cannot simply derive Eq/Ord, since CWAlgReal doesn't have proper instances for these when values are infinitely precise reals. However, we do need a structural eq/ord for Map indexes; so define custom ones here:

Methods

(==) :: CWVal -> CWVal -> Bool #

(/=) :: CWVal -> CWVal -> Bool #

Ord CWVal #

Ord instance for CWVal. Same comments as the Eq instance why this cannot be derived.

Methods

compare :: CWVal -> CWVal -> Ordering #

(<) :: CWVal -> CWVal -> Bool #

(<=) :: CWVal -> CWVal -> Bool #

(>) :: CWVal -> CWVal -> Bool #

(>=) :: CWVal -> CWVal -> Bool #

max :: CWVal -> CWVal -> CWVal #

min :: CWVal -> CWVal -> CWVal #

cwToBool :: CW -> Bool #

Convert a CW to a Haskell boolean (NB. Assumes input is well-kinded)

Arrays of symbolic values

data SArr #

Arrays implemented in terms of SMT-arrays: http://smtlib.cs.uiowa.edu/theories-ArraysEx.shtml

  • Maps directly to SMT-lib arrays
  • Reading from an unintialized value is OK and yields an unspecified result
  • Can check for equality of these arrays
  • Cannot quick-check theorems using SArr values
  • Typically slower as it heavily relies on SMT-solving for the array theory

readSArr :: SArr -> SVal -> SVal #

Read the array element at a

writeSArr :: SArr -> SVal -> SVal -> SArr #

Update the element at a to be b

mergeSArr :: SVal -> SArr -> SArr -> SArr #

Merge two given arrays on the symbolic condition Intuitively: mergeArrays cond a b = if cond then a else b. Merging pushes the if-then-else choice down on to elements

newSArr :: (Kind, Kind) -> (Int -> String) -> Symbolic SArr #

Create a named new array, with an optional initial value

eqSArr :: SArr -> SArr -> SVal #

Compare two arrays for equality

Creating a symbolic variable

data Symbolic a #

A Symbolic computation. Represented by a reader monad carrying the state of the computation, layered on top of IO for creating unique references to hold onto intermediate results.

Instances

Monad Symbolic # 

Methods

(>>=) :: Symbolic a -> (a -> Symbolic b) -> Symbolic b #

(>>) :: Symbolic a -> Symbolic b -> Symbolic b #

return :: a -> Symbolic a #

fail :: String -> Symbolic a #

Functor Symbolic # 

Methods

fmap :: (a -> b) -> Symbolic a -> Symbolic b #

(<$) :: a -> Symbolic b -> Symbolic a #

Applicative Symbolic # 

Methods

pure :: a -> Symbolic a #

(<*>) :: Symbolic (a -> b) -> Symbolic a -> Symbolic b #

(*>) :: Symbolic a -> Symbolic b -> Symbolic b #

(<*) :: Symbolic a -> Symbolic b -> Symbolic a #

MonadIO Symbolic # 

Methods

liftIO :: IO a -> Symbolic a #

Provable Predicate # 
MonadReader State Symbolic # 

Methods

ask :: Symbolic State #

local :: (State -> State) -> Symbolic a -> Symbolic a #

reader :: (State -> a) -> Symbolic a #

NFData a => SExecutable (Symbolic a) # 

data Quantifier #

Quantifiers: forall or exists. Note that we allow arbitrary nestings.

Constructors

ALL 
EX 

Instances

svMkSymVar :: Maybe Quantifier -> Kind -> Maybe String -> State -> IO SVal #

Create a symbolic value, based on the quantifier we have. If an explicit quantifier is given, we just use that. If not, then we pick the quantifier appropriately based on the run-mode. randomCW is used for generating random values for this variable when used for quickCheck or genTest purposes.

Operations on symbolic values

Boolean literals

svTrue :: SVal #

Boolean True.

svFalse :: SVal #

Boolean False.

svBool :: Bool -> SVal #

Convert from a Boolean.

svAsBool :: SVal -> Maybe Bool #

Extract a bool, by properly interpreting the integer stored.

Integer literals

svInteger :: Kind -> Integer -> SVal #

Convert from an Integer.

svAsInteger :: SVal -> Maybe Integer #

Extract an integer from a concrete value.

Float literals

svFloat :: Float -> SVal #

Convert from a Float

svDouble :: Double -> SVal #

Convert from a Float

Algebraic reals (only from rationals)

svReal :: Rational -> SVal #

Convert from a Rational

svNumerator :: SVal -> Maybe Integer #

Grab the numerator of an SReal, if available

svDenominator :: SVal -> Maybe Integer #

Grab the denominator of an SReal, if available

Symbolic equality

svEqual :: SVal -> SVal -> SVal #

Equality.

svNotEqual :: SVal -> SVal -> SVal #

Inequality.

Constructing concrete lists

svEnumFromThenTo :: SVal -> Maybe SVal -> SVal -> Maybe [SVal] #

Constructing [x, y, .. z] and [x .. y]. Only works when all arguments are concrete and integral and the result is guaranteed finite Note that the it isn't "obviously" clear why the following works; after all we're doing the construction over Integer's and mapping it back to other types such as SIntN/SWordN. The reason is that the values we receive are guaranteed to be in their domains; and thus the lifting to Integers preserves the bounds; and then going back is just fine. So, things like [1, 5 .. 200] :: [SInt8] work just fine (end evaluate to empty list), since we see [1, 5 .. -56] in the Integer domain. Also note the explicit check for s /= f below to make sure we don't stutter and produce an infinite list.

Symbolic ordering

svLessThan :: SVal -> SVal -> SVal #

Less than.

svGreaterThan :: SVal -> SVal -> SVal #

Greater than.

svLessEq :: SVal -> SVal -> SVal #

Less than or equal to.

svGreaterEq :: SVal -> SVal -> SVal #

Greater than or equal to.

Arithmetic operations

svPlus :: SVal -> SVal -> SVal #

Addition.

svTimes :: SVal -> SVal -> SVal #

Multiplication.

svMinus :: SVal -> SVal -> SVal #

Subtraction.

svUNeg :: SVal -> SVal #

Unary minus.

svAbs :: SVal -> SVal #

Absolute value.

svDivide :: SVal -> SVal -> SVal #

Division.

svQuot :: SVal -> SVal -> SVal #

Quotient: Overloaded operation whose meaning depends on the kind at which it is used: For unbounded integers, it corresponds to the SMT-Lib "div" operator (Euclidean division, which always has a non-negative remainder). For unsigned bitvectors, it is "bvudiv"; and for signed bitvectors it is "bvsdiv", which rounds toward zero. Division by 0 is defined s.t. x/0 = 0, which holds even when x itself is 0.

svRem :: SVal -> SVal -> SVal #

Remainder: Overloaded operation whose meaning depends on the kind at which it is used: For unbounded integers, it corresponds to the SMT-Lib "mod" operator (always non-negative). For unsigned bitvectors, it is "bvurem"; and for signed bitvectors it is "bvsrem", which rounds toward zero (sign of remainder matches that of x). Division by 0 is defined s.t. x/0 = 0, which holds even when x itself is 0.

svQuotRem :: SVal -> SVal -> (SVal, SVal) #

Combination of quot and rem

svExp :: SVal -> SVal -> SVal #

Exponentiation.

svAddConstant :: Integral a => SVal -> a -> SVal #

Add a constant value:

svIncrement :: SVal -> SVal #

Increment:

svDecrement :: SVal -> SVal #

Decrement:

Logical operations

svAnd :: SVal -> SVal -> SVal #

Bitwise and.

svOr :: SVal -> SVal -> SVal #

Bitwise or.

svXOr :: SVal -> SVal -> SVal #

Bitwise xor.

svNot :: SVal -> SVal #

Bitwise complement.

svShl :: SVal -> Int -> SVal #

Shift left by a constant amount. Translates to the "bvshl" operation in SMT-Lib.

svShr :: SVal -> Int -> SVal #

Shift right by a constant amount. Translates to either "bvlshr" (logical shift right) or "bvashr" (arithmetic shift right) in SMT-Lib, depending on whether x is a signed bitvector.

svRol :: SVal -> Int -> SVal #

Rotate-left, by a constant

svRor :: SVal -> Int -> SVal #

Rotate-right, by a constant

Splitting, joining, and extending

svExtract :: Int -> Int -> SVal -> SVal #

Extract bit-sequences.

svJoin :: SVal -> SVal -> SVal #

Join two words, by concataneting

Sign-casting

svSign :: SVal -> SVal #

Convert a symbolic bitvector from unsigned to signed.

svUnsign :: SVal -> SVal #

Convert a symbolic bitvector from signed to unsigned.

Numeric conversions

svFromIntegral :: Kind -> SVal -> SVal #

Convert a symbolic bitvector from one integral kind to another.

Indexed lookups

svSelect :: [SVal] -> SVal -> SVal -> SVal #

Total indexing operation. svSelect xs default index is intuitively the same as xs !! index, except it evaluates to default if index overflows. Translates to SMT-Lib tables.

Word-level operations

svToWord1 :: SVal -> SVal #

Convert an SVal from kind Bool to an unsigned bitvector of size 1.

svFromWord1 :: SVal -> SVal #

Convert an SVal from a bitvector of size 1 (signed or unsigned) to kind Bool.

svTestBit :: SVal -> Int -> SVal #

Test the value of a bit. Note that we do an extract here as opposed to masking and checking against zero, as we found extraction to be much faster with large bit-vectors.

svSetBit :: SVal -> Int -> SVal #

Set a given bit at index

svShiftLeft :: SVal -> SVal -> SVal #

Generalization of svShl, where the shift-amount is symbolic.

svShiftRight :: SVal -> SVal -> SVal #

Generalization of svShr, where the shift-amount is symbolic.

NB. If the shiftee is signed, then this is an arithmetic shift; otherwise it's logical.

svRotateLeft :: SVal -> SVal -> SVal #

Generalization of svRol, where the rotation amount is symbolic. If the first argument is not bounded, then the this is the same as shift.

svRotateRight :: SVal -> SVal -> SVal #

Generalization of svRor, where the rotation amount is symbolic. If the first argument is not bounded, then the this is the same as shift.

svWordFromBE :: [SVal] -> SVal #

Un-bit-blast from little-endian representation to a word of the right size. The input is assumed to be unsigned.

svWordFromLE :: [SVal] -> SVal #

Un-bit-blast from big-endian representation to a word of the right size. The input is assumed to be unsigned.

svBlastLE :: SVal -> [SVal] #

Bit-blast: Little-endian. Assumes the input is a bit-vector.

svBlastBE :: SVal -> [SVal] #

Bit-blast: Big-endian. Assumes the input is a bit-vector.

Conditionals: Mergeable values

svIte :: SVal -> SVal -> SVal -> SVal #

If-then-else. This one will force branches.

svLazyIte :: Kind -> SVal -> SVal -> SVal -> SVal #

Lazy If-then-else. This one will delay forcing the branches unless it's really necessary.

svSymbolicMerge :: Kind -> Bool -> SVal -> SVal -> SVal -> SVal #

Merge two symbolic values, at kind k, possibly force'ing the branches to make sure they do not evaluate to the same result.

Uninterpreted sorts, constants, and functions

svUninterpreted :: Kind -> String -> Maybe [String] -> [SVal] -> SVal #

Uninterpreted constants and functions. An uninterpreted constant is a value that is indexed by its name. The only property the prover assumes about these values are that they are equivalent to themselves; i.e., (for functions) they return the same results when applied to same arguments. We support uninterpreted-functions as a general means of black-box'ing operations that are irrelevant for the purposes of the proof; i.e., when the proofs can be performed without any knowledge about the function itself.

Properties, proofs, and satisfiability

Proving properties

proveWith :: SMTConfig -> Symbolic SVal -> IO ThmResult #

Proves the predicate using the given SMT-solver

Checking satisfiability

satWith :: SMTConfig -> Symbolic SVal -> IO SatResult #

Find a satisfying assignment using the given SMT-solver

allSatWith :: SMTConfig -> Symbolic SVal -> IO AllSatResult #

Find all satisfying assignments using the given SMT-solver

Checking safety

safeWith :: SMTConfig -> Symbolic SVal -> IO [SafeResult] #

Check safety using the given SMT-solver

Proving properties using multiple solvers

proveWithAll :: [SMTConfig] -> Symbolic SVal -> IO [(Solver, NominalDiffTime, ThmResult)] #

Prove a property with multiple solvers, running them in separate threads. The results will be returned in the order produced.

proveWithAny :: [SMTConfig] -> Symbolic SVal -> IO (Solver, NominalDiffTime, ThmResult) #

Prove a property with multiple solvers, running them in separate threads. Only the result of the first one to finish will be returned, remaining threads will be killed.

satWithAll :: [SMTConfig] -> Symbolic SVal -> IO [(Solver, NominalDiffTime, SatResult)] #

Find a satisfying assignment to a property with multiple solvers, running them in separate threads. The results will be returned in the order produced.

satWithAny :: [SMTConfig] -> Symbolic SVal -> IO (Solver, NominalDiffTime, SatResult) #

Find a satisfying assignment to a property with multiple solvers, running them in separate threads. Only the result of the first one to finish will be returned, remaining threads will be killed.

Quick-check

svQuickCheck :: Symbolic SVal -> IO Bool #

Dynamic variant of quick-check

Model extraction

Inspecting proof results

newtype AllSatResult #

An allSat call results in a AllSatResult. The first boolean says whether we hit the max-model limit as we searched. The second boolean says whether there were prefix-existentials.

Constructors

AllSatResult (Bool, Bool, [SMTResult]) 

newtype SafeResult #

A safe call results in a SafeResult

data OptimizeResult #

An optimize call results in a OptimizeResult. In the ParetoResult case, the boolean is True if we reached pareto-query limit and so there might be more unqueried results remaining. If False, it means that we have all the pareto fronts returned. See the Pareto OptimizeStyle for details.

data SMTResult #

The result of an SMT solver call. Each constructor is tagged with the SMTConfig that created it so that further tools can inspect it and build layers of results, if needed. For ordinary uses of the library, this type should not be needed, instead use the accessor functions on it. (Custom Show instances and model extractors.)

Constructors

Unsatisfiable SMTConfig

Unsatisfiable

Satisfiable SMTConfig SMTModel

Satisfiable with model

SatExtField SMTConfig SMTModel

Prover returned a model, but in an extension field containing Infinite/epsilon

Unknown SMTConfig String

Prover returned unknown, with the given reason

ProofError SMTConfig [String]

Prover errored out

Programmable model extraction

genParse :: Integral a => Kind -> [CW] -> Maybe (a, [CW]) #

Parse a signed/sized value from a sequence of CWs

getModelAssignment :: SMTResult -> Either String (Bool, [CW]) #

Extract a model, the result is a tuple where the first argument (if True) indicates whether the model was "probable". (i.e., if the solver returned unknown.)

getModelDictionary :: SMTResult -> Map String CW #

Extract a model dictionary. Extract a dictionary mapping the variables to their respective values as returned by the SMT solver. Also see getModelDictionaries.

SMT Interface: Configurations and solvers

data SMTConfig #

Solver configuration. See also z3, yices, cvc4, boolector, mathSAT, etc. which are instantiations of this type for those solvers, with reasonable defaults. In particular, custom configuration can be created by varying those values. (Such as z3{verbose=True}.)

Most fields are self explanatory. The notion of precision for printing algebraic reals stems from the fact that such values does not necessarily have finite decimal representations, and hence we have to stop printing at some depth. It is important to emphasize that such values always have infinite precision internally. The issue is merely with how we print such an infinite precision value on the screen. The field printRealPrec controls the printing precision, by specifying the number of digits after the decimal point. The default value is 16, but it can be set to any positive integer.

When printing, SBV will add the suffix ... at the and of a real-value, if the given bound is not sufficient to represent the real-value exactly. Otherwise, the number will be written out in standard decimal notation. Note that SBV will always print the whole value if it is precise (i.e., if it fits in a finite number of digits), regardless of the precision limit. The limit only applies if the representation of the real value is not finite, i.e., if it is not rational.

The printBase field can be used to print numbers in base 2, 10, or 16. If base 2 or 16 is used, then floating-point values will be printed in their internal memory-layout format as well, which can come in handy for bit-precise analysis.

Constructors

SMTConfig 

Fields

Instances

NFData SMTConfig # 

Methods

rnf :: SMTConfig -> () #

data SMTLibVersion #

Representation of SMTLib Program versions. As of June 2015, we're dropping support for SMTLib1, and supporting SMTLib2 only. We keep this data-type around in case SMTLib3 comes along and we want to support 2 and 3 simultaneously.

Constructors

SMTLib2 

data Solver #

Solvers that SBV is aware of

Constructors

Z3 
Yices 
Boolector 
CVC4 
MathSAT 
ABC 

data SMTSolver #

An SMT solver

Constructors

SMTSolver 

Fields

boolector :: SMTConfig #

Default configuration for the Boolector SMT solver

cvc4 :: SMTConfig #

Default configuration for the CVC4 SMT Solver.

yices :: SMTConfig #

Default configuration for the Yices SMT Solver.

z3 :: SMTConfig #

Default configuration for the Z3 SMT solver

mathSAT :: SMTConfig #

Default configuration for the MathSAT SMT solver

abc :: SMTConfig #

Default configuration for the ABC synthesis and verification tool.

defaultSolverConfig :: Solver -> SMTConfig #

The default configs corresponding to supported SMT solvers

defaultSMTCfg :: SMTConfig #

The default solver used by SBV. This is currently set to z3.

sbvCheckSolverInstallation :: SMTConfig -> IO Bool #

Check whether the given solver is installed and is ready to go. This call does a simple call to the solver to ensure all is well.

sbvAvailableSolvers :: IO [SMTConfig] #

Return the known available solver configs, installed on your machine.

Symbolic computations

outputSVal :: SVal -> Symbolic () #

Mark an interim result as an output. Useful when constructing Symbolic programs that return multiple values, or when the result is programmatically computed.

Code generation from symbolic programs

data SBVCodeGen a #

The code-generation monad. Allows for precise layout of input values reference parameters (for returning composite values in languages such as C), and return values.

Setting code-generation options

cgPerformRTCs :: Bool -> SBVCodeGen () #

Sets RTC (run-time-checks) for index-out-of-bounds, shift-with-large value etc. on/off. Default: False.

cgSetDriverValues :: [Integer] -> SBVCodeGen () #

Sets driver program run time values, useful for generating programs with fixed drivers for testing. Default: None, i.e., use random values.

cgGenerateDriver :: Bool -> SBVCodeGen () #

Should we generate a driver program? Default: True. When a library is generated, it will have a driver if any of the contituent functions has a driver. (See compileToCLib.)

cgGenerateMakefile :: Bool -> SBVCodeGen () #

Should we generate a Makefile? Default: True.

Designating inputs

svCgInput :: Kind -> String -> SBVCodeGen SVal #

Creates an atomic input in the generated code.

svCgInputArr :: Kind -> Int -> String -> SBVCodeGen [SVal] #

Creates an array input in the generated code.

Designating outputs

svCgOutput :: String -> SVal -> SBVCodeGen () #

Creates an atomic output in the generated code.

svCgOutputArr :: String -> [SVal] -> SBVCodeGen () #

Creates an array output in the generated code.

Designating return values

svCgReturn :: SVal -> SBVCodeGen () #

Creates a returned (unnamed) value in the generated code.

svCgReturnArr :: [SVal] -> SBVCodeGen () #

Creates a returned (unnamed) array value in the generated code.

Code generation with uninterpreted functions

cgAddPrototype :: [String] -> SBVCodeGen () #

Adds the given lines to the header file generated, useful for generating programs with uninterpreted functions.

cgAddDecl :: [String] -> SBVCodeGen () #

Adds the given lines to the program file generated, useful for generating programs with uninterpreted functions.

cgAddLDFlags :: [String] -> SBVCodeGen () #

Adds the given words to the compiler options in the generated Makefile, useful for linking extra stuff in.

cgIgnoreSAssert :: Bool -> SBVCodeGen () #

Ignore assertions (those generated by sAssert calls) in the generated C code

Code generation with SInteger and SReal types

cgIntegerSize :: Int -> SBVCodeGen () #

Sets number of bits to be used for representing the SInteger type in the generated C code. The argument must be one of 8, 16, 32, or 64. Note that this is essentially unsafe as the semantics of unbounded Haskell integers becomes reduced to the corresponding bit size, as typical in most C implementations.

cgSRealType :: CgSRealType -> SBVCodeGen () #

Sets the C type to be used for representing the SReal type in the generated C code. The setting can be one of C's "float", "double", or "long double", types, depending on the precision needed. Note that this is essentially unsafe as the semantics of infinite precision SReal values becomes reduced to the corresponding floating point type in C, and hence it is subject to rounding errors.

data CgSRealType #

Possible mappings for the SReal type when translated to C. Used in conjunction with the function cgSRealType. Note that the particular characteristics of the mapped types depend on the platform and the compiler used for compiling the generated C program. See http://en.wikipedia.org/wiki/C_data_types for details.

Constructors

CgFloat
float
CgDouble
double
CgLongDouble
long double

Compilation to C

compileToC :: Maybe FilePath -> String -> SBVCodeGen () -> IO () #

Given a symbolic computation, render it as an equivalent collection of files that make up a C program:

  • The first argument is the directory name under which the files will be saved. To save files in the current directory pass Just ".". Use Nothing for printing to stdout.
  • The second argument is the name of the C function to generate.
  • The final argument is the function to be compiled.

Compilation will also generate a Makefile, a header file, and a driver (test) program, etc.

compileToCLib :: Maybe FilePath -> String -> [(String, SBVCodeGen ())] -> IO () #

Create code to generate a library archive (.a) from given symbolic functions. Useful when generating code from multiple functions that work together as a library.

  • The first argument is the directory name under which the files will be saved. To save files in the current directory pass Just ".". Use Nothing for printing to stdout.
  • The second argument is the name of the archive to generate.
  • The third argument is the list of functions to include, in the form of function-name/code pairs, similar to the second and third arguments of compileToC, except in a list.

Compilation to SMTLib

generateSMTBenchmark :: Bool -> Symbolic SVal -> IO String #

Create SMT-Lib benchmarks. The first argument is the basename of the file, we will automatically add ".smt2" per SMT-Lib2 convention. The Bool argument controls whether this is a SAT instance, i.e., translate the query directly, or a PROVE instance, i.e., translate the negated query.