{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module LibRISCV.Semantics.Utils where
import Control.Applicative
import Control.Monad.Freer
import LibRISCV.Effects.Decoding.Language
import LibRISCV.Effects.Expressions.Expr
import LibRISCV.Effects.Expressions.Language
import LibRISCV.Effects.Operations.Language
import qualified LibRISCV.Effects.Operations.Language as Op
decodeAndReadIType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v, v)
decodeAndReadIType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v, v)
decodeAndReadIType = (v -> v -> v -> (v, v, v))
-> Eff r v -> Eff r v -> Eff r v -> Eff r (v, v, v)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 (,,) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS1 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRD Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeImmI
decodeAndReadBType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v, v)
decodeAndReadBType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v, v)
decodeAndReadBType = (v -> v -> v -> (v, v, v))
-> Eff r v -> Eff r v -> Eff r v -> Eff r (v, v, v)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 (,,) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS1 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS2 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeImmB
decodeAndReadSType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v, v)
decodeAndReadSType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v, v)
decodeAndReadSType = (v -> v -> v -> (v, v, v))
-> Eff r v -> Eff r v -> Eff r v -> Eff r (v, v, v)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 (,,) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS1 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS2 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeImmS
decodeAndReadRType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v, v)
decodeAndReadRType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v, v)
decodeAndReadRType = (v -> v -> v -> (v, v, v))
-> Eff r v -> Eff r v -> Eff r v -> Eff r (v, v, v)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 (,,) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS1 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) (Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRS2 Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRD
decodeJType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v)
decodeJType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v)
decodeJType = (v -> v -> (v, v)) -> Eff r v -> Eff r v -> Eff r (v, v)
forall a b c. (a -> b -> c) -> Eff r a -> Eff r b -> Eff r c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRD Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeImmJ
decodeUType :: forall v r. (Member (Decoding v) r, Member (Operations v) r) => Eff r (v, v)
decodeUType :: forall v (r :: [* -> *]).
(Member (Decoding v) r, Member (Operations v) r) =>
Eff r (v, v)
decodeUType = (v -> v -> (v, v)) -> Eff r v -> Eff r v -> Eff r (v, v)
forall a b c. (a -> b -> c) -> Eff r a -> Eff r b -> Eff r c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeRD Eff r v
forall v (effs :: [* -> *]). Member (Decoding v) effs => Eff effs v
decodeImmU
writeRegister :: forall v r. (Member (ExprEval v) r, Member (Operations v) r) => v -> Expr v -> Eff r ()
writeRegister :: forall v (r :: [* -> *]).
(Member (ExprEval v) r, Member (Operations v) r) =>
v -> Expr v -> Eff r ()
writeRegister v
reg Expr v
e = Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
e Eff r v -> (v -> Eff r ()) -> Eff r ()
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> v -> Eff r ()
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> v -> Eff effs ()
Op.writeRegister v
reg
readRegister :: forall v r. (Member (ExprEval v) r, Member (Operations v) r) => Expr v -> Eff r v
readRegister :: forall v (r :: [* -> *]).
(Member (ExprEval v) r, Member (Operations v) r) =>
Expr v -> Eff r v
readRegister Expr v
e = Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
e Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs v
Op.readRegister
writePC :: forall v r. (Member (ExprEval v) r, Member (Operations v) r) => Expr v -> Eff r ()
writePC :: forall v (r :: [* -> *]).
(Member (ExprEval v) r, Member (Operations v) r) =>
Expr v -> Eff r ()
writePC Expr v
e = Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
e Eff r v -> (v -> Eff r ()) -> Eff r ()
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= v -> Eff r ()
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
v -> Eff effs ()
Op.writePC
load :: forall v r. (Member (ExprEval v) r, Member (Operations v) r) => Size -> Expr v -> Eff r v
load :: forall v (r :: [* -> *]).
(Member (ExprEval v) r, Member (Operations v) r) =>
Size -> Expr v -> Eff r v
load Size
s Expr v
e = Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
e Eff r v -> (v -> Eff r v) -> Eff r v
forall a b. Eff r a -> (a -> Eff r b) -> Eff r b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Size -> v -> Eff r v
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
Size -> v -> Eff effs v
Op.load Size
s
store :: forall v r. (Member (ExprEval v) r, Member (Operations v) r) => Size -> Expr v -> Expr v -> Eff r ()
store :: forall v (r :: [* -> *]).
(Member (ExprEval v) r, Member (Operations v) r) =>
Size -> Expr v -> Expr v -> Eff r ()
store Size
s Expr v
r Expr v
e = do
v
reg <- Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
r
v
v <- Expr v -> Eff r v
forall v (effs :: [* -> *]).
Member (ExprEval v) effs =>
Expr v -> Eff effs v
eval Expr v
e
Size -> v -> v -> Eff r ()
forall v (effs :: [* -> *]).
Member (Operations v) effs =>
Size -> v -> v -> Eff effs ()
Op.store Size
s v
reg v
v