{-# LANGUAGE MultiParamTypeClasses #-}

module LibRISCV where

import Data.Ix
import Data.Word

-- | Representation of a 32-bit addresses for RV32.
type Address = Word32

-- | Align an 'Address' on the next word boundary.
align :: Address -> Address
align :: Address -> Address
align Address
addr = Address
addr Address -> Address -> Address
forall a. Num a => a -> a -> a
- Address
addr Address -> Address -> Address
forall a. Integral a => a -> a -> a
`mod` Address
4

-- | Type to represent an index for the register file.
--
-- >>> toEnum 12 :: RegIdx
-- A2
-- >>> toEnum 31 :: RegIdx
-- T6
-- >>> fromEnum (minBound :: RegIdx)
-- 0
{- FOURMOLU_DISABLE -}
data RegIdx = Zero | RA | SP | GP | TP | T0 | T1 | T2 | FP
    | S1 | A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 | S2 | S3
    | S4 | S5 | S6 | S7 | S8 | S9 | S10 | S11 | T3 | T4
    | T5 | T6 deriving (Eq RegIdx
Eq RegIdx =>
(RegIdx -> RegIdx -> Ordering)
-> (RegIdx -> RegIdx -> Bool)
-> (RegIdx -> RegIdx -> Bool)
-> (RegIdx -> RegIdx -> Bool)
-> (RegIdx -> RegIdx -> Bool)
-> (RegIdx -> RegIdx -> RegIdx)
-> (RegIdx -> RegIdx -> RegIdx)
-> Ord RegIdx
RegIdx -> RegIdx -> Bool
RegIdx -> RegIdx -> Ordering
RegIdx -> RegIdx -> RegIdx
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RegIdx -> RegIdx -> Ordering
compare :: RegIdx -> RegIdx -> Ordering
$c< :: RegIdx -> RegIdx -> Bool
< :: RegIdx -> RegIdx -> Bool
$c<= :: RegIdx -> RegIdx -> Bool
<= :: RegIdx -> RegIdx -> Bool
$c> :: RegIdx -> RegIdx -> Bool
> :: RegIdx -> RegIdx -> Bool
$c>= :: RegIdx -> RegIdx -> Bool
>= :: RegIdx -> RegIdx -> Bool
$cmax :: RegIdx -> RegIdx -> RegIdx
max :: RegIdx -> RegIdx -> RegIdx
$cmin :: RegIdx -> RegIdx -> RegIdx
min :: RegIdx -> RegIdx -> RegIdx
Ord, RegIdx -> RegIdx -> Bool
(RegIdx -> RegIdx -> Bool)
-> (RegIdx -> RegIdx -> Bool) -> Eq RegIdx
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RegIdx -> RegIdx -> Bool
== :: RegIdx -> RegIdx -> Bool
$c/= :: RegIdx -> RegIdx -> Bool
/= :: RegIdx -> RegIdx -> Bool
Eq, Ord RegIdx
Ord RegIdx =>
((RegIdx, RegIdx) -> [RegIdx])
-> ((RegIdx, RegIdx) -> RegIdx -> Int)
-> ((RegIdx, RegIdx) -> RegIdx -> Int)
-> ((RegIdx, RegIdx) -> RegIdx -> Bool)
-> ((RegIdx, RegIdx) -> Int)
-> ((RegIdx, RegIdx) -> Int)
-> Ix RegIdx
(RegIdx, RegIdx) -> Int
(RegIdx, RegIdx) -> [RegIdx]
(RegIdx, RegIdx) -> RegIdx -> Bool
(RegIdx, RegIdx) -> RegIdx -> Int
forall a.
Ord a =>
((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
$crange :: (RegIdx, RegIdx) -> [RegIdx]
range :: (RegIdx, RegIdx) -> [RegIdx]
$cindex :: (RegIdx, RegIdx) -> RegIdx -> Int
index :: (RegIdx, RegIdx) -> RegIdx -> Int
$cunsafeIndex :: (RegIdx, RegIdx) -> RegIdx -> Int
unsafeIndex :: (RegIdx, RegIdx) -> RegIdx -> Int
$cinRange :: (RegIdx, RegIdx) -> RegIdx -> Bool
inRange :: (RegIdx, RegIdx) -> RegIdx -> Bool
$crangeSize :: (RegIdx, RegIdx) -> Int
rangeSize :: (RegIdx, RegIdx) -> Int
$cunsafeRangeSize :: (RegIdx, RegIdx) -> Int
unsafeRangeSize :: (RegIdx, RegIdx) -> Int
Ix, RegIdx
RegIdx -> RegIdx -> Bounded RegIdx
forall a. a -> a -> Bounded a
$cminBound :: RegIdx
minBound :: RegIdx
$cmaxBound :: RegIdx
maxBound :: RegIdx
Bounded, Int -> RegIdx -> ShowS
[RegIdx] -> ShowS
RegIdx -> String
(Int -> RegIdx -> ShowS)
-> (RegIdx -> String) -> ([RegIdx] -> ShowS) -> Show RegIdx
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RegIdx -> ShowS
showsPrec :: Int -> RegIdx -> ShowS
$cshow :: RegIdx -> String
show :: RegIdx -> String
$cshowList :: [RegIdx] -> ShowS
showList :: [RegIdx] -> ShowS
Show, Int -> RegIdx
RegIdx -> Int
RegIdx -> [RegIdx]
RegIdx -> RegIdx
RegIdx -> RegIdx -> [RegIdx]
RegIdx -> RegIdx -> RegIdx -> [RegIdx]
(RegIdx -> RegIdx)
-> (RegIdx -> RegIdx)
-> (Int -> RegIdx)
-> (RegIdx -> Int)
-> (RegIdx -> [RegIdx])
-> (RegIdx -> RegIdx -> [RegIdx])
-> (RegIdx -> RegIdx -> [RegIdx])
-> (RegIdx -> RegIdx -> RegIdx -> [RegIdx])
-> Enum RegIdx
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: RegIdx -> RegIdx
succ :: RegIdx -> RegIdx
$cpred :: RegIdx -> RegIdx
pred :: RegIdx -> RegIdx
$ctoEnum :: Int -> RegIdx
toEnum :: Int -> RegIdx
$cfromEnum :: RegIdx -> Int
fromEnum :: RegIdx -> Int
$cenumFrom :: RegIdx -> [RegIdx]
enumFrom :: RegIdx -> [RegIdx]
$cenumFromThen :: RegIdx -> RegIdx -> [RegIdx]
enumFromThen :: RegIdx -> RegIdx -> [RegIdx]
$cenumFromTo :: RegIdx -> RegIdx -> [RegIdx]
enumFromTo :: RegIdx -> RegIdx -> [RegIdx]
$cenumFromThenTo :: RegIdx -> RegIdx -> RegIdx -> [RegIdx]
enumFromThenTo :: RegIdx -> RegIdx -> RegIdx -> [RegIdx]
Enum, ReadPrec [RegIdx]
ReadPrec RegIdx
Int -> ReadS RegIdx
ReadS [RegIdx]
(Int -> ReadS RegIdx)
-> ReadS [RegIdx]
-> ReadPrec RegIdx
-> ReadPrec [RegIdx]
-> Read RegIdx
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS RegIdx
readsPrec :: Int -> ReadS RegIdx
$creadList :: ReadS [RegIdx]
readList :: ReadS [RegIdx]
$creadPrec :: ReadPrec RegIdx
readPrec :: ReadPrec RegIdx
$creadListPrec :: ReadPrec [RegIdx]
readListPrec :: ReadPrec [RegIdx]
Read)
{- FOURMOLU_ENABLE -}