From 6657500c924bdd40c8abf8c6a9655654b9342eca Mon Sep 17 00:00:00 2001 From: Daniel Wirtz Date: Mon, 4 Mar 2019 19:49:27 +0100 Subject: 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 ). --- src/wasm/literal.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/wasm/literal.cpp') 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& 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; } -- cgit v1.2.3