mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2024-12-23 08:45:37 +00:00
Small changes to align with hapstone (Haskell bindings for Capstone)
Enums now derive bounded and made use of Applicative in Utils module
This commit is contained in:
parent
023e4375d0
commit
0a3f83a20c
|
@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
|
||||||
omit (UC_ARM_REG_INVALID,
|
omit (UC_ARM_REG_INVALID,
|
||||||
UC_ARM_REG_ENDING)
|
UC_ARM_REG_ENDING)
|
||||||
with prefix="UC_ARM_REG_"
|
with prefix="UC_ARM_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
|
@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
|
||||||
omit (UC_ARM64_REG_INVALID,
|
omit (UC_ARM64_REG_INVALID,
|
||||||
UC_ARM64_REG_ENDING)
|
UC_ARM64_REG_ENDING)
|
||||||
with prefix="UC_ARM64_REG_"
|
with prefix="UC_ARM64_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
|
@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
|
||||||
omit (UC_M68K_REG_INVALID,
|
omit (UC_M68K_REG_INVALID,
|
||||||
UC_M68K_REG_ENDING)
|
UC_M68K_REG_ENDING)
|
||||||
with prefix="UC_M68K_REG_"
|
with prefix="UC_M68K_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
|
@ -56,6 +56,6 @@ import Unicorn.Internal.Core (Reg)
|
||||||
omit (UC_MIPS_REG_INVALID,
|
omit (UC_MIPS_REG_INVALID,
|
||||||
UC_MIPS_REG_ENDING)
|
UC_MIPS_REG_ENDING)
|
||||||
with prefix="UC_MIPS_REG_"
|
with prefix="UC_MIPS_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
|
@ -24,6 +24,6 @@ import Unicorn.Internal.Core (Reg)
|
||||||
omit (UC_SPARC_REG_INVALID,
|
omit (UC_SPARC_REG_INVALID,
|
||||||
UC_SPARC_REG_ENDING)
|
UC_SPARC_REG_ENDING)
|
||||||
with prefix="UC_SPARC_REG_"
|
with prefix="UC_SPARC_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
|
@ -52,7 +52,7 @@ instance Storable Mmr where
|
||||||
omit (UC_X86_REG_INVALID,
|
omit (UC_X86_REG_INVALID,
|
||||||
UC_X86_REG_ENDING)
|
UC_X86_REG_ENDING)
|
||||||
with prefix="UC_X86_REG_"
|
with prefix="UC_X86_REG_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
instance Reg Register
|
instance Reg Register
|
||||||
|
|
||||||
|
@ -62,4 +62,4 @@ instance Reg Register
|
||||||
omit (UC_X86_INS_INVALID,
|
omit (UC_X86_INS_INVALID,
|
||||||
UC_X86_INS_ENDING)
|
UC_X86_INS_ENDING)
|
||||||
with prefix="UC_X86_INS_"
|
with prefix="UC_X86_INS_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
|
@ -42,7 +42,7 @@ mkEngine ptr =
|
||||||
{# enum uc_err as Error
|
{# enum uc_err as Error
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix = "UC_"
|
with prefix = "UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | The emulator runs in the IO monad and allows for the handling of errors
|
-- | The emulator runs in the IO monad and allows for the handling of errors
|
||||||
-- "under the hood".
|
-- "under the hood".
|
||||||
|
|
|
@ -103,7 +103,7 @@ type Hook = {# type uc_hook #}
|
||||||
UC_HOOK_MEM_WRITE,
|
UC_HOOK_MEM_WRITE,
|
||||||
UC_HOOK_MEM_FETCH)
|
UC_HOOK_MEM_FETCH)
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | Memory hook types (for valid memory accesses).
|
-- | Memory hook types (for valid memory accesses).
|
||||||
{# enum uc_hook_type as MemoryHookType
|
{# enum uc_hook_type as MemoryHookType
|
||||||
|
@ -119,7 +119,7 @@ type Hook = {# type uc_hook #}
|
||||||
UC_HOOK_MEM_WRITE_PROT,
|
UC_HOOK_MEM_WRITE_PROT,
|
||||||
UC_HOOK_MEM_FETCH_PROT)
|
UC_HOOK_MEM_FETCH_PROT)
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | Memory event hook types (for invalid memory accesses).
|
-- | Memory event hook types (for invalid memory accesses).
|
||||||
{# enum uc_hook_type as MemoryEventHookType
|
{# enum uc_hook_type as MemoryEventHookType
|
||||||
|
@ -132,7 +132,7 @@ type Hook = {# type uc_hook #}
|
||||||
UC_HOOK_MEM_WRITE,
|
UC_HOOK_MEM_WRITE,
|
||||||
UC_HOOK_MEM_FETCH)
|
UC_HOOK_MEM_FETCH)
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | Unify the hook types with a type class
|
-- | Unify the hook types with a type class
|
||||||
class Enum a => HookTypeC a
|
class Enum a => HookTypeC a
|
||||||
|
@ -145,7 +145,7 @@ instance HookTypeC MemoryEventHookType
|
||||||
{# enum uc_mem_type as MemoryAccess
|
{# enum uc_mem_type as MemoryAccess
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Hook callbacks
|
-- Hook callbacks
|
||||||
|
|
|
@ -61,19 +61,19 @@ import Unicorn.Internal.Util
|
||||||
{# enum uc_arch as Architecture
|
{# enum uc_arch as Architecture
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix = "UC_"
|
with prefix = "UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | CPU hardware mode.
|
-- | CPU hardware mode.
|
||||||
{# enum uc_mode as Mode
|
{# enum uc_mode as Mode
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | Memory permissions.
|
-- | Memory permissions.
|
||||||
{# enum uc_prot as MemoryPermission
|
{# enum uc_prot as MemoryPermission
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-- | Memory region mapped by 'memMap'. Retrieve the list of memory regions with
|
-- | Memory region mapped by 'memMap'. Retrieve the list of memory regions with
|
||||||
-- 'memRegions'.
|
-- 'memRegions'.
|
||||||
|
@ -102,7 +102,7 @@ instance Storable MemoryRegion where
|
||||||
{# enum uc_query_type as QueryType
|
{# enum uc_query_type as QueryType
|
||||||
{underscoreToCase}
|
{underscoreToCase}
|
||||||
with prefix="UC_"
|
with prefix="UC_"
|
||||||
deriving (Show, Eq) #}
|
deriving (Show, Eq, Bounded) #}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- Emulator control
|
-- Emulator control
|
||||||
|
|
|
@ -6,13 +6,14 @@ License : GPL-2
|
||||||
-}
|
-}
|
||||||
module Unicorn.Internal.Util where
|
module Unicorn.Internal.Util where
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
import Foreign
|
import Foreign
|
||||||
|
|
||||||
-- | Combine a list of Enums by performing a bitwise-OR.
|
-- | Combine a list of Enums by performing a bitwise-OR.
|
||||||
combineEnums :: (Enum a, Num b, Bits b) => [a] -> b
|
combineEnums :: (Enum a, Num b, Bits b) => [a] -> b
|
||||||
combineEnums =
|
combineEnums =
|
||||||
foldr (\p -> (.|.) (enumToNum p)) 0
|
foldr ((.|.) <$> enumToNum) 0
|
||||||
|
|
||||||
-- | Cast a pointer and then peek inside it.
|
-- | Cast a pointer and then peek inside it.
|
||||||
castPtrAndPeek :: Storable a => Ptr b -> IO a
|
castPtrAndPeek :: Storable a => Ptr b -> IO a
|
||||||
|
|
Loading…
Reference in a new issue