Commit 2c0d87d0 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][test] Complete mjsunit infrastructure for wasm-gc

Add support for array and struct definitions and the rest of gc-related
opcodes.

Drive-by: Remove obsolete kWasmAnyFunctionTypeForm, replace it with
kWasmFuncRef.

Bug: v8:7748
Change-Id: I9512ff22d661fead5ad86767871632ae94346465
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2567691Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71533}
parent 366e5e24
......@@ -73,7 +73,8 @@ let kFunctionNamesCode = 1;
let kLocalNamesCode = 2;
let kWasmFunctionTypeForm = 0x60;
let kWasmAnyFunctionTypeForm = 0x70;
let kWasmStructTypeForm = 0x5f;
let kWasmArrayTypeForm = 0x5e;
let kLimitsNoMaximum = 0
let kLimitsHasMaximum = 1;
......@@ -94,21 +95,28 @@ let kDeclFunctionImport = 0x02;
let kDeclFunctionLocals = 0x04;
let kDeclFunctionExport = 0x08;
// Local types
// Value types and related
let kWasmStmt = 0x40;
let kWasmI32 = 0x7f;
let kWasmI64 = 0x7e;
let kWasmF32 = 0x7d;
let kWasmF64 = 0x7c;
let kWasmS128 = 0x7b;
let kWasmI8 = 0x7a;
let kWasmI16 = 0x79;
let kWasmFuncRef = 0x70;
let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec
let kWasmExternRef = 0x6f;
function wasmOptRefType(index) { return {opcode: 0x6c, index: index}; }
function wasmRefType(index) { return {opcode: 0x6b, index: index}; }
let kWasmAnyRef = 0x6e;
let kWasmEqRef = 0x6d;
let kWasmOptRef = 0x6c;
let kWasmRef = 0x6b;
function wasmOptRefType(index) { return {opcode: kWasmOptRef, index: index}; }
function wasmRefType(index) { return {opcode: kWasmRef, index: index}; }
let kWasmI31Ref = 0x6a;
let kWasmRtt = 0x69;
function wasmRtt(index, depth) {
return {opcode: 0x69, index: index, depth: depth};
return {opcode: kWasmRtt, index: index, depth: depth};
}
let kWasmExnRef = 0x68;
......@@ -222,6 +230,7 @@ const kWasmOpcodes = {
'ReturnCallIndirect': 0x13,
'CallRef': 0x14,
'ReturnCallRef': 0x15,
'Let': 0x17,
'Drop': 0x1a,
'Select': 0x1b,
'SelectWithType': 0x1c,
......@@ -421,9 +430,27 @@ for (let prefix in kPrefixOpcodes) {
}
// GC opcodes
let kExprStructNewWithRtt = 0x01;
let kExprStructNewDefault = 0x02;
let kExprStructGet = 0x03;
let kExprStructGetS = 0x04;
let kExprStructGetU = 0x05;
let kExprStructSet = 0x06;
let kExprArrayNewWithRtt = 0x11;
let kExprArrayNewDefault = 0x12;
let kExprArrayGet = 0x13;
let kExprArrayGetS = 0x14;
let kExprArrayGetU = 0x15;
let kExprArraySet = 0x16;
let kExprArrayLen = 0x17;
let kExprI31New = 0x20;
let kExprI31GetS = 0x21;
let kExprI31GetU = 0x22;
let kExprRttCanon = 0x30;
let kExprRttSub = 0x31;
let kExprRefTest = 0x40;
let kExprRefCast = 0x41;
let kExprI31New = 0x20;
let kExprBrOnCast = 0x42;
// Numeric opcodes.
let kExprI32SConvertSatF32 = 0x00;
......@@ -951,6 +978,25 @@ class WasmTableBuilder {
}
}
function makeField(type, mutability) {
assertEquals("boolean", typeof mutability,
"field mutability must be boolean");
return {type: type, mutability: mutability};
}
class WasmStruct {
constructor(fields) {
assertTrue(Array.isArray(fields), "struct fields must be an array");
this.fields = fields;
}
}
class WasmArray {
constructor(type) {
this.type = type;
}
}
class WasmModuleBuilder {
constructor() {
this.types = [];
......@@ -1016,6 +1062,16 @@ class WasmModuleBuilder {
return this.types.length - 1;
}
addStruct(fields) {
this.types.push(new WasmStruct(fields));
return this.types.length - 1;
}
addArray(type) {
this.types.push(new WasmArray(type));
return this.types.length - 1;
}
addGlobal(type, mutable) {
let glob = new WasmGlobalBuilder(this, type, mutable);
glob.index = this.globals.length + this.num_imported_globals;
......@@ -1085,7 +1141,7 @@ class WasmModuleBuilder {
throw new Error('Imported tables must be declared before local ones');
}
let o = {module: module, name: name, kind: kExternalTable, initial: initial,
maximum: maximum, type: type || kWasmAnyFunctionTypeForm};
maximum: maximum, type: type || kWasmFuncRef};
this.imports.push(o);
return this.num_imported_tables++;
}
......@@ -1209,14 +1265,27 @@ class WasmModuleBuilder {
binary.emit_section(kTypeSectionCode, section => {
section.emit_u32v(wasm.types.length);
for (let type of wasm.types) {
section.emit_u8(kWasmFunctionTypeForm);
section.emit_u32v(type.params.length);
for (let param of type.params) {
section.emit_type(param);
}
section.emit_u32v(type.results.length);
for (let result of type.results) {
section.emit_type(result);
if (type instanceof WasmStruct) {
section.emit_u8(kWasmStructTypeForm);
section.emit_u32v(type.fields.length);
for (let field of type.fields) {
section.emit_type(field.type);
section.emit_u8(field.mutability ? 1 : 0);
}
} else if (type instanceof WasmArray) {
section.emit_u8(kWasmArrayTypeForm);
section.emit_type(type.type);
section.emit_u8(1); // Only mutable arrays supported currently.
} else {
section.emit_u8(kWasmFunctionTypeForm);
section.emit_u32v(type.params.length);
for (let param of type.params) {
section.emit_type(param);
}
section.emit_u32v(type.results.length);
for (let result of type.results) {
section.emit_type(result);
}
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment