<!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>[208821] 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/208821">208821</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-11-16 15:34:39 -0800 (Wed, 16 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Wasm function parser should use template functions for each binary and unary opcode
https://bugs.webkit.org/show_bug.cgi?id=164835

Reviewed by Mark Lam.

This patch changes the wasm function parser to call into a template specialization
for each binary/unary opcode. This change makes it easier to have custom implementations
of various opcodes. It is also, in theory a speedup since it does not require switching
on the opcode twice.

* CMakeLists.txt:
* DerivedSources.make:
* wasm/WasmB3IRGenerator.cpp:
(): Deleted.
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser&lt;Context&gt;::binaryCase):
(JSC::Wasm::FunctionParser&lt;Context&gt;::unaryCase):
(JSC::Wasm::FunctionParser&lt;Context&gt;::parseExpression):
* wasm/WasmValidate.cpp:
* wasm/generateWasm.py:
(isBinary):
(isSimple):
* wasm/generateWasmB3IRGeneratorInlinesHeader.py: Added.
(generateSimpleCode):
* wasm/generateWasmOpsHeader.py:
(opcodeMacroizer):
* wasm/generateWasmValidateInlinesHeader.py:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreCMakeListstxt">trunk/Source/JavaScriptCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreDerivedSourcesmake">trunk/Source/JavaScriptCore/DerivedSources.make</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp">trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmFunctionParserh">trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmValidatecpp">trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmgenerateWasmpy">trunk/Source/JavaScriptCore/wasm/generateWasm.py</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmgenerateWasmOpsHeaderpy">trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmgenerateWasmValidateInlinesHeaderpy">trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCorewasmgenerateWasmB3IRGeneratorInlinesHeaderpy">trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/CMakeLists.txt (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/CMakeLists.txt        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/CMakeLists.txt        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -1157,6 +1157,7 @@
</span><span class="cx"> endmacro()
</span><span class="cx"> GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmOpsHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmOps.h)
</span><span class="cx"> GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmValidateInlinesHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmValidateInlines.h)
</span><ins>+GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmB3IRGeneratorInlinesHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmB3IRGeneratorInlines.h)
</ins><span class="cx"> 
</span><span class="cx"> # LUT generator
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-11-16  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        Wasm function parser should use template functions for each binary and unary opcode
+        https://bugs.webkit.org/show_bug.cgi?id=164835
+
+        Reviewed by Mark Lam.
+
+        This patch changes the wasm function parser to call into a template specialization
+        for each binary/unary opcode. This change makes it easier to have custom implementations
+        of various opcodes. It is also, in theory a speedup since it does not require switching
+        on the opcode twice.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * wasm/WasmB3IRGenerator.cpp:
+        (): Deleted.
+        * wasm/WasmFunctionParser.h:
+        (JSC::Wasm::FunctionParser&lt;Context&gt;::binaryCase):
+        (JSC::Wasm::FunctionParser&lt;Context&gt;::unaryCase):
+        (JSC::Wasm::FunctionParser&lt;Context&gt;::parseExpression):
+        * wasm/WasmValidate.cpp:
+        * wasm/generateWasm.py:
+        (isBinary):
+        (isSimple):
+        * wasm/generateWasmB3IRGeneratorInlinesHeader.py: Added.
+        (generateSimpleCode):
+        * wasm/generateWasmOpsHeader.py:
+        (opcodeMacroizer):
+        * wasm/generateWasmValidateInlinesHeader.py:
+
</ins><span class="cx"> 2016-11-16  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ExceptionFuzz functions should use its client's ThrowScope.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreDerivedSourcesmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/DerivedSources.make (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/DerivedSources.make        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/DerivedSources.make        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx">     YarrCanonicalizeUnicode.cpp \
</span><span class="cx">     WasmOps.h \
</span><span class="cx">     WasmValidateInlines.h \
</span><ins>+    WasmB3IRGeneratorInlines.h \
</ins><span class="cx"> #
</span><span class="cx"> 
</span><span class="cx"> # JavaScript builtins.
</span><span class="lines">@@ -306,6 +307,9 @@
</span><span class="cx"> WasmValidateInlines.h: $(JavaScriptCore)/wasm/generateWasmValidateInlinesHeader.py $(JavaScriptCore)/wasm/generateWasm.py $(JavaScriptCore)/wasm/wasm.json
</span><span class="cx">         $(PYTHON) $(JavaScriptCore)/wasm/generateWasmValidateInlinesHeader.py $(JavaScriptCore)/wasm/wasm.json ./WasmValidateInlines.h
</span><span class="cx"> 
</span><ins>+WasmB3IRGeneratorInlines.h: $(JavaScriptCore)/wasm/generateWasmB3IRGeneratorInlinesHeader.py $(JavaScriptCore)/wasm/generateWasm.py $(JavaScriptCore)/wasm/wasm.json
+        $(PYTHON) $(JavaScriptCore)/wasm/generateWasmB3IRGeneratorInlinesHeader.py $(JavaScriptCore)/wasm/wasm.json ./WasmB3IRGeneratorInlines.h
+
</ins><span class="cx"> # Dynamically-defined targets are listed below. Static targets belong up top.
</span><span class="cx"> 
</span><span class="cx"> all : \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmB3IRGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -53,11 +53,11 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC { namespace Wasm {
</span><span class="cx"> 
</span><del>-namespace {
-
</del><span class="cx"> using namespace B3;
</span><span class="cx"> 
</span><ins>+namespace {
</ins><span class="cx"> const bool verbose = false;
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> inline B3::Opcode toB3Op(BinaryOpType op)
</span><span class="cx"> {
</span><span class="lines">@@ -164,8 +164,10 @@
</span><span class="cx">     bool WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
</span><span class="cx"> 
</span><span class="cx">     // Basic operators
</span><del>-    bool WARN_UNUSED_RETURN binaryOp(BinaryOpType, ExpressionType left, ExpressionType right, ExpressionType&amp; result);
-    bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType&amp; result);
</del><ins>+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN addOp(ExpressionType arg, ExpressionType&amp; result);
+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN addOp(ExpressionType left, ExpressionType right, ExpressionType&amp; result);
</ins><span class="cx">     bool WARN_UNUSED_RETURN addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType&amp; result);
</span><span class="cx"> 
</span><span class="cx">     // Control flow
</span><span class="lines">@@ -450,22 +452,6 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool B3IRGenerator::unaryOp(UnaryOpType op, ExpressionType arg, ExpressionType&amp; result)
-{
-    if (!isSimple(op))
-        return false;
-    result = m_currentBlock-&gt;appendNew&lt;Value&gt;(m_proc, toB3Op(op), Origin(), arg);
-    return true;
-}
-
-bool B3IRGenerator::binaryOp(BinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType&amp; result)
-{
-    if (!isSimple(op))
-        return false;
-    result = m_currentBlock-&gt;appendNew&lt;Value&gt;(m_proc, toB3Op(op), Origin(), left, right);
-    return true;
-}
-
</del><span class="cx"> bool B3IRGenerator::addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType&amp; result)
</span><span class="cx"> {
</span><span class="cx">     result = m_currentBlock-&gt;appendNew&lt;Value&gt;(m_proc, B3::Select, Origin(), condition, nonZero, zero);
</span><span class="lines">@@ -675,9 +661,6 @@
</span><span class="cx">     dataLogLn(&quot;\n&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-} // anonymous namespace
-
-
</del><span class="cx"> static std::unique_ptr&lt;Compilation&gt; createJSWrapper(VM&amp; vm, const Signature* signature, MacroAssemblerCodePtr mainFunction, Memory* memory)
</span><span class="cx"> {
</span><span class="cx">     Procedure proc;
</span><span class="lines">@@ -780,4 +763,6 @@
</span><span class="cx"> 
</span><span class="cx"> } } // namespace JSC::Wasm
</span><span class="cx"> 
</span><ins>+#include &quot;WasmB3IRGeneratorInlines.h&quot;
+
</ins><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 (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -65,6 +65,12 @@
</span><span class="cx"> 
</span><span class="cx">     bool WARN_UNUSED_RETURN popExpressionStack(ExpressionType&amp; result);
</span><span class="cx"> 
</span><ins>+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN unaryCase();
+
+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN binaryCase();
+
</ins><span class="cx">     void setErrorMessage(String&amp;&amp; message) { m_context.setErrorMessage(WTFMove(message)); }
</span><span class="cx"> 
</span><span class="cx">     Context&amp; m_context;
</span><span class="lines">@@ -163,40 +169,52 @@
</span><span class="cx">     return m_context.addReturn(returnValues);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#define CREATE_CASE(name, id, b3op) case name:
</del><ins>+template&lt;typename Context&gt;
+template&lt;OpType op&gt;
+bool FunctionParser&lt;Context&gt;::binaryCase()
+{
+    ExpressionType right;
+    if (!popExpressionStack(right))
+        return false;
</ins><span class="cx"> 
</span><ins>+    ExpressionType left;
+    if (!popExpressionStack(left))
+        return false;
+
+    ExpressionType result;
+    if (!m_context.template addOp&lt;op&gt;(left, right, result))
+        return false;
+    m_expressionStack.append(result);
+    return true;
+}
+
</ins><span class="cx"> template&lt;typename Context&gt;
</span><ins>+template&lt;OpType op&gt;
+bool FunctionParser&lt;Context&gt;::unaryCase()
+{
+    ExpressionType value;
+    if (!popExpressionStack(value))
+        return false;
+
+    ExpressionType result;
+    if (!m_context.template addOp&lt;op&gt;(value, result))
+        return false;
+    m_expressionStack.append(result);
+    return true;
+}
+
+template&lt;typename Context&gt;
</ins><span class="cx"> bool FunctionParser&lt;Context&gt;::parseExpression(OpType op)
</span><span class="cx"> {
</span><span class="cx">     switch (op) {
</span><del>-    FOR_EACH_WASM_BINARY_OP(CREATE_CASE) {
-        ExpressionType right;
-        if (!popExpressionStack(right))
-            return false;
</del><ins>+#define CREATE_CASE(name, id, b3op) case OpType::name: return binaryCase&lt;OpType::name&gt;();
+    FOR_EACH_WASM_SIMPLE_BINARY_OP(CREATE_CASE)
+#undef CREATE_CASE
</ins><span class="cx"> 
</span><del>-        ExpressionType left;
-        if (!popExpressionStack(left))
-            return false;
</del><ins>+#define CREATE_CASE(name, id, b3op) case OpType::name: return unaryCase&lt;OpType::name&gt;();
+    FOR_EACH_WASM_SIMPLE_UNARY_OP(CREATE_CASE)
+#undef CREATE_CASE
</ins><span class="cx"> 
</span><del>-        ExpressionType result;
-        if (!m_context.binaryOp(static_cast&lt;BinaryOpType&gt;(op), left, right, result))
-            return false;
-        m_expressionStack.append(result);
-        return true;
-    }
-
-    FOR_EACH_WASM_UNARY_OP(CREATE_CASE) {
-        ExpressionType value;
-        if (!popExpressionStack(value))
-            return false;
-
-        ExpressionType result;
-        if (!m_context.unaryOp(static_cast&lt;UnaryOpType&gt;(op), value, result))
-            return false;
-        m_expressionStack.append(result);
-        return true;
-    }
-
</del><span class="cx">     case OpType::Select: {
</span><span class="cx">         ExpressionType condition;
</span><span class="cx">         if (!popExpressionStack(condition))
</span><span class="lines">@@ -218,6 +236,7 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#define CREATE_CASE(name, id, b3op) case OpType::name:
</ins><span class="cx">     FOR_EACH_WASM_MEMORY_LOAD_OP(CREATE_CASE) {
</span><span class="cx">         uint32_t alignment;
</span><span class="cx">         if (!parseVarUInt32(alignment))
</span><span class="lines">@@ -257,6 +276,7 @@
</span><span class="cx"> 
</span><span class="cx">         return m_context.store(static_cast&lt;StoreOpType&gt;(op), pointer, value, offset);
</span><span class="cx">     }
</span><ins>+#undef CREATE_CASE
</ins><span class="cx"> 
</span><span class="cx">     case OpType::F32Const:
</span><span class="cx">     case OpType::I32Const: {
</span><span class="lines">@@ -454,15 +474,11 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    case OpType::Nop:
-    case OpType::Drop:
-    case OpType::TeeLocal:
-    case OpType::GetGlobal:
-    case OpType::SetGlobal:
-    case OpType::CallIndirect:
</del><ins>+    default: {
</ins><span class="cx">         // FIXME: Not yet implemented.
</span><span class="cx">         return false;
</span><span class="cx">     }
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="cx"> }
</span><span class="lines">@@ -540,8 +556,6 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#undef CREATE_CASE
-
</del><span class="cx"> } } // namespace JSC::Wasm
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(WEBASSEMBLY)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmValidatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -91,8 +91,10 @@
</span><span class="cx">     bool WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
</span><span class="cx"> 
</span><span class="cx">     // Basic operators
</span><del>-    bool WARN_UNUSED_RETURN binaryOp(BinaryOpType, ExpressionType left, ExpressionType right, ExpressionType&amp; result);
-    bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType&amp; result);
</del><ins>+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN addOp(ExpressionType arg, ExpressionType&amp; result);
+    template&lt;OpType&gt;
+    bool WARN_UNUSED_RETURN addOp(ExpressionType left, ExpressionType right, ExpressionType&amp; result);
</ins><span class="cx">     bool WARN_UNUSED_RETURN addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType&amp; result);
</span><span class="cx"> 
</span><span class="cx">     // Control flow
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmgenerateWasmpy"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/generateWasm.py (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/generateWasm.py        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/generateWasm.py        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -28,7 +28,6 @@
</span><span class="cx"> import json
</span><span class="cx"> import re
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> class Wasm:
</span><span class="cx">     def __init__(self, scriptName, jsonPath):
</span><span class="cx">         wasmFile = open(jsonPath, &quot;r&quot;)
</span><span class="lines">@@ -86,3 +85,7 @@
</span><span class="cx"> 
</span><span class="cx"> def isBinary(op):
</span><span class="cx">     return isNormal(op) and len(op[&quot;parameter&quot;]) == 2
</span><ins>+
+
+def isSimple(op):
+    return &quot;b3op&quot; in op
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmgenerateWasmB3IRGeneratorInlinesHeaderpy"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py (0 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py                                (rev 0)
+++ trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -0,0 +1,74 @@
</span><ins>+#!/usr/bin/env python
+
+# Copyright (C) 2016 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:n
+#
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# This tool has a couple of helpful macros to process Wasm files from the wasm.json.
+
+from generateWasm import *
+import optparse
+import sys
+
+parser = optparse.OptionParser(usage=&quot;usage: %prog &lt;wasm.json&gt; &lt;WasmOps.h&gt;&quot;)
+(options, args) = parser.parse_args(sys.argv[0:])
+if len(args) != 3:
+    parser.error(parser.usage)
+
+wasm = Wasm(args[0], args[1])
+opcodes = wasm.opcodes
+wasmB3IRGeneratorHFile = open(args[2], &quot;w&quot;)
+
+
+def generateSimpleCode(op):
+    opcode = op[&quot;opcode&quot;]
+    b3op = opcode[&quot;b3op&quot;]
+    args = [&quot;ExpressionType arg&quot; + str(param) for param in range(len(opcode[&quot;parameter&quot;]))]
+    args.append(&quot;ExpressionType&amp; result&quot;)
+    params = [&quot;arg&quot; + str(param) for param in range(len(opcode[&quot;parameter&quot;]))]
+    return &quot;&quot;&quot;
+template&lt;&gt; bool B3IRGenerator::addOp&lt;OpType::&quot;&quot;&quot; + wasm.toCpp(op[&quot;name&quot;]) + &quot;&gt;(&quot; + &quot;, &quot;.join(args) + &quot;&quot;&quot;)
+{
+    result = m_currentBlock-&gt;appendNew&lt;Value&gt;(m_proc, B3::&quot;&quot;&quot; + opcode[&quot;b3op&quot;] + &quot;, Origin(), &quot; + &quot;, &quot;.join(params) + &quot;&quot;&quot;);
+    return true;
+}
+&quot;&quot;&quot;
+
+definitions = [generateSimpleCode(op) for op in wasm.opcodeIterator(lambda op: isSimple(op) and (isBinary(op) or isUnary(op)))]
+contents = wasm.header + &quot;&quot;&quot;
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC { namespace Wasm {
+
+&quot;&quot;&quot; + &quot;&quot;.join(definitions) + &quot;&quot;&quot;
+
+} } // namespace JSC::Wasm
+
+#endif // ENABLE(WEBASSEMBLY)
+
+&quot;&quot;&quot;
+
+wasmB3IRGeneratorHFile.write(contents)
+wasmB3IRGeneratorHFile.close()
</ins><span class="cx">Property changes on: trunk/Source/JavaScriptCore/wasm/generateWasmB3IRGeneratorInlinesHeader.py
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnexecutable"></a>
<div class="addfile"><h4>Added: svn:executable</h4></div>
<ins>+*
</ins><span class="cx">\ No newline at end of property
</span><a id="trunkSourceJavaScriptCorewasmgenerateWasmOpsHeaderpy"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/generateWasmOpsHeader.py        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> def opcodeMacroizer(filter):
</span><span class="cx">     for op in wasm.opcodeIterator(filter):
</span><span class="cx">         b3op = &quot;Oops&quot;
</span><del>-        if &quot;b3op&quot; in op[&quot;opcode&quot;]:
</del><ins>+        if isSimple(op[&quot;opcode&quot;]):
</ins><span class="cx">             b3op = op[&quot;opcode&quot;][&quot;b3op&quot;]
</span><span class="cx">         yield cppMacro(op[&quot;name&quot;], op[&quot;opcode&quot;][&quot;value&quot;], b3op)
</span><span class="cx"> 
</span><span class="lines">@@ -55,13 +55,13 @@
</span><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro)&quot;)
</span><span class="cx"> defines.extend([op for op in opcodeMacroizer(lambda op: op[&quot;category&quot;] == &quot;control&quot;)])
</span><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_SIMPLE_UNARY_OP(macro)&quot;)
</span><del>-defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and &quot;b3op&quot; in op)])
</del><ins>+defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and isSimple(op))])
</ins><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_UNARY_OP(macro) \\\n    FOR_EACH_WASM_SIMPLE_UNARY_OP(macro)&quot;)
</span><del>-defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and not (&quot;b3op&quot; in op))])
</del><ins>+defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and not (isSimple(op)))])
</ins><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_SIMPLE_BINARY_OP(macro)&quot;)
</span><del>-defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and &quot;b3op&quot; in op)])
</del><ins>+defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and isSimple(op))])
</ins><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_BINARY_OP(macro) \\\n    FOR_EACH_WASM_SIMPLE_BINARY_OP(macro)&quot;)
</span><del>-defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and not (&quot;b3op&quot; in op))])
</del><ins>+defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and not (isSimple(op)))])
</ins><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_MEMORY_LOAD_OP(macro)&quot;)
</span><span class="cx"> defines.extend([op for op in opcodeMacroizer(lambda op: (op[&quot;category&quot;] == &quot;memory&quot; and len(op[&quot;return&quot;]) == 1))])
</span><span class="cx"> defines.append(&quot;\n\n#define FOR_EACH_WASM_MEMORY_STORE_OP(macro)&quot;)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmgenerateWasmValidateInlinesHeaderpy"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py (208820 => 208821)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py        2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py        2016-11-16 23:34:39 UTC (rev 208821)
</span><span class="lines">@@ -60,36 +60,39 @@
</span><span class="cx"> def unaryMacro(name):
</span><span class="cx">     op = opcodes[name]
</span><span class="cx">     return &quot;&quot;&quot;
</span><del>-    case UnaryOpType::&quot;&quot;&quot; + toCpp(name) + &quot;&quot;&quot;: {
-        if (value != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;) {
-            m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(value));
-            return false;
-        }
</del><ins>+template&lt;&gt; bool Validate::addOp&lt;OpType::&quot;&quot;&quot; + toCpp(name) + &quot;&quot;&quot;&gt;(ExpressionType value, ExpressionType&amp; result)
+{
+    if (value != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;) {
+        m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(value));
+        return false;
+    }
</ins><span class="cx"> 
</span><del>-        result = &quot;&quot;&quot; + cppType(op[&quot;return&quot;][0]) + &quot;&quot;&quot;;
-        return true;
-    }&quot;&quot;&quot;
</del><ins>+    result = &quot;&quot;&quot; + cppType(op[&quot;return&quot;][0]) + &quot;&quot;&quot;;
+    return true;
+}
+&quot;&quot;&quot;
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> def binaryMacro(name):
</span><span class="cx">     op = opcodes[name]
</span><span class="cx">     return &quot;&quot;&quot;
</span><del>-    case BinaryOpType::&quot;&quot;&quot; + toCpp(name) + &quot;&quot;&quot;: {
-        if (left != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;) {
-            m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the left value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(left));
-            return false;
-        }
</del><ins>+template&lt;&gt; bool Validate::addOp&lt;OpType::&quot;&quot;&quot; + toCpp(name) + &quot;&quot;&quot;&gt;(ExpressionType left, ExpressionType right, ExpressionType&amp; result)
+{
+    if (left != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;) {
+        m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the left value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(left));
+        return false;
+    }
</ins><span class="cx"> 
</span><del>-        if (right != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][1]) + &quot;&quot;&quot;) {
-            m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the right value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(right));
-            return false;
-        }
</del><ins>+    if (right != &quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][1]) + &quot;&quot;&quot;) {
+        m_errorMessage = makeString(\&quot;&quot;&quot;&quot; + name + &quot;&quot;&quot; expects the right value to be of type: &quot;, toString(&quot;&quot;&quot; + cppType(op[&quot;parameter&quot;][0]) + &quot;&quot;&quot;), &quot; but got a value with type: &quot;, toString(right));
+        return false;
+    }
</ins><span class="cx"> 
</span><del>-        result = &quot;&quot;&quot; + cppType(op[&quot;return&quot;][0]) + &quot;&quot;&quot;;
-        return true;
-    }&quot;&quot;&quot;
</del><ins>+    result = &quot;&quot;&quot; + cppType(op[&quot;return&quot;][0]) + &quot;&quot;&quot;;
+    return true;
+}
+&quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-
</del><span class="cx"> def loadMacro(name):
</span><span class="cx">     op = opcodes[name]
</span><span class="cx">     return &quot;&quot;&quot;
</span><span class="lines">@@ -122,8 +125,8 @@
</span><span class="cx">     }&quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-unaryCases = &quot;&quot;.join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
-binaryCases = &quot;&quot;.join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
</del><ins>+unarySpecializations = &quot;&quot;.join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
+binarySpecializations = &quot;&quot;.join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
</ins><span class="cx"> loadCases = &quot;&quot;.join([op for op in wasm.opcodeIterator(lambda op: op[&quot;category&quot;] == &quot;memory&quot; and len(op[&quot;return&quot;]) == 1, loadMacro)])
</span><span class="cx"> storeCases = &quot;&quot;.join([op for op in wasm.opcodeIterator(lambda op: op[&quot;category&quot;] == &quot;memory&quot; and len(op[&quot;return&quot;]) == 0, storeMacro)])
</span><span class="cx"> 
</span><span class="lines">@@ -136,20 +139,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC { namespace Wasm {
</span><span class="cx"> 
</span><del>-bool Validate::unaryOp(UnaryOpType op, ExpressionType value, ExpressionType&amp; result)
-{
-    switch (op) {
-&quot;&quot;&quot; + unaryCases + &quot;&quot;&quot;
-    }
-}
</del><ins>+&quot;&quot;&quot; + unarySpecializations + binarySpecializations + &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-bool Validate::binaryOp(BinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType&amp; result)
-{
-    switch (op) {
-&quot;&quot;&quot; + binaryCases + &quot;&quot;&quot;
-    }
-}
-
</del><span class="cx"> bool Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType&amp; result, uint32_t)
</span><span class="cx"> {
</span><span class="cx">     switch (op) {
</span></span></pre>
</div>
</div>

</body>
</html>