1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/yarr/YarrJIT.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,172 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * 1.7 + * Copyright (C) 2009 Apple Inc. All rights reserved. 1.8 + * 1.9 + * Redistribution and use in source and binary forms, with or without 1.10 + * modification, are permitted provided that the following conditions 1.11 + * are met: 1.12 + * 1. Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 2. Redistributions in binary form must reproduce the above copyright 1.15 + * notice, this list of conditions and the following disclaimer in the 1.16 + * documentation and/or other materials provided with the distribution. 1.17 + * 1.18 + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 1.19 + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.21 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 1.22 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.23 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.24 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.25 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.26 + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.27 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.28 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.29 + */ 1.30 + 1.31 +#ifndef yarr_YarrJIT_h 1.32 +#define yarr_YarrJIT_h 1.33 + 1.34 +#include "assembler/wtf/Platform.h" 1.35 + 1.36 +#if ENABLE_YARR_JIT 1.37 + 1.38 +#include "assembler/assembler/MacroAssemblerCodeRef.h" 1.39 + 1.40 +#include "yarr/MatchResult.h" 1.41 +#include "yarr/Yarr.h" 1.42 + 1.43 +#if WTF_CPU_X86 && !WTF_COMPILER_MSVC && !WTF_COMPILER_SUNCC 1.44 +#define YARR_CALL __attribute__ ((regparm (3))) 1.45 +#else 1.46 +#define YARR_CALL 1.47 +#endif 1.48 + 1.49 +#include "jit/JitCommon.h" 1.50 + 1.51 +namespace JSC { 1.52 + 1.53 +class JSGlobalData; 1.54 +class ExecutablePool; 1.55 + 1.56 +namespace Yarr { 1.57 + 1.58 +class YarrCodeBlock { 1.59 +#if defined(WTF_CPU_X86_64) && !defined(_WIN64) 1.60 + typedef MatchResult JITMatchResult; 1.61 +#else 1.62 + typedef EncodedMatchResult JITMatchResult; 1.63 +#endif 1.64 + 1.65 + typedef JITMatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL; 1.66 + typedef JITMatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL; 1.67 + typedef JITMatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL; 1.68 + typedef JITMatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL; 1.69 + 1.70 +public: 1.71 + YarrCodeBlock() 1.72 + : m_needFallBack(false) 1.73 + { 1.74 + } 1.75 + 1.76 + ~YarrCodeBlock() 1.77 + { 1.78 + } 1.79 + 1.80 + void setFallBack(bool fallback) { m_needFallBack = fallback; } 1.81 + bool isFallBack() { return m_needFallBack; } 1.82 + 1.83 +#ifdef YARR_8BIT_CHAR_SUPPORT 1.84 + bool has8BitCode() const { return m_ref8.allocSize(); } 1.85 + void set8BitCode(MacroAssemblerCodeRef ref) { m_ref8 = ref; } 1.86 + bool has8BitCodeMatchOnly() const { return m_matchOnly8.allocSize(); } 1.87 + void set8BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly8 = matchOnly; } 1.88 +#endif 1.89 + 1.90 + bool has16BitCode() const { return m_ref16.allocSize(); } 1.91 + void set16BitCode(MacroAssemblerCodeRef ref) { m_ref16 = ref; } 1.92 + 1.93 + bool has16BitCodeMatchOnly() const { return m_matchOnly16.allocSize(); } 1.94 + void set16BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly16 = matchOnly; } 1.95 + 1.96 +#if YARR_8BIT_CHAR_SUPPORT 1.97 + MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output) 1.98 + { 1.99 + ASSERT(has8BitCode()); 1.100 + 1.101 + return MatchResult(reinterpret_cast<YarrJITCode8>(m_ref8.code().executableAddress())(input, start, length, output)); 1.102 + } 1.103 + 1.104 + MatchResult execute(const LChar* input, unsigned start, unsigned length) 1.105 + { 1.106 + ASSERT(has8BitCodeMatchOnly()); 1.107 + 1.108 + return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly8>(m_matchOnly8.code().executableAddress())(input, start, length)); 1.109 + } 1.110 +#endif 1.111 + 1.112 + MatchResult execute(const UChar* input, unsigned start, unsigned length, int* output) 1.113 + { 1.114 + ASSERT(has16BitCode()); 1.115 + 1.116 + YarrJITCode16 fn = JS_FUNC_TO_DATA_PTR(YarrJITCode16, m_ref16.code().executableAddress()); 1.117 + return MatchResult(CALL_GENERATED_YARR_CODE4(fn, input, start, length, output)); 1.118 + } 1.119 + 1.120 + MatchResult execute(const UChar* input, unsigned start, unsigned length) 1.121 + { 1.122 + ASSERT(has16BitCodeMatchOnly()); 1.123 + 1.124 + YarrJITCodeMatchOnly16 fn = JS_FUNC_TO_DATA_PTR(YarrJITCodeMatchOnly16, m_matchOnly16.code().executableAddress()); 1.125 + return MatchResult(CALL_GENERATED_YARR_CODE3(fn, input, start, length)); 1.126 + } 1.127 + 1.128 +#if ENABLE_REGEXP_TRACING 1.129 + void *getAddr() { return m_ref.code().executableAddress(); } 1.130 +#endif 1.131 + 1.132 + void clear() 1.133 + { 1.134 +#ifdef YARR_8BIT_CHAR_SUPPORT 1.135 + m_ref8 = MacroAssemblerCodeRef(); 1.136 + m_matchOnly8 = MacroAssemblerCodeRef(); 1.137 +#endif 1.138 + 1.139 + m_ref16 = MacroAssemblerCodeRef(); 1.140 + m_matchOnly16 = MacroAssemblerCodeRef(); 1.141 + m_needFallBack = false; 1.142 + } 1.143 + 1.144 + void release() { 1.145 +#ifdef YARR_8BIT_CHAR_SUPPORT 1.146 + m_ref8.release(); 1.147 + m_matchOnly8.release(); 1.148 +#endif 1.149 + 1.150 + m_ref16.release(); 1.151 + m_matchOnly16.release(); 1.152 + } 1.153 + 1.154 +private: 1.155 +#ifdef YARR_8BIT_CHAR_SUPPORT 1.156 + MacroAssemblerCodeRef m_ref8; 1.157 + MacroAssemblerCodeRef m_matchOnly8; 1.158 +#endif 1.159 + 1.160 + MacroAssemblerCodeRef m_ref16; 1.161 + MacroAssemblerCodeRef m_matchOnly16; 1.162 + bool m_needFallBack; 1.163 +}; 1.164 + 1.165 +enum YarrJITCompileMode { 1.166 + MatchOnly, 1.167 + IncludeSubpatterns 1.168 +}; 1.169 +void jitCompile(YarrPattern&, YarrCharSize, JSGlobalData*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns); 1.170 + 1.171 +} } // namespace JSC::Yarr 1.172 + 1.173 +#endif 1.174 + 1.175 +#endif /* yarr_YarrJIT_h */