use std::fmt;
use std::str;
use target_lexicon::{CallingConvention, Triple};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum CallConv {
Fast,
Cold,
SystemV,
WindowsFastcall,
Baldrdash,
Probestack,
}
impl CallConv {
pub fn default_for_triple(triple: &Triple) -> Self {
match triple.default_calling_convention() {
Ok(CallingConvention::SystemV) | Err(()) => CallConv::SystemV,
Ok(CallingConvention::WindowsFastcall) => CallConv::WindowsFastcall,
}
}
}
impl fmt::Display for CallConv {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(match *self {
CallConv::Fast => "fast",
CallConv::Cold => "cold",
CallConv::SystemV => "system_v",
CallConv::WindowsFastcall => "windows_fastcall",
CallConv::Baldrdash => "baldrdash",
CallConv::Probestack => "probestack",
})
}
}
impl str::FromStr for CallConv {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"fast" => Ok(CallConv::Fast),
"cold" => Ok(CallConv::Cold),
"system_v" => Ok(CallConv::SystemV),
"windows_fastcall" => Ok(CallConv::WindowsFastcall),
"baldrdash" => Ok(CallConv::Baldrdash),
"probestack" => Ok(CallConv::Probestack),
_ => Err(()),
}
}
}