Skip to content

Commit c6491da

Browse files
feat: changed from TypeKind::Int(bool) to TypeKind::Int(Sign) for more
clarity
1 parent f6af016 commit c6491da

File tree

6 files changed

+47
-32
lines changed

6 files changed

+47
-32
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::common::argument::ArgumentList;
22
use crate::common::indentation::Indentation;
33
use crate::common::intrinsic::{Intrinsic, IntrinsicDefinition};
4-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
4+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
55
use std::ops::{Deref, DerefMut};
66

77
#[derive(Debug, Clone, PartialEq)]
@@ -79,8 +79,9 @@ impl IntrinsicDefinition<ArmIntrinsicType> for Intrinsic<ArmIntrinsicType> {
7979
TypeKind::Float if self.results().inner_size() == 16 => "float16_t".to_string(),
8080
TypeKind::Float if self.results().inner_size() == 32 => "float".to_string(),
8181
TypeKind::Float if self.results().inner_size() == 64 => "double".to_string(),
82-
TypeKind::Int(true) => format!("int{}_t", self.results().inner_size()),
83-
TypeKind::Int(false) => format!("uint{}_t", self.results().inner_size()),
82+
TypeKind::Int(Sign::Signed) => format!("int{}_t", self.results().inner_size()),
83+
TypeKind::Int(Sign::Unsigned) =>
84+
format!("uint{}_t", self.results().inner_size()),
8485
TypeKind::Poly => format!("poly{}_t", self.results().inner_size()),
8586
ty => todo!("print_result_c - Unknown type: {:#?}", ty),
8687
},

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use super::intrinsic::ArmIntrinsicType;
44
use crate::common::cli::Language;
5-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
5+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
66

77
impl IntrinsicTypeDefinition for ArmIntrinsicType {
88
/// Gets a string containing the typename for this type in C format.
@@ -70,8 +70,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
7070
format!(
7171
"vld{len}{quad}_{type}{size}",
7272
type = match k {
73-
TypeKind::Int(false) => "u",
74-
TypeKind::Int(true) => "s",
73+
TypeKind::Int(Sign::Unsigned) => "u",
74+
TypeKind::Int(Sign::Signed) => "s",
7575
TypeKind::Float => "f",
7676
// The ACLE doesn't support 64-bit polynomial loads on Armv7
7777
// if armv7 and bl == 64, use "s", else "p"
@@ -104,8 +104,8 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
104104
format!(
105105
"vget{quad}_lane_{type}{size}",
106106
type = match k {
107-
TypeKind::Int(false) => "u",
108-
TypeKind::Int(true) => "s",
107+
TypeKind::Int(Sign::Unsigned) => "u",
108+
TypeKind::Int(Sign::Signed) => "s",
109109
TypeKind::Float => "f",
110110
TypeKind::Poly => "p",
111111
x => todo!("get_load_function TypeKind: {:#?}", x),
@@ -129,6 +129,10 @@ impl IntrinsicTypeDefinition for ArmIntrinsicType {
129129
};
130130
let s = s.trim_end();
131131
let temp_return = ArmIntrinsicType::from_c(s);
132+
133+
// We are not adding the metadata hashmap here, since
134+
// it is the return of a recursive call and the
135+
// inner call would handle it.
132136
temp_return.and_then(|mut op| {
133137
op.ptr = true;
134138
op.ptr_constant = constant;

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ use super::cli::Language;
99
use super::indentation::Indentation;
1010
use super::values::value_for_array;
1111

12+
#[derive(Debug, PartialEq, Copy, Clone)]
13+
pub enum Sign {
14+
Signed,
15+
Unsigned,
16+
}
17+
1218
#[derive(Debug, PartialEq, Copy, Clone)]
1319
pub enum TypeKind {
1420
BFloat,
1521
Float,
1622

1723
// if signed, then the inner value is true
18-
Int(bool),
19-
Char(bool),
24+
Int(Sign),
25+
Char(Sign),
2026
Poly,
2127
Void,
2228
Mask,
@@ -29,10 +35,12 @@ impl FromStr for TypeKind {
2935
match s {
3036
"bfloat" | "BF16" => Ok(Self::BFloat),
3137
"float" | "double" | "FP16" | "FP32" | "FP64" => Ok(Self::Float),
32-
"int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => Ok(Self::Int(true)),
38+
"int" | "long" | "short" | "SI8" | "SI16" | "SI32" | "SI64" => {
39+
Ok(Self::Int(Sign::Signed))
40+
}
3341
"poly" => Ok(Self::Poly),
34-
"char" => Ok(Self::Char(true)),
35-
"uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok(Self::Int(false)),
42+
"char" => Ok(Self::Char(Sign::Signed)),
43+
"uint" | "unsigned" | "UI8" | "UI16" | "UI32" | "UI64" => Ok(Self::Int(Sign::Unsigned)),
3644
"void" => Ok(Self::Void),
3745
"MASK" => Ok(Self::Mask),
3846
_ => Err(format!("Impossible to parse argument kind {s}")),
@@ -48,12 +56,12 @@ impl fmt::Display for TypeKind {
4856
match self {
4957
Self::BFloat => "bfloat",
5058
Self::Float => "float",
51-
Self::Int(true) => "int",
52-
Self::Int(false) => "uint",
59+
Self::Int(Sign::Signed) => "int",
60+
Self::Int(Sign::Unsigned) => "uint",
5361
Self::Poly => "poly",
5462
Self::Void => "void",
55-
Self::Char(true) => "char",
56-
Self::Char(false) => "unsigned char",
63+
Self::Char(Sign::Signed) => "char",
64+
Self::Char(Sign::Unsigned) => "unsigned char",
5765
Self::Mask => "mask",
5866
}
5967
)
@@ -65,10 +73,10 @@ impl TypeKind {
6573
pub fn c_prefix(&self) -> &str {
6674
match self {
6775
Self::Float => "float",
68-
Self::Int(true) => "int",
69-
Self::Int(false) => "uint",
76+
Self::Int(Sign::Signed) => "int",
77+
Self::Int(Sign::Unsigned) => "uint",
7078
Self::Poly => "poly",
71-
Self::Char(true) => "char",
79+
Self::Char(Sign::Signed) => "char",
7280
_ => unreachable!("Not used: {:#?}", self),
7381
}
7482
}
@@ -77,8 +85,8 @@ impl TypeKind {
7785
pub fn rust_prefix(&self) -> &str {
7886
match self {
7987
Self::Float => "f",
80-
Self::Int(true) => "i",
81-
Self::Int(false) => "u",
88+
Self::Int(Sign::Signed) => "i",
89+
Self::Int(Sign::Unsigned) => "u",
8290
Self::Poly => "u",
8391
_ => unreachable!("Unused type kind: {:#?}", self),
8492
}
@@ -180,8 +188,8 @@ impl IntrinsicType {
180188
bit_len: Some(8),
181189
..
182190
} => match kind {
183-
TypeKind::Int(true) => "(int)",
184-
TypeKind::Int(false) => "(unsigned int)",
191+
TypeKind::Int(Sign::Signed) => "(int)",
192+
TypeKind::Int(Sign::Unsigned) => "(unsigned int)",
185193
TypeKind::Poly => "(unsigned int)(uint8_t)",
186194
_ => "",
187195
},
@@ -241,7 +249,8 @@ impl IntrinsicType {
241249
.format_with(",\n", |i, fmt| {
242250
let src = value_for_array(*bit_len, i);
243251
assert!(src == 0 || src.ilog2() < *bit_len);
244-
if *kind == TypeKind::Int(true) && (src >> (*bit_len - 1)) != 0 {
252+
if *kind == TypeKind::Int(Sign::Signed) && (src >> (*bit_len - 1)) != 0
253+
{
245254
// `src` is a two's complement representation of a negative value.
246255
let mask = !0u64 >> (64 - *bit_len);
247256
let ones_compl = src ^ mask;

crates/intrinsic-test/src/x86/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub fn build_notices(line_prefix: &str) -> String {
22
format!(
33
"\
44
{line_prefix}This is a transient test file, not intended for distribution. Some aspects of the
5-
{line_prefix}test are derived from a JSON specification, published under the same license as the
5+
{line_prefix}test are derived from an XML specification, published under the same license as the
66
{line_prefix}`intrinsic-test` crate.\n
77
"
88
)

crates/intrinsic-test/src/x86/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use itertools::Itertools;
55

66
use super::intrinsic::X86IntrinsicType;
77
use crate::common::cli::Language;
8-
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, TypeKind};
8+
use crate::common::intrinsic_helpers::{IntrinsicType, IntrinsicTypeDefinition, Sign, TypeKind};
9+
use crate::x86::xml_parser::Parameter;
910

1011
impl IntrinsicTypeDefinition for X86IntrinsicType {
1112
/// Gets a string containing the type in C format.
@@ -58,8 +59,8 @@ impl IntrinsicTypeDefinition for X86IntrinsicType {
5859

5960
let kind = if s.find("unsigned").is_some() {
6061
match kind {
61-
TypeKind::Int(_) => TypeKind::Int(false),
62-
TypeKind::Char(_) => TypeKind::Char(false),
62+
TypeKind::Int(_) => TypeKind::Int(Sign::Unsigned),
63+
TypeKind::Char(_) => TypeKind::Char(Sign::Unsigned),
6364
a => a,
6465
}
6566
} else {

crates/intrinsic-test/src/x86/xml_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ struct XMLIntrinsic {
3737
}
3838

3939
#[derive(Deserialize)]
40-
struct Parameter {
40+
pub struct Parameter {
4141
#[serde(rename = "@type")]
42-
type_data: String,
42+
pub type_data: String,
4343
#[serde(rename = "@etype", default)]
4444
pub etype: String,
4545
// #[serde(rename = "@memwidth", default, deserialize_with = "string_to_u16")]
4646
// pub memwidth: u16,
4747
#[serde(rename = "@varname", default)]
48-
var_name: String,
48+
pub var_name: String,
4949
}
5050

5151
pub fn get_xml_intrinsics(

0 commit comments

Comments
 (0)