Skip to content

Commit

Permalink
Reduce code that handles number of parameters in stdarch-gen gen_test
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm authored and Amanieu committed Oct 31, 2023
1 parent 0215f9a commit 4b994c6
Showing 1 changed file with 24 additions and 58 deletions.
82 changes: 24 additions & 58 deletions crates/stdarch-gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::Suffix::*;
use self::TargetFeature::*;
use std::env;
use std::fmt;
use std::fmt::{self, Write as _};
use std::fs::File;
use std::io::prelude::*;
use std::io::{self, BufReader};
Expand Down Expand Up @@ -1856,66 +1856,32 @@ fn gen_test(
1 => type_to_global_type(out_t).to_string(),
_ => format!("[{}; {}]", type_to_native_type(out_t), type_len(out_t)),
};
let t = {
match para_num {
1 => {
format!(
r#"
let a{};
let e{};
let r: {} = transmute({}{}(transmute(a)));
assert_eq!(r, e);
"#,
values(in_t[0], &a),
values(out_t, &e),
r_type,
name,
const_value
)
}
2 => {
format!(
r#"
let a{};
let b{};
let e{};
let r: {} = transmute({}{}(transmute(a), transmute(b)));
assert_eq!(r, e);
"#,
values(in_t[0], &a),
values(in_t[1], &b),
values(out_t, &e),
r_type,
name,
const_value
)
}
3 => {
format!(
r#"
let a{};
let b{};
let c{};
let mut call_params = String::new();
assert!(matches!(para_num, 1..=3));
for i in 0..para_num {
let chr = char::from(b'a' + i as u8);
let v = match i {
0 => &a,
1 => &b,
2 => &c,
_ => unreachable!(),
};
write!(test, "\n let {chr}{};", values(in_t[i as usize], v)).unwrap();
if i != 0 {
call_params.push_str(", ");
}
write!(call_params, "transmute({chr})").unwrap();
}
write!(
test,
r#"
let e{};
let r: {} = transmute({}{}(transmute(a), transmute(b), transmute(c)));
let r: {r_type} = transmute({name}{const_value}({call_params}));
assert_eq!(r, e);
"#,
values(in_t[0], &a),
values(in_t[1], &b),
values(in_t[2], &c),
values(out_t, &e),
r_type,
name,
const_value
)
}
_ => {
panic!("no support para_num:{}", para_num.to_string())
}
}
};

test.push_str(&t);
values(out_t, &e)
)
.unwrap();
}
test.push_str(" }\n");
test
Expand Down

0 comments on commit 4b994c6

Please sign in to comment.