Skip to content

Commit

Permalink
wasmprinter: print the end offset (#1425)
Browse files Browse the repository at this point in the history
* wasmprinter: print the end offset

With `--print-offsets`, print the offset at the end of the module or
component. For example, with an empty module, print this:

```
(module)
(;@8     ;)
```

This change also ensures that top-level modules and components are printed
with a newline at the end, which makes using them on the command line
tidier.

* Update test outputs.
  • Loading branch information
sunfishcode authored Feb 23, 2024
1 parent 74d2abf commit a9223be
Show file tree
Hide file tree
Showing 3,186 changed files with 3,205 additions and 3,191 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
15 changes: 11 additions & 4 deletions crates/wasm-compose/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,11 @@ mod test {
})?;

let wat = wasmprinter::print_bytes(encoded)?;
assert_eq!(r#"(component)"#, wat);
assert_eq!(
r#"(component)
"#,
wat
);

Ok(())
}
Expand All @@ -1356,7 +1360,8 @@ mod test {
)
(import "b" (component (;0;) (type 0)))
(instance (;0;) (instantiate 0))
)"#,
)
"#,
wat
);

Expand All @@ -1382,7 +1387,8 @@ mod test {
r#"(component
(component (;0;))
(instance (;0;) (instantiate 0))
)"#,
)
"#,
wat
);

Expand Down Expand Up @@ -1552,7 +1558,8 @@ mod test {
(with "i5" (type 4))
)
)
)"#,
)
"#,
wat
);

Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-compose/tests/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn component_composing() -> Result<()> {
}
}
}
err.push_str("\n");
(err.replace('\\', "/"), &error_path)
}
}
Expand Down Expand Up @@ -112,16 +113,15 @@ fn component_composing() -> Result<()> {
};

if std::env::var_os("BLESS").is_some() {
fs::write(baseline_path, output + "\n")?;
fs::write(baseline_path, output)?;
} else {
assert_eq!(
fs::read_to_string(baseline_path)
.with_context(|| format!(
"failed to read component baseline `{}`",
baseline_path.display()
))?
.replace("\r\n", "\n")
.trim(),
.replace("\r\n", "\n"),
output,
"failed baseline comparison for test case `{}` ({})",
test_case,
Expand Down
6 changes: 5 additions & 1 deletion crates/wasmprinter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl Printer {
self.print_component_exports(states.last_mut().unwrap(), s)?;
}

Payload::End(_) => {
Payload::End(offset) => {
self.end_group(); // close the `module` or `component` group

let state = states.pop().unwrap();
Expand All @@ -562,6 +562,10 @@ impl Printer {
}
parser = parsers.pop().unwrap();
} else {
self.newline(offset);
if self.print_offsets {
self.result.push('\n');
}
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/wasmprinter/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ fn offsets_and_lines_smoke_test() {
(Some(0x20), " local.get 0\n"),
(None, " )\n"),
(Some(0x17), " (export \"f\" (func 0))\n"),
(None, ")"),
(None, ")\n"),
(Some(0x23), ""),
];

assert_eq!(actual, expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
2 changes: 1 addition & 1 deletion crates/wit-component/tests/components/empty/component.wat
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@
(@producers
(processed-by "wit-component" "$CARGO_PKG_VERSION")
)
)
)
Loading

0 comments on commit a9223be

Please sign in to comment.