@@ -6,10 +6,13 @@ use crate::common::argument::ArgumentList;
66use crate :: common:: intrinsic:: Intrinsic ;
77use crate :: common:: intrinsic_helpers:: TypeKind ;
88
9- // The number of times each intrinsic will be called.
9+ // The number of times each intrinsic will be called - influences the generation of the
10+ // test arrays to minimise repeated testing of the same test values.
1011pub ( crate ) const PASSES : u32 = 20 ;
1112
12- // we need a reflexive equality relation, so treat NaNs as equal
13+ /// Rust definitions that are included verbatim in the generated source. In particular, defines
14+ /// a wrapper around float types that defines `NaN`s to be equal reflexively to enable
15+ /// comparison of results that use floats types.
1316const COMMON_RUST_DEFINITIONS : & str = r#"
1417macro_rules! wrap_partialeq {
1518 ($($wrapper:ident ($inner:ty)),*) => {$(
@@ -36,6 +39,13 @@ macro_rules! concatln {
3639 } ;
3740}
3841
42+ /// Writes a `Cargo.toml` containing a workspace with `module_count` members to `w`.
43+ ///
44+ /// e.g.
45+ /// ```toml
46+ /// [workspace]
47+ /// members = [ "mod_0", "mod_1" ]
48+ /// ```
3949pub fn write_bin_cargo_toml (
4050 w : & mut impl std:: io:: Write ,
4151 module_count : usize ,
@@ -47,6 +57,8 @@ pub fn write_bin_cargo_toml(
4757 writeln ! ( w, "]" )
4858}
4959
60+ /// Writes a `Cargo.toml` for a crate with name `name` to `w` that will contain a single Rust source
61+ /// file with a subset of the testing being generated.
5062pub fn write_lib_cargo_toml ( w : & mut impl std:: io:: Write , name : & str ) -> std:: io:: Result < ( ) > {
5163 write ! (
5264 w,
@@ -73,6 +85,8 @@ pub fn write_lib_cargo_toml(w: &mut impl std::io::Write, name: &str) -> std::io:
7385 )
7486}
7587
88+ /// Writes a Rust source file into `w` with common definitions, static arrays with test values,
89+ /// declarations of C wrapper functions for FFI and Rust test functions.
7690pub fn write_lib_rs < T : IntrinsicTypeDefinition > (
7791 w : & mut impl std:: io:: Write ,
7892 notice : & str ,
@@ -121,6 +135,13 @@ pub fn write_lib_rs<T: IntrinsicTypeDefinition>(
121135 Ok ( ( ) )
122136}
123137
138+ /// Writes the body of an intrinsic test to `w` for `intrinsic`.
139+ ///
140+ /// Each specialisation of the intrinsic (i.e. specific instantiations of the immediate arguments
141+ /// of the intrinsic) is added to an array of specialisations. Each specialisation is tested
142+ /// (first loop) `PASSES` number of times (second loop). For a given iteration of a given
143+ /// specialisation, test values are loaded for each argument and passed to the Rust intrinsic
144+ /// and the C wrapper function, and the results are compared.
124145fn generate_rust_test_loop < T : IntrinsicTypeDefinition > (
125146 w : & mut impl std:: io:: Write ,
126147 intrinsic : & Intrinsic < T > ,
@@ -216,6 +237,8 @@ fn generate_rust_test_loop<T: IntrinsicTypeDefinition>(
216237 )
217238}
218239
240+ /// Writes a test function for an given intrinsic to `w`, with a body generated by
241+ /// `generate_rust_test_loop`.
219242fn create_rust_test < T : IntrinsicTypeDefinition > (
220243 w : & mut impl std:: io:: Write ,
221244 intrinsic : & Intrinsic < T > ,
@@ -235,6 +258,8 @@ fn create_rust_test<T: IntrinsicTypeDefinition>(
235258 Ok ( ( ) )
236259}
237260
261+ /// Writes an `extern "C"` block with function declarations for each of the C wrapper functions into
262+ /// `w`.
238263pub fn write_bindings_rust < T : IntrinsicTypeDefinition > (
239264 w : & mut impl std:: io:: Write ,
240265 i : usize ,
@@ -268,6 +293,8 @@ pub fn write_bindings_rust<T: IntrinsicTypeDefinition>(
268293 writeln ! ( w, "}}" )
269294}
270295
296+ /// Writes a `build.rs` into `w` for each test crate that compiles the corresponding C source code
297+ /// with wrapper functions.
271298pub fn write_build_rs (
272299 w : & mut impl std:: io:: Write ,
273300 i : usize ,
0 commit comments