diff options
author | Ashley Nelson <nashley@google.com> | 2022-06-21 20:57:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 20:57:43 -0700 |
commit | 3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde (patch) | |
tree | c01eb86869401931006b6503e47d60b9a44511b0 /src/binaryen-c.cpp | |
parent | 7fa4c0841c31930759fbad2efb8ada3ef0e6f3ef (diff) | |
download | binaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.tar.gz binaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.tar.bz2 binaryen-3b9c2e85fa5d97ba08a95c0c7cce7d041e699cde.zip |
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
Diffstat (limited to 'src/binaryen-c.cpp')
-rw-r--r-- | src/binaryen-c.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index d70f31912..8a5756f6e 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3768,23 +3768,25 @@ void BinaryenSetMemory(BinaryenModuleRef module, wasm->addExport(memoryExport.release()); } for (BinaryenIndex i = 0; i < numSegments; i++) { - wasm->memory.segments.emplace_back(Name(), - segmentPassive[i], - (Expression*)segmentOffsets[i], - segments[i], - segmentSizes[i]); + auto curr = Builder::makeDataSegment(Name::fromInt(i), + segmentPassive[i], + (Expression*)segmentOffsets[i], + segments[i], + segmentSizes[i]); + curr->hasExplicitName = false; + wasm->dataSegments.push_back(std::move(curr)); } } // Memory segments uint32_t BinaryenGetNumMemorySegments(BinaryenModuleRef module) { - return ((Module*)module)->memory.segments.size(); + return ((Module*)module)->dataSegments.size(); } uint32_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module, BinaryenIndex id) { auto* wasm = (Module*)module; - if (wasm->memory.segments.size() <= id) { + if (wasm->dataSegments.size() <= id) { Fatal() << "invalid segment id."; } @@ -3797,13 +3799,13 @@ uint32_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module, return false; }; - const auto& segment = wasm->memory.segments[id]; + const auto& segment = wasm->dataSegments[id]; int64_t ret; - if (globalOffset(segment.offset, ret)) { + if (globalOffset(segment->offset, ret)) { return ret; } - if (auto* get = segment.offset->dynCast<GlobalGet>()) { + if (auto* get = segment->offset->dynCast<GlobalGet>()) { Global* global = wasm->getGlobal(get->name); if (globalOffset(global->init, ret)) { return ret; @@ -3846,29 +3848,29 @@ bool BinaryenMemoryIsShared(BinaryenModuleRef module) { } size_t BinaryenGetMemorySegmentByteLength(BinaryenModuleRef module, BinaryenIndex id) { - const auto& segments = ((Module*)module)->memory.segments; + const auto& segments = ((Module*)module)->dataSegments; if (segments.size() <= id) { Fatal() << "invalid segment id."; } - return segments[id].data.size(); + return segments[id]->data.size(); } bool BinaryenGetMemorySegmentPassive(BinaryenModuleRef module, BinaryenIndex id) { - const auto& segments = ((Module*)module)->memory.segments; + const auto& segments = ((Module*)module)->dataSegments; if (segments.size() <= id) { Fatal() << "invalid segment id."; } - return segments[id].isPassive; + return segments[id]->isPassive; } void BinaryenCopyMemorySegmentData(BinaryenModuleRef module, BinaryenIndex id, char* buffer) { - const auto& segments = ((Module*)module)->memory.segments; + const auto& segments = ((Module*)module)->dataSegments; if (segments.size() <= id) { Fatal() << "invalid segment id."; } const auto& segment = segments[id]; - std::copy(segment.data.cbegin(), segment.data.cend(), buffer); + std::copy(segment->data.cbegin(), segment->data.cend(), buffer); } // Start function. One per module |