2828#include " ir/import-utils.h"
2929#include " ir/module-utils.h"
3030#include " parsing.h"
31+ #include " source-map.h"
3132#include " wasm-builder.h"
3233#include " wasm-ir-builder.h"
3334#include " wasm-traversal.h"
@@ -1403,41 +1404,13 @@ class WasmBinaryWriter {
14031404 void prepare ();
14041405};
14051406
1407+ extern std::vector<char > defaultEmptySourceMap;
1408+
14061409class WasmBinaryReader {
14071410 Module& wasm;
14081411 MixedArena& allocator;
14091412 const std::vector<char >& input;
14101413
1411- // Source map debugging support.
1412-
1413- std::istream* sourceMap;
1414-
1415- // The binary position that the next debug location refers to. That is, this
1416- // is the first item in a source map entry that we have read (the "column", in
1417- // source map terms, which for wasm means the offset in the binary). We have
1418- // read this entry, but have not used it yet (we use it when we read the
1419- // expression at this binary offset).
1420- //
1421- // This is set to 0 as an invalid value if we reach the end of the source map
1422- // and there is nothing left to read.
1423- size_t nextDebugPos;
1424-
1425- // The debug location (file:line:col) corresponding to |nextDebugPos|. That
1426- // is, this is the next 3 fields in a source map entry that we have read, but
1427- // not used yet.
1428- //
1429- // If that location has no debug info (it lacks those 3 fields), then this
1430- // contains the info from the previous one, because in a source map, these
1431- // fields are relative to their last appearance, so we cannot forget them (we
1432- // can't just do something like std::optional<DebugLocation> or such); for
1433- // example, if we have line number 100, then no debug info, and then line
1434- // number 500, then when we get to 500 we will see "+400" which is relative to
1435- // the last existing line number (we "skip" over a place without debug info).
1436- Function::DebugLocation nextDebugLocation;
1437-
1438- // Whether debug info is present on |nextDebugPos| (see comment there).
1439- bool nextDebugLocationHasDebugInfo;
1440-
14411414 // Settings.
14421415
14431416 bool debugInfo = true ;
@@ -1448,17 +1421,20 @@ class WasmBinaryReader {
14481421
14491422 size_t pos = 0 ;
14501423 Index startIndex = -1 ;
1451- std::set<Function::DebugLocation> debugLocation;
14521424 size_t codeSectionLocation;
14531425 std::unordered_set<uint8_t > seenSections;
14541426
1427+ IRBuilder builder;
1428+ SourceMapReader sourceMapReader;
1429+
14551430 // All types defined in the type section
14561431 std::vector<HeapType> types;
14571432
14581433public:
14591434 WasmBinaryReader (Module& wasm,
14601435 FeatureSet features,
1461- const std::vector<char >& input);
1436+ const std::vector<char >& input,
1437+ const std::vector<char >& sourceMap = defaultEmptySourceMap);
14621438
14631439 void setDebugInfo (bool value) { debugInfo = value; }
14641440 void setDWARF (bool value) { DWARF = value; }
@@ -1584,8 +1560,6 @@ class WasmBinaryReader {
15841560 Expression* readExpression ();
15851561 void readGlobals ();
15861562
1587- IRBuilder builder;
1588-
15891563 // validations that cannot be performed on the Module
15901564 void validateBinary ();
15911565
@@ -1607,13 +1581,6 @@ class WasmBinaryReader {
16071581 void readDylink (size_t );
16081582 void readDylink0 (size_t );
16091583
1610- // Debug information reading helpers
1611- void setDebugLocations (std::istream* sourceMap_) { sourceMap = sourceMap_; }
1612- std::unordered_map<std::string, Index> debugInfoFileIndices;
1613- std::unordered_map<std::string, Index> debugInfoSymbolNameIndices;
1614- void readNextDebugLocation ();
1615- void readSourceMapHeader ();
1616-
16171584 Index readMemoryAccess (Address& alignment, Address& offset);
16181585 std::tuple<Name, Address, Address> getMemarg ();
16191586
0 commit comments