diff options
-rw-r--r-- | src/passes/PostEmscripten.cpp | 1 | ||||
-rw-r--r-- | src/wasm-binary.h | 45 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 183 |
3 files changed, 8 insertions, 221 deletions
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 0e2c268de..20f26e211 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -27,6 +27,7 @@ #include <ir/table-utils.h> #include <pass.h> #include <shared-constants.h> +#include <support/debug.h> #include <wasm-builder.h> #include <wasm-emscripten.h> #include <wasm.h> diff --git a/src/wasm-binary.h b/src/wasm-binary.h index d7fde5913..fe740d56a 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -28,14 +28,11 @@ #include "ir/import-utils.h" #include "ir/module-utils.h" #include "parsing.h" -#include "support/debug.h" #include "wasm-builder.h" #include "wasm-traversal.h" #include "wasm-validator.h" #include "wasm.h" -#define DEBUG_TYPE "binary" - namespace wasm { enum { @@ -158,18 +155,15 @@ public: BufferWithRandomAccess() = default; BufferWithRandomAccess& operator<<(int8_t x) { - BYN_TRACE("writeInt8: " << (int)(uint8_t)x << " (at " << size() << ")\n"); push_back(x); return *this; } BufferWithRandomAccess& operator<<(int16_t x) { - BYN_TRACE("writeInt16: " << x << " (at " << size() << ")\n"); push_back(x & 0xff); push_back(x >> 8); return *this; } BufferWithRandomAccess& operator<<(int32_t x) { - BYN_TRACE("writeInt32: " << x << " (at " << size() << ")\n"); push_back(x & 0xff); x >>= 8; push_back(x & 0xff); @@ -180,7 +174,6 @@ public: return *this; } BufferWithRandomAccess& operator<<(int64_t x) { - BYN_TRACE("writeInt64: " << x << " (at " << size() << ")\n"); push_back(x & 0xff); x >>= 8; push_back(x & 0xff); @@ -199,47 +192,19 @@ public: return *this; } BufferWithRandomAccess& operator<<(U32LEB x) { - [[maybe_unused]] size_t before = -1; - BYN_DEBUG(before = size(); std::cerr << "writeU32LEB: " << x.value - << " (at " << before << ")" - << std::endl;); x.write(this); - BYN_DEBUG(for (size_t i = before; i < size(); i++) { - std::cerr << " " << (int)at(i) << " (at " << i << ")\n"; - }); return *this; } BufferWithRandomAccess& operator<<(U64LEB x) { - [[maybe_unused]] size_t before = -1; - BYN_DEBUG(before = size(); std::cerr << "writeU64LEB: " << x.value - << " (at " << before << ")" - << std::endl;); x.write(this); - BYN_DEBUG(for (size_t i = before; i < size(); i++) { - std::cerr << " " << (int)at(i) << " (at " << i << ")\n"; - }); return *this; } BufferWithRandomAccess& operator<<(S32LEB x) { - [[maybe_unused]] size_t before = -1; - BYN_DEBUG(before = size(); std::cerr << "writeS32LEB: " << x.value - << " (at " << before << ")" - << std::endl;); x.write(this); - BYN_DEBUG(for (size_t i = before; i < size(); i++) { - std::cerr << " " << (int)at(i) << " (at " << i << ")\n"; - }); return *this; } BufferWithRandomAccess& operator<<(S64LEB x) { - [[maybe_unused]] size_t before = -1; - BYN_DEBUG(before = size(); std::cerr << "writeS64LEB: " << x.value - << " (at " << before << ")" - << std::endl;); x.write(this); - BYN_DEBUG(for (size_t i = before; i < size(); i++) { - std::cerr << " " << (int)at(i) << " (at " << i << ")\n"; - }); return *this; } @@ -249,21 +214,17 @@ public: BufferWithRandomAccess& operator<<(uint64_t x) { return *this << (int64_t)x; } BufferWithRandomAccess& operator<<(float x) { - BYN_TRACE("writeFloat32: " << x << " (at " << size() << ")\n"); return *this << Literal(x).reinterpreti32(); } BufferWithRandomAccess& operator<<(double x) { - BYN_TRACE("writeFloat64: " << x << " (at " << size() << ")\n"); return *this << Literal(x).reinterpreti64(); } void writeAt(size_t i, uint16_t x) { - BYN_TRACE("backpatchInt16: " << x << " (at " << i << ")\n"); (*this)[i] = x & 0xff; (*this)[i + 1] = x >> 8; } void writeAt(size_t i, uint32_t x) { - BYN_TRACE("backpatchInt32: " << x << " (at " << i << ")\n"); (*this)[i] = x & 0xff; x >>= 8; (*this)[i + 1] = x & 0xff; @@ -276,16 +237,12 @@ 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) { - BYN_TRACE("backpatchU32LEB: " << x.value << " (at " << i << ")\n"); // 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) { - BYN_TRACE("writeAtU32LEB: " << x.value << " (at " << i << ")\n"); - return x.writeAt(this, i); - } + size_t writeAt(size_t i, U32LEB x) { return x.writeAt(this, i); } template<typename T> void writeTo(T& o) { for (auto c : *this) { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 151a7f911..d8a310103 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -101,7 +101,6 @@ void WasmBinaryWriter::write() { } void WasmBinaryWriter::writeHeader() { - BYN_TRACE("== writeHeader\n"); o << int32_t(BinaryConsts::Magic); // magic number \0asm o << int32_t(BinaryConsts::Version); } @@ -207,7 +206,6 @@ void WasmBinaryWriter::writeStart() { if (!wasm->start.is()) { return; } - BYN_TRACE("== writeStart\n"); auto start = startSection(BinaryConsts::Section::Start); o << U32LEB(getFunctionIndex(wasm->start.str)); finishSection(start); @@ -217,7 +215,6 @@ void WasmBinaryWriter::writeMemories() { if (importInfo->getNumDefinedMemories() == 0) { return; } - BYN_TRACE("== writeMemories\n"); auto start = startSection(BinaryConsts::Section::Memory); auto num = importInfo->getNumDefinedMemories(); o << U32LEB(num); @@ -259,7 +256,6 @@ void WasmBinaryWriter::writeTypes() { } } - BYN_TRACE("== writeTypes\n"); auto start = startSection(BinaryConsts::Section::Type); o << U32LEB(numGroups); std::optional<RecGroup> lastGroup = std::nullopt; @@ -273,7 +269,6 @@ void WasmBinaryWriter::writeTypes() { } lastGroup = currGroup; // Emit the type definition. - BYN_TRACE("write " << type << std::endl); auto super = type.getDeclaredSuperType(); if (super || type.isOpen()) { if (type.isOpen()) { @@ -332,7 +327,6 @@ void WasmBinaryWriter::writeImports() { if (num == 0) { return; } - BYN_TRACE("== writeImports\n"); auto start = startSection(BinaryConsts::Section::Import); o << U32LEB(num); auto writeImportHeader = [&](Importable* import) { @@ -340,27 +334,23 @@ void WasmBinaryWriter::writeImports() { writeInlineString(import->base.str); }; ModuleUtils::iterImportedFunctions(*wasm, [&](Function* func) { - BYN_TRACE("write one function\n"); writeImportHeader(func); o << U32LEB(int32_t(ExternalKind::Function)); o << U32LEB(getTypeIndex(func->type)); }); ModuleUtils::iterImportedGlobals(*wasm, [&](Global* global) { - BYN_TRACE("write one global\n"); writeImportHeader(global); o << U32LEB(int32_t(ExternalKind::Global)); writeType(global->type); o << U32LEB(global->mutable_); }); ModuleUtils::iterImportedTags(*wasm, [&](Tag* tag) { - BYN_TRACE("write one tag\n"); writeImportHeader(tag); o << U32LEB(int32_t(ExternalKind::Tag)); o << uint8_t(0); // Reserved 'attribute' field. Always 0. o << U32LEB(getTypeIndex(tag->sig)); }); ModuleUtils::iterImportedMemories(*wasm, [&](Memory* memory) { - BYN_TRACE("write one memory\n"); writeImportHeader(memory); o << U32LEB(int32_t(ExternalKind::Memory)); writeResizableLimits(memory->initial, @@ -370,7 +360,6 @@ void WasmBinaryWriter::writeImports() { memory->is64()); }); ModuleUtils::iterImportedTables(*wasm, [&](Table* table) { - BYN_TRACE("write one table\n"); writeImportHeader(table); o << U32LEB(int32_t(ExternalKind::Table)); writeType(table->type); @@ -387,13 +376,10 @@ void WasmBinaryWriter::writeFunctionSignatures() { if (importInfo->getNumDefinedFunctions() == 0) { return; } - BYN_TRACE("== writeFunctionSignatures\n"); auto start = startSection(BinaryConsts::Section::Function); o << U32LEB(importInfo->getNumDefinedFunctions()); - ModuleUtils::iterDefinedFunctions(*wasm, [&](Function* func) { - BYN_TRACE("write one\n"); - o << U32LEB(getTypeIndex(func->type)); - }); + ModuleUtils::iterDefinedFunctions( + *wasm, [&](Function* func) { o << U32LEB(getTypeIndex(func->type)); }); finishSection(start); } @@ -411,33 +397,28 @@ void WasmBinaryWriter::writeFunctions() { moduleStackIR.emplace(*wasm, options); } - BYN_TRACE("== writeFunctions\n"); auto sectionStart = startSection(BinaryConsts::Section::Code); o << U32LEB(importInfo->getNumDefinedFunctions()); bool DWARF = Debug::hasDWARFSections(*getModule()); ModuleUtils::iterDefinedFunctions(*wasm, [&](Function* func) { assert(binaryLocationTrackedExpressionsForFunc.empty()); - BYN_TRACE("write one at" << o.size() << std::endl); // Do not smear any debug location from the previous function. writeNoDebugLocation(); size_t sourceMapLocationsSizeAtFunctionStart = sourceMapLocations.size(); size_t sizePos = writeU32LEBPlaceholder(); size_t start = o.size(); - BYN_TRACE("writing" << func->name << std::endl); // Emit Stack IR if present. StackIR* stackIR = nullptr; if (moduleStackIR) { stackIR = moduleStackIR->getStackIROrNull(func); } if (stackIR) { - BYN_TRACE("write Stack IR\n"); StackIRToBinaryWriter writer(*this, o, func, *stackIR, sourceMap, DWARF); writer.write(); if (debugInfo) { funcMappedLocals[func->name] = std::move(writer.getMappedLocals()); } } else { - BYN_TRACE("write Binaryen IR\n"); BinaryenIRToBinaryWriter writer(*this, o, func, sourceMap, DWARF); writer.write(); if (debugInfo) { @@ -446,8 +427,6 @@ void WasmBinaryWriter::writeFunctions() { } size_t size = o.size() - start; assert(size <= std::numeric_limits<uint32_t>::max()); - BYN_TRACE("body size: " << size << ", writing at " << sizePos - << ", next starts at " << o.size() << "\n"); auto sizeFieldSize = o.writeAt(sizePos, U32LEB(size)); // We can move things back if the actual LEB for the size doesn't use the // maximum 5 bytes. In that case we need to adjust offsets after we move @@ -569,7 +548,6 @@ void WasmBinaryWriter::writeGlobals() { if (importInfo->getNumDefinedGlobals() == 0) { return; } - BYN_TRACE("== writeglobals\n"); auto start = startSection(BinaryConsts::Section::Global); // Count and emit the total number of globals after tuple globals have been // expanded into their constituent parts. @@ -578,7 +556,6 @@ void WasmBinaryWriter::writeGlobals() { *wasm, [&num](Global* global) { num += global->type.size(); }); o << U32LEB(num); ModuleUtils::iterDefinedGlobals(*wasm, [&](Global* global) { - BYN_TRACE("write one\n"); size_t i = 0; for (const auto& t : global->type) { writeType(t); @@ -614,11 +591,9 @@ void WasmBinaryWriter::writeExports() { if (wasm->exports.size() == 0) { return; } - BYN_TRACE("== writeexports\n"); auto start = startSection(BinaryConsts::Section::Export); o << U32LEB(wasm->exports.size()); for (auto& curr : wasm->exports) { - BYN_TRACE("write one\n"); writeInlineString(curr->name.str); o << U32LEB(int32_t(curr->kind)); switch (curr->kind) { @@ -764,7 +739,6 @@ void WasmBinaryWriter::writeTableDeclarations() { // defined tables found. skipping" << std::endl; return; } - BYN_TRACE("== writeTableDeclarations\n"); auto start = startSection(BinaryConsts::Section::Table); auto num = importInfo->getNumDefinedTables(); o << U32LEB(num); @@ -789,7 +763,6 @@ void WasmBinaryWriter::writeElementSegments() { return; } - BYN_TRACE("== writeElementSegments\n"); auto start = startSection(BinaryConsts::Section::Element); o << U32LEB(elemCount); @@ -871,12 +844,10 @@ void WasmBinaryWriter::writeTags() { if (importInfo->getNumDefinedTags() == 0) { return; } - BYN_TRACE("== writeTags\n"); auto start = startSection(BinaryConsts::Section::Tag); auto num = importInfo->getNumDefinedTags(); o << U32LEB(num); ModuleUtils::iterDefinedTags(*wasm, [&](Tag* tag) { - BYN_TRACE("write one\n"); o << uint8_t(0); // Reserved 'attribute' field. Always 0. o << U32LEB(getTypeIndex(tag->sig)); }); @@ -885,7 +856,6 @@ void WasmBinaryWriter::writeTags() { } void WasmBinaryWriter::writeNames() { - BYN_TRACE("== writeNames\n"); auto start = startSection(BinaryConsts::Section::Custom); writeInlineString(BinaryConsts::CustomSections::Name); @@ -1198,7 +1168,6 @@ void WasmBinaryWriter::writeNames() { } void WasmBinaryWriter::writeSourceMapUrl() { - BYN_TRACE("== writeSourceMapUrl\n"); auto start = startSection(BinaryConsts::Section::Custom); writeInlineString(BinaryConsts::CustomSections::SourceMapUrl); writeInlineString(sourceMapUrl.c_str()); @@ -1880,7 +1849,6 @@ void WasmBinaryReader::read() { } void WasmBinaryReader::readCustomSection(size_t payloadLen) { - BYN_TRACE("== readCustomSection\n"); auto oldPos = pos; Name sectionName = getInlineString(); size_t read = pos - oldPos; @@ -1927,103 +1895,77 @@ uint8_t WasmBinaryReader::getInt8() { if (!more()) { throwError("unexpected end of input"); } - BYN_TRACE("getInt8: " << (int)(uint8_t)input[pos] << " (at " << pos << ")\n"); return input[pos++]; } uint16_t WasmBinaryReader::getInt16() { - BYN_TRACE("<==\n"); auto ret = uint16_t(getInt8()); ret |= uint16_t(getInt8()) << 8; - BYN_TRACE("getInt16: " << ret << "/0x" << std::hex << ret << std::dec - << " ==>\n"); return ret; } uint32_t WasmBinaryReader::getInt32() { - BYN_TRACE("<==\n"); auto ret = uint32_t(getInt16()); ret |= uint32_t(getInt16()) << 16; - BYN_TRACE("getInt32: " << ret << "/0x" << std::hex << ret << std::dec - << " ==>\n"); return ret; } uint64_t WasmBinaryReader::getInt64() { - BYN_TRACE("<==\n"); auto ret = uint64_t(getInt32()); ret |= uint64_t(getInt32()) << 32; - BYN_TRACE("getInt64: " << ret << "/0x" << std::hex << ret << std::dec - << " ==>\n"); return ret; } uint8_t WasmBinaryReader::getLaneIndex(size_t lanes) { - BYN_TRACE("<==\n"); auto ret = getInt8(); if (ret >= lanes) { throwError("Illegal lane index"); } - BYN_TRACE("getLaneIndex(" << lanes << "): " << ret << " ==>" << std::endl); return ret; } Literal WasmBinaryReader::getFloat32Literal() { - BYN_TRACE("<==\n"); auto ret = Literal(getInt32()); ret = ret.castToF32(); - BYN_TRACE("getFloat32: " << ret << " ==>\n"); return ret; } Literal WasmBinaryReader::getFloat64Literal() { - BYN_TRACE("<==\n"); auto ret = Literal(getInt64()); ret = ret.castToF64(); - BYN_TRACE("getFloat64: " << ret << " ==>\n"); return ret; } Literal WasmBinaryReader::getVec128Literal() { - BYN_TRACE("<==\n"); std::array<uint8_t, 16> bytes; for (auto i = 0; i < 16; ++i) { bytes[i] = getInt8(); } auto ret = Literal(bytes.data()); - BYN_TRACE("getVec128: " << ret << " ==>\n"); return ret; } uint32_t WasmBinaryReader::getU32LEB() { - BYN_TRACE("<==\n"); U32LEB ret; ret.read([&]() { return getInt8(); }); - BYN_TRACE("getU32LEB: " << ret.value << " ==>\n"); return ret.value; } uint64_t WasmBinaryReader::getU64LEB() { - BYN_TRACE("<==\n"); U64LEB ret; ret.read([&]() { return getInt8(); }); - BYN_TRACE("getU64LEB: " << ret.value << " ==>\n"); return ret.value; } int32_t WasmBinaryReader::getS32LEB() { - BYN_TRACE("<==\n"); S32LEB ret; ret.read([&]() { return (int8_t)getInt8(); }); - BYN_TRACE("getS32LEB: " << ret.value << " ==>\n"); return ret.value; } int64_t WasmBinaryReader::getS64LEB() { - BYN_TRACE("<==\n"); S64LEB ret; ret.read([&]() { return (int8_t)getInt8(); }); - BYN_TRACE("getS64LEB: " << ret.value << " ==>\n"); return ret.value; } @@ -2216,13 +2158,11 @@ Type WasmBinaryReader::getConcreteType() { } Name WasmBinaryReader::getInlineString(bool requireValid) { - BYN_TRACE("<==\n"); auto len = getU32LEB(); auto data = getByteView(len); if (requireValid && !String::isUTF8(data)) { throwError("invalid UTF-8 string"); } - BYN_TRACE("getInlineString: " << data << " ==>\n"); return Name(data); } @@ -2255,7 +2195,6 @@ void WasmBinaryReader::verifyInt64(int64_t x) { } void WasmBinaryReader::readHeader() { - BYN_TRACE("== readHeader\n"); verifyInt32(BinaryConsts::Magic); auto version = getInt32(); if (version != BinaryConsts::Version) { @@ -2268,21 +2207,15 @@ void WasmBinaryReader::readHeader() { } } -void WasmBinaryReader::readStart() { - BYN_TRACE("== readStart\n"); - startIndex = getU32LEB(); -} +void WasmBinaryReader::readStart() { startIndex = getU32LEB(); } static Name makeName(std::string prefix, size_t counter) { return Name(prefix + std::to_string(counter)); } void WasmBinaryReader::readMemories() { - BYN_TRACE("== readMemories\n"); auto num = getU32LEB(); - BYN_TRACE("num: " << num << std::endl); for (size_t i = 0; i < num; i++) { - BYN_TRACE("read one\n"); auto memory = Builder::makeMemory(makeName("", i)); getResizableLimits(memory->initial, memory->max, @@ -2294,9 +2227,7 @@ void WasmBinaryReader::readMemories() { } void WasmBinaryReader::readTypes() { - BYN_TRACE("== readTypes\n"); TypeBuilder builder(getU32LEB()); - BYN_TRACE("num: " << builder.size() << std::endl); auto readHeapType = [&]() -> HeapType { int64_t htCode = getS64LEB(); // TODO: Actually s33 @@ -2345,12 +2276,10 @@ void WasmBinaryReader::readTypes() { std::vector<Type> params; std::vector<Type> results; size_t numParams = getU32LEB(); - BYN_TRACE("num params: " << numParams << std::endl); for (size_t j = 0; j < numParams; j++) { params.push_back(readType()); } auto numResults = getU32LEB(); - BYN_TRACE("num results: " << numResults << std::endl); for (size_t j = 0; j < numResults; j++) { results.push_back(readType()); } @@ -2398,7 +2327,6 @@ void WasmBinaryReader::readTypes() { auto readStructDef = [&]() { FieldList fields; size_t numFields = getU32LEB(); - BYN_TRACE("num fields: " << numFields << std::endl); for (size_t j = 0; j < numFields; j++) { fields.push_back(readFieldDef()); } @@ -2406,7 +2334,6 @@ void WasmBinaryReader::readTypes() { }; for (size_t i = 0; i < builder.size(); i++) { - BYN_TRACE("read one\n"); auto form = getInt8(); if (form == BinaryConsts::EncodedType::Rec) { uint32_t groupSize = getU32LEB(); @@ -2558,9 +2485,7 @@ void WasmBinaryReader::getResizableLimits(Address& initial, } void WasmBinaryReader::readImports() { - BYN_TRACE("== readImports\n"); size_t num = getU32LEB(); - BYN_TRACE("num: " << num << std::endl); Builder builder(wasm); size_t tableCounter = 0; size_t memoryCounter = 0; @@ -2568,7 +2493,6 @@ void WasmBinaryReader::readImports() { size_t globalCounter = 0; size_t tagCounter = 0; for (size_t i = 0; i < num; i++) { - BYN_TRACE("read one\n"); auto module = getInlineString(); auto base = getInlineString(); auto kind = (ExternalKind)getU32LEB(); @@ -2668,11 +2592,8 @@ void WasmBinaryReader::requireFunctionContext(const char* error) { } void WasmBinaryReader::readFunctionSignatures() { - BYN_TRACE("== readFunctionSignatures\n"); size_t num = getU32LEB(); - BYN_TRACE("num: " << num << std::endl); for (size_t i = 0; i < num; i++) { - BYN_TRACE("read one\n"); auto index = getU32LEB(); functionTypes.push_back(getTypeByIndex(index)); // Check that the type is a signature. @@ -2712,14 +2633,12 @@ Signature WasmBinaryReader::getSignatureByFunctionIndex(Index index) { } void WasmBinaryReader::readFunctions() { - BYN_TRACE("== readFunctions\n"); auto numImports = wasm.functions.size(); size_t total = getU32LEB(); if (total != functionTypes.size() - numImports) { throwError("invalid function section size, must equal types"); } for (size_t i = 0; i < total; i++) { - BYN_TRACE("read one at " << pos << std::endl); auto sizePos = pos; size_t size = getU32LEB(); if (size == 0) { @@ -2741,14 +2660,11 @@ void WasmBinaryReader::readFunctions() { readNextDebugLocation(); - BYN_TRACE("reading " << i << std::endl); - readVars(); func->prologLocation = debugLocation; { // process the function body - BYN_TRACE("processing function: " << i << std::endl); nextLabel = 0; willBeIgnored = false; // process body @@ -2801,7 +2717,6 @@ void WasmBinaryReader::readFunctions() { debugLocation.clear(); wasm.addFunction(std::move(func)); } - BYN_TRACE(" end function bodies\n"); } void WasmBinaryReader::readVars() { @@ -2825,12 +2740,9 @@ void WasmBinaryReader::readVars() { } void WasmBinaryReader::readExports() { - BYN_TRACE("== readExports\n"); size_t num = getU32LEB(); - BYN_TRACE("num: " << num << std::endl); std::unordered_set<Name> names; for (size_t i = 0; i < num; i++) { - BYN_TRACE("read one\n"); auto curr = std::make_unique<Export>(); curr->name = getInlineString(); if (!names.emplace(curr->name).second) { @@ -3081,11 +2993,8 @@ void WasmBinaryReader::readStrings() { } void WasmBinaryReader::readGlobals() { - BYN_TRACE("== readGlobals\n"); size_t num = getU32LEB(); - BYN_TRACE("num: " << num << std::endl); for (size_t i = 0; i < num; i++) { - BYN_TRACE("read one\n"); auto type = getConcreteType(); auto mutable_ = getU32LEB(); if (mutable_ & ~1) { @@ -3101,14 +3010,12 @@ void WasmBinaryReader::readGlobals() { } void WasmBinaryReader::processExpressions() { - BYN_TRACE("== processExpressions\n"); unreachableInTheWasmSense = false; while (1) { Expression* curr; auto ret = readExpression(curr); if (!curr) { lastSeparator = ret; - BYN_TRACE("== processExpressions finished\n"); return; } pushExpression(curr); @@ -3129,8 +3036,6 @@ void WasmBinaryReader::processExpressions() { peek == BinaryConsts::Catch_Legacy || peek == BinaryConsts::CatchAll_Legacy || peek == BinaryConsts::Delegate) { - BYN_TRACE("== processExpressions finished with unreachable" - << std::endl); lastSeparator = BinaryConsts::ASTNodes(peek); // Read the byte we peeked at. No new instruction is generated for it. Expression* dummy = nullptr; @@ -3146,7 +3051,6 @@ void WasmBinaryReader::processExpressions() { } void WasmBinaryReader::skipUnreachableCode() { - BYN_TRACE("== skipUnreachableCode\n"); // preserve the stack, and restore it. it contains the instruction that made // us unreachable, and we can ignore anything after it. things after it may // pop, we want to undo that @@ -3166,7 +3070,6 @@ void WasmBinaryReader::skipUnreachableCode() { Expression* curr; auto ret = readExpression(curr); if (!curr) { - BYN_TRACE("== skipUnreachableCode finished\n"); lastSeparator = ret; unreachableInTheWasmSense = false; willBeIgnored = before; @@ -3202,12 +3105,10 @@ void WasmBinaryReader::pushExpression(Expression* curr) { } Expression* WasmBinaryReader::popExpression() { - BYN_TRACE("== popExpression\n"); if (expressionStack.empty()) { if (unreachableInTheWasmSense) { // in unreachable code, trying to pop past the polymorphic stack // area results in receiving unreachables - BYN_TRACE("== popping unreachable from polymorphic stack" << std::endl); return allocator.alloc<Unreachable>(); } throwError( @@ -3370,13 +3271,11 @@ void WasmBinaryReader::processNames() { } void WasmBinaryReader::readDataSegmentCount() { - BYN_TRACE("== readDataSegmentCount\n"); hasDataCount = true; dataCount = getU32LEB(); } void WasmBinaryReader::readDataSegments() { - BYN_TRACE("== readDataSegments\n"); auto num = getU32LEB(); for (size_t i = 0; i < num; i++) { auto curr = Builder::makeDataSegment(); @@ -3406,7 +3305,6 @@ void WasmBinaryReader::readDataSegments() { } void WasmBinaryReader::readTableDeclarations() { - BYN_TRACE("== readTableDeclarations\n"); auto numTables = getU32LEB(); for (size_t i = 0; i < numTables; i++) { @@ -3429,7 +3327,6 @@ void WasmBinaryReader::readTableDeclarations() { } void WasmBinaryReader::readElementSegments() { - BYN_TRACE("== readElementSegments\n"); auto numSegments = getU32LEB(); if (numSegments >= Table::kMaxSize) { throwError("Too many segments"); @@ -3507,11 +3404,8 @@ void WasmBinaryReader::readElementSegments() { } void WasmBinaryReader::readTags() { - BYN_TRACE("== readTags\n"); size_t numTags = getU32LEB(); - BYN_TRACE("num: " << numTags << std::endl); for (size_t i = 0; i < numTags; i++) { - BYN_TRACE("read one\n"); getInt8(); // Reserved 'attribute' field auto typeIndex = getU32LEB(); wasm.addTag(Builder::makeTag(makeName("tag$", i), @@ -3609,7 +3503,6 @@ private: } // anonymous namespace void WasmBinaryReader::readNames(size_t payloadLen) { - BYN_TRACE("== readNames\n"); auto sectionPos = pos; uint32_t lastType = 0; while (pos < sectionPos + payloadLen) { @@ -3943,7 +3836,6 @@ void WasmBinaryReader::readDylink(size_t payloadLen) { } void WasmBinaryReader::readDylink0(size_t payloadLen) { - BYN_TRACE("== readDylink0\n"); auto sectionPos = pos; uint32_t lastType = 0; @@ -3988,7 +3880,6 @@ BinaryConsts::ASTNodes WasmBinaryReader::readExpression(Expression*& curr) { if (pos == endOfFunction) { throwError("Reached function end without seeing End opcode"); } - BYN_TRACE("zz recurse into " << ++depth << " at " << pos << std::endl); readNextDebugLocation(); std::set<Function::DebugLocation> currDebugLocation; if (debugLocation.size()) { @@ -3996,7 +3887,6 @@ BinaryConsts::ASTNodes WasmBinaryReader::readExpression(Expression*& curr) { } size_t startPos = pos; uint8_t code = getInt8(); - BYN_TRACE("readExpression seeing " << (int)code << std::endl); switch (code) { case BinaryConsts::Block: visitBlock((curr = allocator.alloc<Block>())->cast<Block>()); @@ -4410,7 +4300,6 @@ BinaryConsts::ASTNodes WasmBinaryReader::readExpression(Expression*& curr) { BinaryLocation(pos - codeSectionLocation)}; } } - BYN_TRACE("zz recurse from " << depth-- << " at " << pos << std::endl); return BinaryConsts::ASTNodes(code); } @@ -4459,7 +4348,6 @@ void WasmBinaryReader::pushBlockElements(Block* curr, Type type, size_t start) { } void WasmBinaryReader::visitBlock(Block* curr) { - BYN_TRACE("zz node: Block\n"); startControlFlow(curr); // special-case Block and de-recurse nested blocks in their first position, as // that is a common pattern that can be very highly nested. @@ -4540,7 +4428,6 @@ Expression* WasmBinaryReader::getBlockOrSingleton(Type type) { } void WasmBinaryReader::visitIf(If* curr) { - BYN_TRACE("zz node: If\n"); startControlFlow(curr); curr->type = getType(); curr->condition = popNonVoidExpression(); @@ -4555,7 +4442,6 @@ void WasmBinaryReader::visitIf(If* curr) { } void WasmBinaryReader::visitLoop(Loop* curr) { - BYN_TRACE("zz node: Loop\n"); startControlFlow(curr); curr->type = getType(); curr->name = getNextLabel(); @@ -4585,7 +4471,6 @@ void WasmBinaryReader::visitLoop(Loop* curr) { } WasmBinaryReader::BreakTarget WasmBinaryReader::getBreakTarget(int32_t offset) { - BYN_TRACE("getBreakTarget " << offset << std::endl); if (breakStack.size() < 1 + size_t(offset)) { throwError("bad breakindex (low)"); } @@ -4593,8 +4478,6 @@ WasmBinaryReader::BreakTarget WasmBinaryReader::getBreakTarget(int32_t offset) { if (index >= breakStack.size()) { throwError("bad breakindex (high)"); } - BYN_TRACE("breaktarget " << breakStack[index].name << " type " - << breakStack[index].type << std::endl); auto& ret = breakStack[index]; // if the break is in literally unreachable code, then we will not emit it // anyhow, so do not note that the target has breaks to it @@ -4605,7 +4488,6 @@ WasmBinaryReader::BreakTarget WasmBinaryReader::getBreakTarget(int32_t offset) { } Name WasmBinaryReader::getExceptionTargetName(int32_t offset) { - BYN_TRACE("getExceptionTarget " << offset << std::endl); // We always start parsing a function by creating a block label and pushing it // in breakStack in getBlockOrSingleton, so if a 'delegate''s target is that // block, it does not mean it targets that block; it throws to the caller. @@ -4616,7 +4498,6 @@ Name WasmBinaryReader::getExceptionTargetName(int32_t offset) { if (index > breakStack.size()) { throwError("bad try index (high)"); } - BYN_TRACE("exception target " << breakStack[index].name << std::endl); auto& ret = breakStack[index]; // if the delegate/rethrow is in literally unreachable code, then we will not // emit it anyhow, so do not note that the target has a reference to it @@ -4627,7 +4508,6 @@ Name WasmBinaryReader::getExceptionTargetName(int32_t offset) { } void WasmBinaryReader::visitBreak(Break* curr, uint8_t code) { - BYN_TRACE("zz node: Break, code " << int32_t(code) << std::endl); BreakTarget target = getBreakTarget(getU32LEB()); curr->name = target.name; if (code == BinaryConsts::BrIf) { @@ -4640,16 +4520,13 @@ void WasmBinaryReader::visitBreak(Break* curr, uint8_t code) { } void WasmBinaryReader::visitSwitch(Switch* curr) { - BYN_TRACE("zz node: Switch\n"); curr->condition = popNonVoidExpression(); auto numTargets = getU32LEB(); - BYN_TRACE("targets: " << numTargets << std::endl); for (size_t i = 0; i < numTargets; i++) { curr->targets.push_back(getBreakTarget(getU32LEB()).name); } auto defaultTarget = getBreakTarget(getU32LEB()); curr->default_ = defaultTarget.name; - BYN_TRACE("default: " << curr->default_ << "\n"); if (defaultTarget.type.isConcrete()) { curr->value = popTypedExpression(defaultTarget.type); } @@ -4657,7 +4534,6 @@ void WasmBinaryReader::visitSwitch(Switch* curr) { } void WasmBinaryReader::visitCall(Call* curr) { - BYN_TRACE("zz node: Call\n"); auto index = getU32LEB(); auto sig = getSignatureByFunctionIndex(index); auto num = sig.params.size(); @@ -4672,7 +4548,6 @@ void WasmBinaryReader::visitCall(Call* curr) { } void WasmBinaryReader::visitCallIndirect(CallIndirect* curr) { - BYN_TRACE("zz node: CallIndirect\n"); auto index = getU32LEB(); curr->heapType = getTypeByIndex(index); Index tableIdx = getU32LEB(); @@ -4689,7 +4564,6 @@ void WasmBinaryReader::visitCallIndirect(CallIndirect* curr) { } void WasmBinaryReader::visitLocalGet(LocalGet* curr) { - BYN_TRACE("zz node: LocalGet " << pos << std::endl); requireFunctionContext("local.get"); curr->index = getU32LEB(); if (curr->index >= currFunction->getNumLocals()) { @@ -4700,7 +4574,6 @@ void WasmBinaryReader::visitLocalGet(LocalGet* curr) { } void WasmBinaryReader::visitLocalSet(LocalSet* curr, uint8_t code) { - BYN_TRACE("zz node: Set|LocalTee\n"); requireFunctionContext("local.set outside of function"); curr->index = getU32LEB(); if (curr->index >= currFunction->getNumLocals()) { @@ -4716,7 +4589,6 @@ void WasmBinaryReader::visitLocalSet(LocalSet* curr, uint8_t code) { } void WasmBinaryReader::visitGlobalGet(GlobalGet* curr) { - BYN_TRACE("zz node: GlobalGet " << pos << std::endl); auto index = getU32LEB(); if (index >= wasm.globals.size()) { throwError("invalid global index"); @@ -4728,7 +4600,6 @@ void WasmBinaryReader::visitGlobalGet(GlobalGet* curr) { } void WasmBinaryReader::visitGlobalSet(GlobalSet* curr) { - BYN_TRACE("zz node: GlobalSet\n"); auto index = getU32LEB(); if (index >= wasm.globals.size()) { throwError("invalid global index"); @@ -4773,9 +4644,7 @@ bool WasmBinaryReader::maybeVisitLoad( uint8_t code, std::optional<BinaryConsts::ASTNodes> prefix) { Load* curr; - auto allocate = [&]() { - curr = allocator.alloc<Load>(); - }; + auto allocate = [&]() { curr = allocator.alloc<Load>(); }; if (!prefix) { switch (code) { case BinaryConsts::I32LoadMem8S: @@ -4856,7 +4725,6 @@ bool WasmBinaryReader::maybeVisitLoad( default: return false; } - BYN_TRACE("zz node: Load\n"); } else if (prefix == BinaryConsts::AtomicPrefix) { switch (code) { case BinaryConsts::I32AtomicLoad8U: @@ -4897,7 +4765,6 @@ bool WasmBinaryReader::maybeVisitLoad( default: return false; } - BYN_TRACE("zz node: AtomicLoad\n"); } else if (prefix == BinaryConsts::MiscPrefix) { switch (code) { case BinaryConsts::F32_F16LoadMem: @@ -4908,7 +4775,6 @@ bool WasmBinaryReader::maybeVisitLoad( default: return false; } - BYN_TRACE("zz node: Load\n"); } else { return false; } @@ -5032,7 +4898,6 @@ bool WasmBinaryReader::maybeVisitStore( } curr->isAtomic = prefix == BinaryConsts::AtomicPrefix; - BYN_TRACE("zz node: Store\n"); Index memIdx = readMemoryAccess(curr->align, curr->offset); memoryRefs[memIdx].push_back(&curr->memory); curr->value = popNonVoidExpression(); @@ -5092,7 +4957,6 @@ bool WasmBinaryReader::maybeVisitAtomicRMW(Expression*& out, uint8_t code) { #undef SET_FOR_OP #undef SET - BYN_TRACE("zz node: AtomicRMW\n"); Address readAlign; Index memIdx = readMemoryAccess(readAlign, curr->offset); memoryRefs[memIdx].push_back(&curr->memory); @@ -5144,7 +5008,6 @@ bool WasmBinaryReader::maybeVisitAtomicCmpxchg(Expression*& out, uint8_t code) { WASM_UNREACHABLE("unexpected opcode"); } - BYN_TRACE("zz node: AtomicCmpxchg\n"); Address readAlign; Index memIdx = readMemoryAccess(readAlign, curr->offset); memoryRefs[memIdx].push_back(&curr->memory); @@ -5177,7 +5040,6 @@ bool WasmBinaryReader::maybeVisitAtomicWait(Expression*& out, uint8_t code) { WASM_UNREACHABLE("unexpected opcode"); } curr->type = Type::i32; - BYN_TRACE("zz node: AtomicWait\n"); curr->timeout = popNonVoidExpression(); curr->expected = popNonVoidExpression(); curr->ptr = popNonVoidExpression(); @@ -5197,7 +5059,6 @@ bool WasmBinaryReader::maybeVisitAtomicNotify(Expression*& out, uint8_t code) { return false; } auto* curr = allocator.alloc<AtomicNotify>(); - BYN_TRACE("zz node: AtomicNotify\n"); curr->type = Type::i32; curr->notifyCount = popNonVoidExpression(); @@ -5218,7 +5079,6 @@ bool WasmBinaryReader::maybeVisitAtomicFence(Expression*& out, uint8_t code) { return false; } auto* curr = allocator.alloc<AtomicFence>(); - BYN_TRACE("zz node: AtomicFence\n"); curr->order = getU32LEB(); curr->finalize(); out = curr; @@ -5227,7 +5087,6 @@ bool WasmBinaryReader::maybeVisitAtomicFence(Expression*& out, uint8_t code) { bool WasmBinaryReader::maybeVisitConst(Expression*& out, uint8_t code) { Const* curr; - BYN_TRACE("zz node: Const, code " << code << std::endl); switch (code) { case BinaryConsts::I32Const: curr = allocator.alloc<Const>(); @@ -5474,7 +5333,6 @@ bool WasmBinaryReader::maybeVisitUnary(Expression*& out, uint8_t code) { default: return false; } - BYN_TRACE("zz node: Unary\n"); curr->value = popNonVoidExpression(); curr->finalize(); out = curr; @@ -5519,7 +5377,6 @@ bool WasmBinaryReader::maybeVisitTruncSat(Expression*& out, uint32_t code) { default: return false; } - BYN_TRACE("zz node: Unary (nontrapping float-to-int)\n"); curr->value = popNonVoidExpression(); curr->finalize(); out = curr; @@ -5750,7 +5607,6 @@ bool WasmBinaryReader::maybeVisitBinary(Expression*& out, uint8_t code) { default: return false; } - BYN_TRACE("zz node: Binary\n"); curr->right = popNonVoidExpression(); curr->left = popNonVoidExpression(); curr->finalize(); @@ -6331,7 +6187,6 @@ bool WasmBinaryReader::maybeVisitSIMDBinary(Expression*& out, uint32_t code) { default: return false; } - BYN_TRACE("zz node: Binary\n"); curr->right = popNonVoidExpression(); curr->left = popNonVoidExpression(); curr->finalize(); @@ -7056,7 +6911,6 @@ bool WasmBinaryReader::maybeVisitSIMDLoadStoreLane(Expression*& out, } void WasmBinaryReader::visitSelect(Select* curr, uint8_t code) { - BYN_TRACE("zz node: Select, code " << int32_t(code) << std::endl); if (code == BinaryConsts::SelectWithType) { size_t numTypes = getU32LEB(); std::vector<Type> types; @@ -7080,7 +6934,6 @@ void WasmBinaryReader::visitSelect(Select* curr, uint8_t code) { } void WasmBinaryReader::visitReturn(Return* curr) { - BYN_TRACE("zz node: Return\n"); requireFunctionContext("return"); Type type = currFunction->getResults(); if (type.isConcrete()) { @@ -7090,7 +6943,6 @@ void WasmBinaryReader::visitReturn(Return* curr) { } void WasmBinaryReader::visitMemorySize(MemorySize* curr) { - BYN_TRACE("zz node: MemorySize\n"); Index index = getU32LEB(); if (getMemory(index)->is64()) { curr->type = Type::i64; @@ -7100,7 +6952,6 @@ void WasmBinaryReader::visitMemorySize(MemorySize* curr) { } void WasmBinaryReader::visitMemoryGrow(MemoryGrow* curr) { - BYN_TRACE("zz node: MemoryGrow\n"); curr->delta = popNonVoidExpression(); Index index = getU32LEB(); if (getMemory(index)->is64()) { @@ -7109,31 +6960,25 @@ void WasmBinaryReader::visitMemoryGrow(MemoryGrow* curr) { memoryRefs[index].push_back(&curr->memory); } -void WasmBinaryReader::visitNop(Nop* curr) { BYN_TRACE("zz node: Nop\n"); } +void WasmBinaryReader::visitNop(Nop* curr) {} -void WasmBinaryReader::visitUnreachable(Unreachable* curr) { - BYN_TRACE("zz node: Unreachable\n"); -} +void WasmBinaryReader::visitUnreachable(Unreachable* curr) {} void WasmBinaryReader::visitDrop(Drop* curr) { - BYN_TRACE("zz node: Drop\n"); curr->value = popNonVoidExpression(); curr->finalize(); } void WasmBinaryReader::visitRefNull(RefNull* curr) { - BYN_TRACE("zz node: RefNull\n"); curr->finalize(getHeapType().getBottom()); } void WasmBinaryReader::visitRefIsNull(RefIsNull* curr) { - BYN_TRACE("zz node: RefIsNull\n"); curr->value = popNonVoidExpression(); curr->finalize(); } void WasmBinaryReader::visitRefFunc(RefFunc* curr) { - BYN_TRACE("zz node: RefFunc\n"); Index index = getU32LEB(); // We don't know function names yet, so record this use to be updated later. // Note that we do not need to check that 'index' is in bounds, as that will @@ -7147,14 +6992,12 @@ void WasmBinaryReader::visitRefFunc(RefFunc* curr) { } void WasmBinaryReader::visitRefEq(RefEq* curr) { - BYN_TRACE("zz node: RefEq\n"); curr->right = popNonVoidExpression(); curr->left = popNonVoidExpression(); curr->finalize(); } void WasmBinaryReader::visitTableGet(TableGet* curr) { - BYN_TRACE("zz node: TableGet\n"); Index tableIdx = getU32LEB(); if (tableIdx >= wasm.tables.size()) { throwError("bad table index"); @@ -7167,7 +7010,6 @@ void WasmBinaryReader::visitTableGet(TableGet* curr) { } void WasmBinaryReader::visitTableSet(TableSet* curr) { - BYN_TRACE("zz node: TableSet\n"); Index tableIdx = getU32LEB(); if (tableIdx >= wasm.tables.size()) { throwError("bad table index"); @@ -7180,7 +7022,6 @@ void WasmBinaryReader::visitTableSet(TableSet* curr) { } void WasmBinaryReader::visitTryOrTryInBlock(Expression*& out) { - BYN_TRACE("zz node: Try\n"); auto* curr = allocator.alloc<Try>(); startControlFlow(curr); // For simplicity of implementation, like if scopes, we create a hidden block @@ -7333,7 +7174,6 @@ void WasmBinaryReader::visitTryOrTryInBlock(Expression*& out) { } void WasmBinaryReader::visitTryTable(TryTable* curr) { - BYN_TRACE("zz node: TryTable\n"); // For simplicity of implementation, like if scopes, we create a hidden block // within each try-body, and let branches target those inner blocks instead. @@ -7378,7 +7218,6 @@ void WasmBinaryReader::visitTryTable(TryTable* curr) { } void WasmBinaryReader::visitThrow(Throw* curr) { - BYN_TRACE("zz node: Throw\n"); auto index = getU32LEB(); if (index >= wasm.tags.size()) { throwError("bad tag index"); @@ -7395,7 +7234,6 @@ void WasmBinaryReader::visitThrow(Throw* curr) { } void WasmBinaryReader::visitRethrow(Rethrow* curr) { - BYN_TRACE("zz node: Rethrow\n"); curr->target = getExceptionTargetName(getU32LEB()); // This special target is valid only for delegates if (curr->target == DELEGATE_CALLER_TARGET) { @@ -7406,13 +7244,11 @@ void WasmBinaryReader::visitRethrow(Rethrow* curr) { } void WasmBinaryReader::visitThrowRef(ThrowRef* curr) { - BYN_TRACE("zz node: ThrowRef\n"); curr->exnref = popNonVoidExpression(); curr->finalize(); } void WasmBinaryReader::visitCallRef(CallRef* curr) { - BYN_TRACE("zz node: CallRef\n"); curr->target = popNonVoidExpression(); HeapType heapType = getTypeByIndex(getU32LEB()); if (!Type::isSubType(curr->target->type, Type(heapType, Nullable))) { @@ -7922,7 +7758,6 @@ bool WasmBinaryReader::maybeVisitStringSliceWTF(Expression*& out, } void WasmBinaryReader::visitRefAs(RefAs* curr, uint8_t code) { - BYN_TRACE("zz node: RefAs\n"); switch (code) { case BinaryConsts::RefAsNonNull: curr->op = RefAsNonNull; @@ -7944,7 +7779,6 @@ void WasmBinaryReader::visitRefAs(RefAs* curr, uint8_t code) { } void WasmBinaryReader::visitContBind(ContBind* curr) { - BYN_TRACE("zz node: ContBind\n"); auto contTypeBeforeIndex = getU32LEB(); curr->contTypeBefore = getTypeByIndex(contTypeBeforeIndex); @@ -7981,7 +7815,6 @@ void WasmBinaryReader::visitContBind(ContBind* curr) { } void WasmBinaryReader::visitContNew(ContNew* curr) { - BYN_TRACE("zz node: ContNew\n"); auto contTypeIndex = getU32LEB(); curr->contType = getTypeByIndex(contTypeIndex); @@ -7995,7 +7828,6 @@ void WasmBinaryReader::visitContNew(ContNew* curr) { } void WasmBinaryReader::visitResume(Resume* curr) { - BYN_TRACE("zz node: Resume\n"); auto contTypeIndex = getU32LEB(); curr->contType = getTypeByIndex(contTypeIndex); @@ -8012,9 +7844,7 @@ void WasmBinaryReader::visitResume(Resume* curr) { curr->handlerTags.resize(numHandlers); curr->handlerBlocks.resize(numHandlers); - BYN_TRACE("handler num: " << numHandlers << std::endl); for (size_t i = 0; i < numHandlers; i++) { - BYN_TRACE("read one tag handler pair \n"); auto tagIndex = getU32LEB(); auto tag = getTagName(tagIndex); @@ -8041,7 +7871,6 @@ void WasmBinaryReader::visitResume(Resume* curr) { } void WasmBinaryReader::visitSuspend(Suspend* curr) { - BYN_TRACE("zz node: Suspend\n"); auto tagIndex = getU32LEB(); if (tagIndex >= wasm.tags.size()) { |