Cranelift: Add LibCall::Memcmp

The comment says the enum is "likely to grow" and the function's been in libc since C89, so hopefully this is ok.

I'd like to use it for emitting things like array equality.
This commit is contained in:
Scott McMurray
2021-05-31 12:27:29 -07:00
parent d1e9a7840e
commit c266f7f4c3
3 changed files with 112 additions and 0 deletions

View File

@@ -56,6 +56,8 @@ pub enum LibCall {
Memset,
/// libc.memmove
Memmove,
/// libc.memcmp
Memcmp,
/// Elf __tls_get_addr
ElfTlsGetAddr,
@@ -92,6 +94,7 @@ impl FromStr for LibCall {
"Memcpy" => Ok(Self::Memcpy),
"Memset" => Ok(Self::Memset),
"Memmove" => Ok(Self::Memmove),
"Memcmp" => Ok(Self::Memcmp),
"ElfTlsGetAddr" => Ok(Self::ElfTlsGetAddr),
_ => Err(()),
@@ -157,6 +160,7 @@ impl LibCall {
Memcpy,
Memset,
Memmove,
Memcmp,
ElfTlsGetAddr,
]
}
@@ -201,4 +205,11 @@ mod tests {
fn parsing() {
assert_eq!("FloorF32".parse(), Ok(LibCall::FloorF32));
}
#[test]
fn all_libcalls_to_from_string() {
for &libcall in LibCall::all_libcalls() {
assert_eq!(libcall.to_string().parse(), Ok(libcall));
}
}
}