<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189563] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189563">189563</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-09-09 18:43:20 -0700 (Wed, 09 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement internal calls in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=148998

Patch by Sukolsak Sakshuwong &lt;sukolsak@gmail.com&gt; on 2015-09-09
Reviewed by Filip Pizlo.

This patch implements internal calls to functions that return a 32-bit
integer in WebAssembly.

* tests/stress/wasm-calls.js: Added.
(shouldBe):
* tests/stress/wasm/calls.wasm: Added.
* wasm/WASMFunctionCompiler.h:
(JSC::WASMFunctionCompiler::WASMFunctionCompiler):
(JSC::WASMFunctionCompiler::endFunction):
(JSC::WASMFunctionCompiler::buildCallInternal):
(JSC::WASMFunctionCompiler::appendExpressionList):
(JSC::WASMFunctionCompiler::emitNakedCall):
(JSC::WASMFunctionCompiler::boxArgumentsAndAdjustStackPointer):
(JSC::WASMFunctionCompiler::callAndUnboxResult):
* wasm/WASMFunctionParser.cpp:
(JSC::WASMFunctionParser::compile):
(JSC::WASMFunctionParser::parseExpressionI32):
(JSC::WASMFunctionParser::parseCallInternalExpressionI32):
(JSC::WASMFunctionParser::parseCallArguments):
(JSC::WASMFunctionParser::parseCallInternal):
* wasm/WASMFunctionParser.h:
* wasm/WASMFunctionSyntaxChecker.h:
(JSC::WASMFunctionSyntaxChecker::buildCallInternal):
(JSC::WASMFunctionSyntaxChecker::appendExpressionList):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionCompilerh">trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParsercpp">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionParserh">trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerh">trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstresswasmcallswasm">trunk/Source/JavaScriptCore/tests/stress/wasm/calls.wasm</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresswasmcallsjs">trunk/Source/JavaScriptCore/tests/stress/wasm-calls.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189562 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-09-10 01:38:34 UTC (rev 189562)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-09-09  Sukolsak Sakshuwong  &lt;sukolsak@gmail.com&gt;
+
+        Implement internal calls in WebAssembly
+        https://bugs.webkit.org/show_bug.cgi?id=148998
+
+        Reviewed by Filip Pizlo.
+
+        This patch implements internal calls to functions that return a 32-bit
+        integer in WebAssembly.
+
+        * tests/stress/wasm-calls.js: Added.
+        (shouldBe):
+        * tests/stress/wasm/calls.wasm: Added.
+        * wasm/WASMFunctionCompiler.h:
+        (JSC::WASMFunctionCompiler::WASMFunctionCompiler):
+        (JSC::WASMFunctionCompiler::endFunction):
+        (JSC::WASMFunctionCompiler::buildCallInternal):
+        (JSC::WASMFunctionCompiler::appendExpressionList):
+        (JSC::WASMFunctionCompiler::emitNakedCall):
+        (JSC::WASMFunctionCompiler::boxArgumentsAndAdjustStackPointer):
+        (JSC::WASMFunctionCompiler::callAndUnboxResult):
+        * wasm/WASMFunctionParser.cpp:
+        (JSC::WASMFunctionParser::compile):
+        (JSC::WASMFunctionParser::parseExpressionI32):
+        (JSC::WASMFunctionParser::parseCallInternalExpressionI32):
+        (JSC::WASMFunctionParser::parseCallArguments):
+        (JSC::WASMFunctionParser::parseCallInternal):
+        * wasm/WASMFunctionParser.h:
+        * wasm/WASMFunctionSyntaxChecker.h:
+        (JSC::WASMFunctionSyntaxChecker::buildCallInternal):
+        (JSC::WASMFunctionSyntaxChecker::appendExpressionList):
+
</ins><span class="cx"> 2015-09-09  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r189522.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresswasmcallswasm"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/wasm/calls.wasm (0 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/wasm/calls.wasm                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/wasm/calls.wasm        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+wasm\xDC\x808\xC0\xA1\xA1\xC0\xA1\xC0\xA2\x80.\xC1\xA0\xC0\xC1#\xC0\xC1\x80! \xC0\xC1\xC0\xC1fibonaccigcdlcm
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresswasmcallsjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/wasm-calls.js (0 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/wasm-calls.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/wasm-calls.js        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -0,0 +1,47 @@
</span><ins>+//@ skip
+
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+/*
+wasm/calls.wasm is generated by pack-asmjs &lt;https://github.com/WebAssembly/polyfill-prototype-1&gt; from the following script:
+
+function asmModule(global, env, buffer) {
+    &quot;use asm&quot;;
+
+    function fibonacci(x) {
+        x = x | 0;
+        if ((x | 0) &lt;= 1)
+            return 1;
+        return ((fibonacci((x - 1) | 0) | 0) + (fibonacci((x - 2) | 0) | 0)) | 0;
+    }
+
+    function gcd(x, y) {
+        x = x | 0;
+        y = y | 0;
+        if (y == 0)
+            return x;
+        return gcd(y, (x | 0) % (y | 0)) | 0;
+    }
+
+    function lcm(x, y) {
+        x = x | 0;
+        y = y | 0;
+        return (((x * y) | 0) / (gcd(x, y) | 0)) | 0;
+    }
+
+    return {
+        fibonacci: fibonacci,
+        gcd: gcd,
+        lcm: lcm,
+    };
+}
+*/
+
+var module = loadWebAssembly(&quot;wasm/calls.wasm&quot;);
+
+shouldBe(module.fibonacci(10), 89);
+shouldBe(module.gcd(15, 25), 5);
+shouldBe(module.lcm(15, 25), 75);
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionCompilerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h (189562 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h        2015-09-10 01:38:34 UTC (rev 189562)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if ENABLE(WEBASSEMBLY)
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CCallHelpers.h&quot;
</span><ins>+#include &quot;JIT.h&quot;
</ins><span class="cx"> #include &quot;JITOperations.h&quot;
</span><span class="cx"> #include &quot;LinkBuffer.h&quot;
</span><span class="cx"> #include &quot;MaxFrameExtentForSlowPathCall.h&quot;
</span><span class="lines">@@ -63,14 +64,16 @@
</span><span class="cx"> public:
</span><span class="cx">     typedef int Expression;
</span><span class="cx">     typedef int Statement;
</span><ins>+    typedef int ExpressionList;
</ins><span class="cx">     struct JumpTarget {
</span><span class="cx">         Label label;
</span><span class="cx">         JumpList jumpList;
</span><span class="cx">     };
</span><span class="cx">     enum class JumpCondition { Zero, NonZero };
</span><span class="cx"> 
</span><del>-    WASMFunctionCompiler(VM&amp; vm, CodeBlock* codeBlock, unsigned stackHeight)
</del><ins>+    WASMFunctionCompiler(VM&amp; vm, CodeBlock* codeBlock, JSWASMModule* module, unsigned stackHeight)
</ins><span class="cx">         : CCallHelpers(&amp;vm, codeBlock)
</span><ins>+        , m_module(module)
</ins><span class="cx">         , m_stackHeight(stackHeight)
</span><span class="cx">     {
</span><span class="cx">     }
</span><span class="lines">@@ -171,9 +174,17 @@
</span><span class="cx"> 
</span><span class="cx">         LinkBuffer patchBuffer(*m_vm, *this, m_codeBlock, JITCompilationMustSucceed);
</span><span class="cx"> 
</span><del>-        for (auto iterator : m_calls)
</del><ins>+        for (const auto&amp; iterator : m_calls)
</ins><span class="cx">             patchBuffer.link(iterator.first, FunctionPtr(iterator.second));
</span><span class="cx"> 
</span><ins>+        for (size_t i = 0; i &lt; m_callCompilationInfo.size(); ++i) {
+            CallCompilationInfo&amp; compilationInfo = m_callCompilationInfo[i];
+            CallLinkInfo&amp; info = *compilationInfo.callLinkInfo;
+            info.setCallLocations(patchBuffer.locationOfNearCall(compilationInfo.callReturnLocation),
+                patchBuffer.locationOf(compilationInfo.hotPathBegin),
+                patchBuffer.locationOfNearCall(compilationInfo.hotPathOther));
+        }
+
</ins><span class="cx">         MacroAssemblerCodePtr withArityCheck = patchBuffer.locationOf(arityCheck);
</span><span class="cx">         CodeRef result = FINALIZE_CODE(patchBuffer, (&quot;Baseline JIT code for WebAssembly&quot;));
</span><span class="cx">         m_codeBlock-&gt;setJITCode(adoptRef(new DirectJITCode(result, withArityCheck, JITCode::BaselineJIT)));
</span><span class="lines">@@ -475,6 +486,19 @@
</span><span class="cx">         return UNUSED;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    int buildCallInternal(uint32_t functionIndex, int, const WASMSignature&amp; signature, WASMExpressionType returnType)
+    {
+        boxArgumentsAndAdjustStackPointer(signature.arguments);
+
+        JSFunction* function = m_module-&gt;functions()[functionIndex].get();
+        move(TrustedImmPtr(function), GPRInfo::regT0);
+
+        callAndUnboxResult(returnType);
+        return UNUSED;
+    }
+
+    void appendExpressionList(int&amp;, int) { }
+
</ins><span class="cx">     void linkTarget(JumpTarget&amp; target)
</span><span class="cx">     {
</span><span class="cx">         target.label = label();
</span><span class="lines">@@ -588,6 +612,13 @@
</span><span class="cx">         m_exceptionChecks.append(emitExceptionCheck());
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    Call emitNakedCall(CodePtr function)
+    {
+        Call nakedCall = nearCall();
+        m_calls.append(std::make_pair(nakedCall, function.executableAddress()));
+        return nakedCall;
+    }
+
</ins><span class="cx">     void callOperation(int32_t JIT_OPERATION (*operation)(int32_t, int32_t), GPRReg src1, GPRReg src2, GPRReg dst)
</span><span class="cx">     {
</span><span class="cx">         setupArguments(src1, src2);
</span><span class="lines">@@ -602,6 +633,77 @@
</span><span class="cx">         move(GPRInfo::returnValueGPR, dst);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void boxArgumentsAndAdjustStackPointer(const Vector&lt;WASMType&gt;&amp; arguments)
+    {
+        size_t argumentCount = arguments.size();
+        int stackOffset = -WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_numberOfLocals + m_tempStackTop + argumentCount + 1 + JSStack::CallFrameHeaderSize);
+
+        storeTrustedValue(jsUndefined(), Address(GPRInfo::callFrameRegister, (stackOffset + CallFrame::thisArgumentOffset()) * sizeof(Register)));
+
+        for (size_t i = 0; i &lt; argumentCount; ++i) {
+            Address address(GPRInfo::callFrameRegister, (stackOffset + CallFrame::argumentOffset(i)) * sizeof(Register));
+            switch (arguments[i]) {
+            case WASMType::I32:
+                load32(temporaryAddress(m_tempStackTop - argumentCount + i), GPRInfo::regT0);
+#if USE(JSVALUE64)
+                or64(GPRInfo::tagTypeNumberRegister, GPRInfo::regT0);
+                store64(GPRInfo::regT0, address);
+#else
+                store32(GPRInfo::regT0, address.withOffset(PayloadOffset));
+                store32(TrustedImm32(JSValue::Int32Tag), address.withOffset(TagOffset));
+#endif
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+        }
+        m_tempStackTop -= argumentCount;
+
+        addPtr(TrustedImm32(stackOffset * sizeof(Register) + sizeof(CallerFrameAndPC)), GPRInfo::callFrameRegister, stackPointerRegister);
+        store32(TrustedImm32(argumentCount + 1), Address(stackPointerRegister, JSStack::ArgumentCount * static_cast&lt;int&gt;(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC)));
+    }
+
+    void callAndUnboxResult(WASMExpressionType returnType)
+    {
+        // regT0 holds callee.
+#if USE(JSVALUE64)
+        store64(GPRInfo::regT0, Address(stackPointerRegister, JSStack::Callee * static_cast&lt;int&gt;(sizeof(Register)) - sizeof(CallerFrameAndPC)));
+#else
+        store32(regT0, Address(stackPointerRegister, JSStack::Callee * static_cast&lt;int&gt;(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC)));
+        store32(TrustedImm32(CellTag), Address(stackPointerRegister, JSStack::Callee * static_cast&lt;int&gt;(sizeof(Register)) + TagOffset - sizeof(CallerFrameAndPC)));
+#endif
+
+        DataLabelPtr addressOfLinkedFunctionCheck;
+        Jump slowCase = branchPtrWithPatch(NotEqual, GPRInfo::regT0, addressOfLinkedFunctionCheck, TrustedImmPtr(0));
+
+        CallLinkInfo* info = m_codeBlock-&gt;addCallLinkInfo();
+        info-&gt;setUpCall(CallLinkInfo::Call, CodeOrigin(), GPRInfo::regT0);
+        m_callCompilationInfo.append(CallCompilationInfo());
+        m_callCompilationInfo.last().hotPathBegin = addressOfLinkedFunctionCheck;
+        m_callCompilationInfo.last().callLinkInfo = info;
+        m_callCompilationInfo.last().hotPathOther = nearCall();
+        Jump end = jump();
+
+        slowCase.link(this);
+        move(TrustedImmPtr(info), GPRInfo::regT2);
+        m_callCompilationInfo.last().callReturnLocation = emitNakedCall(m_vm-&gt;getCTIStub(linkCallThunkGenerator).code());
+
+        end.link(this);
+        addPtr(TrustedImm32(-WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_stackHeight) * sizeof(StackSlot)), GPRInfo::callFrameRegister, stackPointerRegister);
+        checkStackPointerAlignment();
+
+        switch (returnType) {
+        case WASMExpressionType::I32:
+            store32(GPRInfo::returnValueGPR, temporaryAddress(m_tempStackTop++));
+            break;
+        case WASMExpressionType::Void:
+            break;
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
+
+    JSWASMModule* m_module;
</ins><span class="cx">     unsigned m_stackHeight;
</span><span class="cx">     unsigned m_numberOfLocals;
</span><span class="cx">     unsigned m_tempStackTop { 0 };
</span><span class="lines">@@ -617,6 +719,7 @@
</span><span class="cx">     JumpList m_exceptionChecks;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;std::pair&lt;Call, void*&gt;&gt; m_calls;
</span><ins>+    Vector&lt;CallCompilationInfo&gt; m_callCompilationInfo;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp (189562 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-09-10 01:38:34 UTC (rev 189562)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx"> void WASMFunctionParser::compile(VM&amp; vm, CodeBlock* codeBlock, JSWASMModule* module, const SourceCode&amp; source, size_t functionIndex)
</span><span class="cx"> {
</span><span class="cx">     WASMFunctionParser parser(module, source, functionIndex);
</span><del>-    WASMFunctionCompiler compiler(vm, codeBlock, module-&gt;functionStackHeights()[functionIndex]);
</del><ins>+    WASMFunctionCompiler compiler(vm, codeBlock, module, module-&gt;functionStackHeights()[functionIndex]);
</ins><span class="cx">     parser.m_reader.setOffset(module-&gt;functionStartOffsetsInSource()[functionIndex]);
</span><span class="cx">     parser.parseFunction(compiler);
</span><span class="cx">     ASSERT(parser.m_errorMessage.isNull());
</span><span class="lines">@@ -474,6 +474,8 @@
</span><span class="cx">             return parseImmediateExpressionI32(context);
</span><span class="cx">         case WASMOpExpressionI32::GetLocal:
</span><span class="cx">             return parseGetLocalExpressionI32(context);
</span><ins>+        case WASMOpExpressionI32::CallInternal:
+            return parseCallInternalExpressionI32(context);
</ins><span class="cx">         case WASMOpExpressionI32::Negate:
</span><span class="cx">         case WASMOpExpressionI32::BitNot:
</span><span class="cx">         case WASMOpExpressionI32::CountLeadingZeros:
</span><span class="lines">@@ -531,7 +533,6 @@
</span><span class="cx">         case WASMOpExpressionI32::StoreWithOffset16:
</span><span class="cx">         case WASMOpExpressionI32::Store32:
</span><span class="cx">         case WASMOpExpressionI32::StoreWithOffset32:
</span><del>-        case WASMOpExpressionI32::CallInternal:
</del><span class="cx">         case WASMOpExpressionI32::CallIndirect:
</span><span class="cx">         case WASMOpExpressionI32::CallImport:
</span><span class="cx">         case WASMOpExpressionI32::Conditional:
</span><span class="lines">@@ -614,6 +615,12 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template &lt;class Context&gt;
</span><ins>+ContextExpression WASMFunctionParser::parseCallInternalExpressionI32(Context&amp; context)
+{
+    return parseCallInternal(context, WASMExpressionType::I32);
+}
+
+template &lt;class Context&gt;
</ins><span class="cx"> ContextExpression WASMFunctionParser::parseUnaryExpressionI32(Context&amp; context, WASMOpExpressionI32 op)
</span><span class="cx"> {
</span><span class="cx">     ContextExpression expression = parseExpressionI32(context);
</span><span class="lines">@@ -761,6 +768,32 @@
</span><span class="cx">     return parseGetLocalExpressionF64(context, localIndex);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template &lt;class Context&gt;
+ContextExpressionList WASMFunctionParser::parseCallArguments(Context&amp; context, const Vector&lt;WASMType&gt;&amp; arguments)
+{
+    ContextExpressionList argumentList;
+    for (size_t i = 0; i &lt; arguments.size(); ++i) {
+        ContextExpression expression = parseExpression(context, WASMExpressionType(arguments[i]));
+        PROPAGATE_ERROR();
+        context.appendExpressionList(argumentList, expression);
+    }
+    return argumentList;
+}
+
+template &lt;class Context&gt;
+ContextExpression WASMFunctionParser::parseCallInternal(Context&amp; context, WASMExpressionType returnType)
+{
+    uint32_t functionIndex;
+    READ_COMPACT_UINT32_OR_FAIL(functionIndex, &quot;Cannot read the function index.&quot;);
+    FAIL_IF_FALSE(functionIndex &lt; m_module-&gt;functionDeclarations().size(), &quot;The function index is incorrect.&quot;);
+    const WASMSignature&amp; signature = m_module-&gt;signatures()[m_module-&gt;functionDeclarations()[functionIndex].signatureIndex];
+    FAIL_IF_FALSE(signature.returnType == returnType, &quot;Wrong return type.&quot;);
+
+    ContextExpressionList argumentList = parseCallArguments(context, signature.arguments);
+    PROPAGATE_ERROR();
+    return context.buildCallInternal(functionIndex, argumentList, signature, returnType);
+}
+
</ins><span class="cx"> } // namespace JSC
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h (189562 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-09-10 01:38:34 UTC (rev 189562)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx"> 
</span><span class="cx"> #define ContextExpression typename Context::Expression
</span><span class="cx"> #define ContextStatement typename Context::Statement
</span><ins>+#define ContextExpressionList typename Context::ExpressionList
</ins><span class="cx"> #define ContextJumpTarget typename Context::JumpTarget
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="lines">@@ -85,6 +86,7 @@
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseImmediateExpressionI32(Context&amp;);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseGetLocalExpressionI32(Context&amp;, uint32_t localIndex);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseGetLocalExpressionI32(Context&amp;);
</span><ins>+    template &lt;class Context&gt; ContextExpression parseCallInternalExpressionI32(Context&amp;);
</ins><span class="cx">     template &lt;class Context&gt; ContextExpression parseUnaryExpressionI32(Context&amp;, WASMOpExpressionI32);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseBinaryExpressionI32(Context&amp;, WASMOpExpressionI32);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseRelationalI32ExpressionI32(Context&amp;, WASMOpExpressionI32);
</span><span class="lines">@@ -97,6 +99,9 @@
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseGetLocalExpressionF64(Context&amp;, uint32_t localIndex);
</span><span class="cx">     template &lt;class Context&gt; ContextExpression parseGetLocalExpressionF64(Context&amp;);
</span><span class="cx"> 
</span><ins>+    template &lt;class Context&gt; ContextExpressionList parseCallArguments(Context&amp;, const Vector&lt;WASMType&gt;&amp; arguments);
+    template &lt;class Context&gt; ContextExpression parseCallInternal(Context&amp;, WASMExpressionType returnType);
+
</ins><span class="cx">     JSWASMModule* m_module;
</span><span class="cx">     WASMReader m_reader;
</span><span class="cx">     size_t m_functionIndex;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWASMFunctionSyntaxCheckerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h (189562 => 189563)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h        2015-09-10 01:38:34 UTC (rev 189562)
+++ trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h        2015-09-10 01:43:20 UTC (rev 189563)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> public:
</span><span class="cx">     typedef int Expression;
</span><span class="cx">     typedef int Statement;
</span><ins>+    typedef int ExpressionList;
</ins><span class="cx">     typedef int JumpTarget;
</span><span class="cx">     enum class JumpCondition { Zero, NonZero };
</span><span class="cx"> 
</span><span class="lines">@@ -104,6 +105,25 @@
</span><span class="cx">         return UNUSED;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    int buildCallInternal(uint32_t, int, const WASMSignature&amp; signature, WASMExpressionType returnType)
+    {
+        size_t argumentCount = signature.arguments.size();
+
+        // Boxed arguments + this argument + call frame header + padding.
+        m_tempStackTop += argumentCount + 1 + JSStack::CallFrameHeaderSize + 1;
+        updateTempStackHeight();
+        m_tempStackTop -= argumentCount + 1 + JSStack::CallFrameHeaderSize + 1;
+
+        m_tempStackTop -= argumentCount;
+        if (returnType != WASMExpressionType::Void) {
+            m_tempStackTop++;
+            updateTempStackHeight();
+        }
+        return UNUSED;
+    }
+
+    void appendExpressionList(int&amp;, int) { }
+
</ins><span class="cx">     void linkTarget(const int&amp;) { }
</span><span class="cx">     void jumpToTarget(const int&amp;) { }
</span><span class="cx">     void jumpToTargetIf(JumpCondition, int, const int&amp;)
</span></span></pre>
</div>
</div>

</body>
</html>