Path: blob/main/cranelift/codegen/src/ir/known_symbol.rs
1693 views
use core::fmt;1use core::str::FromStr;2#[cfg(feature = "enable-serde")]3use serde_derive::{Deserialize, Serialize};45/// A well-known symbol.6#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]7#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]8pub enum KnownSymbol {9/// ELF well-known linker symbol _GLOBAL_OFFSET_TABLE_10ElfGlobalOffsetTable,11/// TLS index symbol for the current thread.12/// Used in COFF/PE file formats.13CoffTlsIndex,14}1516impl fmt::Display for KnownSymbol {17fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {18fmt::Debug::fmt(self, f)19}20}2122impl FromStr for KnownSymbol {23type Err = ();2425fn from_str(s: &str) -> Result<Self, Self::Err> {26match s {27"ElfGlobalOffsetTable" => Ok(Self::ElfGlobalOffsetTable),28"CoffTlsIndex" => Ok(Self::CoffTlsIndex),29_ => Err(()),30}31}32}3334#[cfg(test)]35mod tests {36use super::*;3738#[test]39fn parsing() {40assert_eq!(41"ElfGlobalOffsetTable".parse(),42Ok(KnownSymbol::ElfGlobalOffsetTable)43);44assert_eq!("CoffTlsIndex".parse(), Ok(KnownSymbol::CoffTlsIndex));45}46}474849