1/*
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#pragma once
27
28#if ENABLE(DFG_JIT)
29
30#include "DFGRegisteredStructureSet.h"
31#include "DumpContext.h"
32#include "StructureSet.h"
33
34namespace JSC { namespace DFG {
35
36class FrozenValue;
37
38class GetByOffsetMethod {
39public:
40 enum Kind {
41 Invalid,
42 // Constant might mean either that we have some fixed property or that the
43 // property is unset and we know the result is undefined. We don't distingish
44 // between these cases because no one cares about this distintion yet.
45 Constant,
46 Load,
47 LoadFromPrototype
48 };
49
50 GetByOffsetMethod()
51 : m_kind(Invalid)
52 {
53 }
54
55 static GetByOffsetMethod constant(FrozenValue* value)
56 {
57 GetByOffsetMethod result;
58 result.m_kind = Constant;
59 result.u.constant = value;
60 return result;
61 }
62
63 static GetByOffsetMethod load(PropertyOffset offset)
64 {
65 GetByOffsetMethod result;
66 result.m_kind = Load;
67 result.u.load.offset = offset;
68 return result;
69 }
70
71 static GetByOffsetMethod loadFromPrototype(FrozenValue* prototype, PropertyOffset offset)
72 {
73 GetByOffsetMethod result;
74 result.m_kind = LoadFromPrototype;
75 result.u.load.prototype = prototype;
76 result.u.load.offset = offset;
77 return result;
78 }
79
80 bool operator!() const { return m_kind == Invalid; }
81
82 Kind kind() const { return m_kind; }
83
84 FrozenValue* constant() const
85 {
86 ASSERT(kind() == Constant);
87 return u.constant;
88 }
89
90 FrozenValue* prototype() const
91 {
92 ASSERT(kind() == LoadFromPrototype);
93 return u.load.prototype;
94 }
95
96 PropertyOffset offset() const
97 {
98 ASSERT(kind() == Load || kind() == LoadFromPrototype);
99 return u.load.offset;
100 }
101
102 void dumpInContext(PrintStream&, DumpContext*) const;
103 void dump(PrintStream&) const;
104
105private:
106 union {
107 FrozenValue* constant;
108 struct {
109 FrozenValue* prototype;
110 PropertyOffset offset;
111 } load;
112 } u;
113 Kind m_kind;
114};
115
116class MultiGetByOffsetCase {
117public:
118 MultiGetByOffsetCase()
119 {
120 }
121
122 MultiGetByOffsetCase(const RegisteredStructureSet& set, const GetByOffsetMethod& method)
123 : m_set(set)
124 , m_method(method)
125 {
126 }
127
128 RegisteredStructureSet& set() { return m_set; }
129 const RegisteredStructureSet& set() const { return m_set; }
130 const GetByOffsetMethod& method() const { return m_method; }
131
132 void dumpInContext(PrintStream&, DumpContext*) const;
133 void dump(PrintStream&) const;
134
135private:
136 RegisteredStructureSet m_set;
137 GetByOffsetMethod m_method;
138};
139
140struct MultiGetByOffsetData {
141 unsigned identifierNumber;
142 Vector<MultiGetByOffsetCase, 2> cases;
143};
144
145} } // namespace JSC::DFG
146
147namespace WTF {
148
149void printInternal(PrintStream&, JSC::DFG::GetByOffsetMethod::Kind);
150
151} // namespace WTF
152
153#endif // ENABLE(DFG_JIT)
154