Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/codegen/src/ir/known_symbol.rs
1693 views
1
use core::fmt;
2
use core::str::FromStr;
3
#[cfg(feature = "enable-serde")]
4
use serde_derive::{Deserialize, Serialize};
5
6
/// A well-known symbol.
7
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
8
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
9
pub enum KnownSymbol {
10
/// ELF well-known linker symbol _GLOBAL_OFFSET_TABLE_
11
ElfGlobalOffsetTable,
12
/// TLS index symbol for the current thread.
13
/// Used in COFF/PE file formats.
14
CoffTlsIndex,
15
}
16
17
impl fmt::Display for KnownSymbol {
18
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19
fmt::Debug::fmt(self, f)
20
}
21
}
22
23
impl FromStr for KnownSymbol {
24
type Err = ();
25
26
fn from_str(s: &str) -> Result<Self, Self::Err> {
27
match s {
28
"ElfGlobalOffsetTable" => Ok(Self::ElfGlobalOffsetTable),
29
"CoffTlsIndex" => Ok(Self::CoffTlsIndex),
30
_ => Err(()),
31
}
32
}
33
}
34
35
#[cfg(test)]
36
mod tests {
37
use super::*;
38
39
#[test]
40
fn parsing() {
41
assert_eq!(
42
"ElfGlobalOffsetTable".parse(),
43
Ok(KnownSymbol::ElfGlobalOffsetTable)
44
);
45
assert_eq!("CoffTlsIndex".parse(), Ok(KnownSymbol::CoffTlsIndex));
46
}
47
}
48
49