about summary refs log tree commit diff
path: root/library/stdarch/crates/intrinsic-test
diff options
context:
space:
mode:
authorMadhav Madhusoodanan <madhavmadhusoodanan@gmail.com>2025-08-05 13:14:39 +0530
committerMadhav Madhusoodanan <madhavmadhusoodanan@gmail.com>2025-08-05 13:21:47 +0530
commit76dce27325207bdefbbdc1e76dab0605fbdc4294 (patch)
treee4d6a2fd816ec549c71e9aa9ba97e3d915ea06f6 /library/stdarch/crates/intrinsic-test
parentdaa742afe5970109c1e15b391226f78087b10439 (diff)
downloadrust-76dce27325207bdefbbdc1e76dab0605fbdc4294.tar.gz
rust-76dce27325207bdefbbdc1e76dab0605fbdc4294.zip
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
Diffstat (limited to 'library/stdarch/crates/intrinsic-test')
-rw-r--r--library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs9
-rw-r--r--library/stdarch/crates/intrinsic-test/src/arm/json_parser.rs2
-rw-r--r--library/stdarch/crates/intrinsic-test/src/arm/types.rs35
-rw-r--r--library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs7
4 files changed, 26 insertions, 27 deletions
diff --git a/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs b/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs
index 16572b2c03f..fd93eff76e0 100644
--- a/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs
+++ b/library/stdarch/crates/intrinsic-test/src/arm/intrinsic.rs
@@ -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
     }
 }
 
diff --git a/library/stdarch/crates/intrinsic-test/src/arm/json_parser.rs b/library/stdarch/crates/intrinsic-test/src/arm/json_parser.rs
index 56ec183bdd3..a7573ebea0e 100644
--- a/library/stdarch/crates/intrinsic-test/src/arm/json_parser.rs
+++ b/library/stdarch/crates/intrinsic-test/src/arm/json_parser.rs
@@ -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
             }
diff --git a/library/stdarch/crates/intrinsic-test/src/arm/types.rs b/library/stdarch/crates/intrinsic-test/src/arm/types.rs
index c06e9355c44..9b858ca9405 100644
--- a/library/stdarch/crates/intrinsic-test/src/arm/types.rs
+++ b/library/stdarch/crates/intrinsic-test/src/arm/types.rs
@@ -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()})
             }
         }
     }
diff --git a/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs b/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs
index b53047b2d38..f5e84ca97af 100644
--- a/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs
+++ b/library/stdarch/crates/intrinsic-test/src/common/intrinsic_helpers.rs
@@ -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;