module Htcc.Asm.Intrinsic.Register (
IsRegister (..),
AccumulatorReg (..),
BaseReg (..),
CounterReg (..),
DataReg (..),
SrcIndexReg (..),
DstIndexReg (..),
BasePtrReg (..),
StackPtrReg (..),
ExtendedReg (..),
Register (..),
rax, eax, ax, ah, al,
rbx, ebx, bx, bh, bl,
rcx, ecx, cx, ch, cl,
rdx, edx, dx, dh, dl,
rsi, esi, si, sil,
rdi, edi, di, dil,
rbp, ebp, bp, bpl,
rsp, esp, sp, spl,
rn, rnd, rnw, rnb,
argRegs,
popRegs
) where
import Numeric.Natural
class Show a => IsRegister a where
byteWidth :: a -> Natural
data AccumulatorReg = RAX
| EAX
| AX
| AH
| AL
instance Show AccumulatorReg where
show :: AccumulatorReg -> String
show RAX = "rax"
show EAX = "eax"
show AX = "ax"
show AH = "ah"
show AL = "al"
instance IsRegister AccumulatorReg where
byteWidth :: AccumulatorReg -> Natural
byteWidth RAX = 8
byteWidth EAX = 4
byteWidth AX = 2
byteWidth AH = 1
byteWidth AL = 1
instance Eq AccumulatorReg where
== :: AccumulatorReg -> AccumulatorReg -> Bool
(==) = ((Natural -> Bool)
-> (AccumulatorReg -> Natural) -> AccumulatorReg -> Bool)
-> (AccumulatorReg -> Natural)
-> (Natural -> Bool)
-> AccumulatorReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool)
-> (AccumulatorReg -> Natural) -> AccumulatorReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) AccumulatorReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> AccumulatorReg -> Bool)
-> (AccumulatorReg -> Natural -> Bool)
-> AccumulatorReg
-> AccumulatorReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (AccumulatorReg -> Natural) -> AccumulatorReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccumulatorReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord AccumulatorReg where
compare :: AccumulatorReg -> AccumulatorReg -> Ordering
compare = ((Natural -> Ordering)
-> (AccumulatorReg -> Natural) -> AccumulatorReg -> Ordering)
-> (AccumulatorReg -> Natural)
-> (Natural -> Ordering)
-> AccumulatorReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (AccumulatorReg -> Natural) -> AccumulatorReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) AccumulatorReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> AccumulatorReg -> Ordering)
-> (AccumulatorReg -> Natural -> Ordering)
-> AccumulatorReg
-> AccumulatorReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (AccumulatorReg -> Natural)
-> AccumulatorReg
-> Natural
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccumulatorReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data BaseReg = RBX
| EBX
| BX
| BH
| BL
instance Show BaseReg where
show :: BaseReg -> String
show RBX = "rbx"
show EBX = "ebx"
show BX = "bx"
show BH = "bh"
show BL = "bl"
instance IsRegister BaseReg where
byteWidth :: BaseReg -> Natural
byteWidth RBX = 8
byteWidth EBX = 4
byteWidth BX = 2
byteWidth BH = 1
byteWidth BL = 1
instance Eq BaseReg where
== :: BaseReg -> BaseReg -> Bool
(==) = ((Natural -> Bool) -> (BaseReg -> Natural) -> BaseReg -> Bool)
-> (BaseReg -> Natural) -> (Natural -> Bool) -> BaseReg -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool) -> (BaseReg -> Natural) -> BaseReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) BaseReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> BaseReg -> Bool)
-> (BaseReg -> Natural -> Bool) -> BaseReg -> BaseReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (BaseReg -> Natural) -> BaseReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BaseReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord BaseReg where
compare :: BaseReg -> BaseReg -> Ordering
compare = ((Natural -> Ordering)
-> (BaseReg -> Natural) -> BaseReg -> Ordering)
-> (BaseReg -> Natural)
-> (Natural -> Ordering)
-> BaseReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (BaseReg -> Natural) -> BaseReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) BaseReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> BaseReg -> Ordering)
-> (BaseReg -> Natural -> Ordering)
-> BaseReg
-> BaseReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (BaseReg -> Natural) -> BaseReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BaseReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data CounterReg = RCX
| ECX
| CX
| CH
| CL
instance Show CounterReg where
show :: CounterReg -> String
show RCX = "rcx"
show ECX = "ecx"
show CX = "cx"
show CH = "ch"
show CL = "cl"
instance IsRegister CounterReg where
byteWidth :: CounterReg -> Natural
byteWidth RCX = 8
byteWidth ECX = 4
byteWidth CX = 2
byteWidth CH = 1
byteWidth CL = 1
instance Eq CounterReg where
== :: CounterReg -> CounterReg -> Bool
(==) = ((Natural -> Bool)
-> (CounterReg -> Natural) -> CounterReg -> Bool)
-> (CounterReg -> Natural)
-> (Natural -> Bool)
-> CounterReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool) -> (CounterReg -> Natural) -> CounterReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) CounterReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> CounterReg -> Bool)
-> (CounterReg -> Natural -> Bool)
-> CounterReg
-> CounterReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (CounterReg -> Natural) -> CounterReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CounterReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord CounterReg where
compare :: CounterReg -> CounterReg -> Ordering
compare = ((Natural -> Ordering)
-> (CounterReg -> Natural) -> CounterReg -> Ordering)
-> (CounterReg -> Natural)
-> (Natural -> Ordering)
-> CounterReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (CounterReg -> Natural) -> CounterReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) CounterReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> CounterReg -> Ordering)
-> (CounterReg -> Natural -> Ordering)
-> CounterReg
-> CounterReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (CounterReg -> Natural) -> CounterReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CounterReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data DataReg = RDX
| EDX
| DX
| DH
| DL
instance Show DataReg where
show :: DataReg -> String
show RDX = "rdx"
show EDX = "edx"
show DX = "dx"
show DH = "dh"
show DL = "dl"
instance IsRegister DataReg where
byteWidth :: DataReg -> Natural
byteWidth RDX = 8
byteWidth EDX = 4
byteWidth DX = 2
byteWidth DH = 1
byteWidth DL = 1
instance Eq DataReg where
== :: DataReg -> DataReg -> Bool
(==) = ((Natural -> Bool) -> (DataReg -> Natural) -> DataReg -> Bool)
-> (DataReg -> Natural) -> (Natural -> Bool) -> DataReg -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool) -> (DataReg -> Natural) -> DataReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) DataReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> DataReg -> Bool)
-> (DataReg -> Natural -> Bool) -> DataReg -> DataReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (DataReg -> Natural) -> DataReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord DataReg where
compare :: DataReg -> DataReg -> Ordering
compare = ((Natural -> Ordering)
-> (DataReg -> Natural) -> DataReg -> Ordering)
-> (DataReg -> Natural)
-> (Natural -> Ordering)
-> DataReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (DataReg -> Natural) -> DataReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) DataReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> DataReg -> Ordering)
-> (DataReg -> Natural -> Ordering)
-> DataReg
-> DataReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (DataReg -> Natural) -> DataReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DataReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data SrcIndexReg = RSI
| ESI
| SI
| SIL
instance Show SrcIndexReg where
show :: SrcIndexReg -> String
show RSI = "rsi"
show ESI = "esi"
show SI = "si"
show SIL = "sil"
instance IsRegister SrcIndexReg where
byteWidth :: SrcIndexReg -> Natural
byteWidth RSI = 8
byteWidth ESI = 4
byteWidth SI = 2
byteWidth SIL = 1
instance Eq SrcIndexReg where
== :: SrcIndexReg -> SrcIndexReg -> Bool
(==) = ((Natural -> Bool)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Bool)
-> (SrcIndexReg -> Natural)
-> (Natural -> Bool)
-> SrcIndexReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) SrcIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> SrcIndexReg -> Bool)
-> (SrcIndexReg -> Natural -> Bool)
-> SrcIndexReg
-> SrcIndexReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord SrcIndexReg where
compare :: SrcIndexReg -> SrcIndexReg -> Ordering
compare = ((Natural -> Ordering)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Ordering)
-> (SrcIndexReg -> Natural)
-> (Natural -> Ordering)
-> SrcIndexReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) SrcIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> SrcIndexReg -> Ordering)
-> (SrcIndexReg -> Natural -> Ordering)
-> SrcIndexReg
-> SrcIndexReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (SrcIndexReg -> Natural) -> SrcIndexReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SrcIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data DstIndexReg = RDI
| EDI
| DI
| DIL
instance Show DstIndexReg where
show :: DstIndexReg -> String
show RDI = "rdi"
show EDI = "edi"
show DI = "di"
show DIL = "dil"
instance IsRegister DstIndexReg where
byteWidth :: DstIndexReg -> Natural
byteWidth RDI = 8
byteWidth EDI = 4
byteWidth DI = 2
byteWidth DIL = 1
instance Eq DstIndexReg where
== :: DstIndexReg -> DstIndexReg -> Bool
(==) = ((Natural -> Bool)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Bool)
-> (DstIndexReg -> Natural)
-> (Natural -> Bool)
-> DstIndexReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) DstIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> DstIndexReg -> Bool)
-> (DstIndexReg -> Natural -> Bool)
-> DstIndexReg
-> DstIndexReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DstIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord DstIndexReg where
compare :: DstIndexReg -> DstIndexReg -> Ordering
compare = ((Natural -> Ordering)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Ordering)
-> (DstIndexReg -> Natural)
-> (Natural -> Ordering)
-> DstIndexReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) DstIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> DstIndexReg -> Ordering)
-> (DstIndexReg -> Natural -> Ordering)
-> DstIndexReg
-> DstIndexReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (DstIndexReg -> Natural) -> DstIndexReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DstIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data BasePtrReg = RBP
| EBP
| BP
| BPL
instance Show BasePtrReg where
show :: BasePtrReg -> String
show RBP = "rbp"
show EBP = "ebp"
show BP = "bp"
show BPL = "bpl"
instance IsRegister BasePtrReg where
byteWidth :: BasePtrReg -> Natural
byteWidth RBP = 8
byteWidth EBP = 4
byteWidth BP = 2
byteWidth BPL = 1
instance Eq BasePtrReg where
== :: BasePtrReg -> BasePtrReg -> Bool
(==) = ((Natural -> Bool)
-> (BasePtrReg -> Natural) -> BasePtrReg -> Bool)
-> (BasePtrReg -> Natural)
-> (Natural -> Bool)
-> BasePtrReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool) -> (BasePtrReg -> Natural) -> BasePtrReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) BasePtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> BasePtrReg -> Bool)
-> (BasePtrReg -> Natural -> Bool)
-> BasePtrReg
-> BasePtrReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (BasePtrReg -> Natural) -> BasePtrReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BasePtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord BasePtrReg where
compare :: BasePtrReg -> BasePtrReg -> Ordering
compare = ((Natural -> Ordering)
-> (BasePtrReg -> Natural) -> BasePtrReg -> Ordering)
-> (BasePtrReg -> Natural)
-> (Natural -> Ordering)
-> BasePtrReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (BasePtrReg -> Natural) -> BasePtrReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) BasePtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> BasePtrReg -> Ordering)
-> (BasePtrReg -> Natural -> Ordering)
-> BasePtrReg
-> BasePtrReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (BasePtrReg -> Natural) -> BasePtrReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BasePtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data StackPtrReg = RSP
| ESP
| SP
| SPL
instance Show StackPtrReg where
show :: StackPtrReg -> String
show RSP = "rsp"
show ESP = "esp"
show SP = "sp"
show SPL = "spl"
instance IsRegister StackPtrReg where
byteWidth :: StackPtrReg -> Natural
byteWidth RSP = 8
byteWidth ESP = 4
byteWidth SP = 2
byteWidth SPL = 1
instance Eq StackPtrReg where
== :: StackPtrReg -> StackPtrReg -> Bool
(==) = ((Natural -> Bool)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Bool)
-> (StackPtrReg -> Natural)
-> (Natural -> Bool)
-> StackPtrReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) StackPtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> StackPtrReg -> Bool)
-> (StackPtrReg -> Natural -> Bool)
-> StackPtrReg
-> StackPtrReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackPtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord StackPtrReg where
compare :: StackPtrReg -> StackPtrReg -> Ordering
compare = ((Natural -> Ordering)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Ordering)
-> (StackPtrReg -> Natural)
-> (Natural -> Ordering)
-> StackPtrReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) StackPtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> StackPtrReg -> Ordering)
-> (StackPtrReg -> Natural -> Ordering)
-> StackPtrReg
-> StackPtrReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (StackPtrReg -> Natural) -> StackPtrReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackPtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data ExtendedReg = Rn Int
| RnD Int
| RnW Int
| RnB Int
instance Show ExtendedReg where
show :: ExtendedReg -> String
show (Rn x :: Int
x)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 8 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 15 = "r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
x
| Bool
otherwise = ShowS
forall a. HasCallStack => String -> a
error ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ "Extended registers should be " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ["r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ ", " | Int
n <- [8..14] :: [Int]] String -> ShowS
forall a. [a] -> [a] -> [a]
++ "or r15."
show (RnD x :: Int
x)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 8 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 15 = "r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ "d"
| Bool
otherwise = ShowS
forall a. HasCallStack => String -> a
error ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ "Extended registers should be " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ["r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ "d, " | Int
n <- [8..14] :: [Int]] String -> ShowS
forall a. [a] -> [a] -> [a]
++ "or r15d."
show (RnW x :: Int
x)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 8 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 15 = "r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ "w"
| Bool
otherwise = ShowS
forall a. HasCallStack => String -> a
error ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ "Extended registers should be " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ["r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ "w, " | Int
n <- [8..14] :: [Int]] String -> ShowS
forall a. [a] -> [a] -> [a]
++ "or r15w."
show (RnB x :: Int
x)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= 8 Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 15 = "r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
x String -> ShowS
forall a. [a] -> [a] -> [a]
++ "b"
| Bool
otherwise = ShowS
forall a. HasCallStack => String -> a
error ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ "Extended registers should be " String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ["r" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
n String -> ShowS
forall a. [a] -> [a] -> [a]
++ "b, " | Int
n <- [8..14] :: [Int]] String -> ShowS
forall a. [a] -> [a] -> [a]
++ "or r15b."
instance IsRegister ExtendedReg where
byteWidth :: ExtendedReg -> Natural
byteWidth (Rn _) = 8
byteWidth (RnD _) = 4
byteWidth (RnW _) = 2
byteWidth (RnB _) = 1
instance Bounded ExtendedReg where
minBound :: ExtendedReg
minBound = Int -> ExtendedReg
Rn 8
maxBound :: ExtendedReg
maxBound = Int -> ExtendedReg
Rn 15
instance Eq ExtendedReg where
== :: ExtendedReg -> ExtendedReg -> Bool
(==) = ((Natural -> Bool)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Bool)
-> (ExtendedReg -> Natural)
-> (Natural -> Bool)
-> ExtendedReg
-> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ExtendedReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> ExtendedReg -> Bool)
-> (ExtendedReg -> Natural -> Bool)
-> ExtendedReg
-> ExtendedReg
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExtendedReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord ExtendedReg where
compare :: ExtendedReg -> ExtendedReg -> Ordering
compare = ((Natural -> Ordering)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Ordering)
-> (ExtendedReg -> Natural)
-> (Natural -> Ordering)
-> ExtendedReg
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ExtendedReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> ExtendedReg -> Ordering)
-> (ExtendedReg -> Natural -> Ordering)
-> ExtendedReg
-> ExtendedReg
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (ExtendedReg -> Natural) -> ExtendedReg -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExtendedReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
data Register = Accumulator AccumulatorReg
| Base BaseReg
| Counter CounterReg
| Data DataReg
| SrcIndex SrcIndexReg
| DstIndex DstIndexReg
| BasePtr BasePtrReg
| StackPtr StackPtrReg
| Extended ExtendedReg
instance Show Register where
show :: Register -> String
show (Accumulator x :: AccumulatorReg
x) = AccumulatorReg -> String
forall a. Show a => a -> String
show AccumulatorReg
x
show (Base x :: BaseReg
x) = BaseReg -> String
forall a. Show a => a -> String
show BaseReg
x
show (Counter x :: CounterReg
x) = CounterReg -> String
forall a. Show a => a -> String
show CounterReg
x
show (Data x :: DataReg
x) = DataReg -> String
forall a. Show a => a -> String
show DataReg
x
show (SrcIndex x :: SrcIndexReg
x) = SrcIndexReg -> String
forall a. Show a => a -> String
show SrcIndexReg
x
show (DstIndex x :: DstIndexReg
x) = DstIndexReg -> String
forall a. Show a => a -> String
show DstIndexReg
x
show (BasePtr x :: BasePtrReg
x) = BasePtrReg -> String
forall a. Show a => a -> String
show BasePtrReg
x
show (StackPtr x :: StackPtrReg
x) = StackPtrReg -> String
forall a. Show a => a -> String
show StackPtrReg
x
show (Extended x :: ExtendedReg
x) = ExtendedReg -> String
forall a. Show a => a -> String
show ExtendedReg
x
instance IsRegister Register where
byteWidth :: Register -> Natural
byteWidth (Accumulator x :: AccumulatorReg
x) = AccumulatorReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth AccumulatorReg
x
byteWidth (Base x :: BaseReg
x) = BaseReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth BaseReg
x
byteWidth (Counter x :: CounterReg
x) = CounterReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth CounterReg
x
byteWidth (Data x :: DataReg
x) = DataReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth DataReg
x
byteWidth (SrcIndex x :: SrcIndexReg
x) = SrcIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth SrcIndexReg
x
byteWidth (DstIndex x :: DstIndexReg
x) = DstIndexReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth DstIndexReg
x
byteWidth (BasePtr x :: BasePtrReg
x) = BasePtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth BasePtrReg
x
byteWidth (StackPtr x :: StackPtrReg
x) = StackPtrReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth StackPtrReg
x
byteWidth (Extended x :: ExtendedReg
x) = ExtendedReg -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ExtendedReg
x
instance Eq Register where
== :: Register -> Register -> Bool
(==) = ((Natural -> Bool) -> (Register -> Natural) -> Register -> Bool)
-> (Register -> Natural) -> (Natural -> Bool) -> Register -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Bool) -> (Register -> Natural) -> Register -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) Register -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Bool) -> Register -> Bool)
-> (Register -> Natural -> Bool) -> Register -> Register -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Natural -> Natural -> Bool)
-> (Register -> Natural) -> Register -> Natural -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Register -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
instance Ord Register where
compare :: Register -> Register -> Ordering
compare = ((Natural -> Ordering)
-> (Register -> Natural) -> Register -> Ordering)
-> (Register -> Natural)
-> (Natural -> Ordering)
-> Register
-> Ordering
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Natural -> Ordering)
-> (Register -> Natural) -> Register -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) Register -> Natural
forall a. IsRegister a => a -> Natural
byteWidth ((Natural -> Ordering) -> Register -> Ordering)
-> (Register -> Natural -> Ordering)
-> Register
-> Register
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Natural -> Natural -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Natural -> Natural -> Ordering)
-> (Register -> Natural) -> Register -> Natural -> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Register -> Natural
forall a. IsRegister a => a -> Natural
byteWidth
{-# INLINE rax #-}
rax :: Register
rax :: Register
rax = AccumulatorReg -> Register
Accumulator AccumulatorReg
RAX
{-# INLINE eax #-}
eax :: Register
eax :: Register
eax = AccumulatorReg -> Register
Accumulator AccumulatorReg
EAX
{-# INLINE ax #-}
ax :: Register
ax :: Register
ax = AccumulatorReg -> Register
Accumulator AccumulatorReg
AX
{-# INLINE ah #-}
ah :: Register
ah :: Register
ah = AccumulatorReg -> Register
Accumulator AccumulatorReg
AH
{-# INLINE al #-}
al :: Register
al :: Register
al = AccumulatorReg -> Register
Accumulator AccumulatorReg
AL
{-# INLINE rbx #-}
rbx :: Register
rbx :: Register
rbx = BaseReg -> Register
Base BaseReg
RBX
{-# INLINE ebx #-}
ebx :: Register
ebx :: Register
ebx = BaseReg -> Register
Base BaseReg
RBX
{-# INLINE bx #-}
bx :: Register
bx :: Register
bx = BaseReg -> Register
Base BaseReg
BX
{-# INLINE bh #-}
bh :: Register
bh :: Register
bh = BaseReg -> Register
Base BaseReg
BH
{-# INLINE bl #-}
bl :: Register
bl :: Register
bl = BaseReg -> Register
Base BaseReg
BL
{-# INLINE rcx #-}
rcx :: Register
rcx :: Register
rcx = CounterReg -> Register
Counter CounterReg
RCX
{-# INLINE ecx #-}
ecx :: Register
ecx :: Register
ecx = CounterReg -> Register
Counter CounterReg
ECX
{-# INLINE cx #-}
cx :: Register
cx :: Register
cx = CounterReg -> Register
Counter CounterReg
CX
{-# INLINE ch #-}
ch :: Register
ch :: Register
ch = CounterReg -> Register
Counter CounterReg
CH
{-# INLINE cl #-}
cl :: Register
cl :: Register
cl = CounterReg -> Register
Counter CounterReg
CL
{-# INLINE rdx #-}
rdx :: Register
rdx :: Register
rdx = DataReg -> Register
Data DataReg
RDX
{-# INLINE edx #-}
edx :: Register
edx :: Register
edx = DataReg -> Register
Data DataReg
EDX
{-# INLINE dx #-}
dx :: Register
dx :: Register
dx = DataReg -> Register
Data DataReg
DX
{-# INLINE dh #-}
dh :: Register
dh :: Register
dh = DataReg -> Register
Data DataReg
DH
{-# INLINE dl #-}
dl :: Register
dl :: Register
dl = DataReg -> Register
Data DataReg
DL
{-# INLINE rsi #-}
rsi :: Register
rsi :: Register
rsi = SrcIndexReg -> Register
SrcIndex SrcIndexReg
RSI
{-# INLINE esi #-}
esi :: Register
esi :: Register
esi = SrcIndexReg -> Register
SrcIndex SrcIndexReg
ESI
{-# INLINE si #-}
si :: Register
si :: Register
si = SrcIndexReg -> Register
SrcIndex SrcIndexReg
SI
{-# INLINE sil #-}
sil :: Register
sil :: Register
sil = SrcIndexReg -> Register
SrcIndex SrcIndexReg
SIL
{-# INLINE rdi #-}
rdi :: Register
rdi :: Register
rdi = DstIndexReg -> Register
DstIndex DstIndexReg
RDI
{-# INLINE edi #-}
edi :: Register
edi :: Register
edi = DstIndexReg -> Register
DstIndex DstIndexReg
EDI
{-# INLINE di #-}
di :: Register
di :: Register
di = DstIndexReg -> Register
DstIndex DstIndexReg
DI
{-# INLINE dil #-}
dil :: Register
dil :: Register
dil = DstIndexReg -> Register
DstIndex DstIndexReg
DIL
{-# INLINE rbp #-}
rbp :: Register
rbp :: Register
rbp = BasePtrReg -> Register
BasePtr BasePtrReg
RBP
{-# INLINE ebp #-}
ebp :: Register
ebp :: Register
ebp = BasePtrReg -> Register
BasePtr BasePtrReg
EBP
{-# INLINE bp #-}
bp :: Register
bp :: Register
bp = BasePtrReg -> Register
BasePtr BasePtrReg
BP
{-# INLINE bpl #-}
bpl :: Register
bpl :: Register
bpl = BasePtrReg -> Register
BasePtr BasePtrReg
BPL
{-# INLINE rsp #-}
rsp :: Register
rsp :: Register
rsp = StackPtrReg -> Register
StackPtr StackPtrReg
RSP
{-# INLINE esp #-}
esp :: Register
esp :: Register
esp = StackPtrReg -> Register
StackPtr StackPtrReg
ESP
{-# INLINE sp #-}
sp :: Register
sp :: Register
sp = StackPtrReg -> Register
StackPtr StackPtrReg
SP
{-# INLINE spl #-}
spl :: Register
spl :: Register
spl = StackPtrReg -> Register
StackPtr StackPtrReg
SPL
{-# INLINE rn #-}
rn :: Int -> Register
rn :: Int -> Register
rn = ExtendedReg -> Register
Extended (ExtendedReg -> Register)
-> (Int -> ExtendedReg) -> Int -> Register
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ExtendedReg
Rn
{-# INLINE rnd #-}
rnd :: Int -> Register
rnd :: Int -> Register
rnd = ExtendedReg -> Register
Extended (ExtendedReg -> Register)
-> (Int -> ExtendedReg) -> Int -> Register
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ExtendedReg
RnD
{-# INLINE rnw #-}
rnw :: Int -> Register
rnw :: Int -> Register
rnw = ExtendedReg -> Register
Extended (ExtendedReg -> Register)
-> (Int -> ExtendedReg) -> Int -> Register
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ExtendedReg
RnW
{-# INLINE rnb #-}
rnb :: Int -> Register
rnb :: Int -> Register
rnb = ExtendedReg -> Register
Extended (ExtendedReg -> Register)
-> (Int -> ExtendedReg) -> Int -> Register
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ExtendedReg
RnB
{-# INLINE argRegs #-}
argRegs :: [[Register]]
argRegs :: [[Register]]
argRegs = [[Register
dil, Register
di, Register
edi, Register
rdi], [Register
sil, Register
si, Register
esi, Register
rsi], [Register
dl, Register
dx, Register
edx, Register
rdx], [Register
cl, Register
cx, Register
ecx, Register
rcx], [Int -> Register
rnb 8, Int -> Register
rnw 8, Int -> Register
rnd 8, Int -> Register
rn 8], [Int -> Register
rnb 9, Int -> Register
rnw 9, Int -> Register
rnd 9, Int -> Register
rn 9]]
{-# INLINE popRegs #-}
popRegs :: Int -> [Register]
popRegs :: Int -> [Register]
popRegs = (Int -> [Register] -> [Register])
-> [Register] -> Int -> [Register]
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> [Register] -> [Register]
forall a. Int -> [a] -> [a]
drop [Int -> Register
rn 9, Int -> Register
rn 8, Register
rcx, Register
rdx, Register
rsi, Register
rdi] (Int -> [Register]) -> (Int -> Int) -> Int -> [Register]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (6Int -> Int -> Int
forall a. Num a => a -> a -> a
-)