blob: f00458af81a6b8f0af5510f94844b9b228fbff11 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details
module SPARC.AddrMode (
AddrMode(..),
addrOffset
)
where
import SPARC.Imm
import SPARC.Base
import Reg
-- addressing modes ------------------------------------------------------------
-- | Represents a memory address in an instruction.
-- Being a RISC machine, the SPARC addressing modes are very regular.
--
data AddrMode
= AddrRegReg Reg Reg -- addr = r1 + r2
| AddrRegImm Reg Imm -- addr = r1 + imm
-- | Add an integer offset to the address in an AddrMode.
--
addrOffset :: AddrMode -> Int -> Maybe AddrMode
addrOffset addr off
= case addr of
AddrRegImm r (ImmInt n)
| fits13Bits n2 -> Just (AddrRegImm r (ImmInt n2))
| otherwise -> Nothing
where n2 = n + off
AddrRegImm r (ImmInteger n)
| fits13Bits n2 -> Just (AddrRegImm r (ImmInt (fromInteger n2)))
| otherwise -> Nothing
where n2 = n + toInteger off
AddrRegReg r (RegReal (RealRegSingle 0))
| fits13Bits off -> Just (AddrRegImm r (ImmInt off))
| otherwise -> Nothing
_ -> Nothing
|