js/src/yarr/YarrJIT.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 *
michael@0 4 * Copyright (C) 2009 Apple Inc. All rights reserved.
michael@0 5 *
michael@0 6 * Redistribution and use in source and binary forms, with or without
michael@0 7 * modification, are permitted provided that the following conditions
michael@0 8 * are met:
michael@0 9 * 1. Redistributions of source code must retain the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer.
michael@0 11 * 2. Redistributions in binary form must reproduce the above copyright
michael@0 12 * notice, this list of conditions and the following disclaimer in the
michael@0 13 * documentation and/or other materials provided with the distribution.
michael@0 14 *
michael@0 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
michael@0 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
michael@0 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 26 */
michael@0 27
michael@0 28 #ifndef yarr_YarrJIT_h
michael@0 29 #define yarr_YarrJIT_h
michael@0 30
michael@0 31 #include "assembler/wtf/Platform.h"
michael@0 32
michael@0 33 #if ENABLE_YARR_JIT
michael@0 34
michael@0 35 #include "assembler/assembler/MacroAssemblerCodeRef.h"
michael@0 36
michael@0 37 #include "yarr/MatchResult.h"
michael@0 38 #include "yarr/Yarr.h"
michael@0 39
michael@0 40 #if WTF_CPU_X86 && !WTF_COMPILER_MSVC && !WTF_COMPILER_SUNCC
michael@0 41 #define YARR_CALL __attribute__ ((regparm (3)))
michael@0 42 #else
michael@0 43 #define YARR_CALL
michael@0 44 #endif
michael@0 45
michael@0 46 #include "jit/JitCommon.h"
michael@0 47
michael@0 48 namespace JSC {
michael@0 49
michael@0 50 class JSGlobalData;
michael@0 51 class ExecutablePool;
michael@0 52
michael@0 53 namespace Yarr {
michael@0 54
michael@0 55 class YarrCodeBlock {
michael@0 56 #if defined(WTF_CPU_X86_64) && !defined(_WIN64)
michael@0 57 typedef MatchResult JITMatchResult;
michael@0 58 #else
michael@0 59 typedef EncodedMatchResult JITMatchResult;
michael@0 60 #endif
michael@0 61
michael@0 62 typedef JITMatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
michael@0 63 typedef JITMatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
michael@0 64 typedef JITMatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL;
michael@0 65 typedef JITMatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL;
michael@0 66
michael@0 67 public:
michael@0 68 YarrCodeBlock()
michael@0 69 : m_needFallBack(false)
michael@0 70 {
michael@0 71 }
michael@0 72
michael@0 73 ~YarrCodeBlock()
michael@0 74 {
michael@0 75 }
michael@0 76
michael@0 77 void setFallBack(bool fallback) { m_needFallBack = fallback; }
michael@0 78 bool isFallBack() { return m_needFallBack; }
michael@0 79
michael@0 80 #ifdef YARR_8BIT_CHAR_SUPPORT
michael@0 81 bool has8BitCode() const { return m_ref8.allocSize(); }
michael@0 82 void set8BitCode(MacroAssemblerCodeRef ref) { m_ref8 = ref; }
michael@0 83 bool has8BitCodeMatchOnly() const { return m_matchOnly8.allocSize(); }
michael@0 84 void set8BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly8 = matchOnly; }
michael@0 85 #endif
michael@0 86
michael@0 87 bool has16BitCode() const { return m_ref16.allocSize(); }
michael@0 88 void set16BitCode(MacroAssemblerCodeRef ref) { m_ref16 = ref; }
michael@0 89
michael@0 90 bool has16BitCodeMatchOnly() const { return m_matchOnly16.allocSize(); }
michael@0 91 void set16BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly16 = matchOnly; }
michael@0 92
michael@0 93 #if YARR_8BIT_CHAR_SUPPORT
michael@0 94 MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output)
michael@0 95 {
michael@0 96 ASSERT(has8BitCode());
michael@0 97
michael@0 98 return MatchResult(reinterpret_cast<YarrJITCode8>(m_ref8.code().executableAddress())(input, start, length, output));
michael@0 99 }
michael@0 100
michael@0 101 MatchResult execute(const LChar* input, unsigned start, unsigned length)
michael@0 102 {
michael@0 103 ASSERT(has8BitCodeMatchOnly());
michael@0 104
michael@0 105 return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly8>(m_matchOnly8.code().executableAddress())(input, start, length));
michael@0 106 }
michael@0 107 #endif
michael@0 108
michael@0 109 MatchResult execute(const UChar* input, unsigned start, unsigned length, int* output)
michael@0 110 {
michael@0 111 ASSERT(has16BitCode());
michael@0 112
michael@0 113 YarrJITCode16 fn = JS_FUNC_TO_DATA_PTR(YarrJITCode16, m_ref16.code().executableAddress());
michael@0 114 return MatchResult(CALL_GENERATED_YARR_CODE4(fn, input, start, length, output));
michael@0 115 }
michael@0 116
michael@0 117 MatchResult execute(const UChar* input, unsigned start, unsigned length)
michael@0 118 {
michael@0 119 ASSERT(has16BitCodeMatchOnly());
michael@0 120
michael@0 121 YarrJITCodeMatchOnly16 fn = JS_FUNC_TO_DATA_PTR(YarrJITCodeMatchOnly16, m_matchOnly16.code().executableAddress());
michael@0 122 return MatchResult(CALL_GENERATED_YARR_CODE3(fn, input, start, length));
michael@0 123 }
michael@0 124
michael@0 125 #if ENABLE_REGEXP_TRACING
michael@0 126 void *getAddr() { return m_ref.code().executableAddress(); }
michael@0 127 #endif
michael@0 128
michael@0 129 void clear()
michael@0 130 {
michael@0 131 #ifdef YARR_8BIT_CHAR_SUPPORT
michael@0 132 m_ref8 = MacroAssemblerCodeRef();
michael@0 133 m_matchOnly8 = MacroAssemblerCodeRef();
michael@0 134 #endif
michael@0 135
michael@0 136 m_ref16 = MacroAssemblerCodeRef();
michael@0 137 m_matchOnly16 = MacroAssemblerCodeRef();
michael@0 138 m_needFallBack = false;
michael@0 139 }
michael@0 140
michael@0 141 void release() {
michael@0 142 #ifdef YARR_8BIT_CHAR_SUPPORT
michael@0 143 m_ref8.release();
michael@0 144 m_matchOnly8.release();
michael@0 145 #endif
michael@0 146
michael@0 147 m_ref16.release();
michael@0 148 m_matchOnly16.release();
michael@0 149 }
michael@0 150
michael@0 151 private:
michael@0 152 #ifdef YARR_8BIT_CHAR_SUPPORT
michael@0 153 MacroAssemblerCodeRef m_ref8;
michael@0 154 MacroAssemblerCodeRef m_matchOnly8;
michael@0 155 #endif
michael@0 156
michael@0 157 MacroAssemblerCodeRef m_ref16;
michael@0 158 MacroAssemblerCodeRef m_matchOnly16;
michael@0 159 bool m_needFallBack;
michael@0 160 };
michael@0 161
michael@0 162 enum YarrJITCompileMode {
michael@0 163 MatchOnly,
michael@0 164 IncludeSubpatterns
michael@0 165 };
michael@0 166 void jitCompile(YarrPattern&, YarrCharSize, JSGlobalData*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns);
michael@0 167
michael@0 168 } } // namespace JSC::Yarr
michael@0 169
michael@0 170 #endif
michael@0 171
michael@0 172 #endif /* yarr_YarrJIT_h */

mercurial