diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 5 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 22 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 8a7f0d744..bb5d420a9 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -307,6 +307,7 @@ void WasmBinaryWriter::writeFunctions() { 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()); size_t sourceMapLocationsSizeAtFunctionStart = sourceMapLocations.size(); @@ -315,12 +316,12 @@ void WasmBinaryWriter::writeFunctions() { size_t start = o.size(); BYN_TRACE("writing" << func->name << std::endl); // Emit Stack IR if present, and if we can - if (func->stackIR && !sourceMap) { + if (func->stackIR && !sourceMap && !DWARF) { BYN_TRACE("write Stack IR\n"); StackIRToBinaryWriter(*this, o, func).write(); } else { BYN_TRACE("write Binaryen IR\n"); - BinaryenIRToBinaryWriter(*this, o, func, sourceMap).write(); + BinaryenIRToBinaryWriter(*this, o, func, sourceMap, DWARF).write(); } size_t size = o.size() - start; assert(size <= std::numeric_limits<uint32_t>::max()); diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index c6c450cfb..9e3ce2afa 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -16,6 +16,7 @@ #include "wasm-stack.h" #include "ir/find_all.h" +#include "wasm-debug.h" namespace wasm { @@ -1780,8 +1781,25 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() { assert(func && "BinaryInstWriter: function is not set"); // Map params for (Index i = 0; i < func->getNumParams(); i++) { - size_t curr = mappedLocals.size(); - mappedLocals[std::make_pair(i, 0)] = curr; + mappedLocals[std::make_pair(i, 0)] = i; + } + // Normally we map all locals of the same type into a range of adjacent + // addresses, which is more compact. However, if we need to keep DWARF valid, + // do not do any reordering at all - instead, do a trivial mapping that + // keeps everything unmoved. + if (DWARF) { + FindAll<TupleExtract> extracts(func->body); + if (!extracts.list.empty()) { + Fatal() << "DWARF + multivalue is not yet complete"; + } + Index varStart = func->getVarIndexBase(); + Index varEnd = varStart + func->getNumVars(); + o << U32LEB(func->getNumVars()); + for (Index i = varStart; i < varEnd; i++) { + mappedLocals[std::make_pair(i, 0)] = i; + o << U32LEB(1) << binaryType(func->getLocalType(i)); + } + return; } for (auto type : func->vars) { for (auto t : type.expand()) { |