Copyright | (c) Galois Inc. 2018 |
---|---|
License | BSD-3 |
Maintainer | benselfridge@galois.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
This module exports a type, BVApp
, to aid in building expression languages over
BitVector
s. Let expr :: Nat -> *
be some ADT of expressions that yield
BitVector
s when evaluated. Then, given one or more values of type expr w
(i.e. one or more of these evaluatable expressions), BVApp
provides the various
constructors necessary for creating compound expressions involving pure BitVector
operations. The expr
type can (and often will) include a constructor of type BVApp
expr w -> expr w
in order to create a recursive expression language.
In addition to the BVApp
type, we provide an evaluator which, given a function
mapping values of type expr w
to BitVector
s, will evaluate the compound
BVApp
expressions.
Synopsis
- data BVApp (expr :: Nat -> *) (w :: Nat) where
- LitBVApp :: BitVector w -> BVApp expr w
- AndApp :: !(expr w) -> !(expr w) -> BVApp expr w
- OrApp :: !(expr w) -> !(expr w) -> BVApp expr w
- XorApp :: !(expr w) -> !(expr w) -> BVApp expr w
- NotApp :: !(expr w) -> BVApp expr w
- SllApp :: !(expr w) -> !(expr w) -> BVApp expr w
- SrlApp :: !(expr w) -> !(expr w) -> BVApp expr w
- SraApp :: !(expr w) -> !(expr w) -> BVApp expr w
- AddApp :: !(expr w) -> !(expr w) -> BVApp expr w
- SubApp :: !(expr w) -> !(expr w) -> BVApp expr w
- MulApp :: !(expr w) -> !(expr w) -> BVApp expr w
- QuotUApp :: !(expr w) -> !(expr w) -> BVApp expr w
- QuotSApp :: !(expr w) -> !(expr w) -> BVApp expr w
- RemUApp :: !(expr w) -> !(expr w) -> BVApp expr w
- RemSApp :: !(expr w) -> !(expr w) -> BVApp expr w
- EqApp :: !(expr w) -> !(expr w) -> BVApp expr 1
- LtuApp :: !(expr w) -> !(expr w) -> BVApp expr 1
- LtsApp :: !(expr w) -> !(expr w) -> BVApp expr 1
- ZExtApp :: NatRepr w' -> !(expr w) -> BVApp expr w'
- SExtApp :: NatRepr w' -> !(expr w) -> BVApp expr w'
- ExtractApp :: NatRepr w' -> Int -> !(expr w) -> BVApp expr w'
- ConcatApp :: !(expr w) -> !(expr w') -> BVApp expr (w + w')
- IteApp :: !(expr 1) -> !(expr w) -> !(expr w) -> BVApp expr w
- evalBVApp :: (forall w'. expr w' -> BitVector w') -> BVApp expr w -> BitVector w
- evalBVAppM :: Monad m => (forall w'. expr w' -> m (BitVector w')) -> BVApp expr w -> m (BitVector w)
- class BVExpr (expr :: Nat -> *) where
- litBV :: BVExpr expr => BitVector w -> expr w
- andE :: BVExpr expr => expr w -> expr w -> expr w
- orE :: BVExpr expr => expr w -> expr w -> expr w
- xorE :: BVExpr expr => expr w -> expr w -> expr w
- notE :: BVExpr expr => expr w -> expr w
- addE :: BVExpr expr => expr w -> expr w -> expr w
- subE :: BVExpr expr => expr w -> expr w -> expr w
- mulE :: BVExpr expr => expr w -> expr w -> expr w
- quotuE :: BVExpr expr => expr w -> expr w -> expr w
- quotsE :: BVExpr expr => expr w -> expr w -> expr w
- remuE :: BVExpr expr => expr w -> expr w -> expr w
- remsE :: BVExpr expr => expr w -> expr w -> expr w
- sllE :: BVExpr expr => expr w -> expr w -> expr w
- srlE :: BVExpr expr => expr w -> expr w -> expr w
- sraE :: BVExpr expr => expr w -> expr w -> expr w
- eqE :: BVExpr expr => expr w -> expr w -> expr 1
- ltuE :: BVExpr expr => expr w -> expr w -> expr 1
- ltsE :: BVExpr expr => expr w -> expr w -> expr 1
- zextE :: (BVExpr expr, KnownNat w') => expr w -> expr w'
- zextEWithRepr :: BVExpr expr => NatRepr w' -> expr w -> expr w'
- sextE :: (BVExpr expr, KnownNat w') => expr w -> expr w'
- sextEWithRepr :: BVExpr expr => NatRepr w' -> expr w -> expr w'
- extractE :: (BVExpr expr, KnownNat w') => Int -> expr w -> expr w'
- extractEWithRepr :: BVExpr expr => NatRepr w' -> Int -> expr w -> expr w'
- concatE :: BVExpr expr => expr w -> expr w' -> expr (w + w')
- iteE :: BVExpr expr => expr 1 -> expr w -> expr w -> expr w
Documentation
data BVApp (expr :: Nat -> *) (w :: Nat) where Source #
Represents the application of a BitVector
operation to one or more
subexpressions.
LitBVApp :: BitVector w -> BVApp expr w | |
AndApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
OrApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
XorApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
NotApp :: !(expr w) -> BVApp expr w | |
SllApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
SrlApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
SraApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
AddApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
SubApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
MulApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
QuotUApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
QuotSApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
RemUApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
RemSApp :: !(expr w) -> !(expr w) -> BVApp expr w | |
EqApp :: !(expr w) -> !(expr w) -> BVApp expr 1 | |
LtuApp :: !(expr w) -> !(expr w) -> BVApp expr 1 | |
LtsApp :: !(expr w) -> !(expr w) -> BVApp expr 1 | |
ZExtApp :: NatRepr w' -> !(expr w) -> BVApp expr w' | |
SExtApp :: NatRepr w' -> !(expr w) -> BVApp expr w' | |
ExtractApp :: NatRepr w' -> Int -> !(expr w) -> BVApp expr w' | |
ConcatApp :: !(expr w) -> !(expr w') -> BVApp expr (w + w') | |
IteApp :: !(expr 1) -> !(expr w) -> !(expr w) -> BVApp expr w |
Instances
FunctorFC BVApp Source # | |
Defined in Data.BitVector.Sized.App | |
FoldableFC BVApp Source # | |
Defined in Data.BitVector.Sized.App foldMapFC :: Monoid m => (forall (x :: k). f x -> m) -> forall (x :: l). BVApp f x -> m # foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> BVApp f x -> b # foldlFC :: (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> BVApp f x -> b # foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> BVApp f x -> b # foldlFC' :: (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> BVApp f x -> b # toListFC :: (forall (x :: k). f x -> a) -> forall (x :: l). BVApp f x -> [a] # | |
TraversableFC BVApp Source # | |
Defined in Data.BitVector.Sized.App traverseFC :: Applicative m => (forall (x :: k). f x -> m (g x)) -> forall (x :: l). BVApp f x -> m (BVApp g x) # | |
TestEquality expr => TestEquality (BVApp expr :: Nat -> *) Source # | |
Defined in Data.BitVector.Sized.App | |
OrdF expr => OrdF (BVApp expr :: Nat -> *) Source # | |
TestEquality expr => Eq (BVApp expr w) Source # | |
OrdF expr => Ord (BVApp expr w) Source # | |
Defined in Data.BitVector.Sized.App |
Evaluate a BVApp
given a pure evaluation function for the parameterized type expr
.
:: Monad m | |
=> (forall w'. expr w' -> m (BitVector w')) | expression evaluator |
-> BVApp expr w | application |
-> m (BitVector w) |
Evaluate a BVApp
given a monadic evaluation function for the parameterized type expr
.
Smart constructors
class BVExpr (expr :: Nat -> *) where Source #
Typeclass for embedding BVApp
constructors into larger expression types.
Bitwise
Arithmetic
subE :: BVExpr expr => expr w -> expr w -> expr w Source #
Subtract the second expression from the first.
mulE :: BVExpr expr => expr w -> expr w -> expr w Source #
Signed multiply two BitVectors
, doubling the width of the result to hold all
arithmetic overflow bits.
quotuE :: BVExpr expr => expr w -> expr w -> expr w Source #
Unsigned divide two BitVectors
, rounding to zero.
quotsE :: BVExpr expr => expr w -> expr w -> expr w Source #
Signed divide two BitVectors
, rounding to zero.
remuE :: BVExpr expr => expr w -> expr w -> expr w Source #
Remainder after unsigned division of two BitVectors
, when rounded to zero.
remsE :: BVExpr expr => expr w -> expr w -> expr w Source #
Remainder after signed division of two BitVectors
, when rounded to zero.
sllE :: BVExpr expr => expr w -> expr w -> expr w Source #
Left logical shift the first expression by the second.
srlE :: BVExpr expr => expr w -> expr w -> expr w Source #
Left logical shift the first expression by the second.
sraE :: BVExpr expr => expr w -> expr w -> expr w Source #
Left logical shift the first expression by the second.
Comparison
Width-changing
zextEWithRepr :: BVExpr expr => NatRepr w' -> expr w -> expr w' Source #
Zero-extension with an explicit width argument
sextEWithRepr :: BVExpr expr => NatRepr w' -> expr w -> expr w' Source #
Sign-extension with an explicit width argument
extractEWithRepr :: BVExpr expr => NatRepr w' -> Int -> expr w -> expr w' Source #
Extract bits with an explicit width argument