Browse Source

Use x.to_string() instead of format!("{}", x).

Both use the Display trait.
pull/3/head
Jakob Stoklund Olesen 9 years ago
parent
commit
5c4f3d01e2
  1. 100
      src/libcretonne/immediates.rs
  2. 6
      src/libcretonne/repr.rs
  3. 59
      src/libcretonne/types.rs
  4. 26
      src/libctonfile/parser.rs
  5. 4
      src/test-all.sh

100
src/libcretonne/immediates.rs

@ -493,7 +493,7 @@ mod tests {
assert_eq!(x, y);
assert_eq!(format!("{:?}", Opcode::IaddImm), "IaddImm");
assert_eq!(format!("{}", Opcode::IaddImm), "iadd_imm");
assert_eq!(Opcode::IaddImm.to_string(), "iadd_imm");
// Check the matcher.
assert_eq!("iadd".parse::<Opcode>(), Ok(Opcode::Iadd));
@ -505,13 +505,13 @@ mod tests {
#[test]
fn format_imm64() {
assert_eq!(format!("{}", Imm64(0)), "0");
assert_eq!(format!("{}", Imm64(9999)), "9999");
assert_eq!(format!("{}", Imm64(10000)), "0x2710");
assert_eq!(format!("{}", Imm64(-9999)), "-9999");
assert_eq!(format!("{}", Imm64(-10000)), "0xffff_ffff_ffff_d8f0");
assert_eq!(format!("{}", Imm64(0xffff)), "0xffff");
assert_eq!(format!("{}", Imm64(0x10000)), "0x0001_0000");
assert_eq!(Imm64(0).to_string(), "0");
assert_eq!(Imm64(9999).to_string(), "9999");
assert_eq!(Imm64(10000).to_string(), "0x2710");
assert_eq!(Imm64(-9999).to_string(), "-9999");
assert_eq!(Imm64(-10000).to_string(), "0xffff_ffff_ffff_d8f0");
assert_eq!(Imm64(0xffff).to_string(), "0xffff");
assert_eq!(Imm64(0x10000).to_string(), "0x0001_0000");
}
// Verify that `text` can be parsed as a `T` into a value that displays as `want`.
@ -520,7 +520,7 @@ mod tests {
{
match text.parse::<T>() {
Err(s) => panic!("\"{}\".parse() error: {}", text, s),
Ok(x) => assert_eq!(format!("{}", x), want),
Ok(x) => assert_eq!(x.to_string(), want),
}
}
@ -529,7 +529,7 @@ mod tests {
where <T as FromStr>::Err: Display
{
match text.parse::<T>() {
Err(s) => assert_eq!(format!("{}", s), msg),
Err(s) => assert_eq!(s.to_string(), msg),
Ok(x) => panic!("Wanted Err({}), but got {}", msg, x),
}
}
@ -584,33 +584,32 @@ mod tests {
#[test]
fn format_ieee32() {
assert_eq!(format!("{}", Ieee32::new(0.0)), "0.0");
assert_eq!(format!("{}", Ieee32::new(-0.0)), "-0.0");
assert_eq!(format!("{}", Ieee32::new(1.0)), "0x1.000000p0");
assert_eq!(format!("{}", Ieee32::new(1.5)), "0x1.800000p0");
assert_eq!(format!("{}", Ieee32::new(0.5)), "0x1.000000p-1");
assert_eq!(format!("{}", Ieee32::new(f32::EPSILON)), "0x1.000000p-23");
assert_eq!(format!("{}", Ieee32::new(f32::MIN)), "-0x1.fffffep127");
assert_eq!(format!("{}", Ieee32::new(f32::MAX)), "0x1.fffffep127");
assert_eq!(Ieee32::new(0.0).to_string(), "0.0");
assert_eq!(Ieee32::new(-0.0).to_string(), "-0.0");
assert_eq!(Ieee32::new(1.0).to_string(), "0x1.000000p0");
assert_eq!(Ieee32::new(1.5).to_string(), "0x1.800000p0");
assert_eq!(Ieee32::new(0.5).to_string(), "0x1.000000p-1");
assert_eq!(Ieee32::new(f32::EPSILON).to_string(), "0x1.000000p-23");
assert_eq!(Ieee32::new(f32::MIN).to_string(), "-0x1.fffffep127");
assert_eq!(Ieee32::new(f32::MAX).to_string(), "0x1.fffffep127");
// Smallest positive normal number.
assert_eq!(format!("{}", Ieee32::new(f32::MIN_POSITIVE)),
assert_eq!(Ieee32::new(f32::MIN_POSITIVE).to_string(),
"0x1.000000p-126");
// Subnormals.
assert_eq!(format!("{}", Ieee32::new(f32::MIN_POSITIVE / 2.0)),
assert_eq!(Ieee32::new(f32::MIN_POSITIVE / 2.0).to_string(),
"0x0.800000p-126");
assert_eq!(format!("{}", Ieee32::new(f32::MIN_POSITIVE * f32::EPSILON)),
assert_eq!(Ieee32::new(f32::MIN_POSITIVE * f32::EPSILON).to_string(),
"0x0.000002p-126");
assert_eq!(format!("{}", Ieee32::new(f32::INFINITY)), "Inf");
assert_eq!(format!("{}", Ieee32::new(f32::NEG_INFINITY)), "-Inf");
assert_eq!(format!("{}", Ieee32::new(f32::NAN)), "NaN");
assert_eq!(format!("{}", Ieee32::new(-f32::NAN)), "-NaN");
assert_eq!(Ieee32::new(f32::INFINITY).to_string(), "Inf");
assert_eq!(Ieee32::new(f32::NEG_INFINITY).to_string(), "-Inf");
assert_eq!(Ieee32::new(f32::NAN).to_string(), "NaN");
assert_eq!(Ieee32::new(-f32::NAN).to_string(), "-NaN");
// Construct some qNaNs with payloads.
assert_eq!(format!("{}", Ieee32::from_bits(0x7fc00001)), "NaN:0x1");
assert_eq!(format!("{}", Ieee32::from_bits(0x7ff00001)), "NaN:0x300001");
assert_eq!(Ieee32::from_bits(0x7fc00001).to_string(), "NaN:0x1");
assert_eq!(Ieee32::from_bits(0x7ff00001).to_string(), "NaN:0x300001");
// Signaling NaNs.
assert_eq!(format!("{}", Ieee32::from_bits(0x7f800001)), "sNaN:0x1");
assert_eq!(format!("{}", Ieee32::from_bits(0x7fa00001)),
"sNaN:0x200001");
assert_eq!(Ieee32::from_bits(0x7f800001).to_string(), "sNaN:0x1");
assert_eq!(Ieee32::from_bits(0x7fa00001).to_string(), "sNaN:0x200001");
}
#[test]
@ -682,38 +681,35 @@ mod tests {
#[test]
fn format_ieee64() {
assert_eq!(format!("{}", Ieee64::new(0.0)), "0.0");
assert_eq!(format!("{}", Ieee64::new(-0.0)), "-0.0");
assert_eq!(format!("{}", Ieee64::new(1.0)), "0x1.0000000000000p0");
assert_eq!(format!("{}", Ieee64::new(1.5)), "0x1.8000000000000p0");
assert_eq!(format!("{}", Ieee64::new(0.5)), "0x1.0000000000000p-1");
assert_eq!(format!("{}", Ieee64::new(f64::EPSILON)),
assert_eq!(Ieee64::new(0.0).to_string(), "0.0");
assert_eq!(Ieee64::new(-0.0).to_string(), "-0.0");
assert_eq!(Ieee64::new(1.0).to_string(), "0x1.0000000000000p0");
assert_eq!(Ieee64::new(1.5).to_string(), "0x1.8000000000000p0");
assert_eq!(Ieee64::new(0.5).to_string(), "0x1.0000000000000p-1");
assert_eq!(Ieee64::new(f64::EPSILON).to_string(),
"0x1.0000000000000p-52");
assert_eq!(format!("{}", Ieee64::new(f64::MIN)),
"-0x1.fffffffffffffp1023");
assert_eq!(format!("{}", Ieee64::new(f64::MAX)),
"0x1.fffffffffffffp1023");
assert_eq!(Ieee64::new(f64::MIN).to_string(), "-0x1.fffffffffffffp1023");
assert_eq!(Ieee64::new(f64::MAX).to_string(), "0x1.fffffffffffffp1023");
// Smallest positive normal number.
assert_eq!(format!("{}", Ieee64::new(f64::MIN_POSITIVE)),
assert_eq!(Ieee64::new(f64::MIN_POSITIVE).to_string(),
"0x1.0000000000000p-1022");
// Subnormals.
assert_eq!(format!("{}", Ieee64::new(f64::MIN_POSITIVE / 2.0)),
assert_eq!(Ieee64::new(f64::MIN_POSITIVE / 2.0).to_string(),
"0x0.8000000000000p-1022");
assert_eq!(format!("{}", Ieee64::new(f64::MIN_POSITIVE * f64::EPSILON)),
assert_eq!(Ieee64::new(f64::MIN_POSITIVE * f64::EPSILON).to_string(),
"0x0.0000000000001p-1022");
assert_eq!(format!("{}", Ieee64::new(f64::INFINITY)), "Inf");
assert_eq!(format!("{}", Ieee64::new(f64::NEG_INFINITY)), "-Inf");
assert_eq!(format!("{}", Ieee64::new(f64::NAN)), "NaN");
assert_eq!(format!("{}", Ieee64::new(-f64::NAN)), "-NaN");
assert_eq!(Ieee64::new(f64::INFINITY).to_string(), "Inf");
assert_eq!(Ieee64::new(f64::NEG_INFINITY).to_string(), "-Inf");
assert_eq!(Ieee64::new(f64::NAN).to_string(), "NaN");
assert_eq!(Ieee64::new(-f64::NAN).to_string(), "-NaN");
// Construct some qNaNs with payloads.
assert_eq!(format!("{}", Ieee64::from_bits(0x7ff8000000000001)),
"NaN:0x1");
assert_eq!(format!("{}", Ieee64::from_bits(0x7ffc000000000001)),
assert_eq!(Ieee64::from_bits(0x7ff8000000000001).to_string(), "NaN:0x1");
assert_eq!(Ieee64::from_bits(0x7ffc000000000001).to_string(),
"NaN:0x4000000000001");
// Signaling NaNs.
assert_eq!(format!("{}", Ieee64::from_bits(0x7ff0000000000001)),
assert_eq!(Ieee64::from_bits(0x7ff0000000000001).to_string(),
"sNaN:0x1");
assert_eq!(format!("{}", Ieee64::from_bits(0x7ff4000000000001)),
assert_eq!(Ieee64::from_bits(0x7ff4000000000001).to_string(),
"sNaN:0x4000000000001");
}

6
src/libcretonne/repr.rs

@ -449,7 +449,7 @@ mod tests {
ty: types::I32,
};
let inst = func.make_inst(idata);
assert_eq!(format!("{}", inst), "inst0");
assert_eq!(inst.to_string(), "inst0");
// Immutable reference resolution.
let ins = func.inst(inst);
@ -463,8 +463,8 @@ mod tests {
let ss0 = func.make_stack_slot(StackSlotData::new(4));
let ss1 = func.make_stack_slot(StackSlotData::new(8));
assert_eq!(format!("{}", ss0), "ss0");
assert_eq!(format!("{}", ss1), "ss1");
assert_eq!(ss0.to_string(), "ss0");
assert_eq!(ss1.to_string(), "ss1");
assert_eq!(func[ss0].size, 4);
assert_eq!(func[ss1].size, 8);

59
src/libcretonne/types.rs

@ -337,38 +337,37 @@ mod tests {
assert_eq!(big.lane_count(), 256);
assert_eq!(big.bits(), 64 * 256);
assert_eq!(format!("{}", big.half_vector().unwrap()), "f64x128");
assert_eq!(format!("{}", B1.by(2).unwrap().half_vector().unwrap()),
"b1");
assert_eq!(big.half_vector().unwrap().to_string(), "f64x128");
assert_eq!(B1.by(2).unwrap().half_vector().unwrap().to_string(), "b1");
assert_eq!(I32.half_vector(), None);
assert_eq!(VOID.half_vector(), None);
}
#[test]
fn format_scalars() {
assert_eq!(format!("{}", VOID), "void");
assert_eq!(format!("{}", B1), "b1");
assert_eq!(format!("{}", B8), "b8");
assert_eq!(format!("{}", B16), "b16");
assert_eq!(format!("{}", B32), "b32");
assert_eq!(format!("{}", B64), "b64");
assert_eq!(format!("{}", I8), "i8");
assert_eq!(format!("{}", I16), "i16");
assert_eq!(format!("{}", I32), "i32");
assert_eq!(format!("{}", I64), "i64");
assert_eq!(format!("{}", F32), "f32");
assert_eq!(format!("{}", F64), "f64");
assert_eq!(VOID.to_string(), "void");
assert_eq!(B1.to_string(), "b1");
assert_eq!(B8.to_string(), "b8");
assert_eq!(B16.to_string(), "b16");
assert_eq!(B32.to_string(), "b32");
assert_eq!(B64.to_string(), "b64");
assert_eq!(I8.to_string(), "i8");
assert_eq!(I16.to_string(), "i16");
assert_eq!(I32.to_string(), "i32");
assert_eq!(I64.to_string(), "i64");
assert_eq!(F32.to_string(), "f32");
assert_eq!(F64.to_string(), "f64");
}
#[test]
fn format_vectors() {
assert_eq!(format!("{}", B1.by(8).unwrap()), "b1x8");
assert_eq!(format!("{}", B8.by(1).unwrap()), "b8");
assert_eq!(format!("{}", B16.by(256).unwrap()), "b16x256");
assert_eq!(format!("{}", B32.by(4).unwrap().by(2).unwrap()), "b32x8");
assert_eq!(format!("{}", B64.by(8).unwrap()), "b64x8");
assert_eq!(format!("{}", I8.by(64).unwrap()), "i8x64");
assert_eq!(format!("{}", F64.by(2).unwrap()), "f64x2");
assert_eq!(B1.by(8).unwrap().to_string(), "b1x8");
assert_eq!(B8.by(1).unwrap().to_string(), "b8");
assert_eq!(B16.by(256).unwrap().to_string(), "b16x256");
assert_eq!(B32.by(4).unwrap().by(2).unwrap().to_string(), "b32x8");
assert_eq!(B64.by(8).unwrap().to_string(), "b64x8");
assert_eq!(I8.by(64).unwrap().to_string(), "i8x64");
assert_eq!(F64.by(2).unwrap().to_string(), "f64x2");
assert_eq!(I8.by(3), None);
assert_eq!(I8.by(512), None);
assert_eq!(VOID.by(4), None);
@ -377,24 +376,24 @@ mod tests {
#[test]
fn argument_type() {
let mut t = ArgumentType::new(I32);
assert_eq!(format!("{}", t), "i32");
assert_eq!(t.to_string(), "i32");
t.extension = ArgumentExtension::Uext;
assert_eq!(format!("{}", t), "i32 uext");
assert_eq!(t.to_string(), "i32 uext");
t.inreg = true;
assert_eq!(format!("{}", t), "i32 uext inreg");
assert_eq!(t.to_string(), "i32 uext inreg");
}
#[test]
fn signatures() {
let mut sig = Signature::new();
assert_eq!(format!("{}", sig), "()");
assert_eq!(sig.to_string(), "()");
sig.argument_types.push(ArgumentType::new(I32));
assert_eq!(format!("{}", sig), "(i32)");
assert_eq!(sig.to_string(), "(i32)");
sig.return_types.push(ArgumentType::new(F32));
assert_eq!(format!("{}", sig), "(i32) -> f32");
assert_eq!(sig.to_string(), "(i32) -> f32");
sig.argument_types.push(ArgumentType::new(I32.by(4).unwrap()));
assert_eq!(format!("{}", sig), "(i32, i32x4) -> f32");
assert_eq!(sig.to_string(), "(i32, i32x4) -> f32");
sig.return_types.push(ArgumentType::new(B8));
assert_eq!(format!("{}", sig), "(i32, i32x4) -> f32, b8");
assert_eq!(sig.to_string(), "(i32, i32x4) -> f32, b8");
}
}

26
src/libctonfile/parser.rs

@ -369,17 +369,15 @@ mod tests {
let sig2 = Parser::new("(i8 inreg uext, f32, f64) -> i32 sext, f64")
.parse_signature()
.unwrap();
assert_eq!(format!("{}", sig2),
assert_eq!(sig2.to_string(),
"(i8 uext inreg, f32, f64) -> i32 sext, f64");
// `void` is not recognized as a type by the lexer. It should not appear in files.
assert_eq!(format!("{}",
Parser::new("() -> void").parse_signature().unwrap_err()),
assert_eq!(Parser::new("() -> void").parse_signature().unwrap_err().to_string(),
"1: expected argument type");
assert_eq!(format!("{}", Parser::new("i8 -> i8").parse_signature().unwrap_err()),
assert_eq!(Parser::new("i8 -> i8").parse_signature().unwrap_err().to_string(),
"1: expected function signature: ( args... )");
assert_eq!(format!("{}",
Parser::new("(i8 -> i8").parse_signature().unwrap_err()),
assert_eq!(Parser::new("(i8 -> i8").parse_signature().unwrap_err().to_string(),
"1: expected ')' after function arguments");
}
@ -394,21 +392,21 @@ mod tests {
assert_eq!(func.name, "foo");
let mut iter = func.stack_slot_iter();
let ss0 = iter.next().unwrap();
assert_eq!(format!("{}", ss0), "ss0");
assert_eq!(ss0.to_string(), "ss0");
assert_eq!(func[ss0].size, 13);
let ss1 = iter.next().unwrap();
assert_eq!(format!("{}", ss1), "ss1");
assert_eq!(ss1.to_string(), "ss1");
assert_eq!(func[ss1].size, 1);
assert_eq!(iter.next(), None);
// Catch suplicate definitions.
assert_eq!(format!("{}",
Parser::new("function bar() {
ss1 = stack_slot 13
ss1 = stack_slot 1
assert_eq!(Parser::new("function bar() {
ss1 = stack_slot 13
ss1 = stack_slot 1
}")
.parse_function()
.unwrap_err()),
.parse_function()
.unwrap_err()
.to_string(),
"3: duplicate stack slot: ss1");
}
}

4
src/test-all.sh

@ -0,0 +1,4 @@
#!/bin/bash
cd $(dirname "$0")/tools
cargo test -p cretonne -p ctonfile -p cretonne-tools
cargo doc -p cretonne -p ctonfile -p cretonne-tools
Loading…
Cancel
Save