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.

     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  */
    28 #ifndef yarr_YarrJIT_h
    29 #define yarr_YarrJIT_h
    31 #include "assembler/wtf/Platform.h"
    33 #if ENABLE_YARR_JIT
    35 #include "assembler/assembler/MacroAssemblerCodeRef.h"
    37 #include "yarr/MatchResult.h"
    38 #include "yarr/Yarr.h"
    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
    46 #include "jit/JitCommon.h"
    48 namespace JSC {
    50 class JSGlobalData;
    51 class ExecutablePool;
    53 namespace Yarr {
    55 class YarrCodeBlock {
    56 #if defined(WTF_CPU_X86_64) && !defined(_WIN64)
    57     typedef MatchResult JITMatchResult;
    58 #else
    59     typedef EncodedMatchResult JITMatchResult;
    60 #endif
    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;
    67 public:
    68     YarrCodeBlock()
    69         : m_needFallBack(false)
    70     {
    71     }
    73     ~YarrCodeBlock()
    74     {
    75     }
    77     void setFallBack(bool fallback) { m_needFallBack = fallback; }
    78     bool isFallBack() { return m_needFallBack; }
    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
    87     bool has16BitCode() const { return m_ref16.allocSize(); }
    88     void set16BitCode(MacroAssemblerCodeRef ref) { m_ref16 = ref; }
    90     bool has16BitCodeMatchOnly() const { return m_matchOnly16.allocSize(); }
    91     void set16BitCodeMatchOnly(MacroAssemblerCodeRef matchOnly) { m_matchOnly16 = matchOnly; }
    93 #if YARR_8BIT_CHAR_SUPPORT
    94     MatchResult execute(const LChar* input, unsigned start, unsigned length, int* output)
    95     {
    96         ASSERT(has8BitCode());
    98         return MatchResult(reinterpret_cast<YarrJITCode8>(m_ref8.code().executableAddress())(input, start, length, output));
    99     }
   101     MatchResult execute(const LChar* input, unsigned start, unsigned length)
   102     {
   103         ASSERT(has8BitCodeMatchOnly());
   105         return MatchResult(reinterpret_cast<YarrJITCodeMatchOnly8>(m_matchOnly8.code().executableAddress())(input, start, length));
   106     }
   107 #endif
   109     MatchResult execute(const UChar* input, unsigned start, unsigned length, int* output)
   110     {
   111         ASSERT(has16BitCode());
   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     }
   117     MatchResult execute(const UChar* input, unsigned start, unsigned length)
   118     {
   119         ASSERT(has16BitCodeMatchOnly());
   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     }
   125 #if ENABLE_REGEXP_TRACING
   126     void *getAddr() { return m_ref.code().executableAddress(); }
   127 #endif
   129     void clear()
   130     {
   131 #ifdef YARR_8BIT_CHAR_SUPPORT
   132         m_ref8 = MacroAssemblerCodeRef();
   133         m_matchOnly8 = MacroAssemblerCodeRef();
   134 #endif
   136         m_ref16 = MacroAssemblerCodeRef();
   137         m_matchOnly16 = MacroAssemblerCodeRef();
   138         m_needFallBack = false;
   139     }
   141     void release() {
   142 #ifdef YARR_8BIT_CHAR_SUPPORT
   143         m_ref8.release();
   144         m_matchOnly8.release();
   145 #endif
   147         m_ref16.release();
   148         m_matchOnly16.release();
   149     }
   151 private:
   152 #ifdef YARR_8BIT_CHAR_SUPPORT
   153     MacroAssemblerCodeRef m_ref8;
   154     MacroAssemblerCodeRef m_matchOnly8;
   155 #endif
   157     MacroAssemblerCodeRef m_ref16;
   158     MacroAssemblerCodeRef m_matchOnly16;
   159     bool m_needFallBack;
   160 };
   162 enum YarrJITCompileMode {
   163     MatchOnly,
   164     IncludeSubpatterns
   165 };
   166 void jitCompile(YarrPattern&, YarrCharSize, JSGlobalData*, YarrCodeBlock& jitObject, YarrJITCompileMode = IncludeSubpatterns);
   168 } } // namespace JSC::Yarr
   170 #endif
   172 #endif /* yarr_YarrJIT_h */

mercurial