| Copyright | (c) Sirui Lu 2024 |
|---|---|
| License | BSD-3-Clause (see the LICENSE file) |
| Maintainer | siruilu@cs.washington.edu |
| Stability | Experimental |
| Portability | GHC only |
| Safe Haskell | None |
| Language | Haskell2010 |
Grisette.Internal.SymPrim.SomeBV
Description
Synopsis
- data SomeBV (bv :: Nat -> Type) where
- type SomeBVKey (bv :: Nat -> Type) = AsKey (SomeBV bv)
- data SomeBVException
- unsafeSomeBV :: Int -> (forall (proxy :: Nat -> Type) (n :: Nat). (KnownNat n, 1 <= n) => proxy n -> bv n) -> SomeBV bv
- conBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV cbv -> SomeBV bv
- conBVView :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV bv -> Maybe (SomeBV cbv)
- pattern ConBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV cbv -> SomeBV bv
- symBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Symbol -> SomeBV bv
- ssymBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Identifier -> SomeBV bv
- isymBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Identifier -> Int -> SomeBV bv
- arbitraryBV :: forall (bv :: Nat -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Arbitrary (bv n)) => Int -> Gen (SomeBV bv)
- pattern SomeIntN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => IntN n -> SomeIntN
- type SomeIntN = SomeBV IntN
- pattern SomeWordN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => WordN n -> SomeWordN
- type SomeWordN = SomeBV WordN
- pattern SomeSymIntN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymIntN n -> SomeSymIntN
- type SomeSymIntN = SomeBV SymIntN
- pattern SomeSymIntNKey :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymIntN n -> SomeSymIntNKey
- type SomeSymIntNKey = SomeBVKey SymIntN
- pattern SomeSymWordN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymWordN n -> SomeSymWordN
- type SomeSymWordN = SomeBV SymWordN
- pattern SomeSymWordNKey :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymWordN n -> SomeSymWordNKey
- type SomeSymWordNKey = SomeBVKey SymWordN
- unarySomeBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> r) -> (SomeBVLit -> r) -> SomeBV bv -> r
- unarySomeBVR1 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n) -> (SomeBVLit -> SomeBVLit) -> SomeBV bv -> SomeBV bv
- binSomeBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> r) -> (SomeBVLit -> SomeBVLit -> r) -> SomeBV bv -> SomeBV bv -> r
- binSomeBVR1 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> bv n) -> (SomeBVLit -> SomeBVLit -> SomeBVLit) -> SomeBV bv -> SomeBV bv -> SomeBV bv
- binSomeBVR2 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> (bv n, bv n)) -> (SomeBVLit -> SomeBVLit -> (SomeBVLit, SomeBVLit)) -> SomeBV bv -> SomeBV bv -> (SomeBV bv, SomeBV bv)
- binSomeBVSafe :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, Mergeable r, forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m r) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m r) -> SomeBV bv -> SomeBV bv -> m r
- binSomeBVSafeR1 :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, forall (n :: Nat). (KnownNat n, 1 <= n) => Mergeable (bv n), forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m (bv n)) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m SomeBVLit) -> SomeBV bv -> SomeBV bv -> m (SomeBV bv)
- binSomeBVSafeR2 :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, forall (n :: Nat). (KnownNat n, 1 <= n) => Mergeable (bv n), forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m (bv n, bv n)) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m (SomeBVLit, SomeBVLit)) -> SomeBV bv -> SomeBV bv -> m (SomeBV bv, SomeBV bv)
Documentation
data SomeBV (bv :: Nat -> Type) where Source #
Non-indexed bitvectors.
The creation of SomeBV can be done with the bv function with a positive
bit width and a value:
>>>bv 4 0xf :: SomeBV IntN0xf
Operations on two SomeBV values require the bitwidths to be the same. So
you should check for the bit width (via finiteBitSize) before performing
operations:
>>>bv 4 0x3 + bv 4 0x3 :: SomeBV IntN0x6>>>bv 4 0x3 + bv 8 0x3 :: SomeBV IntN*** Exception: Bit width does not match ...
One exception is that the equality testing (both concrete and symbolic via
SymEq) does not require the bitwidths to be the same. Different bitwidths
means the values are not equal:
>>>(bv 4 0x3 :: SomeBV IntN) == (bv 8 0x3)False
Note: SomeBV can be constructed out of integer literals without the
bit width provided. Further binary operations will usually require at least
one operand has the bit-width, and will use that as the bit-width for the
result.
For example:
3 :: SomeBV IntN bvlit(3) >>> bv 4 0x1 + 3 :: SomeBV IntN 0x4 >>> 3 * bv 4 0x1 :: SomeBV IntN 0x3 >>> 3 * 3 :: SomeBV IntN *** Exception: Cannot determine bit-width for literals: (*) ...
Some operations allows the literals to be used without the bit-width, such as
(+), (-), negate, toUnsigned, toSigned, .&., .|., xor,
complement, setBit, clearBit, complementBit, shiftL, and
unsafeShiftL.
>>>3 + 3 :: SomeBV IntNbvlit(6)
Constructors
| SomeBV :: forall (n :: Nat) (bv :: Nat -> Type). (KnownNat n, 1 <= n) => bv n -> SomeBV bv | |
| SomeBVLit :: forall (bv :: Nat -> Type). SomeBVLit -> SomeBV bv |
Instances
type SomeBVKey (bv :: Nat -> Type) = AsKey (SomeBV bv) Source #
type with identity equality.SomeBV bv
data SomeBVException Source #
An exception that would be thrown when operations are performed on incompatible bit widths.
Constructors
| BitwidthMismatch | |
| UndeterminedBitwidth Text |
Instances
Constructing and pattern matching on SomeBV
unsafeSomeBV :: Int -> (forall (proxy :: Nat -> Type) (n :: Nat). (KnownNat n, 1 <= n) => proxy n -> bv n) -> SomeBV bv Source #
Construct a SomeBV with a given run-time bitwidth and a polymorphic
value for the underlying bitvector.
conBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV cbv -> SomeBV bv Source #
conBVView :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV bv -> Maybe (SomeBV cbv) Source #
pattern ConBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => SomeBV cbv -> SomeBV bv Source #
symBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Symbol -> SomeBV bv Source #
ssymBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Identifier -> SomeBV bv Source #
isymBV :: forall (cbv :: Natural -> Type) (bv :: Natural -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Solvable (cbv n) (bv n), Solvable (cbv 1) (bv 1)) => Int -> Identifier -> Int -> SomeBV bv Source #
arbitraryBV :: forall (bv :: Nat -> Type). (forall (n :: Nat). (KnownNat n, 1 <= n) => Arbitrary (bv n)) => Int -> Gen (SomeBV bv) Source #
Generate an arbitrary SomeBV with a given run-time bitwidth.
Synonyms
pattern SomeIntN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => IntN n -> SomeIntN Source #
Pattern synonym for SomeBV for concrete signed bitvectors.
pattern SomeWordN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => WordN n -> SomeWordN Source #
Pattern synonym for SomeBV for concrete unsigned bitvectors.
pattern SomeSymIntN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymIntN n -> SomeSymIntN Source #
Pattern synonym for SomeBV for symbolic signed bitvectors.
pattern SomeSymIntNKey :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymIntN n -> SomeSymIntNKey Source #
type SomeSymIntNKey = SomeBVKey SymIntN Source #
SomeSymIntN with identity equality.
pattern SomeSymWordN :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymWordN n -> SomeSymWordN Source #
Pattern synonym for SomeBV for symbolic unsigned bitvectors.
type SomeSymWordN = SomeBV SymWordN Source #
Type synonym for SomeBV for symbolic unsigned bitvectors.
pattern SomeSymWordNKey :: forall (n :: Nat). () => (KnownNat n, 1 <= n) => SymWordN n -> SomeSymWordNKey Source #
type SomeSymWordNKey = SomeBVKey SymWordN Source #
SomeSymWordN with identity equality.
Helpers for manipulating SomeBV
unarySomeBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> r) -> (SomeBVLit -> r) -> SomeBV bv -> r Source #
Lift a unary operation on sized bitvectors that returns anything to
SomeBV.
unarySomeBVR1 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n) -> (SomeBVLit -> SomeBVLit) -> SomeBV bv -> SomeBV bv Source #
binSomeBV :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> r) -> (SomeBVLit -> SomeBVLit -> r) -> SomeBV bv -> SomeBV bv -> r Source #
Lift a binary operation on sized bitvectors that returns anything to
SomeBV. Crash if the bitwidths do not match.
binSomeBVR1 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> bv n) -> (SomeBVLit -> SomeBVLit -> SomeBVLit) -> SomeBV bv -> SomeBV bv -> SomeBV bv Source #
binSomeBVR2 :: (forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> (bv n, bv n)) -> (SomeBVLit -> SomeBVLit -> (SomeBVLit, SomeBVLit)) -> SomeBV bv -> SomeBV bv -> (SomeBV bv, SomeBV bv) Source #
binSomeBVSafe :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, Mergeable r, forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m r) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m r) -> SomeBV bv -> SomeBV bv -> m r Source #
Lift a binary operation on sized bitvectors that returns anything wrapped
with ExceptT to SomeBV. If the bitwidths do not match, throw an
BitwidthMismatch error to the monadic context.
binSomeBVSafeR1 :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, forall (n :: Nat). (KnownNat n, 1 <= n) => Mergeable (bv n), forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m (bv n)) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m SomeBVLit) -> SomeBV bv -> SomeBV bv -> m (SomeBV bv) Source #
Lift a binary operation on sized bitvectors that returns a bitvector
wrapped with ExceptT to SomeBV. The result will also be wrapped with
SomeBV.
If the bitwidths do not match, throw an BitwidthMismatch error to the
monadic context.
binSomeBVSafeR2 :: (MonadError (Either SomeBVException e) m, TryMerge m, Mergeable e, forall (n :: Nat). (KnownNat n, 1 <= n) => Mergeable (bv n), forall (n :: Nat). (KnownNat n, 1 <= n) => Num (bv n), MaySomeBV bv) => (forall (n :: Nat). (KnownNat n, 1 <= n) => bv n -> bv n -> ExceptT e m (bv n, bv n)) -> (SomeBVLit -> SomeBVLit -> ExceptT (Either SomeBVException e) m (SomeBVLit, SomeBVLit)) -> SomeBV bv -> SomeBV bv -> m (SomeBV bv, SomeBV bv) Source #
Lift a binary operation on sized bitvectors that returns two bitvectors
wrapped with ExceptT to SomeBV. The results will also be wrapped with
SomeBV.
If the bitwidths do not match, throw an BitwidthMismatch error to the
monadic context.