Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 843c8b6

Browse files
author
jfbastien@apple.com
committed
WebAssembly: update binary format to 0xD version
https://bugs.webkit.org/show_bug.cgi?id=164724 Reviewed by Saam Barati. As described in the following PR: WebAssembly/design#836 JSTests: * wasm/Builder.js: (const._normalizeFunctionSignature): * wasm/Builder_WebAssemblyBinary.js: (const.emitters.Type): (const.emitters.Code): * wasm/LowLevelBinary.js: (export.default.LowLevelBinary.prototype.block_type): (export.default.LowLevelBinary.prototype.inline_signature_type): Deleted. * wasm/WASM.js: * wasm/js-api/test_basic_api.js: * wasm/self-test/test_BuilderWebAssembly.js: (EmptyModule): (CustomSection): * wasm/self-test/test_WASM.js: * wasm/wasm.json: Source/JavaScriptCore: * wasm/WasmB3IRGenerator.cpp: (JSC::Wasm::B3IRGenerator::B3IRGenerator): (JSC::Wasm::B3IRGenerator::zeroForType): (JSC::Wasm::B3IRGenerator::addConstant): (JSC::Wasm::createJSWrapper): * wasm/WasmCallingConvention.h: (JSC::Wasm::CallingConvention::marshallArgument): * wasm/WasmFormat.cpp: (JSC::Wasm::toString): Deleted. * wasm/WasmFormat.h: (JSC::Wasm::isValueType): (JSC::Wasm::toB3Type): Deleted. * wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * wasm/WasmModuleParser.cpp: (JSC::Wasm::ModuleParser::parse): (JSC::Wasm::ModuleParser::parseType): * wasm/WasmModuleParser.h: * wasm/WasmParser.h: (JSC::Wasm::Parser::parseResultType): * wasm/generateWasm.py: (Wasm.__init__): * wasm/generateWasmOpsHeader.py: (cppMacro): (typeMacroizer): (opcodeMacroizer): * wasm/wasm.json: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@209175 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 3621ca7 commit 843c8b6

22 files changed

+609
-492
lines changed

JSTests/ChangeLog

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
2016-11-30 JF Bastien <jfbastien@apple.com>
2+
3+
WebAssembly: update binary format to 0xD version
4+
https://bugs.webkit.org/show_bug.cgi?id=164724
5+
6+
Reviewed by Saam Barati.
7+
8+
As described in the following PR: https://github.com/WebAssembly/design/pull/836
9+
10+
* wasm/Builder.js:
11+
(const._normalizeFunctionSignature):
12+
* wasm/Builder_WebAssemblyBinary.js:
13+
(const.emitters.Type):
14+
(const.emitters.Code):
15+
* wasm/LowLevelBinary.js:
16+
(export.default.LowLevelBinary.prototype.block_type):
17+
(export.default.LowLevelBinary.prototype.inline_signature_type): Deleted.
18+
* wasm/WASM.js:
19+
* wasm/js-api/test_basic_api.js:
20+
* wasm/self-test/test_BuilderWebAssembly.js:
21+
(EmptyModule):
22+
(CustomSection):
23+
* wasm/self-test/test_WASM.js:
24+
* wasm/wasm.json:
25+
126
2016-11-30 JF Bastien <jfbastien@apple.com>
227

328
WebAssembly builder: don't throw when checker not implemented

JSTests/wasm/Builder.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const _normalizeFunctionSignature = (params, ret) => {
5151
if (typeof(ret) === "undefined")
5252
ret = "void";
5353
assert.isNotArray(ret, `Multiple return values not supported by WebAssembly yet`);
54-
assert.falsy(ret !== "void" && !WASM.isValidValueType(ret), `Type return ${ret} must be valid value type`);
54+
assert.truthy(WASM.isValidBlockType(ret), `Type return ${ret} must be valid block type`);
5555
return [params, ret];
5656
};
5757

@@ -156,7 +156,7 @@ const _exportFunctionContinuation = (builder, section, nextBuilder) => {
156156

157157
const _checkStackArgs = (op, param) => {
158158
for (let expect of param) {
159-
if (WASM.isValidValueType(expect)) {
159+
if (WASM.isValidType(expect)) {
160160
// FIXME implement stack checks for arguments. https://bugs.webkit.org/show_bug.cgi?id=163421
161161
} else {
162162
// Handle our own meta-types.
@@ -177,7 +177,7 @@ const _checkStackArgs = (op, param) => {
177177

178178
const _checkStackReturn = (op, ret) => {
179179
for (let expect of ret) {
180-
if (WASM.isValidValueType(expect)) {
180+
if (WASM.isValidType(expect)) {
181181
// FIXME implement stack checks for return. https://bugs.webkit.org/show_bug.cgi?id=163421
182182
} else {
183183
// Handle our own meta-types.
@@ -221,8 +221,7 @@ const _checkImms = (op, imms, expectedImms, ret) => {
221221
case "default_target": break; // improve checking https://bugs.webkit.org/show_bug.cgi?id=163421
222222
case "relative_depth": break; // improve checking https://bugs.webkit.org/show_bug.cgi?id=163421
223223
case "sig":
224-
// FIXME this should be isValidBlockType https://bugs.webkit.org/show_bug.cgi?id=164724
225-
assert.truthy(imms[idx] === "void" || WASM.isValidValueType(imms[idx]), `Invalid block type on ${op}: "${imms[idx]}"`);
224+
assert.truthy(WASM.isValidBlockType(imms[idx]), `Invalid block type on ${op}: "${imms[idx]}"`);
226225
break;
227226
case "target_count": break; // improve checking https://bugs.webkit.org/show_bug.cgi?id=163421
228227
case "target_table": break; // improve checking https://bugs.webkit.org/show_bug.cgi?id=163421

JSTests/wasm/Builder_WebAssemblyBinary.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ const emitters = {
3333
Type: (section, bin) => {
3434
put(bin, "varuint32", section.data.length);
3535
for (const entry of section.data) {
36-
const funcTypeConstructor = -0x20; // FIXME Move this to wasm.json.
37-
put(bin, "varint7", funcTypeConstructor);
36+
put(bin, "varint7", WASM.typeValue["func"]);
3837
put(bin, "varuint32", entry.params.length);
3938
for (const param of entry.params)
40-
put(bin, "uint8", WASM.valueTypeValue[param]);
39+
put(bin, "varint7", WASM.typeValue[param]);
4140
if (entry.ret === "void")
4241
put(bin, "varuint1", 0);
4342
else {
4443
put(bin, "varuint1", 1);
45-
put(bin, "uint8", WASM.valueTypeValue[entry.ret]);
44+
put(bin, "varint7", WASM.typeValue[entry.ret]);
4645
}
4746
}
4847
},
@@ -107,7 +106,7 @@ const emitters = {
107106
put(funcBin, "varuint32", localCount);
108107
for (let i = func.parameterCount; i < func.locals.length; ++i) {
109108
put(funcBin, "varuint32", 1);
110-
put(funcBin, "uint8", WASM.valueTypeValue[func.locals[i]]);
109+
put(funcBin, "varint7", WASM.typeValue[func.locals[i]]);
111110
}
112111

113112
for (const op of func.code) {

JSTests/wasm/LowLevelBinary.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ export default class LowLevelBinary {
159159
throw new RangeError(`Invalid varuint7 ${v} range is [${varuint32Min}, ${varuint7Max}]`);
160160
this.varuint32(v);
161161
}
162-
inline_signature_type(v) {
163-
this.varint7(WASM.valueTypeValue[v]);
162+
block_type(v) {
163+
if (!WASM.isValidBlockType(v))
164+
throw new Error(`Invalid block type ${v}`);
165+
this.varint7(WASM.typeValue[v]);
164166
}
165167
string(str) {
166168
let patch = this.newPatchable("varuint32");

JSTests/wasm/WASM.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ const _mapValues = from => {
3333
};
3434

3535
export const description = utilities.json("wasm.json");
36-
export const valueType = Object.keys(description.value_type);
37-
const _valueTypeSet = new Set(valueType);
36+
export const type = Object.keys(description.type);
37+
const _typeSet = new Set(type);
38+
export const isValidType = v => _typeSet.has(v);
39+
export const typeValue = _mapValues(description.type);
40+
const _valueTypeSet = new Set(description.value_type);
3841
export const isValidValueType = v => _valueTypeSet.has(v);
39-
export const valueTypeValue = _mapValues(description.value_type);
42+
const _blockTypeSet = new Set(description.block_type);
43+
export const isValidBlockType = v => _blockTypeSet.has(v);
4044
export const externalKindValue = _mapValues(description.external_kind);
4145
export const sections = Object.keys(description.section);
4246
export const sectionEncodingType = description.section[sections[0]].type;

JSTests/wasm/js-api/test_basic_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from '../assert.js';
22
import * as utilities from '../utilities.js';
33

4-
const version = 0xC;
4+
const version = 0x0D;
55
const emptyModuleArray = Uint8Array.of(0x0, 0x61, 0x73, 0x6d, version, 0x00, 0x00, 0x00);
66
const invalidConstructorInputs = [undefined, null, "", 1, {}, []];
77
const invalidInstanceImports = [null, "", 1];

JSTests/wasm/self-test/test_BuilderWebAssembly.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Builder from '../Builder.js';
66
const bin = builder.WebAssembly();
77
// Note: this will change as we update version number.
88
assert.eq(bin.hexdump().trim(),
9-
"00000000 00 61 73 6d 0c 00 00 00 |·asm···· |");
9+
"00000000 00 61 73 6d 0d 00 00 00 |·asm···· |");
1010
})();
1111

1212
(function EmptyModule() {
@@ -27,6 +27,6 @@ import Builder from '../Builder.js';
2727
.End()
2828
.WebAssembly();
2929
assert.eq(bin.hexdump().trim(),
30-
["00000000 00 61 73 6d 0c 00 00 00 00 0a 05 4f 48 48 41 49 |·asm·······OHHAI|",
30+
["00000000 00 61 73 6d 0d 00 00 00 00 0a 05 4f 48 48 41 49 |·asm·······OHHAI|",
3131
"00000010 de ad c0 fe |···· |"].join("\n"));
3232
})();

JSTests/wasm/self-test/test_WASM.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import * as assert from '../assert.js';
22
import * as WASM from '../WASM.js';
33

44
assert.isNotUndef(WASM.description);
5-
assert.isNotUndef(WASM.valueType);
6-
assert.ge(WASM.valueType.length, 4);
5+
assert.isNotUndef(WASM.type);
6+
assert.ge(WASM.type.length, 7);
77

8-
for (const v of WASM.valueType)
9-
if (!WASM.isValidValueType(v))
10-
throw new Error(`Expected value ${v} to be a valid value type`);
8+
for (const v of WASM.type)
9+
if (!WASM.isValidType(v))
10+
throw new Error(`Expected value ${v} to be a valid type`);
1111

1212
const expectedFields = [
1313
"preamble",
14-
"value_type",
15-
"inline_signature_type",
14+
"type",
1615
"external_kind",
1716
"section",
1817
"opcode",

0 commit comments

Comments
 (0)