fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 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 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 27 | |
| 28 | #if ENABLE(DFG_JIT) |
| 29 | |
sbarati@apple.com | 239d20b | 2017-01-26 23:50:58 +0000 | [diff] [blame] | 30 | #include "DFGRegisteredStructureSet.h" |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 31 | #include "DumpContext.h" |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 32 | #include "StructureSet.h" |
| 33 | |
| 34 | namespace JSC { namespace DFG { |
| 35 | |
| 36 | class FrozenValue; |
| 37 | |
| 38 | class GetByOffsetMethod { |
| 39 | public: |
| 40 | enum Kind { |
| 41 | Invalid, |
keith_miller@apple.com | 21a022a | 2016-06-15 19:40:43 +0000 | [diff] [blame] | 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. |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 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 | |
| 105 | private: |
| 106 | union { |
| 107 | FrozenValue* constant; |
| 108 | struct { |
| 109 | FrozenValue* prototype; |
| 110 | PropertyOffset offset; |
| 111 | } load; |
| 112 | } u; |
| 113 | Kind m_kind; |
| 114 | }; |
| 115 | |
| 116 | class MultiGetByOffsetCase { |
| 117 | public: |
| 118 | MultiGetByOffsetCase() |
| 119 | { |
| 120 | } |
| 121 | |
sbarati@apple.com | 239d20b | 2017-01-26 23:50:58 +0000 | [diff] [blame] | 122 | MultiGetByOffsetCase(const RegisteredStructureSet& set, const GetByOffsetMethod& method) |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 123 | : m_set(set) |
| 124 | , m_method(method) |
| 125 | { |
| 126 | } |
| 127 | |
sbarati@apple.com | 239d20b | 2017-01-26 23:50:58 +0000 | [diff] [blame] | 128 | RegisteredStructureSet& set() { return m_set; } |
| 129 | const RegisteredStructureSet& set() const { return m_set; } |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 130 | const GetByOffsetMethod& method() const { return m_method; } |
| 131 | |
| 132 | void dumpInContext(PrintStream&, DumpContext*) const; |
| 133 | void dump(PrintStream&) const; |
| 134 | |
| 135 | private: |
sbarati@apple.com | 239d20b | 2017-01-26 23:50:58 +0000 | [diff] [blame] | 136 | RegisteredStructureSet m_set; |
fpizlo@apple.com | 6b62eaf | 2015-08-03 23:13:56 +0000 | [diff] [blame] | 137 | GetByOffsetMethod m_method; |
| 138 | }; |
| 139 | |
| 140 | struct MultiGetByOffsetData { |
| 141 | unsigned identifierNumber; |
| 142 | Vector<MultiGetByOffsetCase, 2> cases; |
| 143 | }; |
| 144 | |
| 145 | } } // namespace JSC::DFG |
| 146 | |
| 147 | namespace WTF { |
| 148 | |
| 149 | void printInternal(PrintStream&, JSC::DFG::GetByOffsetMethod::Kind); |
| 150 | |
| 151 | } // namespace WTF |
| 152 | |
| 153 | #endif // ENABLE(DFG_JIT) |