summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h39
-rw-r--r--test/dot_s/debug.wast1
2 files changed, 11 insertions, 29 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 0fc0201cd..dd507143b 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -510,6 +510,7 @@ class S2WasmBuilder {
else if (match("data")) {}
else if (match("ident")) skipToEOL();
else if (match("section")) parseToplevelSection();
+ else if (match("file")) parseFile();
else if (match("align") || match("p2align")) skipToEOL();
else if (match("import_global")) {
skipToEOL();
@@ -597,26 +598,16 @@ class S2WasmBuilder {
}
void parseFile() {
+ if (debug) dump("file");
+ size_t fileId = 0;
if (*s != '"') {
- // TODO: optimize, see recordFile below
- size_t fileId = getInt();
+ fileId = getInt();
skipWhitespace();
- auto quoted = getQuoted();
- uint32_t index = wasm->debugInfoFileNames.size();
- fileIndexMap[fileId] = index;
- wasm->debugInfoFileNames.push_back(std::string(quoted.begin(), quoted.end()));
- s = strchr(s, '\n');
- return;
- }
- // '.file' without first index argument points to bc-file
- s++;
- std::string filename;
- while (*s != '"') {
- filename += *s;
- s++;
}
- s++;
- WASM_UNUSED(filename); // TODO: use the filename
+ auto filename = getQuoted();
+ uint32_t index = wasm->debugInfoFileNames.size();
+ wasm->debugInfoFileNames.push_back(std::string(filename.begin(), filename.end()));
+ fileIndexMap[fileId] = index;
}
void parseGlobl() {
@@ -670,16 +661,6 @@ class S2WasmBuilder {
Function::DebugLocation debugLocation = { 0, 0, 0 };
bool useDebugLocation = false;
- auto recordFile = [&]() {
- if (debug) dump("file");
- size_t fileId = getInt();
- skipWhitespace();
- auto quoted = getQuoted();
- 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();
@@ -743,7 +724,7 @@ class S2WasmBuilder {
if (!match(",")) break;
}
} else if (match(".file")) {
- recordFile();
+ parseFile();
skipWhitespace();
} else if (match(".loc")) {
recordLoc();
@@ -1293,7 +1274,7 @@ class S2WasmBuilder {
s = strchr(s, '\n');
break; // the function is done
} else if (match(".file")) {
- recordFile();
+ parseFile();
} else if (match(".loc")) {
recordLoc();
} else if (peek(".L") && strchr(s, ':') < strchr(s, '\n')) {
diff --git a/test/dot_s/debug.wast b/test/dot_s/debug.wast
index d4431ba4f..f85073e19 100644
--- a/test/dot_s/debug.wast
+++ b/test/dot_s/debug.wast
@@ -10,6 +10,7 @@
(local $2 i32)
(local $3 i32)
(local $4 i32)
+ ;;@ fib.c:1:0
(set_local $3
(i32.const 0)
)