summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wasm-stack.h10
-rw-r--r--src/wasm/wasm-binary.cpp4
-rw-r--r--src/wasm/wasm-stack.cpp12
3 files changed, 21 insertions, 5 deletions
diff --git a/src/wasm-stack.h b/src/wasm-stack.h
index d6c0e46ec..0b72774b6 100644
--- a/src/wasm-stack.h
+++ b/src/wasm-stack.h
@@ -508,17 +508,21 @@ class StackIRToBinaryWriter {
public:
StackIRToBinaryWriter(WasmBinaryWriter& parent,
BufferWithRandomAccess& o,
- Function* func)
- : writer(parent, o, func, false /* sourceMap */, false /* DWARF */),
- func(func) {}
+ Function* func,
+ bool sourceMap = false,
+ bool DWARF = false)
+ : parent(parent), writer(parent, o, func, sourceMap, DWARF), func(func),
+ sourceMap(sourceMap) {}
void write();
MappedLocals& getMappedLocals() { return writer.mappedLocals; }
private:
+ WasmBinaryWriter& parent;
BinaryInstWriter writer;
Function* func;
+ bool sourceMap;
};
std::ostream& printStackIR(std::ostream& o, Module* module, bool optimize);
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index b45fe84c8..b655395bf 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -403,9 +403,9 @@ 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 && !DWARF) {
+ if (func->stackIR) {
BYN_TRACE("write Stack IR\n");
- StackIRToBinaryWriter writer(*this, o, func);
+ StackIRToBinaryWriter writer(*this, o, func, sourceMap, DWARF);
writer.write();
if (debugInfo) {
funcMappedLocals[func->name] = std::move(writer.getMappedLocals());
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp
index f1413847f..99aaf517e 100644
--- a/src/wasm/wasm-stack.cpp
+++ b/src/wasm/wasm-stack.cpp
@@ -2779,6 +2779,9 @@ StackInst* StackIRGenerator::makeStackInst(StackInst::Op op,
}
void StackIRToBinaryWriter::write() {
+ if (func->prologLocation.size()) {
+ parent.writeDebugLocation(*func->prologLocation.begin());
+ }
writer.mapLocalsAndEmitHeader();
// Stack to track indices of catches within a try
SmallVector<Index, 4> catchIndexStack;
@@ -2795,7 +2798,13 @@ void StackIRToBinaryWriter::write() {
case StackInst::IfBegin:
case StackInst::LoopBegin:
case StackInst::TryTableBegin: {
+ if (sourceMap) {
+ parent.writeDebugLocation(inst->origin, func);
+ }
writer.visit(inst->origin);
+ if (sourceMap) {
+ parent.writeDebugLocationEnd(inst->origin, func);
+ }
break;
}
case StackInst::TryEnd:
@@ -2830,6 +2839,9 @@ void StackIRToBinaryWriter::write() {
WASM_UNREACHABLE("unexpected op");
}
}
+ if (func->epilogLocation.size()) {
+ parent.writeDebugLocation(*func->epilogLocation.begin());
+ }
writer.emitFunctionEnd();
}