Changeset 246577 in webkit


Ignore:
Timestamp:
Jun 18, 2019 6:18:43 PM (5 years ago)
Author:
Justin Michaud
Message:

[WASM-References] Add support for Table.size, grow and fill instructions
https://bugs.webkit.org/show_bug.cgi?id=198761

Reviewed by Yusuke Suzuki.

JSTests:

  • wasm/Builder_WebAssemblyBinary.js:

(const.putOp):

  • wasm/references/table_misc.js: Added.

(TableSize.End.End.WebAssembly):
(GetLocal.0.GetLocal.1.TableGrow.End.End.WebAssembly):

  • wasm/wasm.json:

Source/JavaScriptCore:

Add support for Table.size, grow and fill instructions. This also required
adding support for two-byte opcodes to the ops generator.

  • wasm/WasmAirIRGenerator.cpp:

(JSC::Wasm::AirIRGenerator::gAnyref):
(JSC::Wasm::AirIRGenerator::tmpForType):
(JSC::Wasm::AirIRGenerator::addTableSize):
(JSC::Wasm::AirIRGenerator::addTableGrow):
(JSC::Wasm::AirIRGenerator::addTableFill):

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::addTableSize):
(JSC::Wasm::B3IRGenerator::addTableGrow):
(JSC::Wasm::B3IRGenerator::addTableFill):

  • wasm/WasmExceptionType.h:
  • wasm/WasmFormat.h:

(JSC::Wasm::TableInformation::wasmType const):

  • wasm/WasmFunctionParser.h:

(JSC::Wasm::FunctionParser<Context>::parseExpression):
(JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):

  • wasm/WasmInstance.cpp:

(JSC::Wasm::doWasmTableGrow):
(JSC::Wasm::doWasmTableFill):

  • wasm/WasmInstance.h:
  • wasm/WasmTable.cpp:

(JSC::Wasm::Table::grow):

  • wasm/WasmValidate.cpp:

(JSC::Wasm::Validate::addTableSize):
(JSC::Wasm::Validate::addTableGrow):
(JSC::Wasm::Validate::addTableFill):

  • wasm/generateWasmOpsHeader.py:

(opcodeMacroizer):
(ExtTableOpType):

  • wasm/wasm.json:
Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r246571 r246577  
     12019-06-18  Justin Michaud  <justin_michaud@apple.com>
     2
     3        [WASM-References] Add support for Table.size, grow and fill instructions
     4        https://bugs.webkit.org/show_bug.cgi?id=198761
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * wasm/Builder_WebAssemblyBinary.js:
     9        (const.putOp):
     10        * wasm/references/table_misc.js: Added.
     11        (TableSize.End.End.WebAssembly):
     12        (GetLocal.0.GetLocal.1.TableGrow.End.End.WebAssembly):
     13        * wasm/wasm.json:
     14
    1152019-06-18  Justin Michaud  <justin_michaud@apple.com>
    216
  • trunk/JSTests/wasm/Builder_WebAssemblyBinary.js

    r245765 r246577  
    6161const putOp = (bin, op) => {
    6262    put(bin, "uint8", op.value);
     63    if (WASM.description.opcode[op.name].extendedOp)
     64        put(bin, "uint8", WASM.description.opcode[op.name].extendedOp);
    6365    if (op.arguments.length !== 0)
    6466        throw new Error(`Unimplemented: arguments`); // FIXME https://bugs.webkit.org/show_bug.cgi?id=162706
  • trunk/JSTests/wasm/wasm.json

    r246571 r246577  
    7070        "table.get":           { "category": "special",    "value":  37, "return": ["anyref"],   "parameter": ["i32"],                  "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "get a table value" },
    7171        "table.set":           { "category": "special",    "value":  38, "return": [],           "parameter": ["i32", "anyref"],        "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "set a table value" },
     72        "table.size":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": [],                       "immediate": [{"name": "global_index",   "type": "varuint32"}],                                            "description": "get the size of a table", "extendedOp": 15 },
     73        "table.grow":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": ["anyref", "i32"],        "immediate": [{"name": "global_index",   "type": "varuint32"}],                                            "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 16 },
     74        "table.fill":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": ["i32", "anyref", "i32"], "immediate": [{"name": "global_index",   "type": "varuint32"}],                                            "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
    7275        "call":                { "category": "call",       "value":  16, "return": ["call"],     "parameter": ["call"],                 "immediate": [{"name": "function_index", "type": "varuint32"}],                                            "description": "call a function by its index" },
    7376        "call_indirect":       { "category": "call",       "value":  17, "return": ["call"],     "parameter": ["call"],                 "immediate": [{"name": "type_index",     "type": "varuint32"}, {"name": "table_index","type": "varuint32"}],"description": "call a function indirect with an expected signature" },
  • trunk/Source/JavaScriptCore/ChangeLog

    r246572 r246577  
     12019-06-18  Justin Michaud  <justin_michaud@apple.com>
     2
     3        [WASM-References] Add support for Table.size, grow and fill instructions
     4        https://bugs.webkit.org/show_bug.cgi?id=198761
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Add support for Table.size, grow and fill instructions. This also required
     9        adding support for two-byte opcodes to the ops generator.
     10
     11        * wasm/WasmAirIRGenerator.cpp:
     12        (JSC::Wasm::AirIRGenerator::gAnyref):
     13        (JSC::Wasm::AirIRGenerator::tmpForType):
     14        (JSC::Wasm::AirIRGenerator::addTableSize):
     15        (JSC::Wasm::AirIRGenerator::addTableGrow):
     16        (JSC::Wasm::AirIRGenerator::addTableFill):
     17        * wasm/WasmB3IRGenerator.cpp:
     18        (JSC::Wasm::B3IRGenerator::addTableSize):
     19        (JSC::Wasm::B3IRGenerator::addTableGrow):
     20        (JSC::Wasm::B3IRGenerator::addTableFill):
     21        * wasm/WasmExceptionType.h:
     22        * wasm/WasmFormat.h:
     23        (JSC::Wasm::TableInformation::wasmType const):
     24        * wasm/WasmFunctionParser.h:
     25        (JSC::Wasm::FunctionParser<Context>::parseExpression):
     26        (JSC::Wasm::FunctionParser<Context>::parseUnreachableExpression):
     27        * wasm/WasmInstance.cpp:
     28        (JSC::Wasm::doWasmTableGrow):
     29        (JSC::Wasm::doWasmTableFill):
     30        * wasm/WasmInstance.h:
     31        * wasm/WasmTable.cpp:
     32        (JSC::Wasm::Table::grow):
     33        * wasm/WasmValidate.cpp:
     34        (JSC::Wasm::Validate::addTableSize):
     35        (JSC::Wasm::Validate::addTableGrow):
     36        (JSC::Wasm::Validate::addTableFill):
     37        * wasm/generateWasmOpsHeader.py:
     38        (opcodeMacroizer):
     39        (ExtTableOpType):
     40        * wasm/wasm.json:
     41
    1422019-06-18  Keith Miller  <keith_miller@apple.com>
    243
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r246571 r246577  
    240240    PartialResult WARN_UNUSED_RETURN addTableGet(unsigned, ExpressionType& index, ExpressionType& result);
    241241    PartialResult WARN_UNUSED_RETURN addTableSet(unsigned, ExpressionType& index, ExpressionType& value);
     242    PartialResult WARN_UNUSED_RETURN addTableSize(unsigned, ExpressionType& result);
     243    PartialResult WARN_UNUSED_RETURN addTableGrow(unsigned, ExpressionType& fill, ExpressionType& delta, ExpressionType& result);
     244    PartialResult WARN_UNUSED_RETURN addTableFill(unsigned, ExpressionType& offset, ExpressionType& fill, ExpressionType& count);
    242245
    243246    // Locals
     
    362365    TypedTmp g32() { return { newTmp(B3::GP), Type::I32 }; }
    363366    TypedTmp g64() { return { newTmp(B3::GP), Type::I64 }; }
     367    TypedTmp gAnyref() { return { newTmp(B3::GP), Type::Anyref }; }
     368    TypedTmp gAnyfunc() { return { newTmp(B3::GP), Type::Anyfunc }; }
    364369    TypedTmp f32() { return { newTmp(B3::FP), Type::F32 }; }
    365370    TypedTmp f64() { return { newTmp(B3::FP), Type::F64 }; }
     
    371376            return g32();
    372377        case Type::I64:
     378            return g64();
     379        case Type::Anyfunc:
     380            return gAnyfunc();
    373381        case Type::Anyref:
    374         case Type::Anyfunc:
    375             return g64();
     382            return gAnyref();
    376383        case Type::F32:
    377384            return f32();
     
    509516                break;
    510517            case Type::I64:
     518            case Type::Anyref:
     519            case Type::Anyfunc:
    511520                resultType = B3::Int64;
    512521                break;
     
    976985    ASSERT(index.tmp());
    977986    ASSERT(index.type() == Type::I32);
    978     result = tmpForType(Type::Anyref);
     987    result = tmpForType(m_info.tables[tableIndex].wasmType());
    979988
    980989    emitCCall(&getWasmTableElement, result, instanceValue(), addConstant(Type::I32, tableIndex), index);
     
    10001009    emitCheck([&] {
    10011010        return Inst(BranchTest32, nullptr, Arg::resCond(MacroAssembler::Zero), shouldThrow, shouldThrow);
     1011    }, [=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
     1012        this->emitThrowException(jit, ExceptionType::OutOfBoundsTableAccess);
     1013    });
     1014
     1015    return { };
     1016}
     1017
     1018auto AirIRGenerator::addTableSize(unsigned tableIndex, ExpressionType& result) -> PartialResult
     1019{
     1020    // FIXME: Emit this inline <https://bugs.webkit.org/show_bug.cgi?id=198506>.
     1021    result = tmpForType(Type::I32);
     1022
     1023    int32_t (*doSize)(Instance*, unsigned) = [] (Instance* instance, unsigned tableIndex) -> int32_t {
     1024        return instance->table(tableIndex)->length();
     1025    };
     1026
     1027    emitCCall(doSize, result, instanceValue(), addConstant(Type::I32, tableIndex));
     1028
     1029    return { };
     1030}
     1031
     1032auto AirIRGenerator::addTableGrow(unsigned tableIndex, ExpressionType& fill, ExpressionType& delta, ExpressionType& result) -> PartialResult
     1033{
     1034    ASSERT(fill.tmp());
     1035    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
     1036    ASSERT(delta.tmp());
     1037    ASSERT(delta.type() == Type::I32);
     1038    result = tmpForType(Type::I32);
     1039
     1040    emitCCall(&doWasmTableGrow, result, instanceValue(), addConstant(Type::I32, tableIndex), fill, delta);
     1041
     1042    return { };
     1043}
     1044
     1045auto AirIRGenerator::addTableFill(unsigned tableIndex, ExpressionType& offset, ExpressionType& fill, ExpressionType& count) -> PartialResult
     1046{
     1047    ASSERT(fill.tmp());
     1048    ASSERT(isSubtype(fill.type(), m_info.tables[tableIndex].wasmType()));
     1049    ASSERT(offset.tmp());
     1050    ASSERT(offset.type() == Type::I32);
     1051    ASSERT(count.tmp());
     1052    ASSERT(count.type() == Type::I32);
     1053
     1054    auto result = tmpForType(Type::I32);
     1055    emitCCall(&doWasmTableFill, result, instanceValue(), addConstant(Type::I32, tableIndex), offset, fill, count);
     1056
     1057    emitCheck([&] {
     1058        return Inst(BranchTest32, nullptr, Arg::resCond(MacroAssembler::Zero), result, result);
    10021059    }, [=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
    10031060        this->emitThrowException(jit, ExceptionType::OutOfBoundsTableAccess);
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r246571 r246577  
    193193    PartialResult WARN_UNUSED_RETURN addTableGet(unsigned, ExpressionType& index, ExpressionType& result);
    194194    PartialResult WARN_UNUSED_RETURN addTableSet(unsigned, ExpressionType& index, ExpressionType& value);
    195 
     195    PartialResult WARN_UNUSED_RETURN addTableSize(unsigned, ExpressionType& result);
     196    PartialResult WARN_UNUSED_RETURN addTableGrow(unsigned, ExpressionType& fill, ExpressionType& delta, ExpressionType& result);
     197    PartialResult WARN_UNUSED_RETURN addTableFill(unsigned, ExpressionType& offset, ExpressionType& fill, ExpressionType& count);
    196198    // Locals
    197199    PartialResult WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result);
     
    618620}
    619621
     622auto B3IRGenerator::addTableSize(unsigned tableIndex, ExpressionType& result) -> PartialResult
     623{
     624    // FIXME: Emit this inline <https://bugs.webkit.org/show_bug.cgi?id=198506>.
     625    uint32_t (*doSize)(Instance*, unsigned) = [] (Instance* instance, unsigned tableIndex) -> uint32_t {
     626        return instance->table(tableIndex)->length();
     627    };
     628
     629    result = m_currentBlock->appendNew<CCallValue>(m_proc, toB3Type(I32), origin(),
     630        m_currentBlock->appendNew<ConstPtrValue>(m_proc, origin(), tagCFunctionPtr<void*>(doSize, B3CCallPtrTag)),
     631        instanceValue(), m_currentBlock->appendNew<Const32Value>(m_proc, origin(), tableIndex));
     632
     633    return { };
     634}
     635
     636auto B3IRGenerator::addTableGrow(unsigned tableIndex, ExpressionType& fill, ExpressionType& delta, ExpressionType& result) -> PartialResult
     637{
     638    result = m_currentBlock->appendNew<CCallValue>(m_proc, toB3Type(I32), origin(),
     639        m_currentBlock->appendNew<ConstPtrValue>(m_proc, origin(), tagCFunctionPtr<void*>(&doWasmTableGrow, B3CCallPtrTag)),
     640        instanceValue(), m_currentBlock->appendNew<Const32Value>(m_proc, origin(), tableIndex), fill, delta);
     641
     642    return { };
     643}
     644
     645auto B3IRGenerator::addTableFill(unsigned tableIndex, ExpressionType& offset, ExpressionType& fill, ExpressionType& count) -> PartialResult
     646{
     647    auto result = m_currentBlock->appendNew<CCallValue>(m_proc, toB3Type(I32), origin(),
     648        m_currentBlock->appendNew<ConstPtrValue>(m_proc, origin(), tagCFunctionPtr<void*>(&doWasmTableFill, B3CCallPtrTag)),
     649        instanceValue(), m_currentBlock->appendNew<Const32Value>(m_proc, origin(), tableIndex), offset, fill, count);
     650
     651    {
     652        CheckValue* check = m_currentBlock->appendNew<CheckValue>(m_proc, Check, origin(),
     653            m_currentBlock->appendNew<Value>(m_proc, Equal, origin(), result, m_currentBlock->appendNew<Const32Value>(m_proc, origin(), 0)));
     654
     655        check->setGenerator([=] (CCallHelpers& jit, const B3::StackmapGenerationParams&) {
     656            this->emitExceptionCheck(jit, ExceptionType::OutOfBoundsTableAccess);
     657        });
     658    }
     659
     660    return { };
     661}
     662
    620663auto B3IRGenerator::getLocal(uint32_t index, ExpressionType& result) -> PartialResult
    621664{
  • trunk/Source/JavaScriptCore/wasm/WasmExceptionType.h

    r246504 r246577  
    3434#define FOR_EACH_EXCEPTION(macro) \
    3535    macro(OutOfBoundsMemoryAccess,  "Out of bounds memory access") \
    36     macro(OutOfBoundsTableAccess,  "Out of bounds table access") \
     36    macro(OutOfBoundsTableAccess, "Out of bounds table access") \
    3737    macro(OutOfBoundsCallIndirect, "Out of bounds call_indirect") \
    3838    macro(NullTableEntry,  "call_indirect to a null table entry") \
  • trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h

    r246571 r246577  
    304304    }
    305305
     306    case ExtTable: {
     307        WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled");
     308        uint8_t extOp;
     309        WASM_PARSER_FAIL_IF(!parseUInt8(extOp), "can't parse table extended opcode");
     310        unsigned tableIndex;
     311        WASM_PARSER_FAIL_IF(!parseVarUInt32(tableIndex), "can't parse table index");
     312
     313        switch (static_cast<ExtTableOpType>(extOp)) {
     314        case ExtTableOpType::TableSize: {
     315            ExpressionType result;
     316            WASM_TRY_ADD_TO_CONTEXT(addTableSize(tableIndex, result));
     317            m_expressionStack.append(result);
     318            break;
     319        }
     320        case ExtTableOpType::TableGrow: {
     321            ExpressionType fill, delta, result;
     322            WASM_TRY_POP_EXPRESSION_STACK_INTO(delta, "table.grow");
     323            WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.grow");
     324            WASM_TRY_ADD_TO_CONTEXT(addTableGrow(tableIndex, fill, delta, result));
     325            m_expressionStack.append(result);
     326            break;
     327        }
     328        case ExtTableOpType::TableFill: {
     329            ExpressionType offset, fill, count;
     330            WASM_TRY_POP_EXPRESSION_STACK_INTO(count, "table.fill");
     331            WASM_TRY_POP_EXPRESSION_STACK_INTO(fill, "table.fill");
     332            WASM_TRY_POP_EXPRESSION_STACK_INTO(offset, "table.fill");
     333            WASM_TRY_ADD_TO_CONTEXT(addTableFill(tableIndex, offset, fill, count));
     334            break;
     335        }
     336        default:
     337            WASM_PARSER_FAIL_IF(true, "invalid extended table op ", extOp);
     338            break;
     339        }
     340        return { };
     341    }
     342
    306343    case RefNull: {
    307344        WASM_PARSER_FAIL_IF(!Options::useWebAssemblyReferences(), "references are not enabled");
     
    689726    }
    690727
     728    case ExtTable:
    691729    case TableGet:
    692730    case TableSet: {
  • trunk/Source/JavaScriptCore/wasm/WasmInstance.cpp

    r246571 r246577  
    160160}
    161161
     162int32_t doWasmTableGrow(Instance* instance, unsigned tableIndex, EncodedJSValue fill, int32_t delta)
     163{
     164    ASSERT(tableIndex < instance->module().moduleInformation().tableCount());
     165    auto oldSize = instance->table(tableIndex)->length();
     166    if (delta < 0)
     167        return oldSize;
     168    auto newSize = instance->table(tableIndex)->grow(delta);
     169    if (!newSize || *newSize == oldSize)
     170        return -1;
     171
     172    for (unsigned i = oldSize; i < instance->table(tableIndex)->length(); ++i)
     173        setWasmTableElement(instance, tableIndex, i, fill);
     174
     175    return oldSize;
     176}
     177
     178bool doWasmTableFill(Instance* instance, unsigned tableIndex, int32_t unsafeOffset, EncodedJSValue fill, int32_t unsafeCount)
     179{
     180    ASSERT(tableIndex < instance->module().moduleInformation().tableCount());
     181    if (unsafeOffset < 0 || unsafeCount < 0)
     182        return false;
     183
     184    unsigned offset = unsafeOffset;
     185    unsigned count = unsafeCount;
     186
     187    if (offset >= instance->table(tableIndex)->length() || offset + count > instance->table(tableIndex)->length())
     188        return false;
     189
     190    for (unsigned j = 0; j < count; ++j)
     191        setWasmTableElement(instance, tableIndex, offset + j, fill);
     192
     193    return true;
     194}
     195
    162196EncodedJSValue doWasmRefFunc(Instance* instance, uint32_t index)
    163197{
  • trunk/Source/JavaScriptCore/wasm/WasmInstance.h

    r246571 r246577  
    4545bool setWasmTableElement(Instance*, unsigned, int32_t, EncodedJSValue encValue);
    4646EncodedJSValue doWasmRefFunc(Instance*, uint32_t);
     47int32_t doWasmTableGrow(Instance*, unsigned, EncodedJSValue fill, int32_t delta);
     48bool doWasmTableFill(Instance*, unsigned, int32_t offset, EncodedJSValue fill, int32_t count);
    4749
    4850class Instance : public ThreadSafeRefCounted<Instance>, public CanMakeWeakPtr<Instance> {
  • trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp

    r246571 r246577  
    109109    Result WARN_UNUSED_RETURN addTableGet(unsigned, ExpressionType& index, ExpressionType& result);
    110110    Result WARN_UNUSED_RETURN addTableSet(unsigned, ExpressionType& index, ExpressionType& value);
    111 
     111    Result WARN_UNUSED_RETURN addTableSize(unsigned, ExpressionType& result);
     112    Result WARN_UNUSED_RETURN addTableGrow(unsigned, ExpressionType& fill, ExpressionType& delta, ExpressionType& result);
     113    Result WARN_UNUSED_RETURN addTableFill(unsigned, ExpressionType& offset, ExpressionType& fill, ExpressionType& count);
    112114    // Locals
    113115    Result WARN_UNUSED_RETURN getLocal(uint32_t index, ExpressionType& result);
     
    195197    WASM_VALIDATOR_FAIL_IF(!isSubtype(value, type), "table.set value to type ", value, " expected ", type);
    196198    RELEASE_ASSERT(m_module.tables[tableIndex].type() == TableElementType::Anyref || m_module.tables[tableIndex].type() == TableElementType::Funcref);
     199
     200    return { };
     201}
     202
     203auto Validate::addTableSize(unsigned tableIndex, ExpressionType& result) -> Result
     204{
     205    result = Type::I32;
     206    WASM_VALIDATOR_FAIL_IF(tableIndex >= m_module.tableCount(), "table index ", tableIndex, " is invalid, limit is ", m_module.tableCount());
     207
     208    return { };
     209}
     210
     211auto Validate::addTableGrow(unsigned tableIndex, ExpressionType& fill, ExpressionType& delta, ExpressionType& result) -> Result
     212{
     213    result = Type::I32;
     214    WASM_VALIDATOR_FAIL_IF(tableIndex >= m_module.tableCount(), "table index ", tableIndex, " is invalid, limit is ", m_module.tableCount());
     215    WASM_VALIDATOR_FAIL_IF(!isSubtype(fill, m_module.tables[tableIndex].wasmType()), "table.grow expects fill value of type ", m_module.tables[tableIndex].wasmType(), " got ", fill);
     216    WASM_VALIDATOR_FAIL_IF(Type::I32 != delta, "table.grow expects an i32 delta value, got ", delta);
     217
     218    return { };
     219}
     220
     221auto Validate::addTableFill(unsigned tableIndex, ExpressionType& offset, ExpressionType& fill, ExpressionType& count) -> Result
     222{
     223    WASM_VALIDATOR_FAIL_IF(tableIndex >= m_module.tableCount(), "table index ", tableIndex, " is invalid, limit is ", m_module.tableCount());
     224    WASM_VALIDATOR_FAIL_IF(!isSubtype(fill, m_module.tables[tableIndex].wasmType()), "table.fill expects fill value of type ", m_module.tables[tableIndex].wasmType(), " got ", fill);
     225    WASM_VALIDATOR_FAIL_IF(Type::I32 != offset, "table.fill expects an i32 offset value, got ", offset);
     226    WASM_VALIDATOR_FAIL_IF(Type::I32 != count, "table.fill expects an i32 count value, got ", count);
    197227
    198228    return { };
  • trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py

    r245496 r246577  
    5656
    5757
    58 def opcodeMacroizer(filter):
     58def opcodeMacroizer(filter, opcodeField="value"):
    5959    inc = 0
    6060    for op in wasm.opcodeIterator(filter):
     
    6262        if isSimple(op["opcode"]):
    6363            b3op = op["opcode"]["b3op"]
    64         yield cppMacro(op["name"], op["opcode"]["value"], b3op, inc)
     64        yield cppMacro(op["name"], op["opcode"][opcodeField], b3op, inc)
    6565        inc += 1
    6666
    6767defines = ["#define FOR_EACH_WASM_SPECIAL_OP(macro)"]
    68 defines.extend([op for op in opcodeMacroizer(lambda op: not (isUnary(op) or isBinary(op) or op["category"] == "control" or op["category"] == "memory"))])
     68defines.extend([op for op in opcodeMacroizer(lambda op: not (isUnary(op) or isBinary(op) or op["category"] == "control" or op["category"] == "memory" or op["category"] == "exttable"))])
    6969defines.append("\n\n#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro)")
    7070defines.extend([op for op in opcodeMacroizer(lambda op: op["category"] == "control")])
     
    8181defines.append("\n\n#define FOR_EACH_WASM_MEMORY_STORE_OP(macro)")
    8282defines.extend([op for op in opcodeMacroizer(lambda op: (op["category"] == "memory" and len(op["return"]) == 0))])
     83defines.append("\n\n#define FOR_EACH_WASM_EXT_TABLE_OP(macro)")
     84defines.extend([op for op in opcodeMacroizer(lambda op: (op["category"] == "exttable"), "extendedOp")])
    8385defines.append("\n\n")
    8486
     
    203205    FOR_EACH_WASM_BINARY_OP(macro) \\
    204206    FOR_EACH_WASM_MEMORY_LOAD_OP(macro) \\
    205     FOR_EACH_WASM_MEMORY_STORE_OP(macro)
     207    FOR_EACH_WASM_MEMORY_STORE_OP(macro) \\
     208    macro(ExtTable, 0xFC, Oops, 0)
    206209
    207210#define CREATE_ENUM_VALUE(name, id, b3op, inc) name = id,
     
    233236enum class StoreOpType : uint8_t {
    234237    FOR_EACH_WASM_MEMORY_STORE_OP(CREATE_ENUM_VALUE)
     238};
     239
     240enum class ExtTableOpType : uint8_t {
     241    FOR_EACH_WASM_EXT_TABLE_OP(CREATE_ENUM_VALUE)
    235242};
    236243
  • trunk/Source/JavaScriptCore/wasm/wasm.json

    r246571 r246577  
    7070        "table.get":           { "category": "special",    "value":  37, "return": ["anyref"],   "parameter": ["i32"],                  "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "get a table value" },
    7171        "table.set":           { "category": "special",    "value":  38, "return": [],           "parameter": ["i32", "anyref"],        "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "set a table value" },
     72        "table.size":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": [],                       "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "get the size of a table", "extendedOp": 15 },
     73        "table.grow":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": ["anyref", "i32"],        "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "grow a table by the given delta and return the previous size, or -1 if enough space cannot be allocated", "extendedOp": 16 },
     74        "table.fill":          { "category": "exttable",   "value":  252, "return": ["i32"],     "parameter": ["i32", "anyref", "i32"], "immediate": [{"name": "table_index",    "type": "varuint32"}],                                            "description": "fill entries [i,i+n) with the given value", "extendedOp": 17 },
    7275        "call":                { "category": "call",       "value":  16, "return": ["call"],     "parameter": ["call"],                 "immediate": [{"name": "function_index", "type": "varuint32"}],                                            "description": "call a function by its index" },
    7376        "call_indirect":       { "category": "call",       "value":  17, "return": ["call"],     "parameter": ["call"],                 "immediate": [{"name": "type_index",     "type": "varuint32"}, {"name": "table_index","type": "varuint32"}],"description": "call a function indirect with an expected signature" },
Note: See TracChangeset for help on using the changeset viewer.