diff options
author | Thomas Lively <tlively@google.com> | 2024-12-03 11:20:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-03 11:20:36 -0800 |
commit | 87f9dac127b387715d8d96ac7ec8fd469d8c2dab (patch) | |
tree | aa1aec906bf6adc3ea3d93c56616d393850e2249 /src/wasm-binary.h | |
parent | f331120e4b942a795d4a6b6d0d5a3d781c1e6a4c (diff) | |
download | binaryen-87f9dac127b387715d8d96ac7ec8fd469d8c2dab.tar.gz binaryen-87f9dac127b387715d8d96ac7ec8fd469d8c2dab.tar.bz2 binaryen-87f9dac127b387715d8d96ac7ec8fd469d8c2dab.zip |
[NFC] Encapsulate source map reader state (#7132)
Move all state relevant to reading source maps out of WasmBinaryReader
and into a new utility, SourceMapReader. This is a prerequisite for
parallelizing the parsing of function bodies, since the source map
reader state is different at the beginning of each function.
Also take the opportunity to simplify the way we read source maps, for
example by deferring the reading of anything but the position of a debug
location until it will be used and by using `std::optional` instead of
singleton `std::set`s to store function prologue and epilogue debug
locations.
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 49 |
1 files changed, 8 insertions, 41 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index b9cbba136..7c32e2169 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -28,6 +28,7 @@ #include "ir/import-utils.h" #include "ir/module-utils.h" #include "parsing.h" +#include "source-map.h" #include "wasm-builder.h" #include "wasm-ir-builder.h" #include "wasm-traversal.h" @@ -1403,41 +1404,13 @@ private: void prepare(); }; +extern std::vector<char> defaultEmptySourceMap; + class WasmBinaryReader { Module& wasm; MixedArena& allocator; const std::vector<char>& input; - // Source map debugging support. - - std::istream* sourceMap; - - // The binary position that the next debug location refers to. That is, this - // is the first item in a source map entry that we have read (the "column", in - // source map terms, which for wasm means the offset in the binary). We have - // read this entry, but have not used it yet (we use it when we read the - // expression at this binary offset). - // - // This is set to 0 as an invalid value if we reach the end of the source map - // and there is nothing left to read. - size_t nextDebugPos; - - // The debug location (file:line:col) corresponding to |nextDebugPos|. That - // is, this is the next 3 fields in a source map entry that we have read, but - // not used yet. - // - // If that location has no debug info (it lacks those 3 fields), then this - // contains the info from the previous one, because in a source map, these - // fields are relative to their last appearance, so we cannot forget them (we - // can't just do something like std::optional<DebugLocation> or such); for - // example, if we have line number 100, then no debug info, and then line - // number 500, then when we get to 500 we will see "+400" which is relative to - // the last existing line number (we "skip" over a place without debug info). - Function::DebugLocation nextDebugLocation; - - // Whether debug info is present on |nextDebugPos| (see comment there). - bool nextDebugLocationHasDebugInfo; - // Settings. bool debugInfo = true; @@ -1448,17 +1421,20 @@ class WasmBinaryReader { size_t pos = 0; Index startIndex = -1; - std::set<Function::DebugLocation> debugLocation; size_t codeSectionLocation; std::unordered_set<uint8_t> seenSections; + IRBuilder builder; + SourceMapReader sourceMapReader; + // All types defined in the type section std::vector<HeapType> types; public: WasmBinaryReader(Module& wasm, FeatureSet features, - const std::vector<char>& input); + const std::vector<char>& input, + const std::vector<char>& sourceMap = defaultEmptySourceMap); void setDebugInfo(bool value) { debugInfo = value; } void setDWARF(bool value) { DWARF = value; } @@ -1584,8 +1560,6 @@ public: Expression* readExpression(); void readGlobals(); - IRBuilder builder; - // validations that cannot be performed on the Module void validateBinary(); @@ -1607,13 +1581,6 @@ public: void readDylink(size_t); void readDylink0(size_t); - // Debug information reading helpers - void setDebugLocations(std::istream* sourceMap_) { sourceMap = sourceMap_; } - std::unordered_map<std::string, Index> debugInfoFileIndices; - std::unordered_map<std::string, Index> debugInfoSymbolNameIndices; - void readNextDebugLocation(); - void readSourceMapHeader(); - Index readMemoryAccess(Address& alignment, Address& offset); std::tuple<Name, Address, Address> getMemarg(); |