Add a function to return the pointer type for a given triple.
Also use a slightly tidier naming convention for such functions.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use std::default::Default;
|
||||
use std::fmt::{self, Debug, Display, Formatter};
|
||||
use target_lexicon::{PointerWidth, Triple};
|
||||
|
||||
/// The type of an SSA value.
|
||||
///
|
||||
@@ -271,6 +272,16 @@ impl Type {
|
||||
pub fn wider_or_equal(self, other: Self) -> bool {
|
||||
self.lane_count() == other.lane_count() && self.lane_bits() >= other.lane_bits()
|
||||
}
|
||||
|
||||
/// Return the pointer type for the given target triple.
|
||||
pub fn triple_pointer_type(triple: &Triple) -> Self {
|
||||
match triple.pointer_width() {
|
||||
Ok(PointerWidth::U16) => I16,
|
||||
Ok(PointerWidth::U32) => I32,
|
||||
Ok(PointerWidth::U64) => I64,
|
||||
Err(()) => panic!("unable to determine architecture pointer width"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Type {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub enum CallConv {
|
||||
|
||||
impl CallConv {
|
||||
/// Return the default calling convention for the given target triple.
|
||||
pub fn default_for_triple(triple: &Triple) -> Self {
|
||||
pub fn triple_default(triple: &Triple) -> Self {
|
||||
match triple.default_calling_convention() {
|
||||
// Default to System V for unknown targets because most everything
|
||||
// uses System V.
|
||||
|
||||
@@ -208,7 +208,7 @@ pub trait TargetIsa: fmt::Display + Sync {
|
||||
|
||||
/// Get the default calling convention of this target.
|
||||
fn default_call_conv(&self) -> CallConv {
|
||||
CallConv::default_for_triple(self.triple())
|
||||
CallConv::triple_default(self.triple())
|
||||
}
|
||||
|
||||
/// Get the pointer type of this ISA.
|
||||
|
||||
Reference in New Issue
Block a user