js/src/yarr/YarrJIT.h

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

mercurial