hasmtlib-2.7.1: A monad for interfacing with external SMT solvers
Safe HaskellSafe-Inferred
LanguageGHC2021

Language.Hasmtlib.Type.Bitvec

Description

This module provides the type-level length-indexed and MSB-first bitvector Bitvec built on top of the package bitvec and Vector.

It also holds it's type of encoding as a phantom-type via BvEnc.

Examples

Expand
>>> minBound @(Bitvec Unsigned 8)
00000000
>>> maxBound @(Bitvec Signed 8)
01111111
>>> (5 :: Bitvec Unsigned 4) + 10
1111
Synopsis

Bitvector encoding

data BvEnc Source #

Type of Bitvector encoding - used as promoted type (data-kind).

Constructors

Unsigned 
Signed 

Instances

Instances details
Show BvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

showsPrec :: Int -> BvEnc -> ShowS #

show :: BvEnc -> String #

showList :: [BvEnc] -> ShowS #

Eq BvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

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

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

Ord BvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

compare :: BvEnc -> BvEnc -> Ordering #

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

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

(>) :: BvEnc -> BvEnc -> Bool #

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

max :: BvEnc -> BvEnc -> BvEnc #

min :: BvEnc -> BvEnc -> BvEnc #

GCompare SBvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

gcompare :: forall (a :: k) (b :: k). SBvEnc a -> SBvEnc b -> GOrdering a b #

GEq SBvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

geq :: forall (a :: k) (b :: k). SBvEnc a -> SBvEnc b -> Maybe (a :~: b) #

data SBvEnc (enc :: BvEnc) where Source #

Singleton for BvEnc.

Instances

Instances details
GCompare SBvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

gcompare :: forall (a :: k) (b :: k). SBvEnc a -> SBvEnc b -> GOrdering a b #

GEq SBvEnc Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

geq :: forall (a :: k) (b :: k). SBvEnc a -> SBvEnc b -> Maybe (a :~: b) #

Show (SBvEnc enc) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

showsPrec :: Int -> SBvEnc enc -> ShowS #

show :: SBvEnc enc -> String #

showList :: [SBvEnc enc] -> ShowS #

Eq (SBvEnc enc) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

(==) :: SBvEnc enc -> SBvEnc enc -> Bool #

(/=) :: SBvEnc enc -> SBvEnc enc -> Bool #

Ord (SBvEnc enc) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

compare :: SBvEnc enc -> SBvEnc enc -> Ordering #

(<) :: SBvEnc enc -> SBvEnc enc -> Bool #

(<=) :: SBvEnc enc -> SBvEnc enc -> Bool #

(>) :: SBvEnc enc -> SBvEnc enc -> Bool #

(>=) :: SBvEnc enc -> SBvEnc enc -> Bool #

max :: SBvEnc enc -> SBvEnc enc -> SBvEnc enc #

min :: SBvEnc enc -> SBvEnc enc -> SBvEnc enc #

class KnownBvEnc (enc :: BvEnc) where Source #

Compute singleton SBvEnc from it's promoted type BvEnc.

Methods

bvEncSing :: SBvEnc enc Source #

Instances

Instances details
KnownBvEnc 'Signed Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

KnownBvEnc 'Unsigned Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

bvEncSing' :: forall enc prxy. KnownBvEnc enc => prxy enc -> SBvEnc enc Source #

Wrapper for bvEncSing which takes a Proxy.

bvEncSing'' :: forall enc a prxy. KnownBvEnc enc => prxy enc a -> SBvEnc enc Source #

Wrapper for bvEncSing which takes a Proxy and some ballast. This is helpful for singing on values of type Bitvec where the ballst is a Nat.

Bitvec type

newtype Bitvec (enc :: BvEnc) (n :: Nat) Source #

Length-indexed bitvector (Vector) carrying a phantom type-level BvEnc.

Most significant bit is first (index 0) for unsigned bitvectors. Signed bitvectors have their sign bit first (index 0) and their most significant bit second (index 1).

Constructors

Bitvec 

Fields

Instances

Instances details
(KnownBvEnc enc, KnownNat n) => Bits (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

(.&.) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

(.|.) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

xor :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

complement :: Bitvec enc n -> Bitvec enc n #

shift :: Bitvec enc n -> Int -> Bitvec enc n #

rotate :: Bitvec enc n -> Int -> Bitvec enc n #

zeroBits :: Bitvec enc n #

bit :: Int -> Bitvec enc n #

setBit :: Bitvec enc n -> Int -> Bitvec enc n #

clearBit :: Bitvec enc n -> Int -> Bitvec enc n #

complementBit :: Bitvec enc n -> Int -> Bitvec enc n #

testBit :: Bitvec enc n -> Int -> Bool #

bitSizeMaybe :: Bitvec enc n -> Maybe Int #

bitSize :: Bitvec enc n -> Int #

isSigned :: Bitvec enc n -> Bool #

shiftL :: Bitvec enc n -> Int -> Bitvec enc n #

unsafeShiftL :: Bitvec enc n -> Int -> Bitvec enc n #

shiftR :: Bitvec enc n -> Int -> Bitvec enc n #

unsafeShiftR :: Bitvec enc n -> Int -> Bitvec enc n #

rotateL :: Bitvec enc n -> Int -> Bitvec enc n #

rotateR :: Bitvec enc n -> Int -> Bitvec enc n #

popCount :: Bitvec enc n -> Int #

(KnownBvEnc enc, KnownNat n) => Bounded (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

minBound :: Bitvec enc n #

maxBound :: Bitvec enc n #

(KnownBvEnc enc, KnownNat n) => Enum (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

succ :: Bitvec enc n -> Bitvec enc n #

pred :: Bitvec enc n -> Bitvec enc n #

toEnum :: Int -> Bitvec enc n #

fromEnum :: Bitvec enc n -> Int #

enumFrom :: Bitvec enc n -> [Bitvec enc n] #

enumFromThen :: Bitvec enc n -> Bitvec enc n -> [Bitvec enc n] #

enumFromTo :: Bitvec enc n -> Bitvec enc n -> [Bitvec enc n] #

enumFromThenTo :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n -> [Bitvec enc n] #

(KnownBvEnc enc, KnownNat n) => Num (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

(+) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

(-) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

(*) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

negate :: Bitvec enc n -> Bitvec enc n #

abs :: Bitvec enc n -> Bitvec enc n #

signum :: Bitvec enc n -> Bitvec enc n #

fromInteger :: Integer -> Bitvec enc n #

(KnownBvEnc enc, KnownNat n) => Integral (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

quot :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

rem :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

div :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

mod :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

quotRem :: Bitvec enc n -> Bitvec enc n -> (Bitvec enc n, Bitvec enc n) #

divMod :: Bitvec enc n -> Bitvec enc n -> (Bitvec enc n, Bitvec enc n) #

toInteger :: Bitvec enc n -> Integer #

(KnownBvEnc enc, KnownNat n) => Real (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

toRational :: Bitvec enc n -> Rational #

Show (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

showsPrec :: Int -> Bitvec enc n -> ShowS #

show :: Bitvec enc n -> String #

showList :: [Bitvec enc n] -> ShowS #

Eq (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

(==) :: Bitvec enc n -> Bitvec enc n -> Bool #

(/=) :: Bitvec enc n -> Bitvec enc n -> Bool #

Ord (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

compare :: Bitvec enc n -> Bitvec enc n -> Ordering #

(<) :: Bitvec enc n -> Bitvec enc n -> Bool #

(<=) :: Bitvec enc n -> Bitvec enc n -> Bool #

(>) :: Bitvec enc n -> Bitvec enc n -> Bool #

(>=) :: Bitvec enc n -> Bitvec enc n -> Bool #

max :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

min :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n #

KnownNat n => Boolean (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Type.Bitvec

Methods

bool :: Bool -> Bitvec enc n Source #

true :: Bitvec enc n Source #

false :: Bitvec enc n Source #

(&&) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

(||) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

(==>) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

(<==) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

(<==>) :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

not :: Bitvec enc n -> Bitvec enc n Source #

xor :: Bitvec enc n -> Bitvec enc n -> Bitvec enc n Source #

Render (Bitvec enc n) Source # 
Instance details

Defined in Language.Hasmtlib.Internal.Render

Methods

render :: Bitvec enc n -> Builder Source #

Construction

bitvecConcat :: Bitvec enc n -> Bitvec enc m -> Bitvec enc (n + m) Source #

Concatenation of two bitvectors.

Conversion

Sign

asUnsigned :: forall enc n. Bitvec enc n -> Bitvec Unsigned n Source #

Convert Bitvec with any encoding BvEnc to Unsigned.

asSigned :: forall enc n. Bitvec enc n -> Bitvec Signed n Source #

Convert Bitvec with any encoding BvEnc to Signed.

Lists

bitvecFromListN :: forall n enc. KnownNat n => [Bit] -> Maybe (Bitvec enc n) Source #

Constructing a bitvector from a list.

bitvecFromListN' :: KnownNat n => Proxy n -> [Bit] -> Maybe (Bitvec enc n) Source #

Constructing a bitvector from a list with length given as Proxy.

Lens

_signBit :: KnownNat (n + 1) => Lens' (Bitvec Signed (n + 1)) Bit Source #

A Lens on the sign-bit of a signed bitvector.