From 3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde Mon Sep 17 00:00:00 2001 From: Ashley Nelson Date: Tue, 21 Jun 2022 20:57:43 -0700 Subject: First class Data Segments (#4733) * Updating wasm.h/cpp for DataSegments * Updating wasm-binary.h/cpp for DataSegments * Removed link from Memory to DataSegments and updated module-utils, Metrics and wasm-traversal * checking isPassive when copying data segments to know whether to construct the data segment with an offset or not * Removing memory member var from DataSegment class as there is only one memory rn. Updated wasm-validator.cpp * Updated wasm-interpreter * First look at updating Passes * Updated wasm-s-parser * Updated files in src/ir * Updating tools files * Last pass on src files before building * added visitDataSegment * Fixing build errors * Data segments need a name * fixing var name * ran clang-format * Ensuring a name on DataSegment * Ensuring more datasegments have names * Adding explicit name support * Fix fuzzing name * Outputting data name in wasm binary only if explicit * Checking temp dataSegments vector to validateBinary because it's the one with the segments before we processNames * Pass on when data segment names are explicitly set * Ran auto_update_tests.py and check.py, success all around * Removed an errant semi-colon and corrected a counter. Everything still passes * Linting * Fixing processing memory names after parsed from binary * Updating the test from the last fix * Correcting error comment * Impl kripken@ comments * Impl tlively@ comments * Updated tests that remove data print when == 0 * Ran clang format * Impl tlively@ comments * Ran clang-format --- src/wasm-binary.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 96927b10e..659e0f58b 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -1158,6 +1158,7 @@ class WasmBinaryWriter { std::unordered_map globalIndexes; std::unordered_map tableIndexes; std::unordered_map elemIndexes; + std::unordered_map dataIndexes; BinaryIndexes(Module& wasm) { auto addIndexes = [&](auto& source, auto& indexes) { @@ -1185,6 +1186,11 @@ class WasmBinaryWriter { elemIndexes[curr->name] = index; } + for (auto& curr : wasm.dataSegments) { + auto index = dataIndexes.size(); + dataIndexes[curr->name] = index; + } + // Globals may have tuple types in the IR, in which case they lower to // multiple globals, one for each tuple element, in the binary. Tuple // globals therefore occupy multiple binary indices, and we have to take @@ -1486,6 +1492,9 @@ public: // names std::vector> elementSegments; + // we store data here after being read from binary, before we know their names + std::vector> dataSegments; + // we store globals here before wasm.addGlobal after we know their names std::vector> globals; // we store global imports here before wasm.addGlobalImport after we know @@ -1590,7 +1599,7 @@ public: bool hasDataCount = false; void readDataSegments(); - void readDataCount(); + void readDataSegmentCount(); void readTableDeclarations(); void readElementSegments(); -- cgit v1.2.3