haikuwebkit/JSTests/wasm/function-tests/i32-load.js

36 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

Relocate wasm tests and actually add them to the test runner https://bugs.webkit.org/show_bug.cgi?id=164668 Reviewed by Yusuke Suzuki. This moves the Wasm tests from their current location down a level. Without relocating, the tests cannot properly be run by the wasm test runner. * wasm.yaml: * wasm/Builder.js: Fix typos, yay lazy synatx checking! * wasm/LowLevelBinary.js: Fix typos, yay lazy synatx checking! (export.default.LowLevelBinary.prototype.get return): * wasm/function-tests/add-12.js: Renamed from JSTests/wasm/js-api/function-tests/add-12.js. * wasm/function-tests/br-if-loop-less-than.js: Renamed from JSTests/wasm/js-api/function-tests/br-if-loop-less-than.js. * wasm/function-tests/brTableAsIf.js: Renamed from JSTests/wasm/js-api/function-tests/brTableAsIf.js. * wasm/function-tests/brTableManyValues.js: Renamed from JSTests/wasm/js-api/function-tests/brTableManyValues.js. * wasm/function-tests/brTableWithLoop.js: Renamed from JSTests/wasm/js-api/function-tests/brTableWithLoop.js. * wasm/function-tests/dumb-eq-if-then-else.js: Renamed from JSTests/wasm/js-api/function-tests/dumb-eq-if-then-else.js. * wasm/function-tests/dumb-less-than-fallthrough.js: Renamed from JSTests/wasm/js-api/function-tests/dumb-less-than-fallthrough.js. * wasm/function-tests/dumb-less-than-ite.js: Renamed from JSTests/wasm/js-api/function-tests/dumb-less-than-ite.js. * wasm/function-tests/factorial.js: Renamed from JSTests/wasm/js-api/function-tests/factorial.js. * wasm/function-tests/float-sub.js: Renamed from JSTests/wasm/js-api/function-tests/float-sub.js. * wasm/function-tests/i32-load.js: Renamed from JSTests/wasm/js-api/function-tests/i32-load.js. * wasm/function-tests/i32-load8-s.js: Renamed from JSTests/wasm/js-api/function-tests/i32-load8-s.js. * wasm/function-tests/if-then-else-fallthrough.js: Renamed from JSTests/wasm/js-api/function-tests/if-then-else-fallthrough.js. * wasm/function-tests/if-then-fallthrough.js: Renamed from JSTests/wasm/js-api/function-tests/if-then-fallthrough.js. * wasm/function-tests/loop-mult.js: Renamed from JSTests/wasm/js-api/function-tests/loop-mult.js. * wasm/function-tests/loop-sum.js: Renamed from JSTests/wasm/js-api/function-tests/loop-sum.js. * wasm/function-tests/ret5.js: Renamed from JSTests/wasm/js-api/function-tests/ret5.js. * wasm/self-test/test_BuilderJSON.js: Rebasline Canonical link: https://commits.webkit.org/182353@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208634 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 02:25:48 +00:00
import Builder from '../Builder.js'
WebAssembly: Implement grow_memory and current_memory https://bugs.webkit.org/show_bug.cgi?id=166448 <rdar://problem/29803676> Reviewed by Keith Miller. JSTests: I rewrote some of the testWasmModuleFunctions that used Memory to use the JS API since the jsc.cpp version can no longer use memory. * wasm.yaml: * wasm/function-tests/add-12.js: (testWasmModuleFunctions): * wasm/function-tests/br-if-loop-less-than.js: (testWasmModuleFunctions): * wasm/function-tests/brTableAsIf.js: (testWasmModuleFunctions): * wasm/function-tests/brTableManyValues.js: (testWasmModuleFunctions): * wasm/function-tests/brTableWithLoop.js: (testWasmModuleFunctions): * wasm/function-tests/dumb-eq-if-then-else.js: * wasm/function-tests/eqz.js: * wasm/function-tests/grow-memory-2.js: Added. (const.func): (assert.eq.instance.exports.foo): * wasm/function-tests/grow-memory-3.js: Added. * wasm/function-tests/grow-memory-4.js: Added. (const.func): * wasm/function-tests/grow-memory.js: Added. (binaryShouldNotParse): (assert.truthy): (assert.eq): (memory.grow): * wasm/function-tests/i32-load.js: (testWasmModuleFunctions): * wasm/function-tests/i32-load8-s.js: * wasm/function-tests/max.js: * wasm/function-tests/min.js: * wasm/js-api/memory-grow.js: Added. (i.i): (assertEq): * wasm/js-api/test_memory.js: * wasm/wasm.json: Source/JavaScriptCore: This patch implements grow_memory, current_memory, and WebAssembly.prototype.grow. See relevant spec texts here: https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory-accesses https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow I also fix a couple miscellaneous bugs: 1. Data section now understands full init_exprs. 2. parseVarUint1 no longer has a bug where we allow values larger than 1 if their bottom 8 bits are zero. Since the JS API can now grow memory, we need to make calling an import and call_indirect refresh the base memory register and the size registers. * jsc.cpp: (functionTestWasmModuleFunctions): * runtime/Options.h: * runtime/VM.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::reloadPinnedRegisters): (JSC::Wasm::B3IRGenerator::emitReloadPinnedRegisters): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::I32InitExpr::I32InitExpr): (JSC::Wasm::I32InitExpr::globalImport): (JSC::Wasm::I32InitExpr::constValue): (JSC::Wasm::I32InitExpr::isConst): (JSC::Wasm::I32InitExpr::isGlobalImport): (JSC::Wasm::I32InitExpr::globalImportIndex): (JSC::Wasm::Segment::byte): (JSC::Wasm::ModuleInformation::importFunctionCount): (JSC::Wasm::ModuleInformation::hasMemory): * wasm/WasmFunctionParser.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::size): (JSC::Wasm::Memory::sizeInPages): (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::isValid): Deleted. (JSC::Wasm::Memory::grow): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::makeI32InitExpr): * wasm/WasmModuleParser.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::bytes): (JSC::Wasm::PageCount::pageCount): (JSC::Wasm::PageCount::fromBytes): (JSC::Wasm::PageCount::operator+): * wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseVarUInt1): * wasm/WasmValidate.cpp: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfMemory): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::~JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::offsetOfMemory): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::functionImportCount): (JSC::JSWebAssemblyModule::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::importCount): Deleted. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::getMemory): (JSC::webAssemblyMemoryProtoFuncBuffer): (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::dataSegmentFail): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/183764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210201 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-29 00:06:52 +00:00
import * as assert from '../assert.js'
Move Wasm tests to JS https://bugs.webkit.org/show_bug.cgi?id=164611 Reviewed by Geoffrey Garen. This patch translates most of the tests from testWasm.cpp to the JS testing api. Most of the ommited tests were earliest tests, which tested trivial things, like adding two constants. Some tests are ommited for other reasons, however. These are: 1) Tests using I64 since the testing api does not yet know how to handle 64-bit numbers. 2) Tests that would validate the memory of the module once wasm was done with it since that's not really possible in JS. In order to make such a translation easier this patch also adds some features to the JS testing api: 1) Blocks can now be done lexically by adding a lambda as the last argument of the block opcode. For example one can do: ... .Block("i32", b => b.I32Const(1) ) and the nested lambda will automatically have an end attached. 2) The JS testing api can now handle inline signature types. 3) Relocate some code to make it easier to follow and prevent 44 space indentation. 4) Rename varuint/varint to varuint32/varint32, this lets them be directly called from the wasm.json without being remapped. 5) Add support for Memory and Function sections to the Builder. 6) Add support for local variables. On the JSC side, we needed to expose a new function to validate the compiled wasm code behaves the way we expect. At least until the JS Wasm API is finished. The new validation function, testWasmModuleFunctions, takes an array buffer containing the wasm binary, the number of functions in the blob and tests for each of those functions. JSTests: * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/test_old_tests.js: Added. (ret5): (brTableWithLoop): (brTableManyValues): (run.brTableManyValues.brTableAsIf): (ifThenFallthrough): (ifThenElseFallthrough): (dumbLessThanFallthrough): (run.dumbLessThanFallthrough.floatSub): (run.floatSub.add12): (run.add12.factorial): (i32load): (run.i32load.i32load8s): (run.i32load8s.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbLessThanIfThenElse): (run.dumbLessThanIfThenElse.loopSum): (run.loopSum.loopMult): (brIfLoopLessThan): (run.brIfLoopLessThan.run): * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/function-tests/add-12.js: Added. * wasm/js-api/function-tests/br-if-loop-less-than.js: Added. * wasm/js-api/function-tests/brTableAsIf.js: Added. * wasm/js-api/function-tests/brTableManyValues.js: Added. * wasm/js-api/function-tests/brTableWithLoop.js: Added. * wasm/js-api/function-tests/dumb-eq-if-then-else.js: Added. * wasm/js-api/function-tests/dumb-less-than-fallthrough.js: Added. * wasm/js-api/function-tests/dumb-less-than-ite.js: Added. * wasm/js-api/function-tests/factorial.js: Added. * wasm/js-api/function-tests/float-sub.js: Added. * wasm/js-api/function-tests/i32-load.js: Added. * wasm/js-api/function-tests/i32-load8-s.js: Added. * wasm/js-api/function-tests/if-then-else-fallthrough.js: Added. * wasm/js-api/function-tests/if-then-fallthrough.js: Added. * wasm/js-api/function-tests/loop-mult.js: Added. * wasm/js-api/function-tests/loop-sum.js: Added. * wasm/js-api/function-tests/ret5.js: Added. * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. Source/JavaScriptCore: * jsc.cpp: (GlobalObject::finishCreation): (box): (callWasmFunction): (functionTestWasmModuleFunctions): * testWasm.cpp: (checkPlan): (runWasmTests): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parse): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseBlock): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseMemory): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): Canonical link: https://commits.webkit.org/182347@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 00:29:36 +00:00
const b = new Builder();
b.Type().End()
.Function().End()
.Memory().InitialMaxPages(1, 1).End()
WebAssembly: Implement grow_memory and current_memory https://bugs.webkit.org/show_bug.cgi?id=166448 <rdar://problem/29803676> Reviewed by Keith Miller. JSTests: I rewrote some of the testWasmModuleFunctions that used Memory to use the JS API since the jsc.cpp version can no longer use memory. * wasm.yaml: * wasm/function-tests/add-12.js: (testWasmModuleFunctions): * wasm/function-tests/br-if-loop-less-than.js: (testWasmModuleFunctions): * wasm/function-tests/brTableAsIf.js: (testWasmModuleFunctions): * wasm/function-tests/brTableManyValues.js: (testWasmModuleFunctions): * wasm/function-tests/brTableWithLoop.js: (testWasmModuleFunctions): * wasm/function-tests/dumb-eq-if-then-else.js: * wasm/function-tests/eqz.js: * wasm/function-tests/grow-memory-2.js: Added. (const.func): (assert.eq.instance.exports.foo): * wasm/function-tests/grow-memory-3.js: Added. * wasm/function-tests/grow-memory-4.js: Added. (const.func): * wasm/function-tests/grow-memory.js: Added. (binaryShouldNotParse): (assert.truthy): (assert.eq): (memory.grow): * wasm/function-tests/i32-load.js: (testWasmModuleFunctions): * wasm/function-tests/i32-load8-s.js: * wasm/function-tests/max.js: * wasm/function-tests/min.js: * wasm/js-api/memory-grow.js: Added. (i.i): (assertEq): * wasm/js-api/test_memory.js: * wasm/wasm.json: Source/JavaScriptCore: This patch implements grow_memory, current_memory, and WebAssembly.prototype.grow. See relevant spec texts here: https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory-accesses https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow I also fix a couple miscellaneous bugs: 1. Data section now understands full init_exprs. 2. parseVarUint1 no longer has a bug where we allow values larger than 1 if their bottom 8 bits are zero. Since the JS API can now grow memory, we need to make calling an import and call_indirect refresh the base memory register and the size registers. * jsc.cpp: (functionTestWasmModuleFunctions): * runtime/Options.h: * runtime/VM.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::reloadPinnedRegisters): (JSC::Wasm::B3IRGenerator::emitReloadPinnedRegisters): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::I32InitExpr::I32InitExpr): (JSC::Wasm::I32InitExpr::globalImport): (JSC::Wasm::I32InitExpr::constValue): (JSC::Wasm::I32InitExpr::isConst): (JSC::Wasm::I32InitExpr::isGlobalImport): (JSC::Wasm::I32InitExpr::globalImportIndex): (JSC::Wasm::Segment::byte): (JSC::Wasm::ModuleInformation::importFunctionCount): (JSC::Wasm::ModuleInformation::hasMemory): * wasm/WasmFunctionParser.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::size): (JSC::Wasm::Memory::sizeInPages): (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::isValid): Deleted. (JSC::Wasm::Memory::grow): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::makeI32InitExpr): * wasm/WasmModuleParser.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::bytes): (JSC::Wasm::PageCount::pageCount): (JSC::Wasm::PageCount::fromBytes): (JSC::Wasm::PageCount::operator+): * wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseVarUInt1): * wasm/WasmValidate.cpp: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfMemory): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::~JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::offsetOfMemory): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::functionImportCount): (JSC::JSWebAssemblyModule::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::importCount): Deleted. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::getMemory): (JSC::webAssemblyMemoryProtoFuncBuffer): (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::dataSegmentFail): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/183764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210201 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-29 00:06:52 +00:00
.Export().Function('f0').End()
Move Wasm tests to JS https://bugs.webkit.org/show_bug.cgi?id=164611 Reviewed by Geoffrey Garen. This patch translates most of the tests from testWasm.cpp to the JS testing api. Most of the ommited tests were earliest tests, which tested trivial things, like adding two constants. Some tests are ommited for other reasons, however. These are: 1) Tests using I64 since the testing api does not yet know how to handle 64-bit numbers. 2) Tests that would validate the memory of the module once wasm was done with it since that's not really possible in JS. In order to make such a translation easier this patch also adds some features to the JS testing api: 1) Blocks can now be done lexically by adding a lambda as the last argument of the block opcode. For example one can do: ... .Block("i32", b => b.I32Const(1) ) and the nested lambda will automatically have an end attached. 2) The JS testing api can now handle inline signature types. 3) Relocate some code to make it easier to follow and prevent 44 space indentation. 4) Rename varuint/varint to varuint32/varint32, this lets them be directly called from the wasm.json without being remapped. 5) Add support for Memory and Function sections to the Builder. 6) Add support for local variables. On the JSC side, we needed to expose a new function to validate the compiled wasm code behaves the way we expect. At least until the JS Wasm API is finished. The new validation function, testWasmModuleFunctions, takes an array buffer containing the wasm binary, the number of functions in the blob and tests for each of those functions. JSTests: * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/test_old_tests.js: Added. (ret5): (brTableWithLoop): (brTableManyValues): (run.brTableManyValues.brTableAsIf): (ifThenFallthrough): (ifThenElseFallthrough): (dumbLessThanFallthrough): (run.dumbLessThanFallthrough.floatSub): (run.floatSub.add12): (run.add12.factorial): (i32load): (run.i32load.i32load8s): (run.i32load8s.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbLessThanIfThenElse): (run.dumbLessThanIfThenElse.loopSum): (run.loopSum.loopMult): (brIfLoopLessThan): (run.brIfLoopLessThan.run): * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/function-tests/add-12.js: Added. * wasm/js-api/function-tests/br-if-loop-less-than.js: Added. * wasm/js-api/function-tests/brTableAsIf.js: Added. * wasm/js-api/function-tests/brTableManyValues.js: Added. * wasm/js-api/function-tests/brTableWithLoop.js: Added. * wasm/js-api/function-tests/dumb-eq-if-then-else.js: Added. * wasm/js-api/function-tests/dumb-less-than-fallthrough.js: Added. * wasm/js-api/function-tests/dumb-less-than-ite.js: Added. * wasm/js-api/function-tests/factorial.js: Added. * wasm/js-api/function-tests/float-sub.js: Added. * wasm/js-api/function-tests/i32-load.js: Added. * wasm/js-api/function-tests/i32-load8-s.js: Added. * wasm/js-api/function-tests/if-then-else-fallthrough.js: Added. * wasm/js-api/function-tests/if-then-fallthrough.js: Added. * wasm/js-api/function-tests/loop-mult.js: Added. * wasm/js-api/function-tests/loop-sum.js: Added. * wasm/js-api/function-tests/ret5.js: Added. * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. Source/JavaScriptCore: * jsc.cpp: (GlobalObject::finishCreation): (box): (callWasmFunction): (functionTestWasmModuleFunctions): * testWasm.cpp: (checkPlan): (runWasmTests): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parse): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseBlock): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseMemory): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): Canonical link: https://commits.webkit.org/182347@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 00:29:36 +00:00
.Code()
WebAssembly: Implement grow_memory and current_memory https://bugs.webkit.org/show_bug.cgi?id=166448 <rdar://problem/29803676> Reviewed by Keith Miller. JSTests: I rewrote some of the testWasmModuleFunctions that used Memory to use the JS API since the jsc.cpp version can no longer use memory. * wasm.yaml: * wasm/function-tests/add-12.js: (testWasmModuleFunctions): * wasm/function-tests/br-if-loop-less-than.js: (testWasmModuleFunctions): * wasm/function-tests/brTableAsIf.js: (testWasmModuleFunctions): * wasm/function-tests/brTableManyValues.js: (testWasmModuleFunctions): * wasm/function-tests/brTableWithLoop.js: (testWasmModuleFunctions): * wasm/function-tests/dumb-eq-if-then-else.js: * wasm/function-tests/eqz.js: * wasm/function-tests/grow-memory-2.js: Added. (const.func): (assert.eq.instance.exports.foo): * wasm/function-tests/grow-memory-3.js: Added. * wasm/function-tests/grow-memory-4.js: Added. (const.func): * wasm/function-tests/grow-memory.js: Added. (binaryShouldNotParse): (assert.truthy): (assert.eq): (memory.grow): * wasm/function-tests/i32-load.js: (testWasmModuleFunctions): * wasm/function-tests/i32-load8-s.js: * wasm/function-tests/max.js: * wasm/function-tests/min.js: * wasm/js-api/memory-grow.js: Added. (i.i): (assertEq): * wasm/js-api/test_memory.js: * wasm/wasm.json: Source/JavaScriptCore: This patch implements grow_memory, current_memory, and WebAssembly.prototype.grow. See relevant spec texts here: https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory-accesses https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow I also fix a couple miscellaneous bugs: 1. Data section now understands full init_exprs. 2. parseVarUint1 no longer has a bug where we allow values larger than 1 if their bottom 8 bits are zero. Since the JS API can now grow memory, we need to make calling an import and call_indirect refresh the base memory register and the size registers. * jsc.cpp: (functionTestWasmModuleFunctions): * runtime/Options.h: * runtime/VM.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::reloadPinnedRegisters): (JSC::Wasm::B3IRGenerator::emitReloadPinnedRegisters): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::I32InitExpr::I32InitExpr): (JSC::Wasm::I32InitExpr::globalImport): (JSC::Wasm::I32InitExpr::constValue): (JSC::Wasm::I32InitExpr::isConst): (JSC::Wasm::I32InitExpr::isGlobalImport): (JSC::Wasm::I32InitExpr::globalImportIndex): (JSC::Wasm::Segment::byte): (JSC::Wasm::ModuleInformation::importFunctionCount): (JSC::Wasm::ModuleInformation::hasMemory): * wasm/WasmFunctionParser.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::size): (JSC::Wasm::Memory::sizeInPages): (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::isValid): Deleted. (JSC::Wasm::Memory::grow): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::makeI32InitExpr): * wasm/WasmModuleParser.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::bytes): (JSC::Wasm::PageCount::pageCount): (JSC::Wasm::PageCount::fromBytes): (JSC::Wasm::PageCount::operator+): * wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseVarUInt1): * wasm/WasmValidate.cpp: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfMemory): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::~JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::offsetOfMemory): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::functionImportCount): (JSC::JSWebAssemblyModule::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::importCount): Deleted. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::getMemory): (JSC::webAssemblyMemoryProtoFuncBuffer): (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::dataSegmentFail): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/183764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210201 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-29 00:06:52 +00:00
.Function('f0', { params: ["i32", "i32"], ret: "i32" })
Move Wasm tests to JS https://bugs.webkit.org/show_bug.cgi?id=164611 Reviewed by Geoffrey Garen. This patch translates most of the tests from testWasm.cpp to the JS testing api. Most of the ommited tests were earliest tests, which tested trivial things, like adding two constants. Some tests are ommited for other reasons, however. These are: 1) Tests using I64 since the testing api does not yet know how to handle 64-bit numbers. 2) Tests that would validate the memory of the module once wasm was done with it since that's not really possible in JS. In order to make such a translation easier this patch also adds some features to the JS testing api: 1) Blocks can now be done lexically by adding a lambda as the last argument of the block opcode. For example one can do: ... .Block("i32", b => b.I32Const(1) ) and the nested lambda will automatically have an end attached. 2) The JS testing api can now handle inline signature types. 3) Relocate some code to make it easier to follow and prevent 44 space indentation. 4) Rename varuint/varint to varuint32/varint32, this lets them be directly called from the wasm.json without being remapped. 5) Add support for Memory and Function sections to the Builder. 6) Add support for local variables. On the JSC side, we needed to expose a new function to validate the compiled wasm code behaves the way we expect. At least until the JS Wasm API is finished. The new validation function, testWasmModuleFunctions, takes an array buffer containing the wasm binary, the number of functions in the blob and tests for each of those functions. JSTests: * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/test_old_tests.js: Added. (ret5): (brTableWithLoop): (brTableManyValues): (run.brTableManyValues.brTableAsIf): (ifThenFallthrough): (ifThenElseFallthrough): (dumbLessThanFallthrough): (run.dumbLessThanFallthrough.floatSub): (run.floatSub.add12): (run.add12.factorial): (i32load): (run.i32load.i32load8s): (run.i32load8s.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbLessThanIfThenElse): (run.dumbLessThanIfThenElse.loopSum): (run.loopSum.loopMult): (brIfLoopLessThan): (run.brIfLoopLessThan.run): * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/function-tests/add-12.js: Added. * wasm/js-api/function-tests/br-if-loop-less-than.js: Added. * wasm/js-api/function-tests/brTableAsIf.js: Added. * wasm/js-api/function-tests/brTableManyValues.js: Added. * wasm/js-api/function-tests/brTableWithLoop.js: Added. * wasm/js-api/function-tests/dumb-eq-if-then-else.js: Added. * wasm/js-api/function-tests/dumb-less-than-fallthrough.js: Added. * wasm/js-api/function-tests/dumb-less-than-ite.js: Added. * wasm/js-api/function-tests/factorial.js: Added. * wasm/js-api/function-tests/float-sub.js: Added. * wasm/js-api/function-tests/i32-load.js: Added. * wasm/js-api/function-tests/i32-load8-s.js: Added. * wasm/js-api/function-tests/if-then-else-fallthrough.js: Added. * wasm/js-api/function-tests/if-then-fallthrough.js: Added. * wasm/js-api/function-tests/loop-mult.js: Added. * wasm/js-api/function-tests/loop-sum.js: Added. * wasm/js-api/function-tests/ret5.js: Added. * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. Source/JavaScriptCore: * jsc.cpp: (GlobalObject::finishCreation): (box): (callWasmFunction): (functionTestWasmModuleFunctions): * testWasm.cpp: (checkPlan): (runWasmTests): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parse): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseBlock): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseMemory): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): Canonical link: https://commits.webkit.org/182347@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 00:29:36 +00:00
.GetLocal(1)
.GetLocal(0)
.I32Store(2, 0)
.GetLocal(1)
.I32Load(2, 0)
.Return()
.End()
WebAssembly: Implement grow_memory and current_memory https://bugs.webkit.org/show_bug.cgi?id=166448 <rdar://problem/29803676> Reviewed by Keith Miller. JSTests: I rewrote some of the testWasmModuleFunctions that used Memory to use the JS API since the jsc.cpp version can no longer use memory. * wasm.yaml: * wasm/function-tests/add-12.js: (testWasmModuleFunctions): * wasm/function-tests/br-if-loop-less-than.js: (testWasmModuleFunctions): * wasm/function-tests/brTableAsIf.js: (testWasmModuleFunctions): * wasm/function-tests/brTableManyValues.js: (testWasmModuleFunctions): * wasm/function-tests/brTableWithLoop.js: (testWasmModuleFunctions): * wasm/function-tests/dumb-eq-if-then-else.js: * wasm/function-tests/eqz.js: * wasm/function-tests/grow-memory-2.js: Added. (const.func): (assert.eq.instance.exports.foo): * wasm/function-tests/grow-memory-3.js: Added. * wasm/function-tests/grow-memory-4.js: Added. (const.func): * wasm/function-tests/grow-memory.js: Added. (binaryShouldNotParse): (assert.truthy): (assert.eq): (memory.grow): * wasm/function-tests/i32-load.js: (testWasmModuleFunctions): * wasm/function-tests/i32-load8-s.js: * wasm/function-tests/max.js: * wasm/function-tests/min.js: * wasm/js-api/memory-grow.js: Added. (i.i): (assertEq): * wasm/js-api/test_memory.js: * wasm/wasm.json: Source/JavaScriptCore: This patch implements grow_memory, current_memory, and WebAssembly.prototype.grow. See relevant spec texts here: https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory-accesses https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow I also fix a couple miscellaneous bugs: 1. Data section now understands full init_exprs. 2. parseVarUint1 no longer has a bug where we allow values larger than 1 if their bottom 8 bits are zero. Since the JS API can now grow memory, we need to make calling an import and call_indirect refresh the base memory register and the size registers. * jsc.cpp: (functionTestWasmModuleFunctions): * runtime/Options.h: * runtime/VM.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::reloadPinnedRegisters): (JSC::Wasm::B3IRGenerator::emitReloadPinnedRegisters): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::I32InitExpr::I32InitExpr): (JSC::Wasm::I32InitExpr::globalImport): (JSC::Wasm::I32InitExpr::constValue): (JSC::Wasm::I32InitExpr::isConst): (JSC::Wasm::I32InitExpr::isGlobalImport): (JSC::Wasm::I32InitExpr::globalImportIndex): (JSC::Wasm::Segment::byte): (JSC::Wasm::ModuleInformation::importFunctionCount): (JSC::Wasm::ModuleInformation::hasMemory): * wasm/WasmFunctionParser.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::size): (JSC::Wasm::Memory::sizeInPages): (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::isValid): Deleted. (JSC::Wasm::Memory::grow): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::makeI32InitExpr): * wasm/WasmModuleParser.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::bytes): (JSC::Wasm::PageCount::pageCount): (JSC::Wasm::PageCount::fromBytes): (JSC::Wasm::PageCount::operator+): * wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseVarUInt1): * wasm/WasmValidate.cpp: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfMemory): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::~JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::offsetOfMemory): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::functionImportCount): (JSC::JSWebAssemblyModule::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::importCount): Deleted. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::getMemory): (JSC::webAssemblyMemoryProtoFuncBuffer): (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::dataSegmentFail): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/183764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210201 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-29 00:06:52 +00:00
.End();
Move Wasm tests to JS https://bugs.webkit.org/show_bug.cgi?id=164611 Reviewed by Geoffrey Garen. This patch translates most of the tests from testWasm.cpp to the JS testing api. Most of the ommited tests were earliest tests, which tested trivial things, like adding two constants. Some tests are ommited for other reasons, however. These are: 1) Tests using I64 since the testing api does not yet know how to handle 64-bit numbers. 2) Tests that would validate the memory of the module once wasm was done with it since that's not really possible in JS. In order to make such a translation easier this patch also adds some features to the JS testing api: 1) Blocks can now be done lexically by adding a lambda as the last argument of the block opcode. For example one can do: ... .Block("i32", b => b.I32Const(1) ) and the nested lambda will automatically have an end attached. 2) The JS testing api can now handle inline signature types. 3) Relocate some code to make it easier to follow and prevent 44 space indentation. 4) Rename varuint/varint to varuint32/varint32, this lets them be directly called from the wasm.json without being remapped. 5) Add support for Memory and Function sections to the Builder. 6) Add support for local variables. On the JSC side, we needed to expose a new function to validate the compiled wasm code behaves the way we expect. At least until the JS Wasm API is finished. The new validation function, testWasmModuleFunctions, takes an array buffer containing the wasm binary, the number of functions in the blob and tests for each of those functions. JSTests: * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/test_old_tests.js: Added. (ret5): (brTableWithLoop): (brTableManyValues): (run.brTableManyValues.brTableAsIf): (ifThenFallthrough): (ifThenElseFallthrough): (dumbLessThanFallthrough): (run.dumbLessThanFallthrough.floatSub): (run.floatSub.add12): (run.add12.factorial): (i32load): (run.i32load.i32load8s): (run.i32load8s.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbLessThanIfThenElse): (run.dumbLessThanIfThenElse.loopSum): (run.loopSum.loopMult): (brIfLoopLessThan): (run.brIfLoopLessThan.run): * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/function-tests/add-12.js: Added. * wasm/js-api/function-tests/br-if-loop-less-than.js: Added. * wasm/js-api/function-tests/brTableAsIf.js: Added. * wasm/js-api/function-tests/brTableManyValues.js: Added. * wasm/js-api/function-tests/brTableWithLoop.js: Added. * wasm/js-api/function-tests/dumb-eq-if-then-else.js: Added. * wasm/js-api/function-tests/dumb-less-than-fallthrough.js: Added. * wasm/js-api/function-tests/dumb-less-than-ite.js: Added. * wasm/js-api/function-tests/factorial.js: Added. * wasm/js-api/function-tests/float-sub.js: Added. * wasm/js-api/function-tests/i32-load.js: Added. * wasm/js-api/function-tests/i32-load8-s.js: Added. * wasm/js-api/function-tests/if-then-else-fallthrough.js: Added. * wasm/js-api/function-tests/if-then-fallthrough.js: Added. * wasm/js-api/function-tests/loop-mult.js: Added. * wasm/js-api/function-tests/loop-sum.js: Added. * wasm/js-api/function-tests/ret5.js: Added. * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. Source/JavaScriptCore: * jsc.cpp: (GlobalObject::finishCreation): (box): (callWasmFunction): (functionTestWasmModuleFunctions): * testWasm.cpp: (checkPlan): (runWasmTests): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parse): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseBlock): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseMemory): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): Canonical link: https://commits.webkit.org/182347@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 00:29:36 +00:00
WebAssembly: Implement grow_memory and current_memory https://bugs.webkit.org/show_bug.cgi?id=166448 <rdar://problem/29803676> Reviewed by Keith Miller. JSTests: I rewrote some of the testWasmModuleFunctions that used Memory to use the JS API since the jsc.cpp version can no longer use memory. * wasm.yaml: * wasm/function-tests/add-12.js: (testWasmModuleFunctions): * wasm/function-tests/br-if-loop-less-than.js: (testWasmModuleFunctions): * wasm/function-tests/brTableAsIf.js: (testWasmModuleFunctions): * wasm/function-tests/brTableManyValues.js: (testWasmModuleFunctions): * wasm/function-tests/brTableWithLoop.js: (testWasmModuleFunctions): * wasm/function-tests/dumb-eq-if-then-else.js: * wasm/function-tests/eqz.js: * wasm/function-tests/grow-memory-2.js: Added. (const.func): (assert.eq.instance.exports.foo): * wasm/function-tests/grow-memory-3.js: Added. * wasm/function-tests/grow-memory-4.js: Added. (const.func): * wasm/function-tests/grow-memory.js: Added. (binaryShouldNotParse): (assert.truthy): (assert.eq): (memory.grow): * wasm/function-tests/i32-load.js: (testWasmModuleFunctions): * wasm/function-tests/i32-load8-s.js: * wasm/function-tests/max.js: * wasm/function-tests/min.js: * wasm/js-api/memory-grow.js: Added. (i.i): (assertEq): * wasm/js-api/test_memory.js: * wasm/wasm.json: Source/JavaScriptCore: This patch implements grow_memory, current_memory, and WebAssembly.prototype.grow. See relevant spec texts here: https://github.com/WebAssembly/design/blob/master/Semantics.md#linear-memory-accesses https://github.com/WebAssembly/design/blob/master/JS.md#webassemblymemoryprototypegrow I also fix a couple miscellaneous bugs: 1. Data section now understands full init_exprs. 2. parseVarUint1 no longer has a bug where we allow values larger than 1 if their bottom 8 bits are zero. Since the JS API can now grow memory, we need to make calling an import and call_indirect refresh the base memory register and the size registers. * jsc.cpp: (functionTestWasmModuleFunctions): * runtime/Options.h: * runtime/VM.h: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::reloadPinnedRegisters): (JSC::Wasm::B3IRGenerator::emitReloadPinnedRegisters): (JSC::Wasm::createJSToWasmWrapper): (JSC::Wasm::parseAndCompile): * wasm/WasmFormat.cpp: (JSC::Wasm::Segment::create): * wasm/WasmFormat.h: (JSC::Wasm::I32InitExpr::I32InitExpr): (JSC::Wasm::I32InitExpr::globalImport): (JSC::Wasm::I32InitExpr::constValue): (JSC::Wasm::I32InitExpr::isConst): (JSC::Wasm::I32InitExpr::isGlobalImport): (JSC::Wasm::I32InitExpr::globalImportIndex): (JSC::Wasm::Segment::byte): (JSC::Wasm::ModuleInformation::importFunctionCount): (JSC::Wasm::ModuleInformation::hasMemory): * wasm/WasmFunctionParser.h: * wasm/WasmMemory.cpp: (JSC::Wasm::Memory::Memory): (JSC::Wasm::Memory::grow): * wasm/WasmMemory.h: (JSC::Wasm::Memory::size): (JSC::Wasm::Memory::sizeInPages): (JSC::Wasm::Memory::offsetOfMemory): (JSC::Wasm::Memory::isValid): Deleted. (JSC::Wasm::Memory::grow): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::makeI32InitExpr): * wasm/WasmModuleParser.h: * wasm/WasmPageCount.h: (JSC::Wasm::PageCount::bytes): (JSC::Wasm::PageCount::pageCount): (JSC::Wasm::PageCount::fromBytes): (JSC::Wasm::PageCount::operator+): * wasm/WasmParser.h: (JSC::Wasm::Parser<SuccessType>::parseVarUInt1): * wasm/WasmValidate.cpp: * wasm/js/JSWebAssemblyInstance.h: (JSC::JSWebAssemblyInstance::offsetOfMemory): * wasm/js/JSWebAssemblyMemory.cpp: (JSC::JSWebAssemblyMemory::~JSWebAssemblyMemory): (JSC::JSWebAssemblyMemory::grow): * wasm/js/JSWebAssemblyMemory.h: (JSC::JSWebAssemblyMemory::offsetOfMemory): * wasm/js/JSWebAssemblyModule.h: (JSC::JSWebAssemblyModule::functionImportCount): (JSC::JSWebAssemblyModule::jsEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::wasmEntrypointCalleeFromFunctionIndexSpace): (JSC::JSWebAssemblyModule::importCount): Deleted. * wasm/js/WebAssemblyFunction.cpp: (JSC::callWebAssemblyFunction): * wasm/js/WebAssemblyInstanceConstructor.cpp: (JSC::constructJSWebAssemblyInstance): * wasm/js/WebAssemblyMemoryConstructor.cpp: (JSC::constructJSWebAssemblyMemory): * wasm/js/WebAssemblyMemoryPrototype.cpp: (JSC::getMemory): (JSC::webAssemblyMemoryProtoFuncBuffer): (JSC::webAssemblyMemoryProtoFuncGrow): * wasm/js/WebAssemblyModuleRecord.cpp: (JSC::WebAssemblyModuleRecord::link): (JSC::dataSegmentFail): (JSC::WebAssemblyModuleRecord::evaluate): * wasm/wasm.json: Canonical link: https://commits.webkit.org/183764@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210201 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-12-29 00:06:52 +00:00
const bin = b.WebAssembly().get();
const instance = new WebAssembly.Instance(new WebAssembly.Module(bin));
function testWasmModuleFunctions(...tests) {
for (let i = 0; i < tests.length; i++) {
const func = instance.exports['f' + i];
for (let test of tests[i]) {
let result = test[0].value;
let args = test[1].map(x => x.value);
assert.eq(result, func(...args));
}
}
}
testWasmModuleFunctions([[{type: "i32", value: 0 }, [{ type: "i32", value: 0 }, { type: "i32", value: 10 }]],
Move Wasm tests to JS https://bugs.webkit.org/show_bug.cgi?id=164611 Reviewed by Geoffrey Garen. This patch translates most of the tests from testWasm.cpp to the JS testing api. Most of the ommited tests were earliest tests, which tested trivial things, like adding two constants. Some tests are ommited for other reasons, however. These are: 1) Tests using I64 since the testing api does not yet know how to handle 64-bit numbers. 2) Tests that would validate the memory of the module once wasm was done with it since that's not really possible in JS. In order to make such a translation easier this patch also adds some features to the JS testing api: 1) Blocks can now be done lexically by adding a lambda as the last argument of the block opcode. For example one can do: ... .Block("i32", b => b.I32Const(1) ) and the nested lambda will automatically have an end attached. 2) The JS testing api can now handle inline signature types. 3) Relocate some code to make it easier to follow and prevent 44 space indentation. 4) Rename varuint/varint to varuint32/varint32, this lets them be directly called from the wasm.json without being remapped. 5) Add support for Memory and Function sections to the Builder. 6) Add support for local variables. On the JSC side, we needed to expose a new function to validate the compiled wasm code behaves the way we expect. At least until the JS Wasm API is finished. The new validation function, testWasmModuleFunctions, takes an array buffer containing the wasm binary, the number of functions in the blob and tests for each of those functions. JSTests: * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/test_old_tests.js: Added. (ret5): (brTableWithLoop): (brTableManyValues): (run.brTableManyValues.brTableAsIf): (ifThenFallthrough): (ifThenElseFallthrough): (dumbLessThanFallthrough): (run.dumbLessThanFallthrough.floatSub): (run.floatSub.add12): (run.add12.factorial): (i32load): (run.i32load.i32load8s): (run.i32load8s.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbEqIfThenElse): (run.dumbEqIfThenElse.dumbLessThanIfThenElse): (run.dumbLessThanIfThenElse.loopSum): (run.loopSum.loopMult): (brIfLoopLessThan): (run.brIfLoopLessThan.run): * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. * wasm/Builder.js: (const._maybeRegisterType): (const): Deleted. (switch.typeof): Deleted. * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Import): (const.emitters.Function): (const.emitters.Memory): (const.emitters.Code): (export.const.Binary): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.get return): (export.default.LowLevelBinary.prototype.varuint32): (export.default.LowLevelBinary.prototype.varint32): (export.default.LowLevelBinary.prototype.varuint1): (export.default.LowLevelBinary.prototype.varint7): (export.default.LowLevelBinary.prototype.varuint7): (export.default.LowLevelBinary.prototype.inline_signature_type): (export.default.LowLevelBinary.prototype.string): (export.default.LowLevelBinary.prototype.getVaruint32): (export.default.LowLevelBinary.prototype.getVarint32): (export.default.LowLevelBinary.prototype.getVaruint7): (export.default.LowLevelBinary.prototype.getString): (export.default.LowLevelBinary): (export.default.LowLevelBinary.prototype.varuint): Deleted. (export.default.LowLevelBinary.prototype.varint): Deleted. (export.default.LowLevelBinary.prototype.getVaruint): Deleted. (export.default.LowLevelBinary.prototype.getVarint): Deleted. * wasm/js-api/function-tests/add-12.js: Added. * wasm/js-api/function-tests/br-if-loop-less-than.js: Added. * wasm/js-api/function-tests/brTableAsIf.js: Added. * wasm/js-api/function-tests/brTableManyValues.js: Added. * wasm/js-api/function-tests/brTableWithLoop.js: Added. * wasm/js-api/function-tests/dumb-eq-if-then-else.js: Added. * wasm/js-api/function-tests/dumb-less-than-fallthrough.js: Added. * wasm/js-api/function-tests/dumb-less-than-ite.js: Added. * wasm/js-api/function-tests/factorial.js: Added. * wasm/js-api/function-tests/float-sub.js: Added. * wasm/js-api/function-tests/i32-load.js: Added. * wasm/js-api/function-tests/i32-load8-s.js: Added. * wasm/js-api/function-tests/if-then-else-fallthrough.js: Added. * wasm/js-api/function-tests/if-then-fallthrough.js: Added. * wasm/js-api/function-tests/loop-mult.js: Added. * wasm/js-api/function-tests/loop-sum.js: Added. * wasm/js-api/function-tests/ret5.js: Added. * wasm/self-test/test_LowLevelBinary_varint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varint.js. * wasm/self-test/test_LowLevelBinary_varuint32.js: Renamed from JSTests/wasm/self-test/test_LowLevelBinary_varuint.js. Source/JavaScriptCore: * jsc.cpp: (GlobalObject::finishCreation): (box): (callWasmFunction): (functionTestWasmModuleFunctions): * testWasm.cpp: (checkPlan): (runWasmTests): * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::parseAndCompile): * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parse): (JSC::Wasm::FunctionParser<Context>::parseBody): (JSC::Wasm::FunctionParser<Context>::parseBlock): Deleted. * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parseMemory): (JSC::Wasm::ModuleParser::parseExport): * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::Plan): (JSC::Wasm::Plan::run): * wasm/WasmPlan.h: * wasm/js/WebAssemblyModuleConstructor.cpp: (JSC::constructJSWebAssemblyModule): Canonical link: https://commits.webkit.org/182347@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-12 00:29:36 +00:00
[{type: "i32", value: 100 }, [{ type: "i32", value: 100 }, { type: "i32", value: 112 }]],
[{type: "i32", value: 1000000 }, [{ type: "i32", value: 1000000 }, { type: "i32", value: 10 }]]
]);