Changeset 189382 in webkit


Ignore:
Timestamp:
Sep 4, 2015 2:00:56 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Implement the GetLocal and SetLocal instructions in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=148793

Patch by Sukolsak Sakshuwong <Sukolsak Sakshuwong> on 2015-09-04
Reviewed by Saam Barati.

This patch implements the GetLocal and SetLocal instructions for locals
of type int32 in WebAssembly. A "local" in this context is either an
argument or a local variable.

  • tests/stress/wasm-locals.js: Added.

(shouldBe):

  • tests/stress/wasm-locals.wasm: Added.
  • wasm/WASMFunctionCompiler.h:

(JSC::WASMFunctionCompiler::buildSetLocal):
(JSC::WASMFunctionCompiler::buildGetLocal):

  • wasm/WASMFunctionParser.cpp:

(JSC::WASMFunctionParser::parseSetLocalStatement):
(JSC::WASMFunctionParser::parseExpressionI32):
(JSC::WASMFunctionParser::parseGetLocalExpressionI32):

  • wasm/WASMFunctionParser.h:
  • wasm/WASMFunctionSyntaxChecker.h:

(JSC::WASMFunctionSyntaxChecker::buildSetLocal):
(JSC::WASMFunctionSyntaxChecker::buildGetLocal):

Location:
trunk/Source/JavaScriptCore
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189376 r189382  
     12015-09-04  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Implement the GetLocal and SetLocal instructions in WebAssembly
     4        https://bugs.webkit.org/show_bug.cgi?id=148793
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch implements the GetLocal and SetLocal instructions for locals
     9        of type int32 in WebAssembly. A "local" in this context is either an
     10        argument or a local variable.
     11
     12        * tests/stress/wasm-locals.js: Added.
     13        (shouldBe):
     14        * tests/stress/wasm-locals.wasm: Added.
     15        * wasm/WASMFunctionCompiler.h:
     16        (JSC::WASMFunctionCompiler::buildSetLocal):
     17        (JSC::WASMFunctionCompiler::buildGetLocal):
     18        * wasm/WASMFunctionParser.cpp:
     19        (JSC::WASMFunctionParser::parseSetLocalStatement):
     20        (JSC::WASMFunctionParser::parseExpressionI32):
     21        (JSC::WASMFunctionParser::parseGetLocalExpressionI32):
     22        * wasm/WASMFunctionParser.h:
     23        * wasm/WASMFunctionSyntaxChecker.h:
     24        (JSC::WASMFunctionSyntaxChecker::buildSetLocal):
     25        (JSC::WASMFunctionSyntaxChecker::buildGetLocal):
     26
    1272015-09-04  Basile Clement  <basile_clement@apple.com>
    228
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h

    r189303 r189382  
    128128    }
    129129
     130    void buildSetLocal(uint32_t localIndex, int, WASMType type)
     131    {
     132        switch (type) {
     133        case WASMType::I32:
     134            load32(temporaryAddress(m_tempStackTop - 1), GPRInfo::regT0);
     135            m_tempStackTop--;
     136            store32(GPRInfo::regT0, localAddress(localIndex));
     137            break;
     138        default:
     139            ASSERT_NOT_REACHED();
     140        }
     141    }
     142
    130143    void buildReturn(int, WASMExpressionType returnType)
    131144    {
     
    149162    {
    150163        store32(TrustedImm32(immediate), temporaryAddress(m_tempStackTop++));
     164        return UNUSED;
     165    }
     166
     167    int buildGetLocal(uint32_t localIndex, WASMType type)
     168    {
     169        switch (type) {
     170        case WASMType::I32:
     171            load32(localAddress(localIndex), GPRInfo::regT0);
     172            m_tempStackTop++;
     173            store32(GPRInfo::regT0, temporaryAddress(m_tempStackTop - 1));
     174            break;
     175        default:
     176            ASSERT_NOT_REACHED();
     177        }
    151178        return UNUSED;
    152179    }
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp

    r189303 r189382  
    211211    FAIL_IF_FALSE(localIndex < m_localTypes.size(), "The local variable index is incorrect.");
    212212    WASMType type = m_localTypes[localIndex];
    213     parseExpression(context, WASMExpressionType(type));
    214     // FIXME: Implement this instruction.
     213    ContextExpression expression = parseExpression(context, WASMExpressionType(type));
     214    PROPAGATE_ERROR();
     215    context.buildSetLocal(localIndex, expression, type);
    215216    return UNUSED;
    216217}
     
    426427        case WASMOpExpressionI32::Immediate:
    427428            return parseImmediateExpressionI32(context);
     429        case WASMOpExpressionI32::GetLocal:
     430            return parseGetLocalExpressionI32(context);
    428431        case WASMOpExpressionI32::Add:
    429432        case WASMOpExpressionI32::Sub:
    430433            return parseBinaryExpressionI32(context, op);
    431434        case WASMOpExpressionI32::ConstantPoolIndex:
    432         case WASMOpExpressionI32::GetLocal:
    433435        case WASMOpExpressionI32::GetGlobal:
    434436        case WASMOpExpressionI32::SetLocal:
     
    508510        case WASMOpExpressionI32WithImmediate::Immediate:
    509511            return parseImmediateExpressionI32(context, immediate);
     512        case WASMOpExpressionI32WithImmediate::GetLocal:
     513            return parseGetLocalExpressionI32(context, immediate);
    510514        case WASMOpExpressionI32WithImmediate::ConstantPoolIndex:
    511         case WASMOpExpressionI32WithImmediate::GetLocal:
    512515            // FIXME: Implement these instructions.
    513516            FAIL_WITH_MESSAGE("Unsupported instruction.");
     
    534537
    535538template <class Context>
     539ContextExpression WASMFunctionParser::parseGetLocalExpressionI32(Context& context, uint32_t localIndex)
     540{
     541    FAIL_IF_FALSE(localIndex < m_localTypes.size(), "The local index is incorrect.");
     542    FAIL_IF_FALSE(m_localTypes[localIndex] == WASMType::I32, "Expected a local of type int32.");
     543    return context.buildGetLocal(localIndex, WASMType::I32);
     544}
     545
     546template <class Context>
     547ContextExpression WASMFunctionParser::parseGetLocalExpressionI32(Context& context)
     548{
     549    uint32_t localIndex;
     550    READ_COMPACT_UINT32_OR_FAIL(localIndex, "Cannot read the local index.");
     551    return parseGetLocalExpressionI32(context, localIndex);
     552}
     553
     554template <class Context>
    536555ContextExpression WASMFunctionParser::parseBinaryExpressionI32(Context& context, WASMOpExpressionI32 op)
    537556{
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h

    r189303 r189382  
    8181    template <class Context> ContextExpression parseImmediateExpressionI32(Context&, uint32_t immediate);
    8282    template <class Context> ContextExpression parseImmediateExpressionI32(Context&);
     83    template <class Context> ContextExpression parseGetLocalExpressionI32(Context&, uint32_t localIndex);
     84    template <class Context> ContextExpression parseGetLocalExpressionI32(Context&);
    8385    template <class Context> ContextExpression parseBinaryExpressionI32(Context&, WASMOpExpressionI32);
    8486
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h

    r189303 r189382  
    4848    }
    4949
     50    void buildSetLocal(uint32_t, int, WASMType)
     51    {
     52        m_tempStackTop--;
     53    }
     54
    5055    void buildReturn(int, WASMExpressionType returnType)
    5156    {
     
    5560
    5661    int buildImmediateI32(uint32_t)
     62    {
     63        m_tempStackTop++;
     64        updateTempStackHeight();
     65        return UNUSED;
     66    }
     67
     68    int buildGetLocal(uint32_t, WASMType)
    5769    {
    5870        m_tempStackTop++;
Note: See TracChangeset for help on using the changeset viewer.