From 6882a04fb36642862b11efe514251d32070c3d65 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 25 Aug 2016 19:20:41 +0300 Subject: Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443) Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev --- Source/JavaScriptCore/wasm/WASMFunctionParser.h | 148 ++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 Source/JavaScriptCore/wasm/WASMFunctionParser.h (limited to 'Source/JavaScriptCore/wasm/WASMFunctionParser.h') diff --git a/Source/JavaScriptCore/wasm/WASMFunctionParser.h b/Source/JavaScriptCore/wasm/WASMFunctionParser.h new file mode 100644 index 000000000..7f09e3e85 --- /dev/null +++ b/Source/JavaScriptCore/wasm/WASMFunctionParser.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015 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: + * 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 INC. ``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 INC. OR + * 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. + */ + +#ifndef WASMFunctionParser_h +#define WASMFunctionParser_h + +#if ENABLE(WEBASSEMBLY) + +#include "SourceCode.h" +#include "WASMReader.h" + +#define ContextExpression typename Context::Expression +#define ContextStatement typename Context::Statement +#define ContextExpressionList typename Context::ExpressionList +#define ContextMemoryAddress typename Context::MemoryAddress +#define ContextJumpTarget typename Context::JumpTarget + +namespace JSC { + +class CodeBlock; +class JSWASMModule; +class VM; + +class WASMFunctionParser { +public: + static bool checkSyntax(JSWASMModule*, const SourceCode&, size_t functionIndex, unsigned startOffsetInSource, unsigned& endOffsetInSource, unsigned& stackHeight, String& errorMessage); + static void compile(VM&, CodeBlock*, JSWASMModule*, const SourceCode&, size_t functionIndex); + +private: + WASMFunctionParser(JSWASMModule* module, const SourceCode& source, size_t functionIndex) + : m_module(module) + , m_reader(static_cast(source.provider())->data()) + , m_functionIndex(functionIndex) + , m_breakScopeDepth(0) + , m_continueScopeDepth(0) + , m_labelDepth(0) + { + } + + template bool parseFunction(Context&); + bool parseLocalVariables(); + + template ContextStatement parseStatement(Context&); + template ContextStatement parseReturnStatement(Context&); + template ContextStatement parseBlockStatement(Context&); + template ContextStatement parseIfStatement(Context&); + template ContextStatement parseIfElseStatement(Context&); + template ContextStatement parseWhileStatement(Context&); + template ContextStatement parseDoStatement(Context&); + template ContextStatement parseLabelStatement(Context&); + template ContextStatement parseBreakStatement(Context&); + template ContextStatement parseBreakLabelStatement(Context&); + template ContextStatement parseContinueStatement(Context&); + template ContextStatement parseContinueLabelStatement(Context&); + template ContextStatement parseSwitchStatement(Context&); + + template ContextExpression parseExpression(Context&, WASMExpressionType); + + template ContextExpression parseExpressionI32(Context&); + template ContextExpression parseConstantPoolIndexExpressionI32(Context&, uint32_t constantPoolIndex); + template ContextExpression parseConstantPoolIndexExpressionI32(Context&); + template ContextExpression parseImmediateExpressionI32(Context&, uint32_t immediate); + template ContextExpression parseImmediateExpressionI32(Context&); + template ContextExpression parseUnaryExpressionI32(Context&, WASMOpExpressionI32); + template ContextExpression parseBinaryExpressionI32(Context&, WASMOpExpressionI32); + template ContextExpression parseRelationalI32ExpressionI32(Context&, WASMOpExpressionI32); + template ContextExpression parseRelationalF32ExpressionI32(Context&, WASMOpExpressionI32); + template ContextExpression parseRelationalF64ExpressionI32(Context&, WASMOpExpressionI32); + template ContextExpression parseMinOrMaxExpressionI32(Context&, WASMOpExpressionI32); + + template ContextExpression parseExpressionF32(Context&); + template ContextExpression parseConstantPoolIndexExpressionF32(Context&, uint32_t constantIndex); + template ContextExpression parseConstantPoolIndexExpressionF32(Context&); + template ContextExpression parseImmediateExpressionF32(Context&); + template ContextExpression parseUnaryExpressionF32(Context&, WASMOpExpressionF32); + template ContextExpression parseBinaryExpressionF32(Context&, WASMOpExpressionF32); + + template ContextExpression parseExpressionF64(Context&); + template ContextExpression parseConstantPoolIndexExpressionF64(Context&, uint32_t constantIndex); + template ContextExpression parseConstantPoolIndexExpressionF64(Context&); + template ContextExpression parseImmediateExpressionF64(Context&); + template ContextExpression parseUnaryExpressionF64(Context&, WASMOpExpressionF64); + template ContextExpression parseBinaryExpressionF64(Context&, WASMOpExpressionF64); + template ContextExpression parseMinOrMaxExpressionF64(Context&, WASMOpExpressionF64); + + template ContextExpression parseExpressionVoid(Context&); + + template ContextExpression parseGetLocalExpression(Context&, WASMType, uint32_t localIndex); + template ContextExpression parseGetLocalExpression(Context&, WASMType); + template ContextExpression parseGetGlobalExpression(Context&, WASMType); + template ContextExpression parseSetLocal(Context&, WASMOpKind, WASMExpressionType, uint32_t localIndex); + template ContextExpression parseSetLocal(Context&, WASMOpKind, WASMExpressionType); + template ContextExpression parseSetGlobal(Context&, WASMOpKind, WASMExpressionType, uint32_t globalIndex); + template ContextExpression parseSetGlobal(Context&, WASMOpKind, WASMExpressionType); + template ContextMemoryAddress parseMemoryAddress(Context&, MemoryAccessOffsetMode); + template ContextExpression parseLoad(Context&, WASMExpressionType, WASMMemoryType, MemoryAccessOffsetMode, MemoryAccessConversion = MemoryAccessConversion::NoConversion); + template ContextExpression parseStore(Context&, WASMOpKind, WASMExpressionType, WASMMemoryType, MemoryAccessOffsetMode); + template ContextExpressionList parseCallArguments(Context&, const Vector& arguments); + template ContextExpression parseCallInternal(Context&, WASMOpKind, WASMExpressionType returnType); + template ContextExpression parseCallIndirect(Context&, WASMOpKind, WASMExpressionType returnType); + template ContextExpression parseCallImport(Context&, WASMOpKind, WASMExpressionType returnType); + template ContextExpression parseConditional(Context&, WASMExpressionType); + template ContextExpression parseComma(Context&, WASMExpressionType); + template ContextExpression parseConvertType(Context&, WASMExpressionType fromType, WASMExpressionType toType, WASMTypeConversion); + + JSWASMModule* m_module; + WASMReader m_reader; + size_t m_functionIndex; + String m_errorMessage; + + WASMExpressionType m_returnType; + Vector m_localTypes; + uint32_t m_numberOfI32LocalVariables; + uint32_t m_numberOfF32LocalVariables; + uint32_t m_numberOfF64LocalVariables; + + unsigned m_breakScopeDepth; + unsigned m_continueScopeDepth; + unsigned m_labelDepth; +}; + +} // namespace JSC + +#endif // ENABLE(WEBASSEMBLY) + +#endif // WASMFunctionParser_h -- cgit v1.2.1