blob: 72680bf613944f77854066c6908cc4731aef9e5e [file] [log] [blame]
fpizlo@apple.com6b62eaf2015-08-03 23:13:56 +00001/*
2 * Copyright (C) 2015 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
26#ifndef DFGMultiGetByOffsetData_h
27#define DFGMultiGetByOffsetData_h
28
29#if ENABLE(DFG_JIT)
30
31#include "DumpContext.h"
32#include "JSObject.h"
33#include "StructureSet.h"
34
35namespace JSC { namespace DFG {
36
37class FrozenValue;
38
39class GetByOffsetMethod {
40public:
41 enum Kind {
42 Invalid,
43 Constant,
44 Load,
45 LoadFromPrototype
46 };
47
48 GetByOffsetMethod()
49 : m_kind(Invalid)
50 {
51 }
52
53 static GetByOffsetMethod constant(FrozenValue* value)
54 {
55 GetByOffsetMethod result;
56 result.m_kind = Constant;
57 result.u.constant = value;
58 return result;
59 }
60
61 static GetByOffsetMethod load(PropertyOffset offset)
62 {
63 GetByOffsetMethod result;
64 result.m_kind = Load;
65 result.u.load.offset = offset;
66 return result;
67 }
68
69 static GetByOffsetMethod loadFromPrototype(FrozenValue* prototype, PropertyOffset offset)
70 {
71 GetByOffsetMethod result;
72 result.m_kind = LoadFromPrototype;
73 result.u.load.prototype = prototype;
74 result.u.load.offset = offset;
75 return result;
76 }
77
78 bool operator!() const { return m_kind == Invalid; }
79
80 Kind kind() const { return m_kind; }
81
82 FrozenValue* constant() const
83 {
84 ASSERT(kind() == Constant);
85 return u.constant;
86 }
87
88 FrozenValue* prototype() const
89 {
90 ASSERT(kind() == LoadFromPrototype);
91 return u.load.prototype;
92 }
93
94 PropertyOffset offset() const
95 {
96 ASSERT(kind() == Load || kind() == LoadFromPrototype);
97 return u.load.offset;
98 }
99
100 void dumpInContext(PrintStream&, DumpContext*) const;
101 void dump(PrintStream&) const;
102
103private:
104 union {
105 FrozenValue* constant;
106 struct {
107 FrozenValue* prototype;
108 PropertyOffset offset;
109 } load;
110 } u;
111 Kind m_kind;
112};
113
114class MultiGetByOffsetCase {
115public:
116 MultiGetByOffsetCase()
117 {
118 }
119
120 MultiGetByOffsetCase(const StructureSet& set, const GetByOffsetMethod& method)
121 : m_set(set)
122 , m_method(method)
123 {
124 }
125
126 StructureSet& set() { return m_set; }
127 const StructureSet& set() const { return m_set; }
128 const GetByOffsetMethod& method() const { return m_method; }
129
130 void dumpInContext(PrintStream&, DumpContext*) const;
131 void dump(PrintStream&) const;
132
133private:
134 StructureSet m_set;
135 GetByOffsetMethod m_method;
136};
137
138struct MultiGetByOffsetData {
139 unsigned identifierNumber;
140 Vector<MultiGetByOffsetCase, 2> cases;
141};
142
143} } // namespace JSC::DFG
144
145namespace WTF {
146
147void printInternal(PrintStream&, JSC::DFG::GetByOffsetMethod::Kind);
148
149} // namespace WTF
150
151#endif // ENABLE(DFG_JIT)
152
153#endif // DFGMultiGetByOffsetData_h
154