-- | Names as used in LLVM IR module LLVM.AST.Name where import LLVM.Prelude import Data.Char import Data.String {- | Objects of various sorts in LLVM IR are identified by address in the LLVM C++ API, and may be given a string name. When printed to (resp. read from) human-readable LLVM assembly, objects without string names are numbered sequentially (resp. must be numbered sequentially). String names may be quoted, and are quoted when printed if they would otherwise be misread - e.g. when containing special characters. > 7 means the seventh unnamed object, while > "7" means the object named with the string "7". This libraries handling of 'UnName's during translation of the AST down into C++ IR is somewhat more forgiving than the LLVM assembly parser: it does not require that unnamed values be numbered sequentially; however, the numbers of 'UnName's passed into C++ cannot be preserved in the C++ objects. If the C++ IR is printed as assembly or translated into a Haskell AST, unnamed nodes will be renumbered sequentially. Thus unnamed node numbers should be thought of as having any scope limited to the 'LLVM.AST.Module' in which they are used. -} data Name = Name ShortByteString -- ^ a string name | UnName Word -- ^ a number for a nameless thing deriving (Name -> Name -> Bool (Name -> Name -> Bool) -> (Name -> Name -> Bool) -> Eq Name forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: Name -> Name -> Bool $c/= :: Name -> Name -> Bool == :: Name -> Name -> Bool $c== :: Name -> Name -> Bool Eq, Eq Name Eq Name => (Name -> Name -> Ordering) -> (Name -> Name -> Bool) -> (Name -> Name -> Bool) -> (Name -> Name -> Bool) -> (Name -> Name -> Bool) -> (Name -> Name -> Name) -> (Name -> Name -> Name) -> Ord Name Name -> Name -> Bool Name -> Name -> Ordering Name -> Name -> Name forall a. Eq a => (a -> a -> Ordering) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> Bool) -> (a -> a -> a) -> (a -> a -> a) -> Ord a min :: Name -> Name -> Name $cmin :: Name -> Name -> Name max :: Name -> Name -> Name $cmax :: Name -> Name -> Name >= :: Name -> Name -> Bool $c>= :: Name -> Name -> Bool > :: Name -> Name -> Bool $c> :: Name -> Name -> Bool <= :: Name -> Name -> Bool $c<= :: Name -> Name -> Bool < :: Name -> Name -> Bool $c< :: Name -> Name -> Bool compare :: Name -> Name -> Ordering $ccompare :: Name -> Name -> Ordering $cp1Ord :: Eq Name Ord, ReadPrec [Name] ReadPrec Name Int -> ReadS Name ReadS [Name] (Int -> ReadS Name) -> ReadS [Name] -> ReadPrec Name -> ReadPrec [Name] -> Read Name forall a. (Int -> ReadS a) -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a readListPrec :: ReadPrec [Name] $creadListPrec :: ReadPrec [Name] readPrec :: ReadPrec Name $creadPrec :: ReadPrec Name readList :: ReadS [Name] $creadList :: ReadS [Name] readsPrec :: Int -> ReadS Name $creadsPrec :: Int -> ReadS Name Read, Int -> Name -> ShowS [Name] -> ShowS Name -> String (Int -> Name -> ShowS) -> (Name -> String) -> ([Name] -> ShowS) -> Show Name forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a showList :: [Name] -> ShowS $cshowList :: [Name] -> ShowS show :: Name -> String $cshow :: Name -> String showsPrec :: Int -> Name -> ShowS $cshowsPrec :: Int -> Name -> ShowS Show, Typeable, Typeable Name DataType Constr Typeable Name => (forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name) -> (forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name) -> (Name -> Constr) -> (Name -> DataType) -> (forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Name)) -> (forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name)) -> ((forall b. Data b => b -> b) -> Name -> Name) -> (forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r) -> (forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r) -> (forall u. (forall d. Data d => d -> u) -> Name -> [u]) -> (forall u. Int -> (forall d. Data d => d -> u) -> Name -> u) -> (forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> Name -> m Name) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name) -> Data Name Name -> DataType Name -> Constr (forall b. Data b => b -> b) -> Name -> Name (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name forall a. Typeable a => (forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> a -> c a) -> (forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c a) -> (a -> Constr) -> (a -> DataType) -> (forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c a)) -> (forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a)) -> ((forall b. Data b => b -> b) -> a -> a) -> (forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r) -> (forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r) -> (forall u. (forall d. Data d => d -> u) -> a -> [u]) -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u) -> (forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> a -> m a) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a) -> (forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> a -> m a) -> Data a forall u. Int -> (forall d. Data d => d -> u) -> Name -> u forall u. (forall d. Data d => d -> u) -> Name -> [u] forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> Name -> m Name forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Name) forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name) $cUnName :: Constr $cName :: Constr $tName :: DataType gmapMo :: (forall d. Data d => d -> m d) -> Name -> m Name $cgmapMo :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name gmapMp :: (forall d. Data d => d -> m d) -> Name -> m Name $cgmapMp :: forall (m :: * -> *). MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name gmapM :: (forall d. Data d => d -> m d) -> Name -> m Name $cgmapM :: forall (m :: * -> *). Monad m => (forall d. Data d => d -> m d) -> Name -> m Name gmapQi :: Int -> (forall d. Data d => d -> u) -> Name -> u $cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Name -> u gmapQ :: (forall d. Data d => d -> u) -> Name -> [u] $cgmapQ :: forall u. (forall d. Data d => d -> u) -> Name -> [u] gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r $cgmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r $cgmapQl :: forall r r'. (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r gmapT :: (forall b. Data b => b -> b) -> Name -> Name $cgmapT :: (forall b. Data b => b -> b) -> Name -> Name dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name) $cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *). Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name) dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c Name) $cdataCast1 :: forall (t :: * -> *) (c :: * -> *). Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Name) dataTypeOf :: Name -> DataType $cdataTypeOf :: Name -> DataType toConstr :: Name -> Constr $ctoConstr :: Name -> Constr gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name $cgunfold :: forall (c :: * -> *). (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name $cgfoldl :: forall (c :: * -> *). (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name $cp1Data :: Typeable Name Data, (forall x. Name -> Rep Name x) -> (forall x. Rep Name x -> Name) -> Generic Name forall x. Rep Name x -> Name forall x. Name -> Rep Name x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cto :: forall x. Rep Name x -> Name $cfrom :: forall x. Name -> Rep Name x Generic) -- | Using 'fromString` on non-ASCII strings will throw an error. instance IsString Name where fromString :: String -> Name fromString s :: String s | (Char -> Bool) -> String -> Bool forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool all Char -> Bool isAscii String s = ShortByteString -> Name Name (String -> ShortByteString forall a. IsString a => String -> a fromString String s) | Bool otherwise = String -> Name forall a. HasCallStack => String -> a error ("Only ASCII strings are automatically converted to LLVM names. " String -> ShowS forall a. Semigroup a => a -> a -> a <> "Other strings need to be encoded to a `ShortByteString` using an arbitrary encoding.") -- | Create a 'Name' based on an ASCII 'String'. -- Non-ASCII strings will throw an error. mkName :: String -> Name mkName :: String -> Name mkName = String -> Name forall a. IsString a => String -> a fromString