diff options
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index aa13685e1..6f159740c 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -118,8 +118,9 @@ template<typename T, typename MiniT> struct LEB { } } value |= significant_payload << shift; - if (last) + if (last) { break; + } shift += 7; if (size_t(shift) >= sizeof(T) * 8) { throw ParseException("LEB overflow"); @@ -160,22 +161,25 @@ public: BufferWithRandomAccess(bool debug = false) : debug(debug) {} BufferWithRandomAccess& operator<<(int8_t x) { - if (debug) + if (debug) { std::cerr << "writeInt8: " << (int)(uint8_t)x << " (at " << size() << ")" << std::endl; + } push_back(x); return *this; } BufferWithRandomAccess& operator<<(int16_t x) { - if (debug) + if (debug) { std::cerr << "writeInt16: " << x << " (at " << size() << ")" << std::endl; + } push_back(x & 0xff); push_back(x >> 8); return *this; } BufferWithRandomAccess& operator<<(int32_t x) { - if (debug) + if (debug) { std::cerr << "writeInt32: " << x << " (at " << size() << ")" << std::endl; + } push_back(x & 0xff); x >>= 8; push_back(x & 0xff); @@ -186,8 +190,9 @@ public: return *this; } BufferWithRandomAccess& operator<<(int64_t x) { - if (debug) + if (debug) { std::cerr << "writeInt64: " << x << " (at " << size() << ")" << std::endl; + } push_back(x & 0xff); x >>= 8; push_back(x & 0xff); @@ -272,27 +277,31 @@ public: BufferWithRandomAccess& operator<<(uint64_t x) { return *this << (int64_t)x; } BufferWithRandomAccess& operator<<(float x) { - if (debug) + if (debug) { std::cerr << "writeFloat32: " << x << " (at " << size() << ")" << std::endl; + } return *this << Literal(x).reinterpreti32(); } BufferWithRandomAccess& operator<<(double x) { - if (debug) + if (debug) { std::cerr << "writeFloat64: " << x << " (at " << size() << ")" << std::endl; + } return *this << Literal(x).reinterpreti64(); } void writeAt(size_t i, uint16_t x) { - if (debug) + if (debug) { std::cerr << "backpatchInt16: " << x << " (at " << i << ")" << std::endl; + } (*this)[i] = x & 0xff; (*this)[i + 1] = x >> 8; } void writeAt(size_t i, uint32_t x) { - if (debug) + if (debug) { std::cerr << "backpatchInt32: " << x << " (at " << i << ")" << std::endl; + } (*this)[i] = x & 0xff; x >>= 8; (*this)[i + 1] = x & 0xff; @@ -305,24 +314,27 @@ public: // writes out an LEB to an arbitrary location. this writes the LEB as a full // 5 bytes, the fixed amount that can easily be set aside ahead of time void writeAtFullFixedSize(size_t i, U32LEB x) { - if (debug) + if (debug) { std::cerr << "backpatchU32LEB: " << x.value << " (at " << i << ")" << std::endl; + } // fill all 5 bytes, we have to do this when backpatching x.writeAt(this, i, MaxLEB32Bytes); } // writes out an LEB of normal size // returns how many bytes were written size_t writeAt(size_t i, U32LEB x) { - if (debug) + if (debug) { std::cerr << "writeAtU32LEB: " << x.value << " (at " << i << ")" << std::endl; + } return x.writeAt(this, i); } template<typename T> void writeTo(T& o) { - for (auto c : *this) + for (auto c : *this) { o << c; + } } std::vector<char> getAsChars() { |