1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * Copyright (C) 2017 Yusuke Suzuki <[email protected]>. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | |
27 | #pragma once |
28 | |
29 | #if ENABLE(JIT) |
30 | |
31 | #include "CCallHelpers.h" |
32 | #include "SnippetReg.h" |
33 | #include "SnippetSlowPathCalls.h" |
34 | |
35 | namespace JSC { |
36 | |
37 | class SnippetParams { |
38 | WTF_MAKE_NONCOPYABLE(SnippetParams); |
39 | public: |
40 | virtual ~SnippetParams() { } |
41 | |
42 | class Value { |
43 | public: |
44 | Value(SnippetReg reg) |
45 | : m_reg(reg) |
46 | { |
47 | } |
48 | |
49 | Value(SnippetReg reg, JSValue value) |
50 | : m_reg(reg) |
51 | , m_value(value) |
52 | { |
53 | } |
54 | |
55 | bool isGPR() const { return m_reg.isGPR(); } |
56 | bool isFPR() const { return m_reg.isFPR(); } |
57 | bool isJSValueRegs() const { return m_reg.isJSValueRegs(); } |
58 | GPRReg gpr() const { return m_reg.gpr(); } |
59 | FPRReg fpr() const { return m_reg.fpr(); } |
60 | JSValueRegs jsValueRegs() const { return m_reg.jsValueRegs(); } |
61 | |
62 | SnippetReg reg() const |
63 | { |
64 | return m_reg; |
65 | } |
66 | |
67 | JSValue value() const |
68 | { |
69 | return m_value; |
70 | } |
71 | |
72 | private: |
73 | SnippetReg m_reg; |
74 | JSValue m_value; |
75 | }; |
76 | |
77 | unsigned size() const { return m_regs.size(); } |
78 | const Value& at(unsigned index) const { return m_regs[index]; } |
79 | const Value& operator[](unsigned index) const { return at(index); } |
80 | |
81 | GPRReg gpScratch(unsigned index) const { return m_gpScratch[index]; } |
82 | FPRReg fpScratch(unsigned index) const { return m_fpScratch[index]; } |
83 | |
84 | SnippetParams(VM& vm, Vector<Value>&& regs, Vector<GPRReg>&& gpScratch, Vector<FPRReg>&& fpScratch) |
85 | : m_vm(vm) |
86 | , m_regs(WTFMove(regs)) |
87 | , m_gpScratch(WTFMove(gpScratch)) |
88 | , m_fpScratch(WTFMove(fpScratch)) |
89 | { |
90 | } |
91 | |
92 | VM& vm() { return m_vm; } |
93 | |
94 | template<typename FunctionType, typename ResultType, typename... Arguments> |
95 | void addSlowPathCall(CCallHelpers::JumpList from, CCallHelpers& jit, FunctionType function, ResultType result, Arguments... arguments) |
96 | { |
97 | addSlowPathCallImpl(from, jit, function, result, std::make_tuple(arguments...)); |
98 | } |
99 | |
100 | private: |
101 | #define JSC_DEFINE_CALL_OPERATIONS(OperationType, ResultType, ...) JS_EXPORT_PRIVATE virtual void addSlowPathCallImpl(CCallHelpers::JumpList, CCallHelpers&, OperationType, ResultType, std::tuple<__VA_ARGS__> args) = 0; |
102 | SNIPPET_SLOW_PATH_CALLS(JSC_DEFINE_CALL_OPERATIONS) |
103 | #undef JSC_DEFINE_CALL_OPERATIONS |
104 | |
105 | VM& m_vm; |
106 | Vector<Value> m_regs; |
107 | Vector<GPRReg> m_gpScratch; |
108 | Vector<FPRReg> m_fpScratch; |
109 | }; |
110 | |
111 | } |
112 | |
113 | #endif |
114 | |