module Data.SpirV.Enum.MemoryAccess where import Data.Bits (Bits) import Data.String (IsString(..)) import Data.Word (Word32) import Foreign (Storable(..)) import GHC.Read (Read(..)) import Text.ParserCombinators.ReadPrec (pfail) import qualified GHC.Read as Read import qualified Text.Read.Lex as Lex newtype MemoryAccess = MemoryAccess Word32 deriving (Eq, Ord, Storable, Bits) pattern Volatile :: MemoryAccess pattern Volatile = MemoryAccess 0x1 pattern Aligned :: MemoryAccess pattern Aligned = MemoryAccess 0x2 pattern Nontemporal :: MemoryAccess pattern Nontemporal = MemoryAccess 0x4 pattern MakePointerAvailable :: MemoryAccess pattern MakePointerAvailable = MemoryAccess 0x8 pattern MakePointerAvailableKHR :: MemoryAccess pattern MakePointerAvailableKHR = MemoryAccess 0x8 pattern MakePointerVisible :: MemoryAccess pattern MakePointerVisible = MemoryAccess 0x10 pattern MakePointerVisibleKHR :: MemoryAccess pattern MakePointerVisibleKHR = MemoryAccess 0x10 pattern NonPrivatePointer :: MemoryAccess pattern NonPrivatePointer = MemoryAccess 0x20 pattern NonPrivatePointerKHR :: MemoryAccess pattern NonPrivatePointerKHR = MemoryAccess 0x20 pattern AliasScopeINTELMask :: MemoryAccess pattern AliasScopeINTELMask = MemoryAccess 0x10000 pattern NoAliasINTELMask :: MemoryAccess pattern NoAliasINTELMask = MemoryAccess 0x20000 toName :: IsString a => MemoryAccess -> a toName x = case x of Volatile -> "Volatile" Aligned -> "Aligned" Nontemporal -> "Nontemporal" MakePointerAvailable -> "MakePointerAvailable" MakePointerAvailableKHR -> "MakePointerAvailableKHR" MakePointerVisible -> "MakePointerVisible" MakePointerVisibleKHR -> "MakePointerVisibleKHR" NonPrivatePointer -> "NonPrivatePointer" NonPrivatePointerKHR -> "NonPrivatePointerKHR" AliasScopeINTELMask -> "AliasScopeINTELMask" NoAliasINTELMask -> "NoAliasINTELMask" unknown -> fromString $ "MemoryAccess " ++ show unknown instance Show MemoryAccess where show = toName fromName :: (IsString a, Eq a) => a -> Maybe MemoryAccess fromName x = case x of "Volatile" -> Just Volatile "Aligned" -> Just Aligned "Nontemporal" -> Just Nontemporal "MakePointerAvailable" -> Just MakePointerAvailable "MakePointerAvailableKHR" -> Just MakePointerAvailableKHR "MakePointerVisible" -> Just MakePointerVisible "MakePointerVisibleKHR" -> Just MakePointerVisibleKHR "NonPrivatePointer" -> Just NonPrivatePointer "NonPrivatePointerKHR" -> Just NonPrivatePointerKHR "AliasScopeINTELMask" -> Just AliasScopeINTELMask "NoAliasINTELMask" -> Just NoAliasINTELMask _unknown -> Nothing instance Read MemoryAccess where readPrec = Read.parens do Lex.Ident s <- Read.lexP maybe pfail pure $ fromName s