qute-0.1.0: A software analysis framework built around the QBE intermediate language.
Safe HaskellNone
LanguageGHC2021

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

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.

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.

neg :: v -> Maybe v Source #

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

Instances details
ValueRepr RegVal Source # 
Instance details

Defined in Language.QBE.Simulator.Default.Expression

Methods

fromLit :: ExtType -> Word64 -> RegVal Source #

fromFloat :: Float -> RegVal Source #

fromDouble :: Double -> RegVal Source #

toWord64 :: RegVal -> Word64 Source #

getType :: RegVal -> ExtType Source #

floatToInt :: ExtType -> Bool -> RegVal -> Maybe RegVal Source #

intToFloat :: ExtType -> Bool -> RegVal -> Maybe RegVal Source #

extendFloat :: RegVal -> Maybe RegVal Source #

truncFloat :: RegVal -> Maybe RegVal Source #

extend :: ExtType -> Bool -> RegVal -> Maybe RegVal Source #

extract :: ExtType -> RegVal -> Maybe RegVal Source #

add :: RegVal -> RegVal -> Maybe RegVal Source #

sub :: RegVal -> RegVal -> Maybe RegVal Source #

mul :: RegVal -> RegVal -> Maybe RegVal Source #

div :: RegVal -> RegVal -> Maybe RegVal Source #

urem :: RegVal -> RegVal -> Maybe RegVal Source #

srem :: RegVal -> RegVal -> Maybe RegVal Source #

udiv :: RegVal -> RegVal -> Maybe RegVal Source #

or :: RegVal -> RegVal -> Maybe RegVal Source #

xor :: RegVal -> RegVal -> Maybe RegVal Source #

and :: RegVal -> RegVal -> Maybe RegVal Source #

neg :: RegVal -> Maybe RegVal Source #

sar :: RegVal -> RegVal -> Maybe RegVal Source #

shr :: RegVal -> RegVal -> Maybe RegVal Source #

shl :: RegVal -> RegVal -> Maybe RegVal Source #

eq :: RegVal -> RegVal -> Maybe RegVal Source #

ne :: RegVal -> RegVal -> Maybe RegVal Source #

sle :: RegVal -> RegVal -> Maybe RegVal Source #

slt :: RegVal -> RegVal -> Maybe RegVal Source #

sge :: RegVal -> RegVal -> Maybe RegVal Source #

sgt :: RegVal -> RegVal -> Maybe RegVal Source #

ule :: RegVal -> RegVal -> Maybe RegVal Source #

ult :: RegVal -> RegVal -> Maybe RegVal Source #

uge :: RegVal -> RegVal -> Maybe RegVal Source #

ugt :: RegVal -> RegVal -> Maybe RegVal Source #

ord :: RegVal -> RegVal -> Maybe RegVal Source #

unord :: RegVal -> RegVal -> Maybe RegVal Source #

Conversion Functions,

fromString :: ValueRepr v => String -> [v] Source #

Convert a string to a list of 8-bit values represented through ValueRepr.

toString :: ValueRepr v => [v] -> String Source #

Inverse of fromString.

boolToValue :: ValueRepr v => Bool -> v Source #

Convert a Boolean value to a 64-bit value in ValueRepr.

Comparision

compareIntExpr :: ValueRepr v => IntCmpOp -> v -> v -> Maybe v Source #

Map a IntCmpOp to the corresponding function from ValueRepr.

compareFloatExpr :: ValueRepr v => FloatCmpOp -> v -> v -> Maybe v Source #

Map a FloatCmpOp to the corresponding function from ValueRepr.