module Language.Fixpoint.Smt.Bitvector
(
Bv (..)
, BvSize (..)
, BvOp (..)
, mkSort
, eOp
, bvTyCon
) where
import Data.Generics (Data)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Language.Fixpoint.Types.Names
import Language.Fixpoint.Types
data Bv = Bv !BvSize !String
data BvSize = S32 | S64
deriving (Eq, Ord, Show, Data, Typeable, Generic)
data BvOp = BvAnd | BvOr
deriving (Eq, Ord, Show, Data, Typeable, Generic)
mkSort :: BvSize -> Sort
mkSort s = fApp (fTyconSort bvTyCon) [ fTyconSort (sizeTyCon s) ]
bvTyCon :: FTycon
bvTyCon = symbolFTycon $ dummyLoc bitVecName
sizeTyCon :: BvSize -> FTycon
sizeTyCon = symbolFTycon . dummyLoc . sizeName
sizeName :: BvSize -> Symbol
sizeName S32 = size32Name
sizeName S64 = size64Name
instance Expression Bv where
expr (Bv sz v) = ECon $ L (T.pack v) (mkSort sz)
eOp :: BvOp -> [Expr] -> Expr
eOp b es = foldl EApp (EVar $ opName b) es
opName :: BvOp -> Symbol
opName BvAnd = bvAndName
opName BvOr = bvOrName