diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 7c8dcab97be..a0f613aa5a2 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -5557,7 +5557,7 @@ BinaryenIndex BinaryenGetNumElementSegments(BinaryenModuleRef module) { } BinaryenExpressionRef BinaryenElementSegmentGetOffset(BinaryenElementSegmentRef elem) { - if (((ElementSegment*)elem)->table.isNull()) { + if (((ElementSegment*)elem)->isPassive()) { Fatal() << "elem segment is passive."; } return ((ElementSegment*)elem)->offset; @@ -5611,12 +5611,12 @@ void BinaryenSetMemory(BinaryenModuleRef module, for (BinaryenIndex i = 0; i < numSegments; i++) { auto explicitName = segmentNames && segmentNames[i]; auto name = explicitName ? Name(segmentNames[i]) : Name::fromInt(i); - auto curr = Builder::makeDataSegment(name, - memory->name, - segmentPassives[i], - (Expression*)segmentOffsets[i], - segmentDatas[i], - segmentSizes[i]); + auto curr = + Builder::makeDataSegment(name, + segmentPassives[i] ? Name() : memory->name, + (Expression*)segmentOffsets[i], + segmentDatas[i], + segmentSizes[i]); curr->hasExplicitName = explicitName; ((Module*)module)->addDataSegment(std::move(curr)); } @@ -5766,7 +5766,7 @@ size_t BinaryenGetDataSegmentByteLength(BinaryenDataSegmentRef segment) { return ((DataSegment*)segment)->data.size(); } bool BinaryenGetDataSegmentPassive(BinaryenDataSegmentRef segment) { - return ((DataSegment*)segment)->isPassive; + return ((DataSegment*)segment)->isPassive(); } void BinaryenCopyDataSegmentData(BinaryenDataSegmentRef segment, char* buffer) { std::copy(((DataSegment*)segment)->data.cbegin(), @@ -5783,12 +5783,12 @@ void BinaryenAddDataSegment(BinaryenModuleRef module, auto* wasm = (Module*)module; auto name = segmentName ? Name(segmentName) : Name::fromInt(wasm->dataSegments.size()); - auto curr = Builder::makeDataSegment(name, - memoryName ? memoryName : "0", - segmentPassive, - (Expression*)segmentOffset, - segmentData, - segmentSize); + auto curr = Builder::makeDataSegment( + name, + segmentPassive ? Name() : (memoryName ? memoryName : "0"), + (Expression*)segmentOffset, + segmentData, + segmentSize); curr->hasExplicitName = segmentName ? true : false; wasm->addDataSegment(std::move(curr)); } @@ -6333,7 +6333,7 @@ void BinaryenElementSegmentSetTable(BinaryenElementSegmentRef elem, ((ElementSegment*)elem)->table = table; } bool BinaryenElementSegmentIsPassive(BinaryenElementSegmentRef elem) { - return ((ElementSegment*)elem)->table.isNull(); + return ((ElementSegment*)elem)->isPassive(); } // diff --git a/src/ir/memory-utils.cpp b/src/ir/memory-utils.cpp index 4bd629e2cbc..6c6a75ebbcb 100644 --- a/src/ir/memory-utils.cpp +++ b/src/ir/memory-utils.cpp @@ -94,7 +94,7 @@ bool flatten(Module& wasm) { std::vector data; for (auto& segment : dataSegments) { - if (segment->isPassive) { + if (segment->isPassive()) { return false; } auto* offset = segment->offset->dynCast(); diff --git a/src/ir/memory-utils.h b/src/ir/memory-utils.h index 2929d17ca9f..db9ff2bcba8 100644 --- a/src/ir/memory-utils.h +++ b/src/ir/memory-utils.h @@ -81,7 +81,7 @@ ensureLimitedSegments(Module& module, numDynamic++; } } - hasPassiveSegments |= segment->isPassive; + hasPassiveSegments |= segment->isPassive(); } if (hasPassiveSegments) { diff --git a/src/ir/module-splitting.cpp b/src/ir/module-splitting.cpp index 78141676375..95abc3306da 100644 --- a/src/ir/module-splitting.cpp +++ b/src/ir/module-splitting.cpp @@ -743,12 +743,12 @@ void ModuleSplitter::shareImportableItems() { // module, it can't. walkSegments(collector, &module); for (auto& segment : module.dataSegments) { - if (segment->memory.is()) { + if (segment->isActive()) { used.memories.insert(segment->memory); } } for (auto& segment : module.elementSegments) { - if (segment->table.is()) { + if (segment->isActive()) { used.tables.insert(segment->table); } } diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp index 4d4a565a7ce..b17d6c772b9 100644 --- a/src/ir/module-utils.cpp +++ b/src/ir/module-utils.cpp @@ -146,7 +146,7 @@ ElementSegment* copyElementSegment(const ElementSegment* segment, Module& out) { return out.addElementSegment(std::move(ret)); }; - if (segment->table.isNull()) { + if (segment->isPassive()) { return copy(std::make_unique()); } else { auto offset = ExpressionManipulator::copy(segment->offset, out); @@ -188,8 +188,7 @@ DataSegment* copyDataSegment(const DataSegment* segment, Module& out) { ret->name = segment->name; ret->hasExplicitName = segment->hasExplicitName; ret->memory = segment->memory; - ret->isPassive = segment->isPassive; - if (!segment->isPassive) { + if (segment->isActive()) { auto offset = ExpressionManipulator::copy(segment->offset, out); ret->offset = offset; } diff --git a/src/ir/module-utils.h b/src/ir/module-utils.h index 09b7900d3c9..860672beef8 100644 --- a/src/ir/module-utils.h +++ b/src/ir/module-utils.h @@ -95,7 +95,7 @@ template inline void iterDefinedMemories(Module& wasm, T visitor) { template inline void iterMemorySegments(Module& wasm, Name memory, T visitor) { for (auto& segment : wasm.dataSegments) { - if (!segment->isPassive && segment->memory == memory) { + if (segment->isActive() && segment->memory == memory) { visitor(segment.get()); } } @@ -104,7 +104,7 @@ inline void iterMemorySegments(Module& wasm, Name memory, T visitor) { template inline void iterActiveDataSegments(Module& wasm, T visitor) { for (auto& segment : wasm.dataSegments) { - if (!segment->isPassive) { + if (segment->isActive()) { visitor(segment.get()); } } @@ -142,7 +142,7 @@ inline void iterTableSegments(Module& wasm, Name table, T visitor) { template inline void iterActiveElementSegments(Module& wasm, T visitor) { for (auto& segment : wasm.elementSegments) { - if (segment->table.is()) { + if (segment->isActive()) { visitor(segment.get()); } } diff --git a/src/parser/context-decls.cpp b/src/parser/context-decls.cpp index 3afa960ee5a..0298f1cee9a 100644 --- a/src/parser/context-decls.cpp +++ b/src/parser/context-decls.cpp @@ -181,7 +181,6 @@ Result<> ParseDeclsCtx::addImplicitData(DataStringT&& data) { auto& mem = *wasm.memories.back(); auto d = std::make_unique(); d->memory = mem.name; - d->isPassive = false; d->offset = Builder(wasm).makeConstPtr(0, mem.addressType); d->data = std::move(data); d->name = Names::getValidDataSegmentName(wasm, "implicit-data"); diff --git a/src/parser/context-defs.cpp b/src/parser/context-defs.cpp index c69c428d5bc..d0d170ed2c5 100644 --- a/src/parser/context-defs.cpp +++ b/src/parser/context-defs.cpp @@ -108,7 +108,6 @@ Result<> ParseDefsCtx::addData( Name, Name* mem, std::optional offset, DataStringT, Index pos) { auto& d = wasm.dataSegments[index]; if (offset) { - d->isPassive = false; d->offset = *offset; if (mem) { d->memory = *mem; @@ -118,7 +117,7 @@ Result<> ParseDefsCtx::addData( return in.err(pos, "active data segment with no memory"); } } else { - d->isPassive = true; + d->memory = Name(); } return Ok{}; } diff --git a/src/passes/LLVMMemoryCopyFillLowering.cpp b/src/passes/LLVMMemoryCopyFillLowering.cpp index 9ccf2934a5a..e61e9891d16 100644 --- a/src/passes/LLVMMemoryCopyFillLowering.cpp +++ b/src/passes/LLVMMemoryCopyFillLowering.cpp @@ -59,13 +59,13 @@ struct LLVMMemoryCopyFillLowering // Check for the presence of any passive data or table segments. for (auto& segment : module->dataSegments) { - if (segment->isPassive) { + if (segment->isPassive()) { Fatal() << "memory.copy lowering should only be run on modules with " "no passive segments"; } } for (auto& segment : module->elementSegments) { - if (!segment->table.is()) { + if (segment->isPassive()) { Fatal() << "memory.copy lowering should only be run on modules with" " no passive segments"; } diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp index a3877254df7..67409fc3ab5 100644 --- a/src/passes/Memory64Lowering.cpp +++ b/src/passes/Memory64Lowering.cpp @@ -192,7 +192,7 @@ struct Memory64Lowering : public WalkerPass> { auto& module = *getModule(); // passive segments don't have any offset to adjust - if (segment->isPassive || !module.getMemory(segment->memory)->is64()) { + if (segment->isPassive() || !module.getMemory(segment->memory)->is64()) { return; } @@ -300,7 +300,7 @@ struct Memory64Lowering : public WalkerPass> { auto& module = *getModule(); // Passive segments don't have any offset to update. - if (segment->table.isNull() || !module.getTable(segment->table)->is64()) { + if (segment->isPassive() || !module.getTable(segment->table)->is64()) { return; } diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index 83fb1b6e494..b43abac2787 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -215,7 +215,7 @@ bool MemoryPacking::canOptimize( // Check if it is ok for us to optimize. Address maxAddress = 0; for (auto& segment : dataSegments) { - if (!segment->isPassive) { + if (segment->isActive()) { auto* c = segment->offset->dynCast(); // If an active segment has a non-constant offset, then what gets written // cannot be known until runtime. That is, the active segments are written @@ -250,7 +250,7 @@ bool MemoryPacking::canOptimize( // TODO: optimize in the trampling case DisjointSpans space; for (auto& segment : dataSegments) { - if (!segment->isPassive) { + if (segment->isActive()) { auto* c = segment->offset->cast(); Address start = c->value.getUnsigned(); DisjointSpans::Span span{start, start + segment->data.size()}; @@ -283,7 +283,7 @@ bool MemoryPacking::canSplit(const std::unique_ptr& segment, for (auto* referrer : referrers) { if (auto* curr = referrer->dynCast()) { - if (segment->isPassive) { + if (segment->isPassive()) { // Do not try to split if there is a nonconstant offset or size if (!curr->offset->is() || !curr->size->is()) { return false; @@ -296,7 +296,7 @@ bool MemoryPacking::canSplit(const std::unique_ptr& segment, } // Active segments can only be split if they have constant offsets - return segment->isPassive || segment->offset->is(); + return segment->isPassive() || segment->offset->is(); } void MemoryPacking::calculateRanges(Module* module, @@ -351,7 +351,7 @@ void MemoryPacking::calculateRanges(Module* module, // entire segment and that all its arguments are constants. These assumptions // are true of all memory.inits generated by the tools. size_t threshold = 0; - if (segment->isPassive) { + if (segment->isPassive()) { // Passive segment metadata size threshold += 2; // Zeroes on the edge do not increase the number of segments or data.drops, @@ -450,7 +450,7 @@ void MemoryPacking::optimizeSegmentOps(Module* module) { void visitMemoryInit(MemoryInit* curr) { Builder builder(*getModule()); auto* segment = getModule()->getDataSegment(curr->segment); - size_t maxRuntimeSize = segment->isPassive ? segment->data.size() : 0; + size_t maxRuntimeSize = segment->isPassive() ? segment->data.size() : 0; bool mustNop = false; bool mustTrap = false; auto* offset = curr->offset->dynCast(); @@ -483,7 +483,7 @@ void MemoryPacking::optimizeSegmentOps(Module* module) { builder.makeDrop(curr->size), builder.makeUnreachable())); needsRefinalizing = true; - } else if (!segment->isPassive) { + } else if (segment->isActive()) { // trap if (dest > memory.size | offset | size) != 0 replaceCurrent(builder.makeIf( builder.makeBinary( @@ -494,7 +494,7 @@ void MemoryPacking::optimizeSegmentOps(Module* module) { } } void visitDataDrop(DataDrop* curr) { - if (!getModule()->getDataSegment(curr->segment)->isPassive) { + if (getModule()->getDataSegment(curr->segment)->isActive()) { ExpressionManipulator::nop(curr); } } @@ -569,7 +569,7 @@ void MemoryPacking::dropUnusedSegments( bool used = false; auto referrersIt = referrers.find(segments[i]->name); bool hasReferrers = referrersIt != referrers.end(); - if (segments[i]->isPassive) { + if (segments[i]->isPassive()) { if (hasReferrers) { for (auto* referrer : referrersIt->second) { if (!referrer->is()) { @@ -623,7 +623,7 @@ void MemoryPacking::createSplitSegments( continue; } Expression* offset = nullptr; - if (!segment->isPassive) { + if (segment->isActive()) { if (auto* c = segment->offset->dynCast()) { if (c->value.type == Type::i32) { offset = addStartAndOffset( @@ -663,7 +663,6 @@ void MemoryPacking::createSplitSegments( } auto curr = Builder::makeDataSegment(name, segment->memory, - segment->isPassive, offset, segment->data.data() + range.start, range.end - range.start); diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp index 12ea129173d..533e5258ba6 100644 --- a/src/passes/PostEmscripten.cpp +++ b/src/passes/PostEmscripten.cpp @@ -107,7 +107,7 @@ static void calcSegmentOffsets(Module& wasm, } for (unsigned i = 0; i < wasm.dataSegments.size(); ++i) { auto& segment = wasm.dataSegments[i]; - if (segment->isPassive) { + if (segment->isPassive()) { auto it = passiveOffsets.find(segment->name); if (it != passiveOffsets.end()) { segmentOffsets.push_back(it->second); diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index d560ca49547..86ce8595683 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -3443,7 +3443,7 @@ void PrintSExpression::visitElementSegment(ElementSegment* curr) { printMedium(o, "elem "); curr->name.print(o); - if (curr->table.is()) { + if (curr->isActive()) { if (usesExpressions || currModule->tables.size() > 1) { // tableuse o << " (table "; @@ -3523,7 +3523,7 @@ void PrintSExpression::visitMemory(Memory* curr) { } void PrintSExpression::visitDataSegment(DataSegment* curr) { - if (!curr->isPassive && !curr->offset) { + if (curr->isActive() && !curr->offset) { // This data segment must have been created from the datacount section but // not parsed yet. Skip it. return; @@ -3533,7 +3533,7 @@ void PrintSExpression::visitDataSegment(DataSegment* curr) { printMajor(o, "data "); curr->name.print(o); o << ' '; - if (!curr->isPassive) { + if (curr->isActive()) { assert(!currModule || currModule->memories.size() > 0); if (!currModule || curr->memory != currModule->memories[0]->name) { o << "(memory "; diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index 22f9b3ff536..fe1c6c91685 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -314,7 +314,7 @@ struct Analyzer { void prepare() { for (auto& elem : module->elementSegments) { - if (!elem->table) { + if (elem->isPassive()) { continue; } auto& flatTableInfo = flatTableInfoMap[elem->table]; @@ -862,7 +862,7 @@ struct RemoveUnusedModuleElements : public Pass { } }; ModuleUtils::iterActiveDataSegments(*module, [&](DataSegment* segment) { - if (segment->memory.is()) { + if (segment->isActive()) { auto* memory = module->getMemory(segment->memory); maybeRootSegment(ModuleElementKind::DataSegment, segment->name, @@ -874,7 +874,7 @@ struct RemoveUnusedModuleElements : public Pass { }); ModuleUtils::iterActiveElementSegments( *module, [&](ElementSegment* segment) { - if (segment->table.is()) { + if (segment->isActive()) { auto* table = module->getTable(segment->table); maybeRootSegment(ModuleElementKind::ElementSegment, segment->name, diff --git a/src/passes/SeparateDataSegments.cpp b/src/passes/SeparateDataSegments.cpp index bd684dbe82c..34a7855f12b 100644 --- a/src/passes/SeparateDataSegments.cpp +++ b/src/passes/SeparateDataSegments.cpp @@ -44,7 +44,7 @@ struct SeparateDataSegments : public Pass { Address base = std::stoi(baseStr); size_t lastEnd = 0; for (auto& seg : module->dataSegments) { - if (seg->isPassive) { + if (seg->isPassive()) { Fatal() << "separating passive segments not implemented"; } if (!seg->offset->is()) { diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index fa5772a221f..457a371a008 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -450,13 +450,13 @@ void TranslateToFuzzReader::setupMemory() { auto segment = builder.makeDataSegment(); segment->setName(Names::getValidDataSegmentName(wasm, Name::fromInt(i)), false); - segment->isPassive = bool(upTo(2)); + bool isPassive = bool(upTo(2)); size_t segSize = upTo(fuzzParams->USABLE_MEMORY * 2); segment->data.resize(segSize); for (size_t j = 0; j < segSize; j++) { segment->data[j] = upTo(512); } - if (!segment->isPassive) { + if (!isPassive) { segment->offset = builder.makeConst( Literal::makeFromInt32(memCovered, memory->addressType)); memCovered += segSize; @@ -643,7 +643,7 @@ void TranslateToFuzzReader::setupTables() { std::any_of(wasm.elementSegments.begin(), wasm.elementSegments.end(), [&](auto& segment) { - return segment->table.is() && segment->type == funcref; + return segment->isActive() && segment->type == funcref; }); auto addressType = wasm.getTable(funcrefTableName)->addressType; if (!hasFuncrefElemSegment) { @@ -869,7 +869,7 @@ void TranslateToFuzzReader::finalizeMemory() { auto& memory = wasm.memories[0]; for (auto& segment : wasm.dataSegments) { Address maxOffset = segment->data.size(); - if (!segment->isPassive) { + if (segment->isActive()) { if (!wasm.features.hasGC()) { // Using a non-imported global in a segment offset is not valid in wasm // unless GC is enabled. This can occur due to us adding a local diff --git a/src/wasm-builder.h b/src/wasm-builder.h index 1c8894c4094..0bf270ab8ef 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -151,15 +151,13 @@ class Builder { static std::unique_ptr makeDataSegment(Name name = "", - Name memory = "", - bool isPassive = false, + Name memory = Name(), Expression* offset = nullptr, const char* init = "", Address size = 0) { auto seg = std::make_unique(); seg->name = name; seg->memory = memory; - seg->isPassive = isPassive; seg->offset = offset; seg->data.resize(size); std::copy_n(init, size, seg->data.begin()); diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 0c4e9f02b77..dd8a68866f9 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3848,7 +3848,7 @@ class ModuleRunnerBase : public ExpressionRunner { // apply active memory segments for (size_t i = 0, e = wasm.dataSegments.size(); i < e; ++i) { auto& segment = wasm.dataSegments[i]; - if (segment->isPassive) { + if (segment->isPassive()) { continue; } diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 9717c053d8c..550a9306b0e 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -172,7 +172,7 @@ struct Walker : public VisitorType { void doWalkFunction(Function* func) { walk(func->body); } void walkElementSegment(ElementSegment* segment) { - if (segment->table.is()) { + if (segment->isActive()) { walk(segment->offset); } for (auto* expr : segment->data) { @@ -189,7 +189,7 @@ struct Walker : public VisitorType { } void walkDataSegment(DataSegment* segment) { - if (!segment->isPassive) { + if (segment->isActive()) { walk(segment->offset); } static_cast(this)->visitDataSegment(segment); diff --git a/src/wasm.h b/src/wasm.h index 40cdf896c19..9f81336144d 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -2571,6 +2571,9 @@ class ElementSegment : public Named { Type type = Type(HeapType::func, Nullable); std::vector data; + bool isActive() const { return bool(table); } + bool isPassive() const { return !table; } + ElementSegment() = default; ElementSegment(Name table, Expression* offset, @@ -2610,9 +2613,11 @@ class Table : public Importable { class DataSegment : public Named { public: Name memory; - bool isPassive = false; Expression* offset = nullptr; std::vector data; // TODO: optimize + + bool isActive() const { return bool(memory); } + bool isPassive() const { return !memory; } }; class Memory : public Importable { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 2adb6ba83d4..49497af127a 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -689,7 +689,7 @@ void WasmBinaryWriter::writeDataSegments() { for (auto& segment : wasm->dataSegments) { uint32_t flags = 0; Index memoryIndex = 0; - if (segment->isPassive) { + if (segment->isPassive()) { flags |= BinaryConsts::IsPassive; } else { memoryIndex = getMemoryIndex(segment->memory); @@ -698,7 +698,7 @@ void WasmBinaryWriter::writeDataSegments() { } } o << U32LEB(flags); - if (!segment->isPassive) { + if (segment->isActive()) { if (memoryIndex) { o << U32LEB(memoryIndex); } @@ -825,7 +825,6 @@ void WasmBinaryWriter::writeElementSegments() { for (auto& segment : wasm->elementSegments) { Index tableIdx = 0; - bool isPassive = segment->table.isNull(); // If the segment is MVP, we can use the shorter form. bool usesExpressions = TableUtils::usesExpressions(segment.get(), wasm); @@ -834,7 +833,7 @@ void WasmBinaryWriter::writeElementSegments() { // supported by the MVP, which also did not support table indices in the // segment encoding. bool hasTableIndex = false; - if (!isPassive) { + if (segment->isActive()) { tableIdx = getTableIndex(segment->table); hasTableIndex = tableIdx > 0 || wasm->getTable(segment->table)->type != funcref; @@ -844,14 +843,14 @@ void WasmBinaryWriter::writeElementSegments() { if (usesExpressions) { flags |= BinaryConsts::UsesExpressions; } - if (isPassive) { + if (segment->isPassive()) { flags |= BinaryConsts::IsPassive; } else if (hasTableIndex) { flags |= BinaryConsts::HasIndex; } o << U32LEB(flags); - if (!isPassive) { + if (segment->isActive()) { if (hasTableIndex) { o << U32LEB(tableIdx); } @@ -859,7 +858,7 @@ void WasmBinaryWriter::writeElementSegments() { o << int8_t(BinaryConsts::End); } - if (isPassive || hasTableIndex) { + if (segment->isPassive() || hasTableIndex) { if (usesExpressions) { // elemType writeType(segment->type); @@ -5023,8 +5022,7 @@ void WasmBinaryReader::readDataSegments() { throwError("bad segment flags, must be 0, 1, or 2, not " + std::to_string(flags)); } - curr->isPassive = flags & BinaryConsts::IsPassive; - if (curr->isPassive) { + if (flags & BinaryConsts::IsPassive) { curr->memory = Name(); curr->offset = nullptr; } else { diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index ebc2df9bc2c..8c2c272c8b9 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -140,7 +140,7 @@ class StringConstantTracker { } for (unsigned i = 0; i < wasm.dataSegments.size(); ++i) { auto& segment = wasm.dataSegments[i]; - if (segment->isPassive) { + if (segment->isPassive()) { auto it = passiveOffsets.find(segment->name); if (it != passiveOffsets.end()) { segmentOffsets.push_back(it->second); diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index a8c9f40e188..8a5a63ca0af 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -5146,7 +5146,7 @@ void validateMemories(Module& module, ValidationInfo& info) { void validateDataSegments(Module& module, ValidationInfo& info) { for (auto& segment : module.dataSegments) { - if (segment->isPassive) { + if (segment->isPassive()) { info.shouldBeTrue( module.features.hasBulkMemory(), segment->offset, @@ -5274,8 +5274,7 @@ void validateTables(Module& module, ValidationInfo& info) { << getMissingFeaturesList(module, typeFeats) << '\n'; } - bool isPassive = !segment->table.is(); - if (isPassive) { + if (segment->isPassive()) { info.shouldBeTrue( !segment->offset, "elem", "passive segment should not have an offset"); } else { diff --git a/src/wasm2js.h b/src/wasm2js.h index 5eb937b0f88..c5bfe650ecc 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -97,7 +97,7 @@ bool isTableExported(Module& wasm) { bool hasActiveSegments(Module& wasm) { for (Index i = 0; i < wasm.dataSegments.size(); i++) { - if (!wasm.dataSegments[i]->isPassive) { + if (wasm.dataSegments[i]->isActive()) { return true; } } @@ -2870,7 +2870,7 @@ void Wasm2JSGlue::emitMemory() { // If we have passive memory segments, we need to store those. for (auto& seg : wasm.dataSegments) { - if (seg->isPassive) { + if (seg->isPassive()) { out << " var memorySegments = {};\n"; break; } @@ -2907,7 +2907,7 @@ void Wasm2JSGlue::emitMemory() { for (Index i = 0; i < wasm.dataSegments.size(); i++) { auto& seg = wasm.dataSegments[i]; - if (seg->isPassive) { + if (seg->isPassive()) { // Fancy passive segments are decoded into typed arrays on the side, for // later copying. out << "memorySegments[" << i @@ -2934,7 +2934,7 @@ void Wasm2JSGlue::emitMemory() { out << "function initActiveSegments(imports) {\n"; for (Index i = 0; i < wasm.dataSegments.size(); i++) { auto& seg = wasm.dataSegments[i]; - if (!seg->isPassive) { + if (seg->isActive()) { // Plain active segments are decoded directly into the main memory. out << " base64DecodeToExistingUint8Array(bufferView, " << globalOffset(*seg) << ", \"" << base64Encode(seg->data)