diff options
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index f1ccb2cfa..84a0efbff 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -250,6 +250,10 @@ public: void visitSIMDShuffle(SIMDShuffle* curr); void visitSIMDBitselect(SIMDBitselect* curr); void visitSIMDShift(SIMDShift* curr); + void visitMemoryInit(MemoryInit* curr); + void visitDataDrop(DataDrop* curr); + void visitMemoryCopy(MemoryCopy* curr); + void visitMemoryFill(MemoryFill* curr); void visitBinary(Binary* curr); void visitUnary(Unary* curr); void visitSelect(Select* curr); @@ -636,6 +640,37 @@ void FunctionValidator::visitSIMDShift(SIMDShift* curr) { shouldBeEqualOrFirstIsUnreachable(curr->shift->type, i32, curr, "expected shift amount to have type i32"); } +void FunctionValidator::visitMemoryInit(MemoryInit* curr) { + shouldBeTrue(info.features.hasBulkMemory(), curr, "Bulk memory operation (bulk memory is disabled)"); + shouldBeEqualOrFirstIsUnreachable(curr->type, none, curr, "memory.init must have type none"); + shouldBeEqualOrFirstIsUnreachable(curr->dest->type, i32, curr, "memory.init dest must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->offset->type, i32, curr, "memory.init offset must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->size->type, i32, curr, "memory.init size must be an i32"); + shouldBeTrue(curr->segment < getModule()->memory.segments.size(), curr, "memory.init segment index out of bounds"); +} + +void FunctionValidator::visitDataDrop(DataDrop* curr) { + shouldBeTrue(info.features.hasBulkMemory(), curr, "Bulk memory operation (bulk memory is disabled)"); + shouldBeEqualOrFirstIsUnreachable(curr->type, none, curr, "data.drop must have type none"); + shouldBeTrue(curr->segment < getModule()->memory.segments.size(), curr, "data.drop segment index out of bounds"); +} + +void FunctionValidator::visitMemoryCopy(MemoryCopy* curr) { + shouldBeTrue(info.features.hasBulkMemory(), curr, "Bulk memory operation (bulk memory is disabled)"); + shouldBeEqualOrFirstIsUnreachable(curr->type, none, curr, "memory.copy must have type none"); + shouldBeEqualOrFirstIsUnreachable(curr->dest->type, i32, curr, "memory.copy dest must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->source->type, i32, curr, "memory.copy source must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->size->type, i32, curr, "memory.copy size must be an i32"); +} + +void FunctionValidator::visitMemoryFill(MemoryFill* curr) { + shouldBeTrue(info.features.hasBulkMemory(), curr, "Bulk memory operation (bulk memory is disabled)"); + shouldBeEqualOrFirstIsUnreachable(curr->type, none, curr, "memory.fill must have type none"); + shouldBeEqualOrFirstIsUnreachable(curr->dest->type, i32, curr, "memory.fill dest must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->value->type, i32, curr, "memory.fill value must be an i32"); + shouldBeEqualOrFirstIsUnreachable(curr->size->type, i32, curr, "memory.fill size must be an i32"); +} + void FunctionValidator::validateMemBytes(uint8_t bytes, Type type, Expression* curr) { switch (type) { case i32: shouldBeTrue(bytes == 1 || bytes == 2 || bytes == 4, curr, "expected i32 operation to touch 1, 2, or 4 bytes"); break; |