Bug 1308056: Allow to index memory/table owner in elem/data sections; r=luke

MozReview-Commit-ID: 1Sk7OJkbKxi

--HG--
extra : rebase_source : a1564144743d8bfa90cca82cc7a2bd817a3a788e
This commit is contained in:
Benjamin Bouvier 2016-10-07 16:22:24 +02:00
parent 66fccf7fcf
commit c2aaf58a70
7 changed files with 52 additions and 34 deletions

View File

@ -2699,15 +2699,26 @@ ParseTypeDef(WasmParseContext& c)
return new(c.lifo) AstSig(name, Move(sig));
}
static bool
MaybeParseOwnerIndex(WasmParseContext& c)
{
if (c.ts.peek().kind() == WasmToken::Index) {
WasmToken elemIndex = c.ts.get();
if (elemIndex.index()) {
c.ts.generateError(elemIndex, "can't handle non-default memory/table yet", c.error);
return false;
}
}
return true;
}
static AstDataSegment*
ParseDataSegment(WasmParseContext& c)
{
AstExpr* offset;
WasmToken dstOffset;
if (c.ts.getIf(WasmToken::Index, &dstOffset))
offset = new(c.lifo) AstConst(Val(dstOffset.index()));
else
offset = ParseExpr(c, true);
if (!MaybeParseOwnerIndex(c))
return nullptr;
AstExpr* offset = ParseExpr(c, true);
if (!offset)
return nullptr;
@ -2961,10 +2972,14 @@ ParseExport(WasmParseContext& c)
break;
}
case WasmToken::Table:
if (!MaybeParseOwnerIndex(c))
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
return new(c.lifo) AstExport(name.text(), DefinitionKind::Table);
case WasmToken::Memory:
if (!MaybeParseOwnerIndex(c))
return nullptr;
if (!c.ts.match(WasmToken::CloseParen, c.error))
return nullptr;
return new(c.lifo) AstExport(name.text(), DefinitionKind::Memory);
@ -3077,6 +3092,9 @@ ParseTable(WasmParseContext& c, WasmToken token, AstModule* module)
static AstElemSegment*
ParseElemSegment(WasmParseContext& c)
{
if (!MaybeParseOwnerIndex(c))
return nullptr;
AstExpr* offset = ParseExpr(c, true);
if (!offset)
return nullptr;

View File

@ -149,26 +149,26 @@ assertEq(obj.memory.buffer.byteLength, 65536);
assertEq(obj.b(), 42);
assertEq(obj.c(), undefined);
var buf = wasmEvalText('(module (memory 1) (data 0 "") (export "memory" memory))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
var buf = wasmEvalText('(module (memory 1) (data 65536 "") (export "memory" memory))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65536) "") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
var buf = wasmEvalText('(module (memory 1) (data 0 "a") (export "memory" memory))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));
var buf = wasmEvalText('(module (memory 1) (data 0 "a") (data 2 "b") (export "memory" memory))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 0) "a") (data (i32.const 2) "b") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 'a'.charCodeAt(0));
assertEq(new Uint8Array(buf)[1], 0);
assertEq(new Uint8Array(buf)[2], 'b'.charCodeAt(0));
var buf = wasmEvalText('(module (memory 1) (data 65535 "c") (export "memory" memory))').exports.memory.buffer;
var buf = wasmEvalText('(module (memory 1) (data (i32.const 65535) "c") (export "memory" memory))').exports.memory.buffer;
assertEq(new Uint8Array(buf)[0], 0);
assertEq(new Uint8Array(buf)[65535], 'c'.charCodeAt(0));
wasmFailValidateText('(module (memory 1) (data 65536 "a") (export "memory" memory))', /data segment does not fit/);
wasmFailValidateText('(module (memory 1) (data 65535 "ab") (export "memory" memory))', /data segment does not fit/);
wasmFailValidateText('(module (memory 1) (data (i32.const 65536) "a") (export "memory" memory))', /data segment does not fit/);
wasmFailValidateText('(module (memory 1) (data (i32.const 65535) "ab") (export "memory" memory))', /data segment does not fit/);
// ----------------------------------------------------------------------------
// locals

View File

@ -65,9 +65,9 @@ function loadTwiceModule(type, ext, offset, align) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data 65520 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 65520) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (param i32) (result ${type})
(drop (${type}.load${ext}
offset=${offset}
@ -87,9 +87,9 @@ function loadTwiceSameBasePlusConstModule(type, ext, offset, align, addConst) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data 65520 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 65520) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (result ${type})
(drop (${type}.load${ext}
offset=${offset}
@ -109,9 +109,9 @@ function loadTwiceSameBasePlusNonConstModule(type, ext, offset, align) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data 65520 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 65520) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (param i32) (result ${type})
(drop (${type}.load${ext}
offset=${offset}

View File

@ -340,8 +340,8 @@ wasmFailValidateText('(module (import "a" "b" (table 1 1 anyfunc)) (import "x" "
var m = new Module(wasmTextToBinary(`
(module
(import "a" "b" (memory 1 1))
(data 0 "\\0a\\0b")
(data 100 "\\0c\\0d")
(data (i32.const 0) "\\0a\\0b")
(data (i32.const 100) "\\0c\\0d")
(func $get (param $p i32) (result i32)
(i32.load8_u (get_local $p)))
(export "get" $get))

View File

@ -3,7 +3,7 @@ load(libdir + "wasm.js");
var i = wasmEvalText(
`(module
(memory 1) (data 0 "\\01\\02\\03\\04\\05\\06\\07\\08")
(memory 1) (data (i32.const 0) "\\01\\02\\03\\04\\05\\06\\07\\08")
(func $off1 (param $base i32) (result i32)
(i32.add
(i32.load8_u (get_local $base))

View File

@ -5,8 +5,8 @@ function loadModule(type, ext, offset, align) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (result ${type})
(${type}.load${ext}
offset=${offset}
@ -22,8 +22,8 @@ function storeModule(type, ext, offset, align) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (param ${type})
(${type}.store${ext}
offset=${offset}
@ -47,8 +47,8 @@ function storeModuleCst(type, ext, offset, align, value) {
return wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32)
(${type}.store${ext}
offset=${offset}
@ -281,8 +281,8 @@ for (var foldOffsets = 0; foldOffsets <= 1; foldOffsets++) {
assertEq(wasmEvalText(
`(module
(memory 1)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data 16 "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")
(func (param i32) (local i32 i32 i32 i32 f32 f64) (result i32)
(set_local 1 (i32.load8_s offset=4 (get_local 0)))
(set_local 2 (i32.load16_s (get_local 1)))

View File

@ -51,6 +51,6 @@ assertEq(wasmEvalText(`(module
)
(get_local $l)
)
(data 0 "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
(export "test" 0)
)`).exports["test"](3), 6);