Improve documentation of the filetest run command (#1645)

* Improve output display of RunCommand

The previous use of Debug for displaying `print` and `run` results was less than clear.

* Avoid checking the types of vectors during trampoline construction

Because DataValue only understands `V128` vectors, we avoid type-checking vector values when constructing the trampoline arguments.

* Improve the documentation of the filetest `run` command

Adds an up-to-date example of how to use the `run` and `print` directives and includes an actual use of the new directives in a SIMD arithmetic filetest.
This commit is contained in:
Andrew Brown
2020-05-04 12:08:27 -07:00
committed by GitHub
parent c284ffe6c0
commit d6796d0d23
4 changed files with 72 additions and 43 deletions

View File

@@ -34,7 +34,7 @@ impl RunCommand {
match self {
RunCommand::Print(invoke) => {
let actual = invoke_fn(&invoke.args);
println!("{:?} -> {:?}", invoke, actual)
println!("{} -> {}", invoke, DisplayDataValues(&actual))
}
RunCommand::Run(invoke, compare, expected) => {
let actual = invoke_fn(&invoke.args);
@@ -43,7 +43,8 @@ impl RunCommand {
Comparison::NotEquals => *expected != actual,
};
if !matched {
return Err(format!("Failed test: {:?}, actual: {:?}", self, actual));
let actual = DisplayDataValues(&actual);
return Err(format!("Failed test: {}, actual: {}", self, actual));
}
}
}
@@ -56,14 +57,8 @@ impl Display for RunCommand {
match self {
RunCommand::Print(invocation) => write!(f, "print: {}", invocation),
RunCommand::Run(invocation, comparison, expected) => {
write!(f, "run: {} {} ", invocation, comparison)?;
if expected.len() == 1 {
write!(f, "{}", expected[0])
} else {
write!(f, "[")?;
write_data_value_list(f, expected)?;
write!(f, "]")
}
let expected = DisplayDataValues(expected);
write!(f, "run: {} {} {}", invocation, comparison, expected)
}
}
}
@@ -125,6 +120,14 @@ impl DataValue {
DataValue::V128(_) => ir::types::I8X16,
}
}
/// Return true if the value is a vector (i.e. `DataValue::V128`).
pub fn is_vector(&self) -> bool {
match self {
DataValue::V128(_) => true,
_ => false,
}
}
}
/// Helper for creating [From] implementations for [DataValue]
@@ -163,6 +166,24 @@ impl Display for DataValue {
}
}
/// Helper structure for printing bracket-enclosed vectors of [DataValue]s.
/// - for empty vectors, display `[]`
/// - for single item vectors, display `42`, e.g.
/// - for multiple item vectors, display `[42, 43, 44]`, e.g.
struct DisplayDataValues<'a>(&'a [DataValue]);
impl<'a> Display for DisplayDataValues<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
if self.0.len() == 1 {
write!(f, "{}", self.0[0])
} else {
write!(f, "[")?;
write_data_value_list(f, &self.0)?;
write!(f, "]")
}
}
}
/// Helper function for displaying `Vec<DataValue>`.
fn write_data_value_list(f: &mut Formatter<'_>, list: &[DataValue]) -> fmt::Result {
match list.len() {