1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=8 sw=4 et tw=99 ft=cpp:
3 : *
4 : * ***** BEGIN LICENSE BLOCK *****
5 : * Copyright (C) 2009 Apple Inc. All rights reserved.
6 : *
7 : * Redistribution and use in source and binary forms, with or without
8 : * modification, are permitted provided that the following conditions
9 : * are met:
10 : * 1. Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * 2. Redistributions in binary form must reproduce the above copyright
13 : * notice, this list of conditions and the following disclaimer in the
14 : * documentation and/or other materials provided with the distribution.
15 : *
16 : * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
17 : * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 : * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
20 : * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 : * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 : * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 : * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 : *
28 : * ***** END LICENSE BLOCK ***** */
29 :
30 : #ifndef YarrJIT_h
31 : #define YarrJIT_h
32 :
33 : #include "assembler/wtf/Platform.h"
34 :
35 : #if ENABLE_YARR_JIT
36 :
37 : #include "assembler/assembler/MacroAssembler.h"
38 : #include "YarrPattern.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 : namespace JSC {
47 :
48 : class JSGlobalData;
49 : class ExecutablePool;
50 :
51 : namespace Yarr {
52 :
53 : class YarrCodeBlock {
54 : typedef int (*YarrJITCode)(const UChar* input, unsigned start, unsigned length, int* output) YARR_CALL;
55 :
56 : public:
57 58244 : YarrCodeBlock()
58 58244 : : m_needFallBack(false)
59 : {
60 58244 : }
61 :
62 58244 : ~YarrCodeBlock()
63 : {
64 58244 : }
65 :
66 61201 : void setFallBack(bool fallback) { m_needFallBack = fallback; }
67 3587200 : bool isFallBack() { return m_needFallBack; }
68 55269 : void set(MacroAssembler::CodeRef ref) { m_ref = ref; }
69 :
70 3461258 : int execute(const UChar* input, unsigned start, unsigned length, int* output)
71 : {
72 3461258 : return JS_EXTENSION((reinterpret_cast<YarrJITCode>(m_ref.m_code.executableAddress()))(input, start, length, output));
73 : }
74 :
75 : #if ENABLE_REGEXP_TRACING
76 : void *getAddr() { return m_ref.m_code.executableAddress(); }
77 : #endif
78 :
79 58244 : void release() { m_ref.release(); }
80 :
81 : private:
82 : MacroAssembler::CodeRef m_ref;
83 : bool m_needFallBack;
84 : };
85 :
86 : void jitCompile(YarrPattern&, JSGlobalData*, YarrCodeBlock& jitObject);
87 : int execute(YarrCodeBlock& jitObject, const UChar* input, unsigned start, unsigned length, int* output);
88 :
89 : } } // namespace JSC::Yarr
90 :
91 : #endif
92 :
93 : #endif // YarrJIT_h
|