@@ -510,6 +510,7 @@ class S2WasmBuilder {
510510 else if (match (" data" )) {}
511511 else if (match (" ident" )) skipToEOL ();
512512 else if (match (" section" )) parseToplevelSection ();
513+ else if (match (" file" )) parseFile ();
513514 else if (match (" align" ) || match (" p2align" )) skipToEOL ();
514515 else if (match (" import_global" )) {
515516 skipToEOL ();
@@ -597,26 +598,16 @@ class S2WasmBuilder {
597598 }
598599
599600 void parseFile () {
601+ if (debug) dump (" file" );
602+ size_t fileId = 0 ;
600603 if (*s != ' "' ) {
601- // TODO: optimize, see recordFile below
602- size_t fileId = getInt ();
604+ fileId = getInt ();
603605 skipWhitespace ();
604- auto quoted = getQuoted ();
605- uint32_t index = wasm->debugInfoFileNames .size ();
606- fileIndexMap[fileId] = index;
607- wasm->debugInfoFileNames .push_back (std::string (quoted.begin (), quoted.end ()));
608- s = strchr (s, ' \n ' );
609- return ;
610- }
611- // '.file' without first index argument points to bc-file
612- s++;
613- std::string filename;
614- while (*s != ' "' ) {
615- filename += *s;
616- s++;
617606 }
618- s++;
619- WASM_UNUSED (filename); // TODO: use the filename
607+ auto filename = getQuoted ();
608+ uint32_t index = wasm->debugInfoFileNames .size ();
609+ wasm->debugInfoFileNames .push_back (std::string (filename.begin (), filename.end ()));
610+ fileIndexMap[fileId] = index;
620611 }
621612
622613 void parseGlobl () {
@@ -670,16 +661,6 @@ class S2WasmBuilder {
670661
671662 Function::DebugLocation debugLocation = { 0 , 0 , 0 };
672663 bool useDebugLocation = false ;
673- auto recordFile = [&]() {
674- if (debug) dump (" file" );
675- size_t fileId = getInt ();
676- skipWhitespace ();
677- auto quoted = getQuoted ();
678- uint32_t index = wasm->debugInfoFileNames .size ();
679- fileIndexMap[fileId] = index;
680- wasm->debugInfoFileNames .push_back (std::string (quoted.begin (), quoted.end ()));
681- s = strchr (s, ' \n ' );
682- };
683664 auto recordLoc = [&]() {
684665 if (debug) dump (" loc" );
685666 size_t fileId = getInt ();
@@ -743,7 +724,7 @@ class S2WasmBuilder {
743724 if (!match (" ," )) break ;
744725 }
745726 } else if (match (" .file" )) {
746- recordFile ();
727+ parseFile ();
747728 skipWhitespace ();
748729 } else if (match (" .loc" )) {
749730 recordLoc ();
@@ -1293,7 +1274,7 @@ class S2WasmBuilder {
12931274 s = strchr (s, ' \n ' );
12941275 break ; // the function is done
12951276 } else if (match (" .file" )) {
1296- recordFile ();
1277+ parseFile ();
12971278 } else if (match (" .loc" )) {
12981279 recordLoc ();
12991280 } else if (peek (" .L" ) && strchr (s, ' :' ) < strchr (s, ' \n ' )) {
0 commit comments