| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Language.QBE.Simulator.Expression
Description
This module provides a generic expression language used to describe
arithmetic and logic operations on instruction operands in the abstract
Simulator description of QBE semantics. Therefore, in
addition to the Simulator monad, it is the
central component for the abstract description of QBE's semantics.
Synopsis
- class ValueRepr v where
- fromLit :: ExtType -> Word64 -> v
- fromFloat :: Float -> v
- fromDouble :: Double -> v
- toWord64 :: v -> Word64
- getType :: v -> ExtType
- floatToInt :: ExtType -> Bool -> v -> Maybe v
- intToFloat :: ExtType -> Bool -> v -> Maybe v
- extendFloat :: v -> Maybe v
- truncFloat :: v -> Maybe v
- extend :: ExtType -> Bool -> v -> Maybe v
- extract :: ExtType -> v -> Maybe v
- add :: v -> v -> Maybe v
- sub :: v -> v -> Maybe v
- mul :: v -> v -> Maybe v
- div :: v -> v -> Maybe v
- urem :: v -> v -> Maybe v
- srem :: v -> v -> Maybe v
- udiv :: v -> v -> Maybe v
- or :: v -> v -> Maybe v
- xor :: v -> v -> Maybe v
- and :: v -> v -> Maybe v
- neg :: v -> Maybe v
- sar :: v -> v -> Maybe v
- shr :: v -> v -> Maybe v
- shl :: v -> v -> Maybe v
- eq :: v -> v -> Maybe v
- ne :: v -> v -> Maybe v
- sle :: v -> v -> Maybe v
- slt :: v -> v -> Maybe v
- sge :: v -> v -> Maybe v
- sgt :: v -> v -> Maybe v
- ule :: v -> v -> Maybe v
- ult :: v -> v -> Maybe v
- uge :: v -> v -> Maybe v
- ugt :: v -> v -> Maybe v
- ord :: v -> v -> Maybe v
- unord :: v -> v -> Maybe v
- fromString :: ValueRepr v => String -> [v]
- toString :: ValueRepr v => [v] -> String
- boolToValue :: ValueRepr v => Bool -> v
- compareIntExpr :: ValueRepr v => IntCmpOp -> v -> v -> Maybe v
- compareFloatExpr :: ValueRepr v => FloatCmpOp -> v -> v -> Maybe v
Expression Abstraction
class ValueRepr v where Source #
Generic expression abstraction operating on values of type ExtType.
Values are either fixed-size bitvectors (8-, 16, 32-, or 64-bit) or
single-precision or double-precision floating point values. The value type
must be tracked internally by the ValueRepr instance. Operations on the
value must return Nothing if the operation is performed on values of
different types.
Minimal complete definition
fromLit, fromFloat, fromDouble, toWord64, getType, floatToInt, intToFloat, extendFloat, truncFloat, extend, extract, add, sub, mul, div, urem, srem, udiv, or, xor, and, neg, sar, shr, shl, eq, ne, sle, slt, sge, sgt, ule, ult, uge, ugt, ord
Methods
fromLit :: ExtType -> Word64 -> v Source #
Create a ValueRepr from an integer literal.
TODO: rename fromLit to fromInt
fromFloat :: Float -> v Source #
fromDouble :: Double -> v Source #
toWord64 :: v -> Word64 Source #
getType :: v -> ExtType Source #
floatToInt :: ExtType -> Bool -> v -> Maybe v Source #
intToFloat :: ExtType -> Bool -> v -> Maybe v Source #
extendFloat :: v -> Maybe v Source #
truncFloat :: v -> Maybe v Source #
extend :: ExtType -> Bool -> v -> Maybe v Source #
Extend a value to the given ExtType. The Bool is true if
the value should be sign-extended, otherwise it is zero-extended.
If the v is a float or if the current size exceeds (or is equal to)
the size of ExtType, then Nothing is returned.
extract :: ExtType -> v -> Maybe v Source #
Extract the least significant bits of a v. The bits to extract
are deduced from the given ExtType. Returns Nothing if the
ExtType is a float type, if the value is a float, or if the size
of ExtType exceeds the size of v.
add :: v -> v -> Maybe v Source #
Addition.
sub :: v -> v -> Maybe v Source #
Subtraction.
mul :: v -> v -> Maybe v Source #
Multiplication.
div :: v -> v -> Maybe v Source #
Unsigned division.
urem :: v -> v -> Maybe v Source #
Unsigned remainder.
srem :: v -> v -> Maybe v Source #
Signed remainder.
udiv :: v -> v -> Maybe v Source #
Unsigned division.
or :: v -> v -> Maybe v Source #
Bitwise or.
xor :: v -> v -> Maybe v Source #
Bitwise xor.
and :: v -> v -> Maybe v Source #
Bitwise and.
Unary negation.
sar :: v -> v -> Maybe v Source #
Arithmetic right shift, preserving the sign bit of the shifted value. Shift amount must always be a 32-bit value, the shifted value must be 32- or 64-bit.
shr :: v -> v -> Maybe v Source #
Logical shift right, filling the newly freed bits with zeroes. Shift amount must always be a 32-bit value, the shifted value must be 32- or 64-bit.
shl :: v -> v -> Maybe v Source #
Logical shift left, always fills the freed bits with zeroes. Shift amount must always be a 32-bit value, the shifted value must be 32- or 64-bit.
eq :: v -> v -> Maybe v Source #
Check for equality.
ne :: v -> v -> Maybe v Source #
Check if two values are not equal.
sle :: v -> v -> Maybe v Source #
Signed less than or equal to.
slt :: v -> v -> Maybe v Source #
Signed less than.
sge :: v -> v -> Maybe v Source #
Signed greater than or equal to.
sgt :: v -> v -> Maybe v Source #
Signed greater than.
ule :: v -> v -> Maybe v Source #
Unsigned less than or equal to.
ult :: v -> v -> Maybe v Source #
Unsigned less than.
uge :: v -> v -> Maybe v Source #
Unsigned greater than or equal to.
ugt :: v -> v -> Maybe v Source #
Unsigned greater then.
ord :: v -> v -> Maybe v Source #
Ordered, no operand is a NaN.
Only defined for floating points, must return Nothing otherwise.
unord :: v -> v -> Maybe v Source #
Unordered, at least one operand is a NaN.
Only defined for floating points, must return Nothing otherwise.
Instances
Conversion Functions,
fromString :: ValueRepr v => String -> [v] Source #
Convert a string to a list of 8-bit values represented through ValueRepr.
boolToValue :: ValueRepr v => Bool -> v Source #
Convert a Boolean value to a 64-bit value in ValueRepr.
Comparision
compareFloatExpr :: ValueRepr v => FloatCmpOp -> v -> v -> Maybe v Source #
Map a FloatCmpOp to the corresponding function from ValueRepr.