From ebfd6a04d548cab0cf56fb33b51f19f75053af49 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Sep 2024 18:16:05 -0500 Subject: [PATCH] Tweak printing page sizes in text format (#1769) Put a space before `(pagesize ...)` and additionally use `start_group`/`end_group` so it gets colors automatically applied. --- crates/wasmprinter/src/lib.rs | 6 +++++- .../local/custom-page-sizes/custom-page-sizes.wast/0.print | 2 +- .../local/custom-page-sizes/custom-page-sizes.wast/1.print | 2 +- .../local/custom-page-sizes/custom-page-sizes.wast/19.print | 2 +- .../local/custom-page-sizes/custom-page-sizes.wast/2.print | 2 +- .../local/custom-page-sizes/custom-page-sizes.wast/23.print | 4 ++-- .../local/custom-page-sizes/custom-page-sizes.wast/3.print | 2 +- .../local/custom-page-sizes/custom-page-sizes.wast/4.print | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/wasmprinter/src/lib.rs b/crates/wasmprinter/src/lib.rs index 4c54dc8c87..c682e92d58 100644 --- a/crates/wasmprinter/src/lib.rs +++ b/crates/wasmprinter/src/lib.rs @@ -1159,7 +1159,11 @@ impl Printer<'_, '_> { let p = 1_u64 .checked_shl(p) .ok_or_else(|| anyhow!("left shift overflow").context("invalid page size"))?; - write!(self.result, "(pagesize {p:#x})")?; + + self.result.write_str(" ")?; + self.start_group("pagesize ")?; + write!(self.result, "{p:#x}")?; + self.end_group()?; } Ok(()) } diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/0.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/0.print index bdb1afc777..01f8bab139 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/0.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/0.print @@ -1,3 +1,3 @@ (module - (memory (;0;) 1(pagesize 0x1)) + (memory (;0;) 1 (pagesize 0x1)) ) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/1.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/1.print index c263f1833f..a86edfbcef 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/1.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/1.print @@ -1,3 +1,3 @@ (module - (memory (;0;) 1(pagesize 0x10000)) + (memory (;0;) 1 (pagesize 0x10000)) ) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/19.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/19.print index 2f377e5a28..9d393fba79 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/19.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/19.print @@ -4,6 +4,6 @@ local.get 0 memory.grow ) - (memory (;0;) 0(pagesize 0x10000)) + (memory (;0;) 0 (pagesize 0x10000)) (export "grow" (func 0)) ) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/2.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/2.print index b28b44796e..fccfed30d0 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/2.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/2.print @@ -1,3 +1,3 @@ (module - (memory (;0;) 1 2(pagesize 0x1)) + (memory (;0;) 1 2 (pagesize 0x1)) ) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/23.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/23.print index 1c3b7326d8..c247b5f533 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/23.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/23.print @@ -21,8 +21,8 @@ local.get 0 i32.load8_u ) - (memory $small (;0;) 10(pagesize 0x1)) - (memory $large (;1;) 1(pagesize 0x10000)) + (memory $small (;0;) 10 (pagesize 0x1)) + (memory $large (;1;) 1 (pagesize 0x10000)) (export "copy-small-to-large" (func 0)) (export "copy-large-to-small" (func 1)) (export "load8-small" (func 2)) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/3.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/3.print index afb7ad5c56..f8915ffd73 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/3.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/3.print @@ -1,3 +1,3 @@ (module - (memory (;0;) 1 2(pagesize 0x10000)) + (memory (;0;) 1 2 (pagesize 0x10000)) ) diff --git a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/4.print b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/4.print index 388265c290..71c30c5fdc 100644 --- a/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/4.print +++ b/tests/snapshots/local/custom-page-sizes/custom-page-sizes.wast/4.print @@ -18,7 +18,7 @@ local.get 1 i32.store ) - (memory (;0;) 0(pagesize 0x1)) + (memory (;0;) 0 (pagesize 0x1)) (export "size" (func 0)) (export "grow" (func 1)) (export "load" (func 2))