Skip to content

Commit 1abd579

Browse files
Added a macro to simplify <Arch>IntrinsicType definitions
1 parent 2058ab6 commit 1abd579

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

crates/intrinsic-test/src/arm/intrinsic.rs

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,12 @@ use crate::common::argument::ArgumentList;
33
use crate::common::format::Indentation;
44
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
55
use crate::common::intrinsic_types::{
6-
BaseIntrinsicTypeDefinition, IntrinsicType, IntrinsicTypeDefinition, TypeKind,
6+
BaseIntrinsicTypeDefinition, IntrinsicTypeDefinition, TypeKind,
77
};
88
use crate::common::types::Language;
9+
use crate::base_intrinsictype_trait_def_macro;
910

10-
#[derive(Debug, Clone, PartialEq)]
11-
pub struct ArmIntrinsicType(pub IntrinsicType);
12-
13-
impl BaseIntrinsicTypeDefinition for ArmIntrinsicType {
14-
fn kind(&self) -> TypeKind {
15-
self.0.kind()
16-
}
17-
fn inner_size(&self) -> u32 {
18-
self.0.inner_size()
19-
}
20-
fn num_lanes(&self) -> u32 {
21-
self.0.num_lanes()
22-
}
23-
fn num_vectors(&self) -> u32 {
24-
self.0.num_vectors()
25-
}
26-
fn is_simd(&self) -> bool {
27-
self.0.is_simd()
28-
}
29-
fn is_ptr(&self) -> bool {
30-
self.0.is_ptr()
31-
}
32-
fn c_scalar_type(&self) -> String {
33-
self.0.c_scalar_type()
34-
}
35-
fn rust_scalar_type(&self) -> String {
36-
self.0.rust_scalar_type()
37-
}
38-
fn c_promotion(&self) -> &str {
39-
self.0.c_promotion()
40-
}
41-
fn populate_random(&self, indentation: Indentation, loads: u32, language: &Language) -> String {
42-
self.0.populate_random(indentation, loads, language)
43-
}
44-
fn is_rust_vals_array_const(&self) -> bool {
45-
self.0.is_rust_vals_array_const()
46-
}
47-
fn as_call_param_c(&self, name: &String) -> String {
48-
self.0.as_call_param_c(name)
49-
}
50-
}
11+
base_intrinsictype_trait_def_macro!{ArmIntrinsicType}
5112

5213
impl IntrinsicDefinition<ArmIntrinsicType, Constraint> for Intrinsic<ArmIntrinsicType, Constraint> {
5314
fn arguments(&self) -> ArgumentList<ArmIntrinsicType, Constraint> {

crates/intrinsic-test/src/common/intrinsic_types.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,52 @@ pub trait IntrinsicTypeDefinition: BaseIntrinsicTypeDefinition {
350350
unimplemented!("Different architectures must implement rust_type!")
351351
}
352352
}
353+
354+
/// Defines the basic structure of achitecture-specific derivatives
355+
/// of IntrinsicType.
356+
#[macro_export]
357+
macro_rules! base_intrinsictype_trait_def_macro {
358+
($T:ident) => {
359+
#[derive(Debug, Clone, PartialEq)]
360+
pub struct $T(pub IntrinsicType);
361+
362+
impl BaseIntrinsicTypeDefinition for $T {
363+
fn kind(&self) -> TypeKind {
364+
self.0.kind()
365+
}
366+
fn inner_size(&self) -> u32 {
367+
self.0.inner_size()
368+
}
369+
fn num_lanes(&self) -> u32 {
370+
self.0.num_lanes()
371+
}
372+
fn num_vectors(&self) -> u32 {
373+
self.0.num_vectors()
374+
}
375+
fn is_simd(&self) -> bool {
376+
self.0.is_simd()
377+
}
378+
fn is_ptr(&self) -> bool {
379+
self.0.is_ptr()
380+
}
381+
fn c_scalar_type(&self) -> String {
382+
self.0.c_scalar_type()
383+
}
384+
fn rust_scalar_type(&self) -> String {
385+
self.0.rust_scalar_type()
386+
}
387+
fn c_promotion(&self) -> &str {
388+
self.0.c_promotion()
389+
}
390+
fn populate_random(&self, indentation: Indentation, loads: u32, language: &Language) -> String {
391+
self.0.populate_random(indentation, loads, language)
392+
}
393+
fn is_rust_vals_array_const(&self) -> bool {
394+
self.0.is_rust_vals_array_const()
395+
}
396+
fn as_call_param_c(&self, name: &String) -> String {
397+
self.0.as_call_param_c(name)
398+
}
399+
}
400+
}
401+
}

0 commit comments

Comments
 (0)