summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 6ba4750ec..efa4ad601 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -44,6 +44,7 @@ class S2WasmBuilder {
MixedArena* allocator;
LinkerObject* linkerObj;
std::unique_ptr<LinkerObject::SymbolInfo> symbolInfo;
+ std::unordered_map<uint32_t, uint32_t> fileIndexMap;
public:
S2WasmBuilder(const char* input, bool debug)
@@ -601,7 +602,9 @@ class S2WasmBuilder {
size_t fileId = getInt();
skipWhitespace();
auto quoted = getQuoted();
- WASM_UNUSED(fileId); WASM_UNUSED(quoted); // TODO: use the fileId and quoted
+ uint32_t index = wasm->debugInfoFileNames.size();
+ fileIndexMap[fileId] = index;
+ wasm->debugInfoFileNames.push_back(std::string(quoted.begin(), quoted.end()));
s = strchr(s, '\n');
return;
}
@@ -665,22 +668,31 @@ class S2WasmBuilder {
mustMatch(":");
+ Function::DebugLocation debugLocation = { 0, 0, 0 };
+ bool useDebugLocation = false;
auto recordFile = [&]() {
if (debug) dump("file");
size_t fileId = getInt();
skipWhitespace();
auto quoted = getQuoted();
- WASM_UNUSED(fileId); WASM_UNUSED(quoted); // TODO: use the fileId and quoted
+ uint32_t index = wasm->debugInfoFileNames.size();
+ fileIndexMap[fileId] = index;
+ wasm->debugInfoFileNames.push_back(std::string(quoted.begin(), quoted.end()));
s = strchr(s, '\n');
};
auto recordLoc = [&]() {
if (debug) dump("loc");
size_t fileId = getInt();
skipWhitespace();
- size_t row = getInt();
+ uint32_t row = getInt();
skipWhitespace();
- size_t column = getInt();
- WASM_UNUSED(fileId); WASM_UNUSED(row); WASM_UNUSED(column); // TODO: use the fileId, row and column
+ uint32_t column = getInt();
+ auto iter = fileIndexMap.find(fileId);
+ if (iter == fileIndexMap.end()) {
+ abort_on("idx");
+ }
+ useDebugLocation = true;
+ debugLocation = { iter->second, row, column };
s = strchr(s, '\n');
};
auto recordLabel = [&]() {
@@ -746,7 +758,10 @@ class S2WasmBuilder {
// parse body
func->body = allocator->alloc<Block>();
std::vector<Expression*> bstack;
- auto addToBlock = [&bstack](Expression* curr) {
+ auto addToBlock = [&](Expression* curr) {
+ if (useDebugLocation) {
+ func->debugLocations[curr] = debugLocation;
+ }
Expression* last = bstack.back();
if (last->is<Loop>()) {
last = last->cast<Loop>()->body;