]>
Commit | Line | Data |
---|---|---|
ba379fdc A |
1 | /* |
2 | * Copyright (C) 2009 Apple Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions | |
6 | * are met: | |
7 | * 1. Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | */ | |
25 | ||
14957cd0 A |
26 | #ifndef YarrJIT_h |
27 | #define YarrJIT_h | |
ba379fdc | 28 | |
ba379fdc A |
29 | #if ENABLE(YARR_JIT) |
30 | ||
14957cd0 | 31 | #include "JSGlobalData.h" |
6fe7ccc8 A |
32 | #include "MacroAssemblerCodeRef.h" |
33 | #include "MatchResult.h" | |
14957cd0 | 34 | #include "UString.h" |
6fe7ccc8 | 35 | #include "Yarr.h" |
14957cd0 | 36 | #include "YarrPattern.h" |
ba379fdc | 37 | |
f9bf01c6 | 38 | #if CPU(X86) && !COMPILER(MSVC) |
ba379fdc A |
39 | #define YARR_CALL __attribute__ ((regparm (3))) |
40 | #else | |
41 | #define YARR_CALL | |
42 | #endif | |
43 | ||
44 | namespace JSC { | |
45 | ||
46 | class JSGlobalData; | |
47 | class ExecutablePool; | |
48 | ||
49 | namespace Yarr { | |
50 | ||
14957cd0 | 51 | class YarrCodeBlock { |
6fe7ccc8 A |
52 | #if CPU(X86_64) |
53 | typedef MatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL; | |
54 | typedef MatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL; | |
55 | typedef MatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL; | |
56 | typedef MatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL; | |
57 | #else | |
58 | typedef EncodedMatchResult (*YarrJITCode8)(const LChar* input, unsigned start, unsigned length, int* output) YARR_CALL; | |
59 | typedef EncodedMatchResult (*YarrJITCode16)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL; | |
60 | typedef EncodedMatchResult (*YarrJITCodeMatchOnly8)(const LChar* input, unsigned start, unsigned length) YARR_CALL; | |
61 | typedef EncodedMatchResult (*YarrJITCodeMatchOnly16)(const UChar* input, unsigned start, unsigned length) YARR_CALL; | |
62 | #endif | |
ba379fdc A |
63 | |
64 | public: | |
14957cd0 A |
65 | YarrCodeBlock() |
66 | : m_needFallBack(false) | |
ba379fdc A |
67 | { |
68 | } | |
69 | ||
14957cd0 | 70 | ~YarrCodeBlock() |
ba379fdc | 71 | { |
ba379fdc A |
72 | } |
73 | ||
14957cd0 A |
74 | void setFallBack(bool fallback) { m_needFallBack = fallback; } |
75 | bool isFallBack() { return m_needFallBack; } | |
ba379fdc | 76 | |
6fe7ccc8 A |
77 | bool has8BitCode() { return m_ref8.size(); } |
78 | bool has16BitCode() { return m_ref16.size(); } | |
79 | void set8BitCode(MacroAssemblerCodeRef ref) { m_ref8 = ref; } | |
80 | void set16BitCode(MacroAssemblerCodeRef ref) { m_ref16 = ref; } | |
81 | ||
82 | bool has8BitCodeMatchOnly() { return m_matchOnly8.size(); } | |
83 | bool has16BitCodeMatchOnly() { return m_matchOnly16.size(); } | |
84 | void set8BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly8 = matchOnly; } | |
85 | void set16BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly16 = matchOnly; } | |
86 | ||
87 | MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output) | |
ba379fdc | 88 | { |
6fe7ccc8 A |
89 | ASSERT(has8BitCode()); |
90 | return MatchResult(reinterpret_cast<YarrJITCode8>(m_ref8.code().executableAddress())(input, start, length, output)); | |
91 | } | |
92 | ||
93 | MatchResult execute(const UChar* input, unsigned start, unsigned length, int* output) | |
94 | { | |
95 | ASSERT(has16BitCode()); | |
96 | return MatchResult(reinterpret_cast<YarrJITCode16>(m_ref16.code().executableAddress())(input, start, length, output)); | |
97 | } | |
98 | ||
99 | MatchResult execute(const LChar* input, unsigned start, unsigned length) | |
100 | { | |
101 | ASSERT(has8BitCodeMatchOnly()); | |
102 | return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly8>(m_matchOnly8.code().executableAddress())(input, start, length)); | |
103 | } | |
104 | ||
105 | MatchResult execute(const UChar* input, unsigned start, unsigned length) | |
106 | { | |
107 | ASSERT(has16BitCodeMatchOnly()); | |
108 | return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly16>(m_matchOnly16.code().executableAddress())(input, start, length)); | |
ba379fdc A |
109 | } |
110 | ||
14957cd0 | 111 | #if ENABLE(REGEXP_TRACING) |
6fe7ccc8 | 112 | void *getAddr() { return m_ref.code().executableAddress(); } |
14957cd0 A |
113 | #endif |
114 | ||
6fe7ccc8 A |
115 | void clear() |
116 | { | |
117 | m_ref8 = MacroAssemblerCodeRef(); | |
118 | m_ref16 = MacroAssemblerCodeRef(); | |
119 | m_matchOnly8 = MacroAssemblerCodeRef(); | |
120 | m_matchOnly16 = MacroAssemblerCodeRef(); | |
121 | m_needFallBack = false; | |
122 | } | |
123 | ||
ba379fdc | 124 | private: |
6fe7ccc8 A |
125 | MacroAssemblerCodeRef m_ref8; |
126 | MacroAssemblerCodeRef m_ref16; | |
127 | MacroAssemblerCodeRef m_matchOnly8; | |
128 | MacroAssemblerCodeRef m_matchOnly16; | |
14957cd0 | 129 | bool m_needFallBack; |
ba379fdc A |
130 | }; |
131 | ||
6fe7ccc8 A |
132 | enum YarrJITCompileMode { |
133 | MatchOnly, | |
134 | IncludeSubpatterns | |
135 | }; | |
136 | void jitCompile(YarrPattern&, YarrCharSize, JSGlobalData*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns); | |
ba379fdc A |
137 | |
138 | } } // namespace JSC::Yarr | |
139 | ||
140 | #endif | |
141 | ||
14957cd0 | 142 | #endif // YarrJIT_h |