mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009, 2012-2015 Apple Inc. All rights reserved. |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca> |
commit-queue@webkit.org | 2fea740 | 2012-02-01 19:37:00 +0000 | [diff] [blame] | 4 | * Copyright (C) 2012 Igalia, S.L. |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 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 | * |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 15 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 16 | * its contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
ggaren@apple.com | 8e06f20 | 2008-11-15 21:05:23 +0000 | [diff] [blame] | 31 | #ifndef BytecodeGenerator_h |
| 32 | #define BytecodeGenerator_h |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 33 | |
| 34 | #include "CodeBlock.h" |
eric@webkit.org | 3979f2d | 2012-03-07 08:50:54 +0000 | [diff] [blame] | 35 | #include <wtf/HashTraits.h> |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 36 | #include "Instruction.h" |
ggaren@apple.com | 2efe3de | 2008-11-17 16:18:13 +0000 | [diff] [blame] | 37 | #include "Label.h" |
ggaren@apple.com | 4dbab80 | 2008-10-31 19:59:08 +0000 | [diff] [blame] | 38 | #include "LabelScope.h" |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame] | 39 | #include "Interpreter.h" |
fpizlo@apple.com | bb8aa75 | 2013-02-18 06:28:54 +0000 | [diff] [blame] | 40 | #include "ParserError.h" |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 41 | #include "RegisterID.h" |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 42 | #include "SymbolTable.h" |
cwzwarich@webkit.org | a691b5a | 2008-10-31 05:56:58 +0000 | [diff] [blame] | 43 | #include "Debugger.h" |
cwzwarich@webkit.org | 3ff0e6a | 2008-11-07 00:18:07 +0000 | [diff] [blame] | 44 | #include "Nodes.h" |
ggaren@apple.com | c862eac | 2013-01-29 05:48:01 +0000 | [diff] [blame] | 45 | #include "StaticPropertyAnalyzer.h" |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 46 | #include "TemplateRegistryKey.h" |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 47 | #include "UnlinkedCodeBlock.h" |
oliver@apple.com | 72f8a82 | 2013-10-17 01:02:34 +0000 | [diff] [blame] | 48 | |
| 49 | #include <functional> |
| 50 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 51 | #include <wtf/PassRefPtr.h> |
ddkilzer@apple.com | 0a028aa | 2009-06-20 13:14:41 +0000 | [diff] [blame] | 52 | #include <wtf/SegmentedVector.h> |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 53 | #include <wtf/Vector.h> |
| 54 | |
oliver@apple.com | 72f8a82 | 2013-10-17 01:02:34 +0000 | [diff] [blame] | 55 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 56 | namespace JSC { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 57 | |
| 58 | class Identifier; |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 59 | class JSTemplateRegistryKey; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 60 | |
fpizlo@apple.com | 4500e35 | 2012-10-17 21:39:11 +0000 | [diff] [blame] | 61 | enum ExpectedFunction { |
| 62 | NoExpectedFunction, |
| 63 | ExpectObjectConstructor, |
| 64 | ExpectArrayConstructor |
| 65 | }; |
| 66 | |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 67 | class CallArguments { |
| 68 | public: |
oliver@apple.com | 20a9bf0 | 2013-10-04 20:35:24 +0000 | [diff] [blame] | 69 | CallArguments(BytecodeGenerator&, ArgumentsNode*, unsigned additionalArguments = 0); |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 70 | |
| 71 | RegisterID* thisRegister() { return m_argv[0].get(); } |
| 72 | RegisterID* argumentRegister(unsigned i) { return m_argv[i + 1].get(); } |
fpizlo@apple.com | e94ae4a | 2013-11-22 20:18:18 +0000 | [diff] [blame] | 73 | unsigned stackOffset() { return -m_argv[0]->index() + JSStack::CallFrameHeaderSize; } |
| 74 | unsigned argumentCountIncludingThis() { return m_argv.size() - m_padding; } |
commit-queue@webkit.org | 90ba187 | 2010-11-17 08:05:39 +0000 | [diff] [blame] | 75 | RegisterID* profileHookRegister() { return m_profileHookRegister.get(); } |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 76 | ArgumentsNode* argumentsNode() { return m_argumentsNode; } |
| 77 | |
| 78 | private: |
commit-queue@webkit.org | 90ba187 | 2010-11-17 08:05:39 +0000 | [diff] [blame] | 79 | RefPtr<RegisterID> m_profileHookRegister; |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 80 | ArgumentsNode* m_argumentsNode; |
oliver@apple.com | 4e3f965 | 2013-04-08 04:14:50 +0000 | [diff] [blame] | 81 | Vector<RefPtr<RegisterID>, 8, UnsafeVectorOverflow> m_argv; |
fpizlo@apple.com | e94ae4a | 2013-11-22 20:18:18 +0000 | [diff] [blame] | 82 | unsigned m_padding; |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 85 | struct FinallyContext { |
fpizlo@apple.com | dd58bf9 | 2012-04-04 04:25:56 +0000 | [diff] [blame] | 86 | StatementNode* finallyBlock; |
utatane.tea@gmail.com | bc07449 | 2015-04-01 09:36:15 +0000 | [diff] [blame] | 87 | RegisterID* iterator; |
| 88 | ThrowableExpressionData* enumerationNode; |
fpizlo@apple.com | dd58bf9 | 2012-04-04 04:25:56 +0000 | [diff] [blame] | 89 | unsigned scopeContextStackSize; |
| 90 | unsigned switchContextStackSize; |
| 91 | unsigned forInContextStackSize; |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 92 | unsigned tryContextStackSize; |
fpizlo@apple.com | dd58bf9 | 2012-04-04 04:25:56 +0000 | [diff] [blame] | 93 | unsigned labelScopesSize; |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 94 | unsigned symbolTableStackSize; |
fpizlo@apple.com | dd58bf9 | 2012-04-04 04:25:56 +0000 | [diff] [blame] | 95 | int finallyDepth; |
| 96 | int dynamicScopeDepth; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 97 | }; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 98 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 99 | struct ControlFlowContext { |
| 100 | bool isFinallyBlock; |
| 101 | FinallyContext finallyContext; |
| 102 | }; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 103 | |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 104 | class ForInContext { |
| 105 | public: |
fpizlo@apple.com | caf3505 | 2014-08-20 02:38:46 +0000 | [diff] [blame] | 106 | ForInContext(RegisterID* localRegister) |
| 107 | : m_localRegister(localRegister) |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 108 | , m_isValid(true) |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | virtual ~ForInContext() |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | bool isValid() const { return m_isValid; } |
| 117 | void invalidate() { m_isValid = false; } |
| 118 | |
| 119 | enum ForInContextType { |
| 120 | StructureForInContextType, |
| 121 | IndexedForInContextType |
| 122 | }; |
| 123 | virtual ForInContextType type() const = 0; |
| 124 | |
| 125 | RegisterID* local() const { return m_localRegister.get(); } |
| 126 | |
| 127 | private: |
| 128 | RefPtr<RegisterID> m_localRegister; |
| 129 | bool m_isValid; |
| 130 | }; |
| 131 | |
| 132 | class StructureForInContext : public ForInContext { |
| 133 | public: |
fpizlo@apple.com | caf3505 | 2014-08-20 02:38:46 +0000 | [diff] [blame] | 134 | StructureForInContext(RegisterID* localRegister, RegisterID* indexRegister, RegisterID* propertyRegister, RegisterID* enumeratorRegister) |
| 135 | : ForInContext(localRegister) |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 136 | , m_indexRegister(indexRegister) |
| 137 | , m_propertyRegister(propertyRegister) |
| 138 | , m_enumeratorRegister(enumeratorRegister) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | virtual ForInContextType type() const |
| 143 | { |
| 144 | return StructureForInContextType; |
| 145 | } |
| 146 | |
| 147 | RegisterID* index() const { return m_indexRegister.get(); } |
| 148 | RegisterID* property() const { return m_propertyRegister.get(); } |
| 149 | RegisterID* enumerator() const { return m_enumeratorRegister.get(); } |
| 150 | |
| 151 | private: |
| 152 | RefPtr<RegisterID> m_indexRegister; |
| 153 | RefPtr<RegisterID> m_propertyRegister; |
| 154 | RefPtr<RegisterID> m_enumeratorRegister; |
| 155 | }; |
| 156 | |
| 157 | class IndexedForInContext : public ForInContext { |
| 158 | public: |
fpizlo@apple.com | caf3505 | 2014-08-20 02:38:46 +0000 | [diff] [blame] | 159 | IndexedForInContext(RegisterID* localRegister, RegisterID* indexRegister) |
| 160 | : ForInContext(localRegister) |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 161 | , m_indexRegister(indexRegister) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | virtual ForInContextType type() const |
| 166 | { |
| 167 | return IndexedForInContextType; |
| 168 | } |
| 169 | |
| 170 | RegisterID* index() const { return m_indexRegister.get(); } |
| 171 | |
| 172 | private: |
| 173 | RefPtr<RegisterID> m_indexRegister; |
oliver@apple.com | 0a4803c | 2009-10-29 01:25:02 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 176 | struct TryData { |
| 177 | RefPtr<Label> target; |
| 178 | unsigned targetScopeDepth; |
mark.lam@apple.com | 1559ba9 | 2015-06-01 23:22:22 +0000 | [diff] [blame] | 179 | HandlerType handlerType; |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | struct TryContext { |
| 183 | RefPtr<Label> start; |
| 184 | TryData* tryData; |
| 185 | }; |
| 186 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 187 | class Variable { |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 188 | public: |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 189 | enum VariableKind { NormalVariable, SpecialVariable }; |
| 190 | |
| 191 | Variable() |
| 192 | : m_offset() |
| 193 | , m_local(nullptr) |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 194 | , m_attributes(0) |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 195 | , m_kind(NormalVariable) |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 196 | , m_symbolTableConstantIndex(0) // This is meaningless here for this kind of Variable. |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 197 | , m_isLexicallyScoped(false) |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 198 | { |
| 199 | } |
| 200 | |
| 201 | Variable(const Identifier& ident) |
| 202 | : m_ident(ident) |
| 203 | , m_local(nullptr) |
| 204 | , m_attributes(0) |
| 205 | , m_kind(NormalVariable) // This is somewhat meaningless here for this kind of Variable. |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 206 | , m_symbolTableConstantIndex(0) // This is meaningless here for this kind of Variable. |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 207 | , m_isLexicallyScoped(false) |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 208 | { |
| 209 | } |
| 210 | |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 211 | Variable(const Identifier& ident, VarOffset offset, RegisterID* local, unsigned attributes, VariableKind kind, int symbolTableConstantIndex, bool isLexicallyScoped) |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 212 | : m_ident(ident) |
| 213 | , m_offset(offset) |
| 214 | , m_local(local) |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 215 | , m_attributes(attributes) |
oliver@apple.com | f129dfb | 2014-10-02 20:35:58 +0000 | [diff] [blame] | 216 | , m_kind(kind) |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 217 | , m_symbolTableConstantIndex(symbolTableConstantIndex) |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 218 | , m_isLexicallyScoped(isLexicallyScoped) |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 219 | { |
| 220 | } |
| 221 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 222 | // If it's unset, then it is a non-locally-scoped variable. If it is set, then it could be |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 223 | // a stack variable, a scoped variable in a local scope, or a variable captured in the |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 224 | // direct arguments object. |
| 225 | bool isResolved() const { return !!m_offset; } |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 226 | int symbolTableConstantIndex() const { ASSERT(isResolved() && !isSpecial()); return m_symbolTableConstantIndex; } |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 227 | |
| 228 | const Identifier& ident() const { return m_ident; } |
| 229 | |
| 230 | VarOffset offset() const { return m_offset; } |
| 231 | bool isLocal() const { return m_offset.isStack(); } |
| 232 | RegisterID* local() const { return m_local; } |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 233 | |
oliver@apple.com | f129dfb | 2014-10-02 20:35:58 +0000 | [diff] [blame] | 234 | bool isReadOnly() const { return m_attributes & ReadOnly; } |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 235 | bool isSpecial() const { return m_kind != NormalVariable; } |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 236 | bool isConst() const { return isReadOnly() && m_isLexicallyScoped; } |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 237 | |
| 238 | private: |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 239 | Identifier m_ident; |
| 240 | VarOffset m_offset; |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 241 | RegisterID* m_local; |
| 242 | unsigned m_attributes; |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 243 | VariableKind m_kind; |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 244 | int m_symbolTableConstantIndex; |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 245 | bool m_isLexicallyScoped; |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 248 | struct TryRange { |
| 249 | RefPtr<Label> start; |
| 250 | RefPtr<Label> end; |
| 251 | TryData* tryData; |
| 252 | }; |
| 253 | |
commit-queue@webkit.org | 2ed31ec | 2014-08-21 01:03:20 +0000 | [diff] [blame] | 254 | enum ProfileTypeBytecodeFlag { |
| 255 | ProfileTypeBytecodePutToScope, |
| 256 | ProfileTypeBytecodeGetFromScope, |
oliver@apple.com | f129dfb | 2014-10-02 20:35:58 +0000 | [diff] [blame] | 257 | ProfileTypeBytecodePutToLocalScope, |
| 258 | ProfileTypeBytecodeGetFromLocalScope, |
commit-queue@webkit.org | 2ed31ec | 2014-08-21 01:03:20 +0000 | [diff] [blame] | 259 | ProfileTypeBytecodeHasGlobalID, |
| 260 | ProfileTypeBytecodeDoesNotHaveGlobalID, |
| 261 | ProfileTypeBytecodeFunctionArgument, |
| 262 | ProfileTypeBytecodeFunctionReturnStatement |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 265 | class BytecodeGenerator { |
| 266 | WTF_MAKE_FAST_ALLOCATED; |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 267 | WTF_MAKE_NONCOPYABLE(BytecodeGenerator); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 268 | public: |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 269 | typedef DeclarationStacks::FunctionStack FunctionStack; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 270 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 271 | BytecodeGenerator(VM&, ProgramNode*, UnlinkedProgramCodeBlock*, DebuggerMode, ProfilerMode, const VariableEnvironment*); |
| 272 | BytecodeGenerator(VM&, FunctionNode*, UnlinkedFunctionCodeBlock*, DebuggerMode, ProfilerMode, const VariableEnvironment*); |
| 273 | BytecodeGenerator(VM&, EvalNode*, UnlinkedEvalCodeBlock*, DebuggerMode, ProfilerMode, const VariableEnvironment*); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 274 | |
oliver@apple.com | 780d3cc | 2011-10-25 00:21:29 +0000 | [diff] [blame] | 275 | ~BytecodeGenerator(); |
| 276 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 277 | VM* vm() const { return m_vm; } |
ggaren@apple.com | c0ccae0 | 2014-12-03 23:23:56 +0000 | [diff] [blame] | 278 | ParserArena& parserArena() const { return m_scopeNode->parserArena(); } |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 279 | const CommonIdentifiers& propertyNames() const { return *m_vm->propertyNames; } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 280 | |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 281 | bool isConstructor() const { return m_codeBlock->isConstructor(); } |
| 282 | #if ENABLE(ES6_CLASS_SYNTAX) |
rniwa@webkit.org | e6f8349 | 2015-03-13 23:01:51 +0000 | [diff] [blame] | 283 | ConstructorKind constructorKind() const { return m_codeBlock->constructorKind(); } |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 284 | #else |
rniwa@webkit.org | e6f8349 | 2015-03-13 23:01:51 +0000 | [diff] [blame] | 285 | ConstructorKind constructorKind() const { return ConstructorKind::None; } |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 286 | #endif |
barraclough@apple.com | fdaf8dc | 2010-05-20 04:57:20 +0000 | [diff] [blame] | 287 | |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 288 | ParserError generate(); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 289 | |
ggaren@apple.com | 50c5ac2 | 2011-11-14 23:16:27 +0000 | [diff] [blame] | 290 | bool isArgumentNumber(const Identifier&, int); |
barraclough@apple.com | b467c4c | 2010-07-13 20:34:11 +0000 | [diff] [blame] | 291 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 292 | Variable variable(const Identifier&); |
fpizlo@apple.com | 0309686b | 2013-12-02 19:49:43 +0000 | [diff] [blame] | 293 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 294 | enum ExistingVariableMode { VerifyExisting, IgnoreExisting }; |
saambarati1@gmail.com | 3321f09 | 2015-07-20 21:16:41 +0000 | [diff] [blame] | 295 | void createVariable(const Identifier&, VarKind, SymbolTable*, ExistingVariableMode = VerifyExisting); // Creates the variable, or asserts that the already-created variable is sufficiently compatible. |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 296 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 297 | // Returns the register storing "this" |
ggaren@apple.com | 873cb42 | 2008-06-02 20:45:13 +0000 | [diff] [blame] | 298 | RegisterID* thisRegister() { return &m_thisRegister; } |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 299 | RegisterID* argumentsRegister() { return m_argumentsRegister; } |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 300 | RegisterID* newTarget() { return m_newTargetRegister; } |
| 301 | |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 302 | RegisterID* scopeRegister() { return m_scopeRegister; } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 303 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 304 | // Returns the next available temporary register. Registers returned by |
| 305 | // newTemporary require a modified form of reference counting: any |
| 306 | // register with a refcount of 0 is considered "available", meaning that |
| 307 | // the next instruction may overwrite it. |
| 308 | RegisterID* newTemporary(); |
| 309 | |
| 310 | // The same as newTemporary(), but this function returns "suggestion" if |
| 311 | // "suggestion" is a temporary. This function is helpful in situations |
| 312 | // where you've put "suggestion" in a RefPtr, but you'd like to allow |
| 313 | // the next instruction to overwrite it anyway. |
| 314 | RegisterID* newTemporaryOr(RegisterID* suggestion) { return suggestion->isTemporary() ? suggestion : newTemporary(); } |
| 315 | |
| 316 | // Functions for handling of dst register |
| 317 | |
cwzwarich@webkit.org | d47b49a | 2008-12-03 06:13:58 +0000 | [diff] [blame] | 318 | RegisterID* ignoredResult() { return &m_ignoredResultRegister; } |
| 319 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 320 | // This will be allocated in the temporary region of registers, but it will |
| 321 | // not be marked as a temporary. This will ensure that finalDestination() does |
| 322 | // not overwrite a block scope variable that it mistakes as a temporary. These |
| 323 | // registers can be (and are) reclaimed when the lexical scope they belong to |
| 324 | // is no longer on the symbol table stack. |
| 325 | RegisterID* newBlockScopeVariable(); |
| 326 | |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 327 | // Returns a place to write intermediate values of an operation |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 328 | // which reuses dst if it is safe to do so. |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 329 | RegisterID* tempDestination(RegisterID* dst) |
| 330 | { |
| 331 | return (dst && dst != ignoredResult() && dst->isTemporary()) ? dst : newTemporary(); |
| 332 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 333 | |
| 334 | // Returns the place to write the final output of an operation. |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 335 | RegisterID* finalDestination(RegisterID* originalDst, RegisterID* tempDst = 0) |
| 336 | { |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 337 | if (originalDst && originalDst != ignoredResult()) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 338 | return originalDst; |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 339 | ASSERT(tempDst != ignoredResult()); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 340 | if (tempDst && tempDst->isTemporary()) |
| 341 | return tempDst; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 342 | return newTemporary(); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 343 | } |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 344 | |
| 345 | RegisterID* destinationForAssignResult(RegisterID* dst) |
| 346 | { |
weinig@apple.com | cb26d81 | 2008-12-06 22:01:05 +0000 | [diff] [blame] | 347 | if (dst && dst != ignoredResult() && m_codeBlock->needsFullScopeChain()) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 348 | return dst->isTemporary() ? dst : newTemporary(); |
| 349 | return 0; |
| 350 | } |
| 351 | |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 352 | // Moves src to dst if dst is not null and is different from src, otherwise just returns src. |
| 353 | RegisterID* moveToDestinationIfNeeded(RegisterID* dst, RegisterID* src) |
| 354 | { |
| 355 | return dst == ignoredResult() ? 0 : (dst && dst != src) ? emitMove(dst, src) : src; |
| 356 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 357 | |
oliver@apple.com | 6a97645 | 2013-03-11 21:02:39 +0000 | [diff] [blame] | 358 | LabelScopePtr newLabelScope(LabelScope::Type, const Identifier* = 0); |
ggaren@apple.com | fae5b80 | 2008-11-15 22:33:58 +0000 | [diff] [blame] | 359 | PassRefPtr<Label> newLabel(); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 360 | |
ggaren@apple.com | d786e6b | 2013-04-04 23:16:20 +0000 | [diff] [blame] | 361 | void emitNode(RegisterID* dst, StatementNode* n) |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 362 | { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 363 | // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary. |
darin@apple.com | 87255fc | 2008-06-28 16:03:11 +0000 | [diff] [blame] | 364 | ASSERT(!dst || dst == ignoredResult() || !dst->isTemporary() || dst->refCount()); |
mark.lam@apple.com | 3072125 | 2013-11-21 05:29:42 +0000 | [diff] [blame] | 365 | if (!m_vm->isSafeToRecurse()) { |
ggaren@apple.com | d786e6b | 2013-04-04 23:16:20 +0000 | [diff] [blame] | 366 | emitThrowExpressionTooDeepException(); |
| 367 | return; |
| 368 | } |
| 369 | n->emitBytecode(*this, dst); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 370 | } |
| 371 | |
ggaren@apple.com | d786e6b | 2013-04-04 23:16:20 +0000 | [diff] [blame] | 372 | void emitNode(StatementNode* n) |
| 373 | { |
| 374 | emitNode(0, n); |
| 375 | } |
| 376 | |
| 377 | RegisterID* emitNode(RegisterID* dst, ExpressionNode* n) |
| 378 | { |
| 379 | // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary. |
| 380 | ASSERT(!dst || dst == ignoredResult() || !dst->isTemporary() || dst->refCount()); |
mark.lam@apple.com | 3072125 | 2013-11-21 05:29:42 +0000 | [diff] [blame] | 381 | if (!m_vm->isSafeToRecurse()) |
ggaren@apple.com | d786e6b | 2013-04-04 23:16:20 +0000 | [diff] [blame] | 382 | return emitThrowExpressionTooDeepException(); |
| 383 | return n->emitBytecode(*this, dst); |
| 384 | } |
| 385 | |
| 386 | RegisterID* emitNode(ExpressionNode* n) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 387 | { |
| 388 | return emitNode(0, n); |
| 389 | } |
| 390 | |
ggaren@apple.com | d7cf35d | 2013-03-29 19:12:18 +0000 | [diff] [blame] | 391 | void emitNodeInConditionContext(ExpressionNode* n, Label* trueTarget, Label* falseTarget, FallThroughMode fallThroughMode) |
mjs@apple.com | a46c49c | 2009-12-06 09:42:03 +0000 | [diff] [blame] | 392 | { |
mark.lam@apple.com | 3072125 | 2013-11-21 05:29:42 +0000 | [diff] [blame] | 393 | if (!m_vm->isSafeToRecurse()) { |
mjs@apple.com | a46c49c | 2009-12-06 09:42:03 +0000 | [diff] [blame] | 394 | emitThrowExpressionTooDeepException(); |
ggaren@apple.com | d786e6b | 2013-04-04 23:16:20 +0000 | [diff] [blame] | 395 | return; |
| 396 | } |
| 397 | |
| 398 | n->emitBytecodeInConditionContext(*this, trueTarget, falseTarget, fallThroughMode); |
mjs@apple.com | a46c49c | 2009-12-06 09:42:03 +0000 | [diff] [blame] | 399 | } |
| 400 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 401 | void emitExpressionInfo(const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd) |
| 402 | { |
| 403 | ASSERT(divot.offset >= divotStart.offset); |
| 404 | ASSERT(divotEnd.offset >= divot.offset); |
| 405 | |
mark.lam@apple.com | 5b45f90 | 2013-07-09 16:15:12 +0000 | [diff] [blame] | 406 | int sourceOffset = m_scopeNode->source().startOffset(); |
| 407 | unsigned firstLine = m_scopeNode->source().firstLine(); |
| 408 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 409 | int divotOffset = divot.offset - sourceOffset; |
| 410 | int startOffset = divot.offset - divotStart.offset; |
| 411 | int endOffset = divotEnd.offset - divot.offset; |
mark.lam@apple.com | 5b45f90 | 2013-07-09 16:15:12 +0000 | [diff] [blame] | 412 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 413 | unsigned line = divot.line; |
| 414 | ASSERT(line >= firstLine); |
| 415 | line -= firstLine; |
| 416 | |
| 417 | int lineStart = divot.lineStartOffset; |
mark.lam@apple.com | 5b45f90 | 2013-07-09 16:15:12 +0000 | [diff] [blame] | 418 | if (lineStart > sourceOffset) |
| 419 | lineStart -= sourceOffset; |
| 420 | else |
| 421 | lineStart = 0; |
oliver@apple.com | d055db6 | 2013-10-02 19:11:04 +0000 | [diff] [blame] | 422 | |
| 423 | if (divotOffset < lineStart) |
| 424 | return; |
| 425 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 426 | unsigned column = divotOffset - lineStart; |
mark.lam@apple.com | 5b45f90 | 2013-07-09 16:15:12 +0000 | [diff] [blame] | 427 | |
| 428 | unsigned instructionOffset = instructions().size(); |
oliver@apple.com | 4cbc701 | 2014-02-14 23:29:31 +0000 | [diff] [blame] | 429 | if (!m_isBuiltinFunction) |
| 430 | m_codeBlock->addExpressionInfo(instructionOffset, divotOffset, startOffset, endOffset, line, column); |
oliver@apple.com | 90b88ae | 2008-07-19 01:44:24 +0000 | [diff] [blame] | 431 | } |
cwzwarich@webkit.org | 2ead1b3 | 2008-12-12 22:48:53 +0000 | [diff] [blame] | 432 | |
fpizlo@apple.com | 2c4a7e9 | 2014-08-06 05:27:46 +0000 | [diff] [blame] | 433 | |
cwzwarich@webkit.org | 2947759 | 2008-06-15 05:24:21 +0000 | [diff] [blame] | 434 | ALWAYS_INLINE bool leftHandSideNeedsCopy(bool rightHasAssignments, bool rightIsPure) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 435 | { |
weinig@apple.com | cb26d81 | 2008-12-06 22:01:05 +0000 | [diff] [blame] | 436 | return (m_codeType != FunctionCode || m_codeBlock->needsFullScopeChain() || rightHasAssignments) && !rightIsPure; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 437 | } |
| 438 | |
cwzwarich@webkit.org | 2947759 | 2008-06-15 05:24:21 +0000 | [diff] [blame] | 439 | ALWAYS_INLINE PassRefPtr<RegisterID> emitNodeForLeftHandSide(ExpressionNode* n, bool rightHasAssignments, bool rightIsPure) |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 440 | { |
cwzwarich@webkit.org | 2947759 | 2008-06-15 05:24:21 +0000 | [diff] [blame] | 441 | if (leftHandSideNeedsCopy(rightHasAssignments, rightIsPure)) { |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 442 | PassRefPtr<RegisterID> dst = newTemporary(); |
| 443 | emitNode(dst.get(), n); |
| 444 | return dst; |
| 445 | } |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 446 | |
ggaren@apple.com | bcf06d3 | 2012-01-12 00:14:42 +0000 | [diff] [blame] | 447 | return emitNode(n); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 448 | } |
| 449 | |
commit-queue@webkit.org | 2ed31ec | 2014-08-21 01:03:20 +0000 | [diff] [blame] | 450 | void emitTypeProfilerExpressionInfo(const JSTextPosition& startDivot, const JSTextPosition& endDivot); |
| 451 | void emitProfileType(RegisterID* registerToProfile, ProfileTypeBytecodeFlag, const Identifier*); |
fpizlo@apple.com | 3378c48 | 2014-07-27 23:14:40 +0000 | [diff] [blame] | 452 | |
saambarati1@gmail.com | b4f28a5 | 2014-12-05 05:58:07 +0000 | [diff] [blame] | 453 | void emitProfileControlFlow(int); |
| 454 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 455 | RegisterID* emitLoad(RegisterID* dst, bool); |
darin@apple.com | a372f0a | 2008-09-21 20:35:20 +0000 | [diff] [blame] | 456 | RegisterID* emitLoad(RegisterID* dst, const Identifier&); |
benjamin@webkit.org | 54d94f5 | 2015-02-28 03:21:37 +0000 | [diff] [blame] | 457 | RegisterID* emitLoad(RegisterID* dst, JSValue, SourceCodeRepresentation = SourceCodeRepresentation::Other); |
oliver@apple.com | 75f804e | 2013-03-07 00:25:20 +0000 | [diff] [blame] | 458 | RegisterID* emitLoadGlobalObject(RegisterID* dst); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 459 | |
ggaren@apple.com | 1fd4237 | 2008-12-02 21:52:24 +0000 | [diff] [blame] | 460 | RegisterID* emitUnaryOp(OpcodeID, RegisterID* dst, RegisterID* src); |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 461 | RegisterID* emitBinaryOp(OpcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2, OperandTypes); |
| 462 | RegisterID* emitEqualityOp(OpcodeID, RegisterID* dst, RegisterID* src1, RegisterID* src2); |
| 463 | RegisterID* emitUnaryNoDstOp(OpcodeID, RegisterID* src); |
mjs@apple.com | 33b7578 | 2008-06-15 23:59:24 +0000 | [diff] [blame] | 464 | |
ggaren@apple.com | c862eac | 2013-01-29 05:48:01 +0000 | [diff] [blame] | 465 | RegisterID* emitCreateThis(RegisterID* dst); |
rniwa@webkit.org | eb7ac19 | 2015-03-13 01:11:15 +0000 | [diff] [blame] | 466 | void emitTDZCheck(RegisterID* target); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 467 | bool needsTDZCheck(const Variable&); |
| 468 | void emitTDZCheckIfNecessary(const Variable&, RegisterID* target, RegisterID* scope); |
| 469 | void liftTDZCheckIfPossible(const Variable&); |
weinig@apple.com | 3412bb4 | 2008-09-01 21:22:54 +0000 | [diff] [blame] | 470 | RegisterID* emitNewObject(RegisterID* dst); |
oliver@apple.com | a991d69 | 2011-06-14 23:39:25 +0000 | [diff] [blame] | 471 | RegisterID* emitNewArray(RegisterID* dst, ElementNode*, unsigned length); // stops at first elision |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 472 | |
oliver@apple.com | 4725226 | 2014-10-07 18:57:57 +0000 | [diff] [blame] | 473 | RegisterID* emitNewFunction(RegisterID* dst, FunctionBodyNode*); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 474 | RegisterID* emitNewFunctionInternal(RegisterID* dst, unsigned index); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 475 | RegisterID* emitNewFunctionExpression(RegisterID* dst, FuncExprNode* func); |
rniwa@webkit.org | d81805e | 2015-03-17 04:02:52 +0000 | [diff] [blame] | 476 | RegisterID* emitNewDefaultConstructor(RegisterID* dst, ConstructorKind, const Identifier& name); |
oliver@apple.com | 5652af7 | 2011-05-26 01:12:46 +0000 | [diff] [blame] | 477 | RegisterID* emitNewRegExp(RegisterID* dst, RegExp*); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 478 | |
rniwa@webkit.org | 49d0cc1 | 2015-04-25 22:03:30 +0000 | [diff] [blame] | 479 | RegisterID* emitMoveLinkTimeConstant(RegisterID* dst, LinkTimeConstant); |
joepeck@webkit.org | 408f4815 | 2015-03-27 02:55:57 +0000 | [diff] [blame] | 480 | RegisterID* emitMoveEmptyValue(RegisterID* dst); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 481 | RegisterID* emitMove(RegisterID* dst, RegisterID* src); |
| 482 | |
ggaren@apple.com | f303611 | 2013-04-27 23:14:04 +0000 | [diff] [blame] | 483 | RegisterID* emitToNumber(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_to_number, dst, src); } |
utatane.tea@gmail.com | 4014aea | 2015-04-27 00:27:28 +0000 | [diff] [blame] | 484 | RegisterID* emitToString(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_to_string, dst, src); } |
ggaren@apple.com | f303611 | 2013-04-27 23:14:04 +0000 | [diff] [blame] | 485 | RegisterID* emitInc(RegisterID* srcDst); |
| 486 | RegisterID* emitDec(RegisterID* srcDst); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 487 | |
barraclough@apple.com | b46d57b4 | 2012-09-22 00:43:03 +0000 | [diff] [blame] | 488 | void emitCheckHasInstance(RegisterID* dst, RegisterID* value, RegisterID* base, Label* target); |
barraclough@apple.com | 094dbd9 | 2012-09-22 01:18:54 +0000 | [diff] [blame] | 489 | RegisterID* emitInstanceOf(RegisterID* dst, RegisterID* value, RegisterID* basePrototype); |
ggaren@apple.com | 1fd4237 | 2008-12-02 21:52:24 +0000 | [diff] [blame] | 490 | RegisterID* emitTypeOf(RegisterID* dst, RegisterID* src) { return emitUnaryOp(op_typeof, dst, src); } |
barraclough@apple.com | b8b15e2 | 2008-09-27 01:44:15 +0000 | [diff] [blame] | 491 | RegisterID* emitIn(RegisterID* dst, RegisterID* property, RegisterID* base) { return emitBinaryOp(op_in, dst, property, base, OperandTypes()); } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 492 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 493 | RegisterID* emitGetById(RegisterID* dst, RegisterID* base, const Identifier& property); |
| 494 | RegisterID* emitPutById(RegisterID* base, const Identifier& property, RegisterID* value); |
joepeck@webkit.org | a26e6e5 | 2015-03-06 21:31:27 +0000 | [diff] [blame] | 495 | RegisterID* emitDirectPutById(RegisterID* base, const Identifier& property, RegisterID* value, PropertyNode::PutType); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 496 | RegisterID* emitDeleteById(RegisterID* dst, RegisterID* base, const Identifier&); |
| 497 | RegisterID* emitGetByVal(RegisterID* dst, RegisterID* base, RegisterID* property); |
oliver@apple.com | 74e00b0 | 2010-09-25 21:42:00 +0000 | [diff] [blame] | 498 | RegisterID* emitGetArgumentByVal(RegisterID* dst, RegisterID* base, RegisterID* property); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 499 | RegisterID* emitPutByVal(RegisterID* base, RegisterID* property, RegisterID* value); |
oliver@apple.com | e050d64 | 2013-10-19 00:09:28 +0000 | [diff] [blame] | 500 | RegisterID* emitDirectPutByVal(RegisterID* base, RegisterID* property, RegisterID* value); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 501 | RegisterID* emitDeleteByVal(RegisterID* dst, RegisterID* base, RegisterID* property); |
| 502 | RegisterID* emitPutByIndex(RegisterID* base, unsigned index, RegisterID* value); |
commit-queue@webkit.org | fb471b4 | 2015-05-14 01:32:25 +0000 | [diff] [blame] | 503 | |
| 504 | void emitPutGetterById(RegisterID* base, const Identifier& property, RegisterID* getter); |
| 505 | void emitPutSetterById(RegisterID* base, const Identifier& property, RegisterID* setter); |
barraclough@apple.com | 09a5568 | 2012-01-30 18:28:39 +0000 | [diff] [blame] | 506 | void emitPutGetterSetter(RegisterID* base, const Identifier& property, RegisterID* getter, RegisterID* setter); |
fpizlo@apple.com | 4500e35 | 2012-10-17 21:39:11 +0000 | [diff] [blame] | 507 | |
| 508 | ExpectedFunction expectedFunctionForIdentifier(const Identifier&); |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 509 | RegisterID* emitCall(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
| 510 | RegisterID* emitCallEval(RegisterID* dst, RegisterID* func, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
oliver@apple.com | 2f5c83b | 2014-02-25 06:59:38 +0000 | [diff] [blame] | 511 | RegisterID* emitCallVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
mjs@apple.com | 33b7578 | 2008-06-15 23:59:24 +0000 | [diff] [blame] | 512 | |
rniwa@webkit.org | 49d0cc1 | 2015-04-25 22:03:30 +0000 | [diff] [blame] | 513 | enum PropertyDescriptorOption { |
| 514 | PropertyConfigurable = 1, |
| 515 | PropertyWritable = 1 << 1, |
| 516 | PropertyEnumerable = 1 << 2, |
| 517 | }; |
| 518 | void emitCallDefineProperty(RegisterID* newObj, RegisterID* propertyNameRegister, |
| 519 | RegisterID* valueRegister, RegisterID* getterRegister, RegisterID* setterRegister, unsigned options, const JSTextPosition&); |
| 520 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 521 | void emitEnumeration(ThrowableExpressionData* enumerationNode, ExpressionNode* subjectNode, const std::function<void(BytecodeGenerator&, RegisterID*)>& callBack, VariableEnvironmentNode* = nullptr, RegisterID* forLoopSymbolTable = nullptr); |
ossy@webkit.org | db39125 | 2015-05-21 12:29:43 +0000 | [diff] [blame] | 522 | |
| 523 | #if ENABLE(ES6_TEMPLATE_LITERAL_SYNTAX) |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 524 | RegisterID* emitGetTemplateObject(RegisterID* dst, TaggedTemplateNode*); |
ossy@webkit.org | db39125 | 2015-05-21 12:29:43 +0000 | [diff] [blame] | 525 | #endif |
| 526 | |
cwzwarich@webkit.org | a3b5f8a | 2008-10-06 06:00:58 +0000 | [diff] [blame] | 527 | RegisterID* emitReturn(RegisterID* src); |
mjs@apple.com | 33b7578 | 2008-06-15 23:59:24 +0000 | [diff] [blame] | 528 | RegisterID* emitEnd(RegisterID* src) { return emitUnaryNoDstOp(op_end, src); } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 529 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 530 | RegisterID* emitConstruct(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
barraclough@apple.com | 14dc4e1 | 2009-05-07 00:06:07 +0000 | [diff] [blame] | 531 | RegisterID* emitStrcat(RegisterID* dst, RegisterID* src, int count); |
| 532 | void emitToPrimitive(RegisterID* dst, RegisterID* src); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 533 | |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 534 | ResolveType resolveType(); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 535 | RegisterID* emitResolveConstantLocal(RegisterID* dst, const Variable&); |
| 536 | RegisterID* emitResolveScope(RegisterID* dst, const Variable&); |
| 537 | RegisterID* emitGetFromScope(RegisterID* dst, RegisterID* scope, const Variable&, ResolveMode); |
| 538 | RegisterID* emitPutToScope(RegisterID* scope, const Variable&, RegisterID* value, ResolveMode); |
| 539 | RegisterID* initializeVariable(const Variable&, RegisterID* value); |
oliver@apple.com | 58c8675 | 2013-07-25 04:02:40 +0000 | [diff] [blame] | 540 | |
ggaren@apple.com | fae5b80 | 2008-11-15 22:33:58 +0000 | [diff] [blame] | 541 | PassRefPtr<Label> emitLabel(Label*); |
fpizlo@apple.com | a71ab05 | 2011-09-13 05:35:53 +0000 | [diff] [blame] | 542 | void emitLoopHint(); |
ggaren@apple.com | fae5b80 | 2008-11-15 22:33:58 +0000 | [diff] [blame] | 543 | PassRefPtr<Label> emitJump(Label* target); |
| 544 | PassRefPtr<Label> emitJumpIfTrue(RegisterID* cond, Label* target); |
| 545 | PassRefPtr<Label> emitJumpIfFalse(RegisterID* cond, Label* target); |
oliver@apple.com | 6c10600 | 2009-03-28 03:50:39 +0000 | [diff] [blame] | 546 | PassRefPtr<Label> emitJumpIfNotFunctionCall(RegisterID* cond, Label* target); |
oliver@apple.com | 65e286e | 2009-04-08 23:08:28 +0000 | [diff] [blame] | 547 | PassRefPtr<Label> emitJumpIfNotFunctionApply(RegisterID* cond, Label* target); |
msaboff@apple.com | c5b9539 | 2014-10-31 21:27:10 +0000 | [diff] [blame] | 548 | void emitPopScopes(RegisterID* srcDst, int targetScopeDepth); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 549 | |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 550 | RegisterID* emitHasIndexedProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName); |
| 551 | RegisterID* emitHasStructureProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName, RegisterID* enumerator); |
| 552 | RegisterID* emitHasGenericProperty(RegisterID* dst, RegisterID* base, RegisterID* propertyName); |
msaboff@apple.com | b644c25 | 2015-03-24 10:05:21 +0000 | [diff] [blame] | 553 | RegisterID* emitGetPropertyEnumerator(RegisterID* dst, RegisterID* base); |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 554 | RegisterID* emitGetEnumerableLength(RegisterID* dst, RegisterID* base); |
| 555 | RegisterID* emitGetStructurePropertyEnumerator(RegisterID* dst, RegisterID* base, RegisterID* length); |
| 556 | RegisterID* emitGetGenericPropertyEnumerator(RegisterID* dst, RegisterID* base, RegisterID* length, RegisterID* structureEnumerator); |
msaboff@apple.com | b644c25 | 2015-03-24 10:05:21 +0000 | [diff] [blame] | 557 | RegisterID* emitEnumeratorStructurePropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index); |
| 558 | RegisterID* emitEnumeratorGenericPropertyName(RegisterID* dst, RegisterID* enumerator, RegisterID* index); |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 559 | RegisterID* emitToIndexString(RegisterID* dst, RegisterID* index); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 560 | |
utatane.tea@gmail.com | 4ddd519 | 2015-03-05 14:57:17 +0000 | [diff] [blame] | 561 | RegisterID* emitIsObject(RegisterID* dst, RegisterID* src); |
| 562 | RegisterID* emitIsUndefined(RegisterID* dst, RegisterID* src); |
| 563 | |
utatane.tea@gmail.com | 412d761 | 2015-06-26 03:13:25 +0000 | [diff] [blame] | 564 | RegisterID* emitIteratorNext(RegisterID* dst, RegisterID* iterator, const ThrowableExpressionData* node); |
utatane.tea@gmail.com | 5210f30 | 2015-06-20 11:04:27 +0000 | [diff] [blame] | 565 | void emitIteratorClose(RegisterID* iterator, const ThrowableExpressionData* node); |
utatane.tea@gmail.com | bc07449 | 2015-04-01 09:36:15 +0000 | [diff] [blame] | 566 | |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 567 | bool emitReadOnlyExceptionIfNeeded(const Variable&); |
ggaren@apple.com | 6e30982 | 2012-09-05 21:44:43 +0000 | [diff] [blame] | 568 | |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 569 | // Start a try block. 'start' must have been emitted. |
| 570 | TryData* pushTry(Label* start); |
| 571 | // End a try block. 'end' must have been emitted. |
mark.lam@apple.com | 6ed0827 | 2015-06-05 18:52:12 +0000 | [diff] [blame] | 572 | void popTryAndEmitCatch(TryData*, RegisterID* exceptionRegister, RegisterID* thrownValueRegister, Label* end, HandlerType); |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 573 | |
oliver@apple.com | faeca00 | 2010-06-18 20:14:23 +0000 | [diff] [blame] | 574 | void emitThrow(RegisterID* exc) |
| 575 | { |
| 576 | m_usesExceptions = true; |
| 577 | emitUnaryNoDstOp(op_throw, exc); |
| 578 | } |
| 579 | |
benjamin@webkit.org | cff06e4 | 2012-08-30 21:23:51 +0000 | [diff] [blame] | 580 | void emitThrowReferenceError(const String& message); |
utatane.tea@gmail.com | 4ddd519 | 2015-03-05 14:57:17 +0000 | [diff] [blame] | 581 | void emitThrowTypeError(const String& message); |
barraclough@apple.com | 4920ae9 | 2010-11-12 03:06:07 +0000 | [diff] [blame] | 582 | |
msaboff@apple.com | c5b9539 | 2014-10-31 21:27:10 +0000 | [diff] [blame] | 583 | void emitPushFunctionNameScope(RegisterID* dst, const Identifier& property, RegisterID* value, unsigned attributes); |
| 584 | void emitPushCatchScope(RegisterID* dst, const Identifier& property, RegisterID* value, unsigned attributes); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 585 | |
msaboff@apple.com | 8b6b341 | 2014-11-04 03:36:28 +0000 | [diff] [blame] | 586 | void emitGetScope(); |
msaboff@apple.com | c5b9539 | 2014-10-31 21:27:10 +0000 | [diff] [blame] | 587 | RegisterID* emitPushWithScope(RegisterID* dst, RegisterID* scope); |
saambarati1@gmail.com | 3fff23c | 2015-07-19 00:36:45 +0000 | [diff] [blame] | 588 | void emitPopScope(RegisterID* dst, RegisterID* scope); |
| 589 | void emitPopWithOrCatchScope(RegisterID* srcDst); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 590 | RegisterID* emitGetParentScope(RegisterID* dst, RegisterID* scope); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 591 | |
mark.lam@apple.com | e72693d | 2013-09-24 23:52:57 +0000 | [diff] [blame] | 592 | void emitDebugHook(DebugHookID, unsigned line, unsigned charOffset, unsigned lineStart); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 593 | |
oliver@apple.com | 05740a7 | 2009-03-18 07:24:39 +0000 | [diff] [blame] | 594 | bool hasFinaliser() { return m_finallyDepth != 0; } |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 595 | |
fpizlo@apple.com | dd58bf9 | 2012-04-04 04:25:56 +0000 | [diff] [blame] | 596 | void pushFinallyContext(StatementNode* finallyBlock); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 597 | void popFinallyContext(); |
utatane.tea@gmail.com | bc07449 | 2015-04-01 09:36:15 +0000 | [diff] [blame] | 598 | void pushIteratorCloseContext(RegisterID* iterator, ThrowableExpressionData* enumerationNode); |
| 599 | void popIteratorCloseContext(); |
ggaren@apple.com | 4dbab80 | 2008-10-31 19:59:08 +0000 | [diff] [blame] | 600 | |
fpizlo@apple.com | caf3505 | 2014-08-20 02:38:46 +0000 | [diff] [blame] | 601 | void pushIndexedForInScope(RegisterID* local, RegisterID* index); |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 602 | void popIndexedForInScope(RegisterID* local); |
fpizlo@apple.com | caf3505 | 2014-08-20 02:38:46 +0000 | [diff] [blame] | 603 | void pushStructureForInScope(RegisterID* local, RegisterID* index, RegisterID* property, RegisterID* enumerator); |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 604 | void popStructureForInScope(RegisterID* local); |
| 605 | void invalidateForInContextForLocal(RegisterID* local); |
oliver@apple.com | 0a4803c | 2009-10-29 01:25:02 +0000 | [diff] [blame] | 606 | |
mark.lam@apple.com | ee88ae0 | 2014-03-21 23:48:39 +0000 | [diff] [blame] | 607 | LabelScopePtr breakTarget(const Identifier&); |
| 608 | LabelScopePtr continueTarget(const Identifier&); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 609 | |
oliver@apple.com | 8007f46 | 2008-07-24 00:49:46 +0000 | [diff] [blame] | 610 | void beginSwitch(RegisterID*, SwitchInfo::SwitchType); |
ggaren@apple.com | fae5b80 | 2008-11-15 22:33:58 +0000 | [diff] [blame] | 611 | void endSwitch(uint32_t clauseCount, RefPtr<Label>*, ExpressionNode**, Label* defaultLabel, int32_t min, int32_t range); |
oliver@apple.com | 8007f46 | 2008-07-24 00:49:46 +0000 | [diff] [blame] | 612 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 613 | CodeType codeType() const { return m_codeType; } |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 614 | |
barraclough@apple.com | 9835d1d | 2010-06-01 23:13:23 +0000 | [diff] [blame] | 615 | bool shouldEmitProfileHooks() { return m_shouldEmitProfileHooks; } |
ggaren@apple.com | 81c68cc | 2013-04-27 06:43:33 +0000 | [diff] [blame] | 616 | bool shouldEmitDebugHooks() { return m_shouldEmitDebugHooks; } |
oliver@apple.com | 5930185 | 2010-10-11 19:12:29 +0000 | [diff] [blame] | 617 | |
| 618 | bool isStrictMode() const { return m_codeBlock->isStrictMode(); } |
oliver@apple.com | ba848d1 | 2014-02-12 17:14:23 +0000 | [diff] [blame] | 619 | |
| 620 | bool isBuiltinFunction() const { return m_isBuiltinFunction; } |
rniwa@webkit.org | 679fb98f | 2015-01-22 02:06:33 +0000 | [diff] [blame] | 621 | |
| 622 | OpcodeID lastOpcodeID() const { return m_lastOpcodeID; } |
| 623 | |
saambarati1@gmail.com | 3bde530 | 2015-07-24 18:40:58 +0000 | [diff] [blame^] | 624 | private: |
| 625 | void pushLexicalScopeInternal(VariableEnvironment&, bool canOptimizeTDZChecks, RegisterID** constantSymbolTableResult); |
| 626 | public: |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 627 | void pushLexicalScope(VariableEnvironmentNode*, bool canOptimizeTDZChecks, RegisterID** constantSymbolTableResult = nullptr); |
| 628 | void popLexicalScope(VariableEnvironmentNode*); |
| 629 | void prepareLexicalScopeForNextForLoopIteration(VariableEnvironmentNode*, RegisterID* loopSymbolTable); |
saambarati1@gmail.com | 3fff23c | 2015-07-19 00:36:45 +0000 | [diff] [blame] | 630 | int labelScopeDepth() const; |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 631 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 632 | private: |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 633 | void reclaimFreeRegisters(); |
saambarati1@gmail.com | e455672 | 2015-07-19 16:57:44 +0000 | [diff] [blame] | 634 | Variable variableForLocalEntry(const Identifier&, const SymbolTableEntry&, int symbolTableConstantIndex, bool isLexicallyScoped); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 635 | |
ggaren@apple.com | 47d3f05 | 2008-11-15 21:37:49 +0000 | [diff] [blame] | 636 | void emitOpcode(OpcodeID); |
fpizlo@apple.com | 75c91a7 | 2012-11-08 22:28:25 +0000 | [diff] [blame] | 637 | UnlinkedArrayAllocationProfile newArrayAllocationProfile(); |
ggaren@apple.com | c862eac | 2013-01-29 05:48:01 +0000 | [diff] [blame] | 638 | UnlinkedObjectAllocationProfile newObjectAllocationProfile(); |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 639 | UnlinkedArrayProfile newArrayProfile(); |
| 640 | UnlinkedValueProfile emitProfiledOpcode(OpcodeID); |
ggaren@apple.com | c862eac | 2013-01-29 05:48:01 +0000 | [diff] [blame] | 641 | int kill(RegisterID* dst) |
| 642 | { |
| 643 | int index = dst->index(); |
| 644 | m_staticPropertyAnalyzer.kill(index); |
| 645 | return index; |
| 646 | } |
| 647 | |
cwzwarich@webkit.org | d195dd8 | 2008-06-11 19:48:15 +0000 | [diff] [blame] | 648 | void retrieveLastBinaryOp(int& dstIndex, int& src1Index, int& src2Index); |
oliver@apple.com | 1566494 | 2008-08-13 03:17:19 +0000 | [diff] [blame] | 649 | void retrieveLastUnaryOp(int& dstIndex, int& srcIndex); |
commit-queue@webkit.org | fcb562d | 2010-10-01 17:50:39 +0000 | [diff] [blame] | 650 | ALWAYS_INLINE void rewindBinaryOp(); |
| 651 | ALWAYS_INLINE void rewindUnaryOp(); |
cwzwarich@webkit.org | d195dd8 | 2008-06-11 19:48:15 +0000 | [diff] [blame] | 652 | |
msaboff@apple.com | 5e62e3f | 2014-11-21 23:41:26 +0000 | [diff] [blame] | 653 | void allocateAndEmitScope(); |
msaboff@apple.com | c5b9539 | 2014-10-31 21:27:10 +0000 | [diff] [blame] | 654 | void emitComplexPopScopes(RegisterID*, ControlFlowContext* topScope, ControlFlowContext* bottomScope); |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 655 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 656 | typedef HashMap<double, JSValue> NumberMap; |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 657 | typedef HashMap<UniquedStringImpl*, JSString*, IdentifierRepHash> IdentifierStringMap; |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 658 | typedef HashMap<TemplateRegistryKey, JSTemplateRegistryKey*> TemplateRegistryKeyMap; |
oliver@apple.com | 65e286e | 2009-04-08 23:08:28 +0000 | [diff] [blame] | 659 | |
fpizlo@apple.com | 4500e35 | 2012-10-17 21:39:11 +0000 | [diff] [blame] | 660 | // Helper for emitCall() and emitConstruct(). This works because the set of |
| 661 | // expected functions have identical behavior for both call and construct |
| 662 | // (i.e. "Object()" is identical to "new Object()"). |
| 663 | ExpectedFunction emitExpectedFunctionSnippet(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, Label* done); |
| 664 | |
mark.lam@apple.com | 3b256ca | 2013-07-30 17:01:40 +0000 | [diff] [blame] | 665 | RegisterID* emitCall(OpcodeID, RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
oliver@apple.com | f61c9a1 | 2010-09-24 19:06:29 +0000 | [diff] [blame] | 666 | |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 667 | RegisterID* newRegister(); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 668 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 669 | // Adds an anonymous local var slot. To give this slot a name, add it to symbolTable(). |
ggaren@apple.com | 83ce11c | 2010-05-19 05:10:11 +0000 | [diff] [blame] | 670 | RegisterID* addVar() |
| 671 | { |
| 672 | ++m_codeBlock->m_numVars; |
fpizlo@apple.com | e3b7687 | 2015-02-06 16:04:39 +0000 | [diff] [blame] | 673 | RegisterID* result = newRegister(); |
| 674 | ASSERT(VirtualRegister(result->index()).toLocal() == m_codeBlock->m_numVars - 1); |
| 675 | result->ref(); // We should never free this slot. |
| 676 | return result; |
ggaren@apple.com | 83ce11c | 2010-05-19 05:10:11 +0000 | [diff] [blame] | 677 | } |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 678 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 679 | // Initializes the stack form the parameter; does nothing for the symbol table. |
| 680 | RegisterID* initializeNextParameter(); |
saambarati1@gmail.com | cc3bcb6 | 2015-07-02 23:53:10 +0000 | [diff] [blame] | 681 | UniquedStringImpl* visibleNameForParameter(DestructuringPatternNode*); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 682 | |
| 683 | RegisterID& registerFor(VirtualRegister reg) |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 684 | { |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 685 | if (reg.isLocal()) |
| 686 | return m_calleeRegisters[reg.toLocal()]; |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 687 | |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 688 | if (reg.offset() == JSStack::Callee) |
ggaren@apple.com | f820008 | 2012-09-07 01:42:53 +0000 | [diff] [blame] | 689 | return m_calleeRegister; |
| 690 | |
ggaren@apple.com | 99e9f3f | 2011-06-22 20:07:37 +0000 | [diff] [blame] | 691 | ASSERT(m_parameters.size()); |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 692 | return m_parameters[reg.toArgument()]; |
ggaren@apple.com | 107bd0e | 2008-09-24 00:27:18 +0000 | [diff] [blame] | 693 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 694 | |
mark.lam@apple.com | dd72307 | 2015-01-22 19:05:42 +0000 | [diff] [blame] | 695 | bool hasConstant(const Identifier&) const; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 696 | unsigned addConstant(const Identifier&); |
benjamin@webkit.org | 54d94f5 | 2015-02-28 03:21:37 +0000 | [diff] [blame] | 697 | RegisterID* addConstantValue(JSValue, SourceCodeRepresentation = SourceCodeRepresentation::Other); |
ggaren@apple.com | 63a291e | 2012-09-10 20:23:50 +0000 | [diff] [blame] | 698 | RegisterID* addConstantEmptyValue(); |
oliver@apple.com | 5652af7 | 2011-05-26 01:12:46 +0000 | [diff] [blame] | 699 | unsigned addRegExp(RegExp*); |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 700 | |
oliver@apple.com | 673aed6 | 2011-06-28 20:21:37 +0000 | [diff] [blame] | 701 | unsigned addConstantBuffer(unsigned length); |
oliver@apple.com | a991d69 | 2011-06-14 23:39:25 +0000 | [diff] [blame] | 702 | |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 703 | UnlinkedFunctionExecutable* makeFunction(FunctionBodyNode* body) |
| 704 | { |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 705 | VariableEnvironment variablesUnderTDZ; |
| 706 | getVariablesUnderTDZ(variablesUnderTDZ); |
utatane.tea@gmail.com | 54887a1 | 2015-07-23 02:36:20 +0000 | [diff] [blame] | 707 | |
| 708 | FunctionParseMode parseMode = body->parseMode(); |
| 709 | ConstructAbility constructAbility = ConstructAbility::CanConstruct; |
| 710 | if (parseMode == GetterMode || parseMode == SetterMode || parseMode == ArrowFunctionMode || (parseMode == MethodMode && body->constructorKind() == ConstructorKind::None)) |
| 711 | constructAbility = ConstructAbility::CannotConstruct; |
| 712 | |
| 713 | return UnlinkedFunctionExecutable::create(m_vm, m_scopeNode->source(), body, isBuiltinFunction() ? UnlinkedBuiltinFunction : UnlinkedNormalFunction, constructAbility, variablesUnderTDZ); |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 714 | } |
| 715 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 716 | void getVariablesUnderTDZ(VariableEnvironment&); |
| 717 | |
rniwa@webkit.org | fda6b5e | 2015-02-25 00:41:35 +0000 | [diff] [blame] | 718 | RegisterID* emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 719 | RegisterID* emitCallVarargs(OpcodeID, RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition& divot, const JSTextPosition& divotStart, const JSTextPosition& divotEnd); |
oliver@apple.com | f129dfb | 2014-10-02 20:35:58 +0000 | [diff] [blame] | 720 | |
saambarati1@gmail.com | 3bde530 | 2015-07-24 18:40:58 +0000 | [diff] [blame^] | 721 | void initializeVarLexicalEnvironment(int symbolTableConstantIndex); |
| 722 | void initializeDefaultParameterValuesAndSetupFunctionScopeStack(FunctionParameters&, FunctionNode*, SymbolTable*, int symbolTableConstantIndex, const std::function<bool (UniquedStringImpl*)>& captures); |
| 723 | |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 724 | public: |
ggaren@apple.com | 81c68cc | 2013-04-27 06:43:33 +0000 | [diff] [blame] | 725 | JSString* addStringConstant(const Identifier&); |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 726 | JSTemplateRegistryKey* addTemplateRegistryKeyConstant(const TemplateRegistryKey&); |
ggaren@apple.com | 81c68cc | 2013-04-27 06:43:33 +0000 | [diff] [blame] | 727 | |
oliver@apple.com | 4e3f965 | 2013-04-08 04:14:50 +0000 | [diff] [blame] | 728 | Vector<UnlinkedInstruction, 0, UnsafeVectorOverflow>& instructions() { return m_instructions; } |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 729 | |
darin@apple.com | fa06950 | 2008-11-10 01:04:30 +0000 | [diff] [blame] | 730 | RegisterID* emitThrowExpressionTooDeepException(); |
| 731 | |
rniwa@webkit.org | 679fb98f | 2015-01-22 02:06:33 +0000 | [diff] [blame] | 732 | private: |
oliver@apple.com | 4e3f965 | 2013-04-08 04:14:50 +0000 | [diff] [blame] | 733 | Vector<UnlinkedInstruction, 0, UnsafeVectorOverflow> m_instructions; |
oliver@apple.com | be38ac4 | 2009-05-12 08:58:56 +0000 | [diff] [blame] | 734 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 735 | bool m_shouldEmitDebugHooks; |
ggaren@apple.com | 4b8c0fb | 2008-10-20 16:48:30 +0000 | [diff] [blame] | 736 | bool m_shouldEmitProfileHooks; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 737 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 738 | struct SymbolTableStackEntry { |
| 739 | Strong<SymbolTable> m_symbolTable; |
| 740 | RegisterID* m_scope; |
| 741 | bool m_isWithOrCatch; |
| 742 | int m_symbolTableConstantIndex; |
| 743 | }; |
| 744 | Vector<SymbolTableStackEntry> m_symbolTableStack; |
| 745 | Vector<std::pair<VariableEnvironment, bool>> m_TDZStack; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 746 | |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 747 | ScopeNode* const m_scopeNode; |
oliver@apple.com | f0c01b8 | 2012-11-07 00:13:54 +0000 | [diff] [blame] | 748 | Strong<UnlinkedCodeBlock> m_codeBlock; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 749 | |
ggaren@apple.com | e010bc1b | 2009-03-26 02:34:54 +0000 | [diff] [blame] | 750 | // Some of these objects keep pointers to one another. They are arranged |
| 751 | // to ensure a sane destruction order that avoids references to freed memory. |
utatane.tea@gmail.com | 8268d39 | 2015-05-23 18:41:53 +0000 | [diff] [blame] | 752 | HashSet<RefPtr<UniquedStringImpl>, IdentifierRepHash> m_functions; |
cwzwarich@webkit.org | d47b49a | 2008-12-03 06:13:58 +0000 | [diff] [blame] | 753 | RegisterID m_ignoredResultRegister; |
ggaren@apple.com | 873cb42 | 2008-06-02 20:45:13 +0000 | [diff] [blame] | 754 | RegisterID m_thisRegister; |
ggaren@apple.com | f820008 | 2012-09-07 01:42:53 +0000 | [diff] [blame] | 755 | RegisterID m_calleeRegister; |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 756 | RegisterID* m_scopeRegister { nullptr }; |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 757 | RegisterID* m_argumentsRegister { nullptr }; |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 758 | RegisterID* m_lexicalEnvironmentRegister { nullptr }; |
| 759 | RegisterID* m_emptyValueRegister { nullptr }; |
| 760 | RegisterID* m_globalObjectRegister { nullptr }; |
rniwa@webkit.org | 059ef9b | 2015-03-09 23:47:06 +0000 | [diff] [blame] | 761 | RegisterID* m_newTargetRegister { nullptr }; |
rniwa@webkit.org | 49d0cc1 | 2015-04-25 22:03:30 +0000 | [diff] [blame] | 762 | RegisterID* m_linkTimeConstantRegisters[LinkTimeConstantCount]; |
oliver@apple.com | 71684cb | 2014-10-17 16:07:08 +0000 | [diff] [blame] | 763 | |
darin@apple.com | 1828ba2 | 2009-08-14 01:15:15 +0000 | [diff] [blame] | 764 | SegmentedVector<RegisterID, 32> m_constantPoolRegisters; |
| 765 | SegmentedVector<RegisterID, 32> m_calleeRegisters; |
| 766 | SegmentedVector<RegisterID, 32> m_parameters; |
darin@apple.com | 1828ba2 | 2009-08-14 01:15:15 +0000 | [diff] [blame] | 767 | SegmentedVector<Label, 32> m_labels; |
oliver@apple.com | 6a97645 | 2013-03-11 21:02:39 +0000 | [diff] [blame] | 768 | LabelScopeStore m_labelScopes; |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 769 | int m_finallyDepth { 0 }; |
| 770 | int m_localScopeDepth { 0 }; |
| 771 | const CodeType m_codeType; |
weinig@apple.com | a963b96 | 2008-06-05 05:36:55 +0000 | [diff] [blame] | 772 | |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 773 | int calculateTargetScopeDepthForExceptionHandler() const; |
saambarati1@gmail.com | 3fff23c | 2015-07-19 00:36:45 +0000 | [diff] [blame] | 774 | int localScopeDepth() const; |
| 775 | void pushScopedControlFlowContext(); |
| 776 | void popScopedControlFlowContext(); |
saambarati1@gmail.com | 144f17c | 2015-07-15 21:41:08 +0000 | [diff] [blame] | 777 | |
oliver@apple.com | 4e3f965 | 2013-04-08 04:14:50 +0000 | [diff] [blame] | 778 | Vector<ControlFlowContext, 0, UnsafeVectorOverflow> m_scopeContextStack; |
oliver@apple.com | 8007f46 | 2008-07-24 00:49:46 +0000 | [diff] [blame] | 779 | Vector<SwitchInfo> m_switchContextStack; |
fpizlo@apple.com | a398a56 | 2014-08-06 21:32:55 +0000 | [diff] [blame] | 780 | Vector<std::unique_ptr<ForInContext>> m_forInContextStack; |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 781 | Vector<TryContext> m_tryContextStack; |
saambarati1@gmail.com | 03edc3b | 2015-05-08 01:59:14 +0000 | [diff] [blame] | 782 | enum FunctionVariableType : uint8_t { NormalFunctionVariable, GlobalFunctionVariable }; |
| 783 | Vector<std::pair<FunctionBodyNode*, FunctionVariableType>> m_functionsToInitialize; |
fpizlo@apple.com | da834ae | 2015-03-26 04:28:43 +0000 | [diff] [blame] | 784 | bool m_needToInitializeArguments { false }; |
fpizlo@apple.com | b08ed27 | 2012-08-27 00:49:25 +0000 | [diff] [blame] | 785 | |
| 786 | Vector<TryRange> m_tryRanges; |
| 787 | SegmentedVector<TryData, 8> m_tryData; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 788 | |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 789 | int m_nextConstantOffset { 0 }; |
ggaren@apple.com | 82a62d0 | 2008-06-27 22:35:33 +0000 | [diff] [blame] | 790 | |
oliver@apple.com | f61c9a1 | 2010-09-24 19:06:29 +0000 | [diff] [blame] | 791 | typedef HashMap<FunctionBodyNode*, unsigned> FunctionOffsetMap; |
| 792 | FunctionOffsetMap m_functionOffsets; |
| 793 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 794 | // Constant pool |
| 795 | IdentifierMap m_identifierMap; |
benjamin@webkit.org | 54d94f5 | 2015-02-28 03:21:37 +0000 | [diff] [blame] | 796 | |
| 797 | typedef HashMap<EncodedJSValueWithRepresentation, unsigned, EncodedJSValueWithRepresentationHash, EncodedJSValueWithRepresentationHashTraits> JSValueMap; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 798 | JSValueMap m_jsValueMap; |
darin@apple.com | a372f0a | 2008-09-21 20:35:20 +0000 | [diff] [blame] | 799 | IdentifierStringMap m_stringMap; |
utatane.tea@gmail.com | d68d248 | 2015-05-14 16:07:54 +0000 | [diff] [blame] | 800 | TemplateRegistryKeyMap m_templateRegistryKeyMap; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 801 | |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 802 | StaticPropertyAnalyzer m_staticPropertyAnalyzer { &m_instructions }; |
ggaren@apple.com | c862eac | 2013-01-29 05:48:01 +0000 | [diff] [blame] | 803 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 804 | VM* m_vm; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 805 | |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 806 | OpcodeID m_lastOpcodeID = op_end; |
commit-queue@webkit.org | 6ef841b | 2010-08-05 22:22:49 +0000 | [diff] [blame] | 807 | #ifndef NDEBUG |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 808 | size_t m_lastOpcodePosition { 0 }; |
commit-queue@webkit.org | 6ef841b | 2010-08-05 22:22:49 +0000 | [diff] [blame] | 809 | #endif |
commit-queue@webkit.org | ad641af | 2013-02-26 09:07:57 +0000 | [diff] [blame] | 810 | |
benjamin@webkit.org | b8d53f9 | 2015-02-12 22:20:18 +0000 | [diff] [blame] | 811 | bool m_usesExceptions { false }; |
| 812 | bool m_expressionTooDeep { false }; |
| 813 | bool m_isBuiltinFunction { false }; |
saambarati1@gmail.com | 3321f09 | 2015-07-20 21:16:41 +0000 | [diff] [blame] | 814 | bool m_usesNonStrictEval { false }; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | } |
| 818 | |
ggaren@apple.com | 8e06f20 | 2008-11-15 21:05:23 +0000 | [diff] [blame] | 819 | #endif // BytecodeGenerator_h |