macaw-base
Safe HaskellNone
LanguageHaskell2010

Data.Macaw.CFG.App

Description

This defines a data type App for representing operations that can be applied to a range of values. We call it an App because it represents an application of an operation. In mathematics, we would probably call it a signature.

Synopsis

App

data App (f :: Type -> Type) (tp :: Type) where Source #

This datatype defines operations used on multiple architectures.

These operations are all total functions. Different architecture tend to have different ways of raising signals or exceptions, and so partial functions are all architecture specific.

Constructors

Eq :: forall (f :: Type -> Type) (tp1 :: Type). !(f tp1) -> !(f tp1) -> App f 'BoolType

Compare for equality.

Mux :: forall (tp :: Type) (f :: Type -> Type). !(TypeRepr tp) -> !(f BoolType) -> !(f tp) -> !(f tp) -> App f tp 
AndApp :: forall (f :: Type -> Type). !(f BoolType) -> !(f BoolType) -> App f 'BoolType 
OrApp :: forall (f :: Type -> Type). !(f BoolType) -> !(f BoolType) -> App f 'BoolType 
NotApp :: forall (f :: Type -> Type). !(f BoolType) -> App f 'BoolType 
XorApp :: forall (f :: Type -> Type). !(f BoolType) -> !(f BoolType) -> App f 'BoolType 
MkTuple :: forall (flds :: [Type]) (f :: Type -> Type). !(List TypeRepr flds) -> !(List f flds) -> App f ('TupleType flds)

Create a tuple from a list of fields

TupleField :: forall (l :: [Type]) (f :: Type -> Type) (tp :: Type). !(List TypeRepr l) -> !(f (TupleType l)) -> !(Index l tp) -> App f tp

Extract the value out of a tuple.

ExtractElement :: forall (tp :: Type) (f :: Type -> Type) (n :: Nat). !(TypeRepr tp) -> !(f (VecType n tp)) -> !Int -> App f tp

Extracts an element at given constant index from vector

InsertElement :: forall (n :: Nat) (tp1 :: Type) (f :: Type -> Type). !(TypeRepr (VecType n tp1)) -> !(f (VecType n tp1)) -> !Int -> !(f tp1) -> App f ('VecType n tp1)

Sets an element at given constant in vector.

Trunc :: forall (n :: Natural) (m :: Natural) (f :: Type -> Type). (1 <= n, (n + 1) <= m) => !(f (BVType m)) -> !(NatRepr n) -> App f ('BVType n)

Given a m-bit bitvector and a natural number n less than m, this returns the bitvector with the n least significant bits.

SExt :: forall (m :: Natural) (n :: Natural) (f :: Type -> Type). (1 <= m, (m + 1) <= n, 1 <= n) => !(f (BVType m)) -> !(NatRepr n) -> App f ('BVType n)

Given a m-bit bitvector x and a natural number n greater than m, this returns the bitvector with the same m least signficant bits, and where the new bits are the same as the most significant bit in x.

UExt :: forall (m :: Natural) (n :: Natural) (f :: Type -> Type). (1 <= m, (m + 1) <= n, 1 <= n) => !(f (BVType m)) -> !(NatRepr n) -> App f ('BVType n)

Given a m-bit bitvector x and a natural number n greater than m, this returns the bitvector with the same m least signficant bits, and where the new bits are all false.

Bitcast :: forall (f :: Type -> Type) (tp1 :: Type) (tp :: Type). !(f tp1) -> !(WidthEqProof tp1 tp) -> App f tp

This casts an expression from one type to another that should use the same number of bytes in memory.

BVAdd :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n)

BVAdd w x y denotes x + y.

BVAdc :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f ('BVType n)

BVAdc w x y c denotes x + y + (c ? 1 : 0).

BVSub :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n)

BVSub w x y denotes x - y.

BVSbb :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f ('BVType n)

BVSbb w x y b denotes (x - y) - (b ? 1 : 0).

BVMul :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n) 
BVUnsignedLe :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> App f 'BoolType 
BVUnsignedLt :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> App f 'BoolType 
BVSignedLe :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> App f 'BoolType 
BVSignedLt :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> App f 'BoolType 
BVTestBit :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> App f 'BoolType 
BVComplement :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> App f ('BVType n) 
BVAnd :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n) 
BVOr :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n) 
BVXor :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n) 
BVShl :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n)

Left shift (e.g. `BVShl x y` denotes `fromUnsigned (toUnsigned x * 2 ^ toUnsigned y)`

BVShr :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n)

Unsigned right shift (e.g. `BVShr x y` denotes `fromUnsigned (toUnsigned x / 2 ^ toUnsigned y)`

BVSar :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> !(f (BVType n)) -> App f ('BVType n)

Arithmetic right shift (e.g. `BVSar x y` denotes `fromUnsigned (toSigned x / 2 ^ toUnsigned y)`

UadcOverflows :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f 'BoolType

Add two values and a carry bit to determine if they have an unsigned overflow.

This is the sum of three three values cannot be represented as an unsigned number.

SadcOverflows :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f 'BoolType

Add two values and a carry bit to determine if they have a signed overflow.

SadcOverflows w x y c should be true iff the result toNat x + toNat y + (c ? 1 : 0) is greater than 2^w-1.

UsbbOverflows :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f 'BoolType

Unsigned subtract with borrow overflow

UsbbOverflows w x y c should be true iff the result (toNat x - toNat y) - (c ? 1 : 0) is non-negative. Since everything is unsigned, this is equivalent to x unsignedLt (y + (c ? 1 : 0).

SsbbOverflows :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(f (BVType n)) -> !(f (BVType n)) -> !(f BoolType) -> App f 'BoolType

Signed subtract with borrow overflow.

SsbbOverflows w x y c should be true iff the result (toInt x - toInt y) - (c ? 1 : 0) is not between -2^(w-1) and 2^(w-1)-1. An equivalent way to express this is that x and y should have opposite signs and the sign of the result should differ from the sign of x.

PopCount :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> App f ('BVType n)

This returns the number of true bits in the input.

ReverseBytes :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType (8 * n))) -> App f ('BVType (8 * n))

Reverse the bytes in a bitvector expression.

Bsf :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> App f ('BVType n)

bsf "bit scan forward" returns the index of the least-significant bit that is 1. An equivalent way of stating this is that it returns the number zero-bits starting from the least significant bit. This returns n if the value is zero.

Bsr :: forall (n :: Natural) (f :: Type -> Type). 1 <= n => !(NatRepr n) -> !(f (BVType n)) -> App f ('BVType n)

bsr "bit scan reverse" returns the index of the most-significant bit that is 1. An equivalent way of stating this is that it returns the number zero-bits starting from the most-significant bit location. This returns n if the value is zero.

Instances

Instances details
FoldableFC App Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

foldMapFC :: forall f m. Monoid m => (forall (x :: Type). f x -> m) -> forall (x :: Type). App f x -> m #

foldrFC :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> App f x -> b #

foldlFC :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> App f x -> b #

foldrFC' :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> App f x -> b #

foldlFC' :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> App f x -> b #

toListFC :: (forall (x :: Type). f x -> a) -> forall (x :: Type). App f x -> [a] #

FunctorFC App Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

fmapFC :: (forall (x :: Type). f x -> g x) -> forall (x :: Type). App f x -> App g x

TraversableFC App Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

traverseFC :: forall f g m. Applicative m => (forall (x :: Type). f x -> m (g x)) -> forall (x :: Type). App f x -> m (App g x)

TestEquality f => TestEquality (App f :: Type -> Type) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

testEquality :: forall (a :: Type) (b :: Type). App f a -> App f b -> Maybe (a :~: b) #

(HashableF f, TestEquality f) => HashableF (App f :: Type -> Type) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

hashWithSaltF :: forall (tp :: Type). Int -> App f tp -> Int

hashF :: forall (tp :: Type). App f tp -> Int

OrdF f => OrdF (App f :: Type -> Type) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

compareF :: forall (x :: Type) (y :: Type). App f x -> App f y -> OrderingF x y

leqF :: forall (x :: Type) (y :: Type). App f x -> App f y -> Bool

ltF :: forall (x :: Type) (y :: Type). App f x -> App f y -> Bool

geqF :: forall (x :: Type) (y :: Type). App f x -> App f y -> Bool

gtF :: forall (x :: Type) (y :: Type). App f x -> App f y -> Bool

HasRepr (App f :: Type -> Type) TypeRepr Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

typeRepr :: forall (tp :: Type). App f tp -> TypeRepr tp Source #

TestEquality f => Eq (App f tp) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

(==) :: App f tp -> App f tp -> Bool #

(/=) :: App f tp -> App f tp -> Bool #

OrdF f => Ord (App f tp) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

compare :: App f tp -> App f tp -> Ordering #

(<) :: App f tp -> App f tp -> Bool #

(<=) :: App f tp -> App f tp -> Bool #

(>) :: App f tp -> App f tp -> Bool #

(>=) :: App f tp -> App f tp -> Bool #

max :: App f tp -> App f tp -> App f tp #

min :: App f tp -> App f tp -> App f tp #

(HashableF f, TestEquality f) => Hashable (App f tp) Source # 
Instance details

Defined in Data.Macaw.CFG.App

Methods

hashWithSalt :: Int -> App f tp -> Int

hash :: App f tp -> Int

ppApp :: forall f ann (tp :: Type). (forall (u :: Type). f u -> Doc ann) -> App f tp -> Doc ann Source #

ppAppA :: forall m f (tp :: Type) ann. Applicative m => (forall (u :: Type). f u -> m (Doc ann)) -> App f tp -> m (Doc ann) Source #

Pretty print an App as an expression using the given function for printing arguments.

Rendering

data AppRender (f :: Type -> Type) Source #

Constructors

AppRender Text [AppRenderArg f] 

data AppRenderArg (f :: Type -> Type) where Source #

Constructors

Val :: forall (f :: Type -> Type) (tp :: Type). f tp -> AppRenderArg f 
Type :: forall (tp :: Type) (f :: Type -> Type). !(TypeRepr tp) -> AppRenderArg f 
Index :: forall (f :: Type -> Type). Natural -> AppRenderArg f 
Width :: forall (f :: Type -> Type). Natural -> AppRenderArg f 

rendApp :: forall (f :: Type -> Type) (tp :: Type). App f tp -> AppRender f Source #

Pretty print an App as an expression using the given function for printing arguments.

Casting proof objects.

data WidthEqProof (in_tp :: Type) (out_tp :: Type) where Source #

Data type to represent that two types use the same number of bits, and thus can be bitcast.

Note. This datatype needs to balance several competing requirements. It needs to support all bitcasts needed by architectures, represent bitcasts compactly, allow bitcasts to be removed during optimization, and allow bitcasts to be symbolically simulated.

Due to these requirements, we have a fairly limited set of proof rules. New rules can be added, but need to be balanced against the above set of goals. By design we do not have transitivity or equality, as those can be obtained by respectively chaining bitcasts or eliminating them.

Constructors

PackBits :: forall (n :: Natural) (w :: Natural). (1 <= n, 2 <= n, 1 <= w) => !(NatRepr n) -> !(NatRepr w) -> WidthEqProof ('VecType n (BVType w)) ('BVType (n * w)) 
UnpackBits :: forall (n :: Natural) (w :: Natural). (1 <= n, 2 <= n, 1 <= w) => !(NatRepr n) -> !(NatRepr w) -> WidthEqProof ('BVType (n * w)) ('VecType n (BVType w)) 
FromFloat :: forall (ftp :: FloatInfo). !(FloatInfoRepr ftp) -> WidthEqProof ('FloatType ftp) ('BVType (FloatInfoBits ftp)) 
ToFloat :: forall (ftp :: FloatInfo). !(FloatInfoRepr ftp) -> WidthEqProof ('BVType (FloatInfoBits ftp)) ('FloatType ftp) 
VecEqCongruence :: forall (n :: Nat) (i :: Type) (o :: Type). !(NatRepr n) -> !(WidthEqProof i o) -> WidthEqProof ('VecType n i) ('VecType n o)

Convert between vector types that are equivalent.

WidthEqRefl :: forall (in_tp :: Type). !(TypeRepr in_tp) -> WidthEqProof in_tp in_tp

Type is equal to itself.

WidthEqTrans :: forall (in_tp :: Type) (y :: Type) (out_tp :: Type). !(WidthEqProof in_tp y) -> !(WidthEqProof y out_tp) -> WidthEqProof in_tp out_tp

Allows transitivity composing proofs.

widthEqProofEq :: forall (xi :: Type) (xo :: Type) (yi :: Type) (yo :: Type). WidthEqProof xi xo -> WidthEqProof yi yo -> Maybe (WidthEqProof xi xo :~: WidthEqProof yi yo) Source #

Compare two proofs, and return truei if the input/output types are the same.

widthEqProofCompare :: forall (xi :: Type) (xo :: Type) (yi :: Type) (yo :: Type). WidthEqProof xi xo -> WidthEqProof yi yo -> OrderingF (WidthEqProof xi xo) (WidthEqProof yi yo) Source #

Compare proofs based on ordering of source and target.

widthEqSource :: forall (i :: Type) (o :: Type). WidthEqProof i o -> TypeRepr i Source #

Return the input type of the width equality proof

widthEqTarget :: forall (i :: Type) (o :: Type). WidthEqProof i o -> TypeRepr o Source #

Return the result type of the width equality proof

widthEqSym :: forall (x :: Type) (y :: Type). WidthEqProof x y -> WidthEqProof y x Source #

Apply symmetry to a width equality proof.