blarney-0.1.0.0
Copyright(c) Alexandre Joannou 2020-2021
LicenseMIT
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageGHC2021

Blarney.Backend.SMT.Utils

Description

This module provides basic pretty printing utilities for SMT code generation

Synopsis

general numerical helpers

showAtBase :: (Integral a, Show a) => a -> a -> Doc Source #

pretty print an Integral in a given base

showHex :: (Integral a, Show a) => a -> Doc Source #

pretty print an Integral in hexadecimal

showBin :: (Integral a, Show a) => a -> Doc Source #

pretty print an Integral in binary

formatting helpers

psep :: [Doc] -> Doc Source #

pretty print a whitespace separated list of Doc in parentheses

plist :: [(Doc, Doc)] -> Doc Source #

pretty print a whitespace separated list of parenthesised pairs of Docs in parentheses

applyOp :: Doc -> [Doc] -> Doc Source #

pretty print the application of an operator to a list of arguments

bvHexLit :: Integer -> Doc Source #

pretty print an Integer as an SMT BitVec hexadecimal literal

bvBinLit :: Integer -> Doc Source #

pretty print an Integer as an SMT BitVec binary literal

bvSlice :: Int -> Int -> Doc -> Doc Source #

extract the bitslice from lo to hi from the bv SMT BitVec

bvSortStr :: Int -> String Source #

return a string representing the BitVec SMT sort of the given width n

bvSort :: Int -> Doc Source #

pretty print the BitVec SMT sort of the given width n

int2bv :: Int -> Integer -> Doc Source #

cast the Int sorted SMT value n to a (BitVec w) sorted SMT value

bvIsFalse :: Doc -> Doc Source #

test a (BitVec 1) sorted SMT value for "false"

bvIsTrue :: Doc -> Doc Source #

test a (BitVec 1) sorted SMT value for "true"

bv2Bool :: Doc -> Doc Source #

cast a (BitVec 1) sorted SMT value to a Bool sorted SMT value

bool2bv :: Doc -> Doc Source #

cast a Bool sorted SMT value to a (BitVec 1) sorted SMT value

SMT binders and qualifiers

qualify :: Doc -> Doc -> Doc Source #

wrap the SMT expression expr in the "as" qualifier with the given sort

parBind :: [String] -> Doc -> Doc Source #

wrap the SMT parametric expression expr in the "par" sort parameter binder with the pars list of sort parameters

forallBind :: [(Doc, Doc)] -> Doc -> Doc Source #

wrap an SMT expression in the "forall" universal quantifier with the provided list of pairs of (variable name, sort)

existsBind :: [(Doc, Doc)] -> Doc -> Doc Source #

wrap an SMT expression in the "exists" existential quantifier with the provided list of pairs of (variable name, sort)

matchBind :: Doc -> [(Doc, Doc)] -> Doc Source #

wrap an SMT expression in the "match" binder, pattern matching the SMT expression against each of the patterns provided in the argument list of pairs of (pattern, expression)

letBind :: [(Doc, Doc)] -> Doc -> Doc Source #

wrap an SMT expression in the "let" binder with the provided list of pairs of (variable name, sort)

nestLetBind :: [[(Doc, Doc)]] -> Doc -> Doc Source #

wrap an SMT expression in a sequence of nested "let" binders, each introducing one of the variables provided by the argument list of pairs of (variable name, sort), in the provided order

SMT datatype declarations

declareDataTypes :: [(String, [String], [(String, [String])])] -> Doc Source #

pretty print the declaration of the datatypes provided in the argument list of triples each representing a single datatype: its name, a potentially empty list of parameters, and a non empty list of constructors consisting of a name and a potentially empty list of fields

declareDataType :: String -> [String] -> [(String, [(String, String)])] -> Doc Source #

pretty print the declaration of a single datatype given its name, a potentially empty list of parameters, and a non empty list of constructors consisting of a name and a potentially empty list of fields

SMT function definitions

defineFun :: Doc -> [(Doc, Doc)] -> Doc -> Doc -> Doc Source #

pretty print the definition of a function given its name, a potentially empty list of arguments, a return type and a function body

defineFunRec :: Doc -> [(Doc, Doc)] -> Doc -> Doc -> Doc Source #

pretty print the definition of a recursive function given its name, a potentially empty list of arguments, a return type and a function body

defineFunsRec :: [(String, [(String, String)], String, Doc)] -> Doc Source #

pretty print the definition of the potentially mutually recursive functions provided in the argument list of triples each representing a single potentially recursive function: its name, a potentially empty list of arguments, a return type and a function body