diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 25 |
4 files changed, 37 insertions, 18 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 0f5a03117..ebc5888a0 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1354,7 +1354,7 @@ WasmBinaryBuilder::getByteView(size_t size) { throwError("unexpected end of input"); } pos += size; - return {&input[pos - size], &input[pos]}; + return {input.data() + (pos - size), input.data() + pos}; } uint8_t WasmBinaryBuilder::getInt8() { diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 50b4e9b8f..339214f43 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -168,7 +168,7 @@ private: segmentOffsets.push_back(UNKNOWN_OFFSET); } } else if (auto* addrConst = segment.offset->dynCast<Const>()) { - auto address = addrConst->value.geti32(); + auto address = addrConst->value.getUnsigned(); segmentOffsets.push_back(address); } else { // TODO(sbc): Wasm shared libraries have data segments with non-const @@ -285,7 +285,7 @@ void AsmConstWalker::visitCall(Call* curr) { } auto* value = arg->cast<Const>(); - Address address = value->value.getInteger(); + Address address = value->value.getUnsigned(); asmConsts.push_back({address, stringTracker.stringAtAddr(address)}); } @@ -341,7 +341,7 @@ static void removeSegment(Module& wasm, Index segment) { static Address getExportedAddress(Module& wasm, Export* export_) { Global* g = wasm.getGlobal(export_->value); auto* addrConst = g->init->dynCast<Const>(); - return addrConst->value.getInteger(); + return addrConst->value.getUnsigned(); } static std::vector<AsmConst> findEmAsmConsts(Module& wasm, @@ -413,11 +413,11 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { return; } - int64_t address; + Address address; if (curr->kind == ExternalKind::Global) { auto* global = wasm.getGlobal(curr->value); Const* const_ = global->init->cast<Const>(); - address = const_->value.getInteger(); + address = const_->value.getUnsigned(); } else if (curr->kind == ExternalKind::Function) { auto* func = wasm.getFunction(curr->value); // An EM_JS has a single const in the body. Typically it is just returned, @@ -429,7 +429,7 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { << curr->name; } auto* addrConst = consts.list[0]; - address = addrConst->value.getInteger(); + address = addrConst->value.getUnsigned(); } else { return; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 169470181..339d3a04e 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2615,7 +2615,12 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { } // (memory (data ..)) format auto j = parseMemoryIndex(inner, 1); - auto offset = allocator.alloc<Const>()->set(Literal(int32_t(0))); + auto offset = allocator.alloc<Const>(); + if (wasm.memory.is64()) { + offset->set(Literal(int64_t(0))); + } else { + offset->set(Literal(int32_t(0))); + } parseInnerData(inner, j, {}, offset, false); wasm.memory.initial = wasm.memory.segments[0].data.size(); return; @@ -2641,8 +2646,13 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { } const char* input = curr[j]->c_str(); auto* offset = allocator.alloc<Const>(); - offset->type = Type::i32; - offset->value = Literal(int32_t(offsetValue)); + if (wasm.memory.is64()) { + offset->type = Type::i64; + offset->value = Literal(offsetValue); + } else { + offset->type = Type::i32; + offset->value = Literal(int32_t(offsetValue)); + } if (auto size = strlen(input)) { std::vector<char> data; stringToBinary(input, size, data); diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 6bcdb0e7c..7e9c30c77 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2818,7 +2818,7 @@ static void validateMemory(Module& module, ValidationInfo& info) { "memory is shared, but atomics are disabled"); } for (auto& segment : curr.segments) { - Index size = segment.data.size(); + auto size = segment.data.size(); if (segment.isPassive) { info.shouldBeTrue(module.features.hasBulkMemory(), segment.offset, @@ -2828,11 +2828,20 @@ static void validateMemory(Module& module, ValidationInfo& info) { segment.offset, "passive segment should not have an offset"); } else { - if (!info.shouldBeEqual(segment.offset->type, - Type(Type::i32), - segment.offset, - "segment offset should be i32")) { - continue; + if (curr.is64()) { + if (!info.shouldBeEqual(segment.offset->type, + Type(Type::i64), + segment.offset, + "segment offset should be i64")) { + continue; + } + } else { + if (!info.shouldBeEqual(segment.offset->type, + Type(Type::i32), + segment.offset, + "segment offset should be i32")) { + continue; + } } info.shouldBeTrue(checkSegmentOffset(segment.offset, segment.data.size(), @@ -2840,8 +2849,8 @@ static void validateMemory(Module& module, ValidationInfo& info) { segment.offset, "memory segment offset should be reasonable"); if (segment.offset->is<Const>()) { - Index start = segment.offset->cast<Const>()->value.geti32(); - Index end = start + size; + auto start = segment.offset->cast<Const>()->value.getUnsigned(); + auto end = start + size; info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (end)"); |