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:
Dan Gohman
2018-12-06 10:50:12 -05:00
parent 38d1d58e06
commit 566c160c37
3 changed files with 13 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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.

View File

@@ -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.