Title: [208821] trunk/Source/_javascript_Core
Revision
208821
Author
[email protected]
Date
2016-11-16 15:34:39 -0800 (Wed, 16 Nov 2016)

Log Message

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<Context>::binaryCase):
(JSC::Wasm::FunctionParser<Context>::unaryCase):
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* wasm/WasmValidate.cpp:
* wasm/generateWasm.py:
(isBinary):
(isSimple):
* wasm/generateWasmB3IRGeneratorInlinesHeader.py: Added.
(generateSimpleCode):
* wasm/generateWasmOpsHeader.py:
(opcodeMacroizer):
* wasm/generateWasmValidateInlinesHeader.py:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (208820 => 208821)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2016-11-16 23:34:39 UTC (rev 208821)
@@ -1157,6 +1157,7 @@
 endmacro()
 GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmOpsHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmOps.h)
 GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmValidateInlinesHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmValidateInlines.h)
+GENERATE_PYTHON(${CMAKE_CURRENT_SOURCE_DIR}/wasm/generateWasmB3IRGeneratorInlinesHeader.py ${CMAKE_CURRENT_SOURCE_DIR}/wasm/wasm.json ${DERIVED_SOURCES_JAVASCRIPTCORE_DIR}/WasmB3IRGeneratorInlines.h)
 
 # LUT generator
 

Modified: trunk/Source/_javascript_Core/ChangeLog (208820 => 208821)


--- trunk/Source/_javascript_Core/ChangeLog	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-11-16 23:34:39 UTC (rev 208821)
@@ -1,3 +1,33 @@
+2016-11-16  Keith Miller  <[email protected]>
+
+        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<Context>::binaryCase):
+        (JSC::Wasm::FunctionParser<Context>::unaryCase):
+        (JSC::Wasm::FunctionParser<Context>::parseExpression):
+        * wasm/WasmValidate.cpp:
+        * wasm/generateWasm.py:
+        (isBinary):
+        (isSimple):
+        * wasm/generateWasmB3IRGeneratorInlinesHeader.py: Added.
+        (generateSimpleCode):
+        * wasm/generateWasmOpsHeader.py:
+        (opcodeMacroizer):
+        * wasm/generateWasmValidateInlinesHeader.py:
+
 2016-11-16  Mark Lam  <[email protected]>
 
         ExceptionFuzz functions should use its client's ThrowScope.

Modified: trunk/Source/_javascript_Core/DerivedSources.make (208820 => 208821)


--- trunk/Source/_javascript_Core/DerivedSources.make	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/DerivedSources.make	2016-11-16 23:34:39 UTC (rev 208821)
@@ -65,6 +65,7 @@
     YarrCanonicalizeUnicode.cpp \
     WasmOps.h \
     WasmValidateInlines.h \
+    WasmB3IRGeneratorInlines.h \
 #
 
 # _javascript_ builtins.
@@ -306,6 +307,9 @@
 WasmValidateInlines.h: $(_javascript_Core)/wasm/generateWasmValidateInlinesHeader.py $(_javascript_Core)/wasm/generateWasm.py $(_javascript_Core)/wasm/wasm.json
 	$(PYTHON) $(_javascript_Core)/wasm/generateWasmValidateInlinesHeader.py $(_javascript_Core)/wasm/wasm.json ./WasmValidateInlines.h
 
+WasmB3IRGeneratorInlines.h: $(_javascript_Core)/wasm/generateWasmB3IRGeneratorInlinesHeader.py $(_javascript_Core)/wasm/generateWasm.py $(_javascript_Core)/wasm/wasm.json
+	$(PYTHON) $(_javascript_Core)/wasm/generateWasmB3IRGeneratorInlinesHeader.py $(_javascript_Core)/wasm/wasm.json ./WasmB3IRGeneratorInlines.h
+
 # Dynamically-defined targets are listed below. Static targets belong up top.
 
 all : \

Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2016-11-16 23:34:39 UTC (rev 208821)
@@ -53,11 +53,11 @@
 
 namespace JSC { namespace Wasm {
 
-namespace {
-
 using namespace B3;
 
+namespace {
 const bool verbose = false;
+}
 
 inline B3::Opcode toB3Op(BinaryOpType op)
 {
@@ -164,8 +164,10 @@
     bool WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
 
     // Basic operators
-    bool WARN_UNUSED_RETURN binaryOp(BinaryOpType, ExpressionType left, ExpressionType right, ExpressionType& result);
-    bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType& result);
+    template<OpType>
+    bool WARN_UNUSED_RETURN addOp(ExpressionType arg, ExpressionType& result);
+    template<OpType>
+    bool WARN_UNUSED_RETURN addOp(ExpressionType left, ExpressionType right, ExpressionType& result);
     bool WARN_UNUSED_RETURN addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType& result);
 
     // Control flow
@@ -450,22 +452,6 @@
     return true;
 }
 
-bool B3IRGenerator::unaryOp(UnaryOpType op, ExpressionType arg, ExpressionType& result)
-{
-    if (!isSimple(op))
-        return false;
-    result = m_currentBlock->appendNew<Value>(m_proc, toB3Op(op), Origin(), arg);
-    return true;
-}
-
-bool B3IRGenerator::binaryOp(BinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType& result)
-{
-    if (!isSimple(op))
-        return false;
-    result = m_currentBlock->appendNew<Value>(m_proc, toB3Op(op), Origin(), left, right);
-    return true;
-}
-
 bool B3IRGenerator::addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType& result)
 {
     result = m_currentBlock->appendNew<Value>(m_proc, B3::Select, Origin(), condition, nonZero, zero);
@@ -675,9 +661,6 @@
     dataLogLn("\n");
 }
 
-} // anonymous namespace
-
-
 static std::unique_ptr<Compilation> createJSWrapper(VM& vm, const Signature* signature, MacroAssemblerCodePtr mainFunction, Memory* memory)
 {
     Procedure proc;
@@ -780,4 +763,6 @@
 
 } } // namespace JSC::Wasm
 
+#include "WasmB3IRGeneratorInlines.h"
+
 #endif // ENABLE(WEBASSEMBLY)

Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-11-16 23:34:39 UTC (rev 208821)
@@ -65,6 +65,12 @@
 
     bool WARN_UNUSED_RETURN popExpressionStack(ExpressionType& result);
 
+    template<OpType>
+    bool WARN_UNUSED_RETURN unaryCase();
+
+    template<OpType>
+    bool WARN_UNUSED_RETURN binaryCase();
+
     void setErrorMessage(String&& message) { m_context.setErrorMessage(WTFMove(message)); }
 
     Context& m_context;
@@ -163,40 +169,52 @@
     return m_context.addReturn(returnValues);
 }
 
-#define CREATE_CASE(name, id, b3op) case name:
+template<typename Context>
+template<OpType op>
+bool FunctionParser<Context>::binaryCase()
+{
+    ExpressionType right;
+    if (!popExpressionStack(right))
+        return false;
 
+    ExpressionType left;
+    if (!popExpressionStack(left))
+        return false;
+
+    ExpressionType result;
+    if (!m_context.template addOp<op>(left, right, result))
+        return false;
+    m_expressionStack.append(result);
+    return true;
+}
+
 template<typename Context>
+template<OpType op>
+bool FunctionParser<Context>::unaryCase()
+{
+    ExpressionType value;
+    if (!popExpressionStack(value))
+        return false;
+
+    ExpressionType result;
+    if (!m_context.template addOp<op>(value, result))
+        return false;
+    m_expressionStack.append(result);
+    return true;
+}
+
+template<typename Context>
 bool FunctionParser<Context>::parseExpression(OpType op)
 {
     switch (op) {
-    FOR_EACH_WASM_BINARY_OP(CREATE_CASE) {
-        ExpressionType right;
-        if (!popExpressionStack(right))
-            return false;
+#define CREATE_CASE(name, id, b3op) case OpType::name: return binaryCase<OpType::name>();
+    FOR_EACH_WASM_SIMPLE_BINARY_OP(CREATE_CASE)
+#undef CREATE_CASE
 
-        ExpressionType left;
-        if (!popExpressionStack(left))
-            return false;
+#define CREATE_CASE(name, id, b3op) case OpType::name: return unaryCase<OpType::name>();
+    FOR_EACH_WASM_SIMPLE_UNARY_OP(CREATE_CASE)
+#undef CREATE_CASE
 
-        ExpressionType result;
-        if (!m_context.binaryOp(static_cast<BinaryOpType>(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<UnaryOpType>(op), value, result))
-            return false;
-        m_expressionStack.append(result);
-        return true;
-    }
-
     case OpType::Select: {
         ExpressionType condition;
         if (!popExpressionStack(condition))
@@ -218,6 +236,7 @@
         return true;
     }
 
+#define CREATE_CASE(name, id, b3op) case OpType::name:
     FOR_EACH_WASM_MEMORY_LOAD_OP(CREATE_CASE) {
         uint32_t alignment;
         if (!parseVarUInt32(alignment))
@@ -257,6 +276,7 @@
 
         return m_context.store(static_cast<StoreOpType>(op), pointer, value, offset);
     }
+#undef CREATE_CASE
 
     case OpType::F32Const:
     case OpType::I32Const: {
@@ -454,15 +474,11 @@
         return true;
     }
 
-    case OpType::Nop:
-    case OpType::Drop:
-    case OpType::TeeLocal:
-    case OpType::GetGlobal:
-    case OpType::SetGlobal:
-    case OpType::CallIndirect:
+    default: {
         // FIXME: Not yet implemented.
         return false;
     }
+    }
 
     ASSERT_NOT_REACHED();
 }
@@ -540,8 +556,6 @@
     return false;
 }
 
-#undef CREATE_CASE
-
 } } // namespace JSC::Wasm
 
 #endif // ENABLE(WEBASSEMBLY)

Modified: trunk/Source/_javascript_Core/wasm/WasmValidate.cpp (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/WasmValidate.cpp	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/WasmValidate.cpp	2016-11-16 23:34:39 UTC (rev 208821)
@@ -91,8 +91,10 @@
     bool WARN_UNUSED_RETURN store(StoreOpType, ExpressionType pointer, ExpressionType value, uint32_t offset);
 
     // Basic operators
-    bool WARN_UNUSED_RETURN binaryOp(BinaryOpType, ExpressionType left, ExpressionType right, ExpressionType& result);
-    bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType& result);
+    template<OpType>
+    bool WARN_UNUSED_RETURN addOp(ExpressionType arg, ExpressionType& result);
+    template<OpType>
+    bool WARN_UNUSED_RETURN addOp(ExpressionType left, ExpressionType right, ExpressionType& result);
     bool WARN_UNUSED_RETURN addSelect(ExpressionType condition, ExpressionType nonZero, ExpressionType zero, ExpressionType& result);
 
     // Control flow

Modified: trunk/Source/_javascript_Core/wasm/generateWasm.py (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/generateWasm.py	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/generateWasm.py	2016-11-16 23:34:39 UTC (rev 208821)
@@ -28,7 +28,6 @@
 import json
 import re
 
-
 class Wasm:
     def __init__(self, scriptName, jsonPath):
         wasmFile = open(jsonPath, "r")
@@ -86,3 +85,7 @@
 
 def isBinary(op):
     return isNormal(op) and len(op["parameter"]) == 2
+
+
+def isSimple(op):
+    return "b3op" in op

Added: trunk/Source/_javascript_Core/wasm/generateWasmB3IRGeneratorInlinesHeader.py (0 => 208821)


--- trunk/Source/_javascript_Core/wasm/generateWasmB3IRGeneratorInlinesHeader.py	                        (rev 0)
+++ trunk/Source/_javascript_Core/wasm/generateWasmB3IRGeneratorInlinesHeader.py	2016-11-16 23:34:39 UTC (rev 208821)
@@ -0,0 +1,74 @@
+#!/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 "AS IS" 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="usage: %prog <wasm.json> <WasmOps.h>")
+(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], "w")
+
+
+def generateSimpleCode(op):
+    opcode = op["opcode"]
+    b3op = opcode["b3op"]
+    args = ["ExpressionType arg" + str(param) for param in range(len(opcode["parameter"]))]
+    args.append("ExpressionType& result")
+    params = ["arg" + str(param) for param in range(len(opcode["parameter"]))]
+    return """
+template<> bool B3IRGenerator::addOp<OpType::""" + wasm.toCpp(op["name"]) + ">(" + ", ".join(args) + """)
+{
+    result = m_currentBlock->appendNew<Value>(m_proc, B3::""" + opcode["b3op"] + ", Origin(), " + ", ".join(params) + """);
+    return true;
+}
+"""
+
+definitions = [generateSimpleCode(op) for op in wasm.opcodeIterator(lambda op: isSimple(op) and (isBinary(op) or isUnary(op)))]
+contents = wasm.header + """
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+namespace JSC { namespace Wasm {
+
+""" + "".join(definitions) + """
+
+} } // namespace JSC::Wasm
+
+#endif // ENABLE(WEBASSEMBLY)
+
+"""
+
+wasmB3IRGeneratorHFile.write(contents)
+wasmB3IRGeneratorHFile.close()
Property changes on: trunk/Source/_javascript_Core/wasm/generateWasmB3IRGeneratorInlinesHeader.py
___________________________________________________________________

Added: svn:executable

+* \ No newline at end of property

Modified: trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2016-11-16 23:34:39 UTC (rev 208821)
@@ -46,7 +46,7 @@
 def opcodeMacroizer(filter):
     for op in wasm.opcodeIterator(filter):
         b3op = "Oops"
-        if "b3op" in op["opcode"]:
+        if isSimple(op["opcode"]):
             b3op = op["opcode"]["b3op"]
         yield cppMacro(op["name"], op["opcode"]["value"], b3op)
 
@@ -55,13 +55,13 @@
 defines.append("\n\n#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro)")
 defines.extend([op for op in opcodeMacroizer(lambda op: op["category"] == "control")])
 defines.append("\n\n#define FOR_EACH_WASM_SIMPLE_UNARY_OP(macro)")
-defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and "b3op" in op)])
+defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and isSimple(op))])
 defines.append("\n\n#define FOR_EACH_WASM_UNARY_OP(macro) \\\n    FOR_EACH_WASM_SIMPLE_UNARY_OP(macro)")
-defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and not ("b3op" in op))])
+defines.extend([op for op in opcodeMacroizer(lambda op: isUnary(op) and not (isSimple(op)))])
 defines.append("\n\n#define FOR_EACH_WASM_SIMPLE_BINARY_OP(macro)")
-defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and "b3op" in op)])
+defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and isSimple(op))])
 defines.append("\n\n#define FOR_EACH_WASM_BINARY_OP(macro) \\\n    FOR_EACH_WASM_SIMPLE_BINARY_OP(macro)")
-defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and not ("b3op" in op))])
+defines.extend([op for op in opcodeMacroizer(lambda op: isBinary(op) and not (isSimple(op)))])
 defines.append("\n\n#define FOR_EACH_WASM_MEMORY_LOAD_OP(macro)")
 defines.extend([op for op in opcodeMacroizer(lambda op: (op["category"] == "memory" and len(op["return"]) == 1))])
 defines.append("\n\n#define FOR_EACH_WASM_MEMORY_STORE_OP(macro)")

Modified: trunk/Source/_javascript_Core/wasm/generateWasmValidateInlinesHeader.py (208820 => 208821)


--- trunk/Source/_javascript_Core/wasm/generateWasmValidateInlinesHeader.py	2016-11-16 23:32:32 UTC (rev 208820)
+++ trunk/Source/_javascript_Core/wasm/generateWasmValidateInlinesHeader.py	2016-11-16 23:34:39 UTC (rev 208821)
@@ -60,36 +60,39 @@
 def unaryMacro(name):
     op = opcodes[name]
     return """
-    case UnaryOpType::""" + toCpp(name) + """: {
-        if (value != """ + cppType(op["parameter"][0]) + """) {
-            m_errorMessage = makeString(\"""" + name + """ expects the value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(value));
-            return false;
-        }
+template<> bool Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType value, ExpressionType& result)
+{
+    if (value != """ + cppType(op["parameter"][0]) + """) {
+        m_errorMessage = makeString(\"""" + name + """ expects the value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(value));
+        return false;
+    }
 
-        result = """ + cppType(op["return"][0]) + """;
-        return true;
-    }"""
+    result = """ + cppType(op["return"][0]) + """;
+    return true;
+}
+"""
 
 
 def binaryMacro(name):
     op = opcodes[name]
     return """
-    case BinaryOpType::""" + toCpp(name) + """: {
-        if (left != """ + cppType(op["parameter"][0]) + """) {
-            m_errorMessage = makeString(\"""" + name + """ expects the left value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(left));
-            return false;
-        }
+template<> bool Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType left, ExpressionType right, ExpressionType& result)
+{
+    if (left != """ + cppType(op["parameter"][0]) + """) {
+        m_errorMessage = makeString(\"""" + name + """ expects the left value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(left));
+        return false;
+    }
 
-        if (right != """ + cppType(op["parameter"][1]) + """) {
-            m_errorMessage = makeString(\"""" + name + """ expects the right value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(right));
-            return false;
-        }
+    if (right != """ + cppType(op["parameter"][1]) + """) {
+        m_errorMessage = makeString(\"""" + name + """ expects the right value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(right));
+        return false;
+    }
 
-        result = """ + cppType(op["return"][0]) + """;
-        return true;
-    }"""
+    result = """ + cppType(op["return"][0]) + """;
+    return true;
+}
+"""
 
-
 def loadMacro(name):
     op = opcodes[name]
     return """
@@ -122,8 +125,8 @@
     }"""
 
 
-unaryCases = "".join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
-binaryCases = "".join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
+unarySpecializations = "".join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
+binarySpecializations = "".join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
 loadCases = "".join([op for op in wasm.opcodeIterator(lambda op: op["category"] == "memory" and len(op["return"]) == 1, loadMacro)])
 storeCases = "".join([op for op in wasm.opcodeIterator(lambda op: op["category"] == "memory" and len(op["return"]) == 0, storeMacro)])
 
@@ -136,20 +139,8 @@
 
 namespace JSC { namespace Wasm {
 
-bool Validate::unaryOp(UnaryOpType op, ExpressionType value, ExpressionType& result)
-{
-    switch (op) {
-""" + unaryCases + """
-    }
-}
+""" + unarySpecializations + binarySpecializations + """
 
-bool Validate::binaryOp(BinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType& result)
-{
-    switch (op) {
-""" + binaryCases + """
-    }
-}
-
 bool Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType& result, uint32_t)
 {
     switch (op) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to