feat: cleaned the IntrinsicType struct and associated functions.
Changes: 1. Removed `from_c` from the IntrinsicType definition. 2. Moved the `from_c` arm-specific definition to an ArmIntrinsicType-specific impl block
This commit is contained in:
parent
daa742afe5
commit
76dce27325
4 changed files with 26 additions and 27 deletions
|
|
@ -5,19 +5,22 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
|
|||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ArmIntrinsicType(pub IntrinsicType);
|
||||
pub struct ArmIntrinsicType {
|
||||
pub data: IntrinsicType,
|
||||
pub target: String,
|
||||
}
|
||||
|
||||
impl Deref for ArmIntrinsicType {
|
||||
type Target = IntrinsicType;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
&self.data
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for ArmIntrinsicType {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
&mut self.data
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ fn json_to_intrinsic(
|
|||
// The JSON doesn't list immediates as const
|
||||
let IntrinsicType {
|
||||
ref mut constant, ..
|
||||
} = arg.ty.0;
|
||||
} = arg.ty.data;
|
||||
if arg.name.starts_with("imm") {
|
||||
*constant = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, S
|
|||
impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
||||
/// Gets a string containing the typename for this type in C format.
|
||||
fn c_type(&self) -> String {
|
||||
let prefix = self.0.kind.c_prefix();
|
||||
let const_prefix = if self.0.constant { "const " } else { "" };
|
||||
let prefix = self.kind.c_prefix();
|
||||
let const_prefix = if self.constant { "const " } else { "" };
|
||||
|
||||
if let (Some(bit_len), simd_len, vec_len) =
|
||||
(self.0.bit_len, self.0.simd_len, self.0.vec_len)
|
||||
(self.bit_len, self.simd_len, self.vec_len)
|
||||
{
|
||||
match (simd_len, vec_len) {
|
||||
(None, None) => format!("{const_prefix}{prefix}{bit_len}_t"),
|
||||
|
|
@ -23,10 +23,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
}
|
||||
|
||||
fn c_single_vector_type(&self) -> String {
|
||||
if let (Some(bit_len), Some(simd_len)) = (self.0.bit_len, self.0.simd_len) {
|
||||
if let (Some(bit_len), Some(simd_len)) = (self.bit_len, self.simd_len) {
|
||||
format!(
|
||||
"{prefix}{bit_len}x{simd_len}_t",
|
||||
prefix = self.0.kind.c_prefix()
|
||||
prefix = self.kind.c_prefix()
|
||||
)
|
||||
} else {
|
||||
unreachable!("Shouldn't be called on this type")
|
||||
|
|
@ -40,9 +40,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
bit_len: Some(bl),
|
||||
simd_len,
|
||||
vec_len,
|
||||
target,
|
||||
..
|
||||
} = &self.0
|
||||
} = &self.data
|
||||
{
|
||||
let quad = if simd_len.unwrap_or(1) * bl > 64 {
|
||||
"q"
|
||||
|
|
@ -50,7 +49,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
""
|
||||
};
|
||||
|
||||
let choose_workaround = language == Language::C && target.contains("v7");
|
||||
let choose_workaround = language == Language::C && self.target.contains("v7");
|
||||
format!(
|
||||
"vld{len}{quad}_{type}{size}",
|
||||
type = match k {
|
||||
|
|
@ -78,7 +77,7 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
bit_len: Some(bl),
|
||||
simd_len,
|
||||
..
|
||||
} = &self.0
|
||||
} = &self.data
|
||||
{
|
||||
let quad = if (simd_len.unwrap_or(1) * bl) > 64 {
|
||||
"q"
|
||||
|
|
@ -101,8 +100,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
todo!("get_lane_function IntrinsicType: {:#?}", self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_c(s: &str, target: &str) -> Result<Self, String> {
|
||||
impl ArmIntrinsicType {
|
||||
pub fn from_c(s: &str, target: &str) -> Result<Self, String> {
|
||||
const CONST_STR: &str = "const";
|
||||
if let Some(s) = s.strip_suffix('*') {
|
||||
let (s, constant) = match s.trim().strip_suffix(CONST_STR) {
|
||||
|
|
@ -143,7 +144,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
),
|
||||
None => None,
|
||||
};
|
||||
Ok(ArmIntrinsicType(IntrinsicType {
|
||||
Ok(ArmIntrinsicType{
|
||||
data: IntrinsicType {
|
||||
ptr: false,
|
||||
ptr_constant: false,
|
||||
constant,
|
||||
|
|
@ -151,15 +153,16 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
bit_len: Some(bit_len),
|
||||
simd_len,
|
||||
vec_len,
|
||||
target: target.to_string(),
|
||||
}))
|
||||
},
|
||||
target: target.to_string()})
|
||||
} else {
|
||||
let kind = start.parse::<TypeKind>()?;
|
||||
let bit_len = match kind {
|
||||
TypeKind::Int(_) => Some(32),
|
||||
_ => None,
|
||||
};
|
||||
Ok(ArmIntrinsicType(IntrinsicType {
|
||||
Ok(ArmIntrinsicType{
|
||||
data: IntrinsicType {
|
||||
ptr: false,
|
||||
ptr_constant: false,
|
||||
constant,
|
||||
|
|
@ -167,8 +170,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
|
|||
bit_len,
|
||||
simd_len: None,
|
||||
vec_len: None,
|
||||
target: target.to_string(),
|
||||
}))
|
||||
},
|
||||
target: target.to_string()})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,8 +120,6 @@ pub struct IntrinsicType {
|
|||
/// rows encoded in the type (e.g. uint8x8_t).
|
||||
/// A value of `None` can be assumed to be 1 though.
|
||||
pub vec_len: Option<u32>,
|
||||
|
||||
pub target: String,
|
||||
}
|
||||
|
||||
impl IntrinsicType {
|
||||
|
|
@ -321,11 +319,6 @@ pub trait IntrinsicTypeDefinition: Deref<Target = IntrinsicType> {
|
|||
/// can be implemented in an `impl` block
|
||||
fn get_lane_function(&self) -> String;
|
||||
|
||||
/// can be implemented in an `impl` block
|
||||
fn from_c(_s: &str, _target: &str) -> Result<Self, String>
|
||||
where
|
||||
Self: Sized;
|
||||
|
||||
/// Gets a string containing the typename for this type in C format.
|
||||
/// can be directly defined in `impl` blocks
|
||||
fn c_type(&self) -> String;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue