@@ -35,38 +35,45 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
35
35
panic ! ( "Invalid {}: {}" , component_or_module, e) ;
36
36
}
37
37
38
- // After validation make sure that binary-to-text and text-to-binary
39
- // transforms all work as well.
38
+ // Round-trip `wasm_bytes` through text and back to binary.
40
39
let wat_string = wasmprinter:: print_bytes ( & wasm_bytes) . unwrap_or_else ( |e| {
41
40
panic ! (
42
41
"failed first disassembly of Wasm into wat with `wasmprinter::print_bytes`: {}" ,
43
42
e
44
43
)
45
44
} ) ;
46
-
47
45
let wasm_bytes = wat:: parse_str ( & wat_string) . unwrap_or_else ( |e| {
48
46
panic ! (
49
47
"failed to assemble wat into Wasm with `wat::parse_str`: {}" ,
50
48
e
51
49
)
52
50
} ) ;
53
- if log:: log_enabled!( log:: Level :: Debug ) {
54
- log:: debug!( "Writing roundtripped wasm to `test2.wasm`..." ) ;
55
- std:: fs:: write ( "test2.wasm" , & wasm_bytes) . unwrap ( ) ;
56
- }
51
+ crate :: log_wasm ( & wasm_bytes, & config) ;
57
52
58
- let wat_string2 = wasmprinter:: print_bytes ( & wasm_bytes) . unwrap_or_else ( |e| {
53
+ let mut wat_string2 = String :: new ( ) ;
54
+ // Now round-trip the result one more time, but this time with "folded
55
+ // instructions" (e.g. s-expressions in the text format).
56
+ wasmprinter:: Config :: new ( )
57
+ . fold_instructions ( true )
58
+ . print (
59
+ & wasm_bytes,
60
+ & mut wasmprinter:: PrintFmtWrite ( & mut wat_string2) ,
61
+ )
62
+ . unwrap_or_else ( |e| {
63
+ panic ! (
64
+ "failed second disassembly of Wasm into wat with `wasmprinter::print_bytes`: {}" ,
65
+ e
66
+ )
67
+ } ) ;
68
+ let wasm_bytes2 = wat:: parse_str ( & wat_string2) . unwrap_or_else ( |e| {
59
69
panic ! (
60
- "failed second disassembly of Wasm into wat with `wasmprinter::print_bytes `: {}" ,
70
+ "failed to assemble wat into Wasm with `wat::parse_str `: {}" ,
61
71
e
62
72
)
63
73
} ) ;
64
- if log:: log_enabled!( log:: Level :: Debug ) {
65
- log:: debug!( "Writing round tripped text format to `test2.wat`..." ) ;
66
- std:: fs:: write ( "test2.wat" , & wat_string2) . unwrap ( ) ;
67
- }
74
+ crate :: log_wasm ( & wasm_bytes2, & config) ;
68
75
69
- if wat_string != wat_string2 {
76
+ if wasm_bytes != wasm_bytes2 {
70
77
panic ! ( "failed to roundtrip valid module" ) ;
71
78
}
72
79
Ok ( ( ) )
0 commit comments