{-# LANGUAGE TemplateHaskell #-}
-- generateImmediates doesn't generate signatures.
{-# OPTIONS_GHC -Wno-missing-signatures #-}

-- | Defines the expression abstraction to express arithmetic and logic
-- operations within the formal description of RISC-V instructions. The
-- abstraction is just a non-monadic algebraic data type called 'Expr'.
-- In addition to the the data type definition, this module also provides
-- several smart constructors for utilzing the expression lanuage, these
-- are generated using template-haskell.
module LibRISCV.Effects.Expressions.Expr (
    module LibRISCV.Effects.Expressions.Type,
    module LibRISCV.Effects.Expressions.Expr,
) where

import Data.Function (on)
import LibRISCV.Effects.Expressions.Generator
import LibRISCV.Effects.Expressions.Type

-- | Extract shamt value from an expression (lower 5 bits).
regShamt :: Int -> Expr a -> Expr a
regShamt :: forall a. Int -> Expr a -> Expr a
regShamt Int
w Expr a
a = Expr a
a Expr a -> Expr a -> Expr a
forall a. Expr a -> Expr a -> Expr a
`And` Int -> Integer -> Expr a
forall a. Int -> Integer -> Expr a
FromInt Int
w Integer
0x1f

------------------------------------------------------------------------

zextImm :: Int -> a -> Expr a
zextImm :: forall a. Int -> a -> Expr a
zextImm Int
w = Int -> Expr a -> Expr a
forall a. Int -> Expr a -> Expr a
ZExt Int
w (Expr a -> Expr a) -> (a -> Expr a) -> a -> Expr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Expr a
forall a. a -> Expr a
FromImm

sextImm :: Int -> a -> Expr a
sextImm :: forall a. Int -> a -> Expr a
sextImm Int
w = Int -> Expr a -> Expr a
forall a. Int -> Expr a -> Expr a
SExt Int
w (Expr a -> Expr a) -> (a -> Expr a) -> a -> Expr a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Expr a
forall a. a -> Expr a
FromImm

a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
a -> a -> Expr a
addImm :: a -> a -> Expr a
subImm :: a -> a -> Expr a
eqImm :: a -> a -> Expr a
sltImm :: a -> a -> Expr a
sgeImm :: a -> a -> Expr a
ultImm :: a -> a -> Expr a
ugeImm :: a -> a -> Expr a
andImm :: a -> a -> Expr a
orImm :: a -> a -> Expr a
xorImm :: a -> a -> Expr a
lshlImm :: a -> a -> Expr a
lshrImm :: a -> a -> Expr a
ashrImm :: a -> a -> Expr a
mulImm :: a -> a -> Expr a
udivImm :: a -> a -> Expr a
sdivImm :: a -> a -> Expr a
uremImm :: a -> a -> Expr a
sremImm :: a -> a -> Expr a
add :: a -> a -> Expr a
sub :: a -> a -> Expr a
eq :: a -> a -> Expr a
slt :: a -> a -> Expr a
sge :: a -> a -> Expr a
ult :: a -> a -> Expr a
uge :: a -> a -> Expr a
and :: a -> a -> Expr a
or :: a -> a -> Expr a
xor :: a -> a -> Expr a
lshl :: a -> a -> Expr a
lshr :: a -> a -> Expr a
ashr :: a -> a -> Expr a
mul :: a -> a -> Expr a
udiv :: a -> a -> Expr a
sdiv :: a -> a -> Expr a
urem :: a -> a -> Expr a
srem :: a -> a -> Expr a
generateImmediates