module SPARC.AddrMode (
AddrMode(..),
addrOffset
)
where
import GhcPrelude
import SPARC.Imm
import SPARC.Base
import Reg
data AddrMode
= AddrRegReg Reg Reg
| AddrRegImm Reg Imm
addrOffset :: AddrMode -> Int -> Maybe AddrMode
addrOffset :: AddrMode -> Int -> Maybe AddrMode
addrOffset AddrMode
addr Int
off
= case AddrMode
addr of
AddrRegImm Reg
r (ImmInt Int
n)
| Int -> Bool
forall a. Integral a => a -> Bool
fits13Bits Int
n2 -> AddrMode -> Maybe AddrMode
forall a. a -> Maybe a
Just (Reg -> Imm -> AddrMode
AddrRegImm Reg
r (Int -> Imm
ImmInt Int
n2))
| Bool
otherwise -> Maybe AddrMode
forall a. Maybe a
Nothing
where n2 :: Int
n2 = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
off
AddrRegImm Reg
r (ImmInteger Integer
n)
| Integer -> Bool
forall a. Integral a => a -> Bool
fits13Bits Integer
n2 -> AddrMode -> Maybe AddrMode
forall a. a -> Maybe a
Just (Reg -> Imm -> AddrMode
AddrRegImm Reg
r (Int -> Imm
ImmInt (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
n2)))
| Bool
otherwise -> Maybe AddrMode
forall a. Maybe a
Nothing
where n2 :: Integer
n2 = Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
off
AddrRegReg Reg
r (RegReal (RealRegSingle Int
0))
| Int -> Bool
forall a. Integral a => a -> Bool
fits13Bits Int
off -> AddrMode -> Maybe AddrMode
forall a. a -> Maybe a
Just (Reg -> Imm -> AddrMode
AddrRegImm Reg
r (Int -> Imm
ImmInt Int
off))
| Bool
otherwise -> Maybe AddrMode
forall a. Maybe a
Nothing
AddrMode
_ -> Maybe AddrMode
forall a. Maybe a
Nothing