diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2019-02-05 12:35:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-05 12:35:09 -0800 |
commit | f424f81886405fc26a415fc86900c0f8d0df14eb (patch) | |
tree | 5896c316f216fca9654f55e41809839d181ca53b /src/wasm/wasm-validator.cpp | |
parent | 484f62f985cb2180139d1cf991ac04ee41635417 (diff) | |
download | binaryen-f424f81886405fc26a415fc86900c0f8d0df14eb.tar.gz binaryen-f424f81886405fc26a415fc86900c0f8d0df14eb.tar.bz2 binaryen-f424f81886405fc26a415fc86900c0f8d0df14eb.zip |
Bulk memory operations (#1892)
Bulk memory operations
The only parts missing are the interpreter implementation
and spec tests.
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; |