diff options
author | Daniel Wirtz <dcode@dcode.io> | 2019-03-04 19:49:27 +0100 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2019-03-04 10:49:27 -0800 |
commit | 6657500c924bdd40c8abf8c6a9655654b9342eca (patch) | |
tree | 226039d3480cd9bbf805aae8ee3084de187b2c0b /src/wasm/literal.cpp | |
parent | 689fe405a3417fbfd59456035add6f6f53149f35 (diff) | |
download | binaryen-6657500c924bdd40c8abf8c6a9655654b9342eca.tar.gz binaryen-6657500c924bdd40c8abf8c6a9655654b9342eca.tar.bz2 binaryen-6657500c924bdd40c8abf8c6a9655654b9342eca.zip |
Align v128 text format with WABT (#1930)
This PR changes the formatting of v128.const literals in text format / stack ir like so
- v128.const i32 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x80
+ v128.const i32 0x04030201 0x08070605 0x0c0b0a09 0x800f0e0d
Recently hit this when trying to load Binaryen generated text format with WABT, which errored with `error: unexpected token 0x5, expected ).
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 4ec256aae..bc45f5834 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -223,9 +223,14 @@ void Literal::printDouble(std::ostream& o, double d) { void Literal::printVec128(std::ostream& o, const std::array<uint8_t, 16>& v) { o << std::hex; - for (auto i = 0; i < 16; ++i) { - o << "0x" << uint32_t(v[i]); - if (i < 15) o << " "; + for (auto i = 0; i < 16; i += 4) { + if (i) o << " "; + o << "0x" << std::setfill('0') << std::setw(8) << uint32_t( + v[i ] | + (v[i + 1] << 8) | + (v[i + 2] << 16) | + (v[i + 3] << 24) + ); } o << std::dec; } |