jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_FULL_CODEGEN_H_ |
| 29 | #define V8_FULL_CODEGEN_H_ |
| 30 | |
| 31 | #include "v8.h" |
| 32 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 33 | #include "allocation.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 34 | #include "ast.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 35 | #include "code-stubs.h" |
| 36 | #include "codegen.h" |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 37 | #include "compiler.h" |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 38 | #include "data-flow.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 39 | |
| 40 | namespace v8 { |
| 41 | namespace internal { |
| 42 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 43 | // Forward declarations. |
| 44 | class JumpPatchSite; |
| 45 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 46 | // AST node visitor which can tell whether a given statement will be breakable |
| 47 | // when the code is compiled by the full compiler in the debugger. This means |
| 48 | // that there will be an IC (load/store/call) in the code generated for the |
| 49 | // debugger to piggybag on. |
| 50 | class BreakableStatementChecker: public AstVisitor { |
| 51 | public: |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 52 | BreakableStatementChecker() : is_breakable_(false) { |
| 53 | InitializeAstVisitor(); |
| 54 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 55 | |
| 56 | void Check(Statement* stmt); |
| 57 | void Check(Expression* stmt); |
| 58 | |
| 59 | bool is_breakable() { return is_breakable_; } |
| 60 | |
| 61 | private: |
| 62 | // AST node visit functions. |
| 63 | #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 64 | AST_NODE_LIST(DECLARE_VISIT) |
| 65 | #undef DECLARE_VISIT |
| 66 | |
| 67 | bool is_breakable_; |
| 68 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 69 | DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 70 | DISALLOW_COPY_AND_ASSIGN(BreakableStatementChecker); |
| 71 | }; |
| 72 | |
| 73 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 74 | // ----------------------------------------------------------------------------- |
| 75 | // Full code generator. |
| 76 | |
| 77 | class FullCodeGenerator: public AstVisitor { |
| 78 | public: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 79 | enum State { |
| 80 | NO_REGISTERS, |
| 81 | TOS_REG |
| 82 | }; |
| 83 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 84 | FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 85 | : masm_(masm), |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 86 | info_(info), |
| 87 | scope_(info->scope()), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 88 | nesting_stack_(NULL), |
| 89 | loop_depth_(0), |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 90 | globals_(NULL), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 91 | context_(NULL), |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 92 | bailout_entries_(info->HasDeoptimizationSupport() |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 93 | ? info->function()->ast_node_count() : 0, |
| 94 | info->zone()), |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 95 | back_edges_(2, info->zone()), |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 96 | type_feedback_cells_(info->HasDeoptimizationSupport() |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 97 | ? info->function()->ast_node_count() : 0, |
| 98 | info->zone()), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 99 | ic_total_count_(0), |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 100 | zone_(info->zone()) { |
| 101 | Initialize(); |
| 102 | } |
| 103 | |
| 104 | void Initialize(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 105 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 106 | static bool MakeCode(CompilationInfo* info); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 107 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 108 | // Encode state and pc-offset as a BitField<type, start, size>. |
| 109 | // Only use 30 bits because we encode the result as a smi. |
| 110 | class StateField : public BitField<State, 0, 1> { }; |
| 111 | class PcField : public BitField<unsigned, 1, 30-1> { }; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 112 | |
| 113 | static const char* State2String(State state) { |
| 114 | switch (state) { |
| 115 | case NO_REGISTERS: return "NO_REGISTERS"; |
| 116 | case TOS_REG: return "TOS_REG"; |
| 117 | } |
| 118 | UNREACHABLE(); |
| 119 | return NULL; |
| 120 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 121 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 122 | Zone* zone() const { return zone_; } |
| 123 | |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 124 | static const int kMaxBackEdgeWeight = 127; |
| 125 | |
| 126 | #if V8_TARGET_ARCH_IA32 |
| 127 | static const int kBackEdgeDistanceUnit = 100; |
| 128 | #elif V8_TARGET_ARCH_X64 |
| 129 | static const int kBackEdgeDistanceUnit = 162; |
| 130 | #elif V8_TARGET_ARCH_ARM |
| 131 | static const int kBackEdgeDistanceUnit = 142; |
| 132 | #elif V8_TARGET_ARCH_MIPS |
| 133 | static const int kBackEdgeDistanceUnit = 142; |
| 134 | #else |
| 135 | #error Unsupported target architecture. |
| 136 | #endif |
| 137 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 138 | static const int kBackEdgeEntrySize = 2 * kIntSize + kOneByteSize; |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 139 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 140 | private: |
| 141 | class Breakable; |
| 142 | class Iteration; |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 143 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 144 | class TestContext; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 145 | |
| 146 | class NestedStatement BASE_EMBEDDED { |
| 147 | public: |
| 148 | explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) { |
| 149 | // Link into codegen's nesting stack. |
| 150 | previous_ = codegen->nesting_stack_; |
| 151 | codegen->nesting_stack_ = this; |
| 152 | } |
| 153 | virtual ~NestedStatement() { |
| 154 | // Unlink from codegen's nesting stack. |
| 155 | ASSERT_EQ(this, codegen_->nesting_stack_); |
| 156 | codegen_->nesting_stack_ = previous_; |
| 157 | } |
| 158 | |
| 159 | virtual Breakable* AsBreakable() { return NULL; } |
| 160 | virtual Iteration* AsIteration() { return NULL; } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 161 | |
| 162 | virtual bool IsContinueTarget(Statement* target) { return false; } |
| 163 | virtual bool IsBreakTarget(Statement* target) { return false; } |
| 164 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 165 | // Notify the statement that we are exiting it via break, continue, or |
| 166 | // return and give it a chance to generate cleanup code. Return the |
| 167 | // next outer statement in the nesting stack. We accumulate in |
| 168 | // *stack_depth the amount to drop the stack and in *context_length the |
| 169 | // number of context chain links to unwind as we traverse the nesting |
| 170 | // stack from an exit to its target. |
| 171 | virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
| 172 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 173 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 174 | |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 175 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 176 | MacroAssembler* masm() { return codegen_->masm(); } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 177 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 178 | FullCodeGenerator* codegen_; |
| 179 | NestedStatement* previous_; |
jkummerow@chromium.org | 05ed9dd | 2012-01-23 14:42:48 +0000 | [diff] [blame] | 180 | |
| 181 | private: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 182 | DISALLOW_COPY_AND_ASSIGN(NestedStatement); |
| 183 | }; |
| 184 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 185 | // A breakable statement such as a block. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 186 | class Breakable : public NestedStatement { |
| 187 | public: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 188 | Breakable(FullCodeGenerator* codegen, BreakableStatement* statement) |
| 189 | : NestedStatement(codegen), statement_(statement) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 190 | } |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 191 | virtual ~Breakable() {} |
| 192 | |
| 193 | virtual Breakable* AsBreakable() { return this; } |
| 194 | virtual bool IsBreakTarget(Statement* target) { |
| 195 | return statement() == target; |
| 196 | } |
| 197 | |
| 198 | BreakableStatement* statement() { return statement_; } |
| 199 | Label* break_label() { return &break_label_; } |
| 200 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 201 | private: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 202 | BreakableStatement* statement_; |
| 203 | Label break_label_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 206 | // An iteration statement such as a while, for, or do loop. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 207 | class Iteration : public Breakable { |
| 208 | public: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 209 | Iteration(FullCodeGenerator* codegen, IterationStatement* statement) |
| 210 | : Breakable(codegen, statement) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 211 | } |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 212 | virtual ~Iteration() {} |
| 213 | |
| 214 | virtual Iteration* AsIteration() { return this; } |
| 215 | virtual bool IsContinueTarget(Statement* target) { |
| 216 | return statement() == target; |
| 217 | } |
| 218 | |
| 219 | Label* continue_label() { return &continue_label_; } |
| 220 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 221 | private: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 222 | Label continue_label_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 225 | // A nested block statement. |
| 226 | class NestedBlock : public Breakable { |
| 227 | public: |
| 228 | NestedBlock(FullCodeGenerator* codegen, Block* block) |
| 229 | : Breakable(codegen, block) { |
| 230 | } |
| 231 | virtual ~NestedBlock() {} |
| 232 | |
| 233 | virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 234 | if (statement()->AsBlock()->scope() != NULL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 235 | ++(*context_length); |
| 236 | } |
| 237 | return previous_; |
| 238 | }; |
| 239 | }; |
| 240 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 241 | // The try block of a try/catch statement. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 242 | class TryCatch : public NestedStatement { |
| 243 | public: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 244 | explicit TryCatch(FullCodeGenerator* codegen) : NestedStatement(codegen) { |
| 245 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 246 | virtual ~TryCatch() {} |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 247 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 248 | virtual NestedStatement* Exit(int* stack_depth, int* context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 251 | // The try block of a try/finally statement. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 252 | class TryFinally : public NestedStatement { |
| 253 | public: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 254 | TryFinally(FullCodeGenerator* codegen, Label* finally_entry) |
| 255 | : NestedStatement(codegen), finally_entry_(finally_entry) { |
| 256 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 257 | virtual ~TryFinally() {} |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 258 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 259 | virtual NestedStatement* Exit(int* stack_depth, int* context_length); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 260 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 261 | private: |
| 262 | Label* finally_entry_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 265 | // The finally block of a try/finally statement. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 266 | class Finally : public NestedStatement { |
| 267 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 268 | static const int kElementCount = 5; |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 269 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 270 | explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { } |
| 271 | virtual ~Finally() {} |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 272 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 273 | virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 274 | *stack_depth += kElementCount; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 275 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 276 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 279 | // The body of a for/in loop. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 280 | class ForIn : public Iteration { |
| 281 | public: |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 282 | static const int kElementCount = 5; |
| 283 | |
| 284 | ForIn(FullCodeGenerator* codegen, ForInStatement* statement) |
| 285 | : Iteration(codegen, statement) { |
| 286 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 287 | virtual ~ForIn() {} |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 288 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 289 | virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 290 | *stack_depth += kElementCount; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 291 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 292 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 293 | }; |
| 294 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 295 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 296 | // The body of a with or catch. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 297 | class WithOrCatch : public NestedStatement { |
| 298 | public: |
| 299 | explicit WithOrCatch(FullCodeGenerator* codegen) |
| 300 | : NestedStatement(codegen) { |
| 301 | } |
| 302 | virtual ~WithOrCatch() {} |
| 303 | |
| 304 | virtual NestedStatement* Exit(int* stack_depth, int* context_length) { |
| 305 | ++(*context_length); |
| 306 | return previous_; |
| 307 | } |
| 308 | }; |
| 309 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 310 | // Type of a member function that generates inline code for a native function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 311 | typedef void (FullCodeGenerator::*InlineFunctionGenerator)(CallRuntime* expr); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 312 | |
| 313 | static const InlineFunctionGenerator kInlineFunctionGenerators[]; |
| 314 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 315 | // A platform-specific utility to overwrite the accumulator register |
| 316 | // with a GC-safe value. |
| 317 | void ClearAccumulator(); |
| 318 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 319 | // Determine whether or not to inline the smi case for the given |
| 320 | // operation. |
| 321 | bool ShouldInlineSmiCase(Token::Value op); |
| 322 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 323 | // Helper function to convert a pure value into a test context. The value |
| 324 | // is expected on the stack or the accumulator, depending on the platform. |
| 325 | // See the platform-specific implementation for details. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 326 | void DoTest(Expression* condition, |
| 327 | Label* if_true, |
| 328 | Label* if_false, |
| 329 | Label* fall_through); |
| 330 | void DoTest(const TestContext* context); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 331 | |
| 332 | // Helper function to split control flow and avoid a branch to the |
| 333 | // fall-through label if it is set up. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 334 | #ifdef V8_TARGET_ARCH_MIPS |
| 335 | void Split(Condition cc, |
| 336 | Register lhs, |
| 337 | const Operand& rhs, |
| 338 | Label* if_true, |
| 339 | Label* if_false, |
| 340 | Label* fall_through); |
| 341 | #else // All non-mips arch. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 342 | void Split(Condition cc, |
| 343 | Label* if_true, |
| 344 | Label* if_false, |
| 345 | Label* fall_through); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 346 | #endif // V8_TARGET_ARCH_MIPS |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 347 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 348 | // Load the value of a known (PARAMETER, LOCAL, or CONTEXT) variable into |
| 349 | // a register. Emits a context chain walk if if necessary (so does |
| 350 | // SetVar) so avoid calling both on the same variable. |
| 351 | void GetVar(Register destination, Variable* var); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 352 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 353 | // Assign to a known (PARAMETER, LOCAL, or CONTEXT) variable. If it's in |
| 354 | // the context, the write barrier will be emitted and source, scratch0, |
| 355 | // scratch1 will be clobbered. Emits a context chain walk if if necessary |
| 356 | // (so does GetVar) so avoid calling both on the same variable. |
| 357 | void SetVar(Variable* var, |
| 358 | Register source, |
| 359 | Register scratch0, |
| 360 | Register scratch1); |
| 361 | |
| 362 | // An operand used to read/write a stack-allocated (PARAMETER or LOCAL) |
| 363 | // variable. Writing does not need the write barrier. |
| 364 | MemOperand StackOperand(Variable* var); |
| 365 | |
| 366 | // An operand used to read/write a known (PARAMETER, LOCAL, or CONTEXT) |
| 367 | // variable. May emit code to traverse the context chain, loading the |
| 368 | // found context into the scratch register. Writing to this operand will |
| 369 | // need the write barrier if location is CONTEXT. |
| 370 | MemOperand VarOperand(Variable* var, Register scratch); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 371 | |
| 372 | void VisitForEffect(Expression* expr) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 373 | EffectContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 374 | Visit(expr); |
| 375 | PrepareForBailout(expr, NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 376 | } |
| 377 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 378 | void VisitForAccumulatorValue(Expression* expr) { |
| 379 | AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 380 | Visit(expr); |
| 381 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void VisitForStackValue(Expression* expr) { |
| 385 | StackValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 386 | Visit(expr); |
| 387 | PrepareForBailout(expr, NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 388 | } |
| 389 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 390 | void VisitForControl(Expression* expr, |
| 391 | Label* if_true, |
| 392 | Label* if_false, |
| 393 | Label* fall_through) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 394 | TestContext context(this, expr, if_true, if_false, fall_through); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 395 | Visit(expr); |
| 396 | // For test contexts, we prepare for bailout before branching, not at |
| 397 | // the end of the entire expression. This happens as part of visiting |
| 398 | // the expression. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 399 | } |
| 400 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 401 | void VisitInDuplicateContext(Expression* expr); |
| 402 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 403 | void VisitDeclarations(ZoneList<Declaration*>* declarations); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 404 | void DeclareModules(Handle<FixedArray> descriptions); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 405 | void DeclareGlobals(Handle<FixedArray> pairs); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 406 | int DeclareGlobalsFlags(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 407 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 408 | // Generate code to allocate all (including nested) modules and contexts. |
| 409 | // Because of recursive linking and the presence of module alias declarations, |
| 410 | // this has to be a separate pass _before_ populating or executing any module. |
| 411 | void AllocateModules(ZoneList<Declaration*>* declarations); |
| 412 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 413 | // Generator code to return a fresh iterator result object. The "value" |
| 414 | // property is set to a value popped from the stack, and "done" is set |
| 415 | // according to the argument. |
| 416 | void EmitReturnIteratorResult(bool done); |
| 417 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 418 | // Try to perform a comparison as a fast inlined literal compare if |
| 419 | // the operands allow it. Returns true if the compare operations |
| 420 | // has been matched and all code generated; false otherwise. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 421 | bool TryLiteralCompare(CompareOperation* compare); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 422 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 423 | // Platform-specific code for comparing the type of a value with |
| 424 | // a given literal string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 425 | void EmitLiteralCompareTypeof(Expression* expr, |
| 426 | Expression* sub_expr, |
| 427 | Handle<String> check); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 428 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 429 | // Platform-specific code for equality comparison with a nil-like value. |
| 430 | void EmitLiteralCompareNil(CompareOperation* expr, |
| 431 | Expression* sub_expr, |
| 432 | NilValue nil); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 433 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 434 | // Bailout support. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 435 | void PrepareForBailout(Expression* node, State state); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 436 | void PrepareForBailoutForId(BailoutId id, State state); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 437 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 438 | // Cache cell support. This associates AST ids with global property cells |
| 439 | // that will be cleared during GC and collected by the type-feedback oracle. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 440 | void RecordTypeFeedbackCell(TypeFeedbackId id, |
| 441 | Handle<JSGlobalPropertyCell> cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 442 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 443 | // Record a call's return site offset, used to rebuild the frame if the |
| 444 | // called function was inlined at the site. |
| 445 | void RecordJSReturnSite(Call* call); |
| 446 | |
| 447 | // Prepare for bailout before a test (or compare) and branch. If |
| 448 | // should_normalize, then the following comparison will not handle the |
| 449 | // canonical JS true value so we will insert a (dead) test against true at |
| 450 | // the actual bailout target from the optimized code. If not |
| 451 | // should_normalize, the true and false labels are ignored. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 452 | void PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 453 | bool should_normalize, |
| 454 | Label* if_true, |
| 455 | Label* if_false); |
| 456 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 457 | // If enabled, emit debug code for checking that the current context is |
| 458 | // neither a with nor a catch context. |
| 459 | void EmitDebugCheckDeclarationContext(Variable* variable); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 460 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 461 | // This is meant to be called at loop back edges, |back_edge_target| is |
| 462 | // the jump target of the back edge and is used to approximate the amount |
| 463 | // of code inside the loop. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 464 | void EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 465 | Label* back_edge_target); |
| 466 | // Record the OSR AST id corresponding to a back edge in the code. |
| 467 | void RecordBackEdge(BailoutId osr_ast_id); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 468 | // Emit a table of back edge ids, pcs and loop depths into the code stream. |
| 469 | // Return the offset of the start of the table. |
| 470 | unsigned EmitBackEdgeTable(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 471 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 472 | void EmitProfilingCounterDecrement(int delta); |
| 473 | void EmitProfilingCounterReset(); |
| 474 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 475 | // Platform-specific return sequence |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 476 | void EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 477 | |
| 478 | // Platform-specific code sequences for calls |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 479 | void EmitCallWithStub(Call* expr, CallFunctionFlags flags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 480 | void EmitCallWithIC(Call* expr, Handle<Object> name, RelocInfo::Mode mode); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 481 | void EmitKeyedCallWithIC(Call* expr, Expression* key); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 482 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 483 | // Platform-specific code for inline runtime calls. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 484 | InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id); |
| 485 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 486 | void EmitInlineRuntimeCall(CallRuntime* expr); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 487 | |
| 488 | #define EMIT_INLINE_RUNTIME_CALL(name, x, y) \ |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 489 | void Emit##name(CallRuntime* expr); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 490 | INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 491 | INLINE_RUNTIME_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) |
| 492 | #undef EMIT_INLINE_RUNTIME_CALL |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 493 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 494 | // Platform-specific code for resuming generators. |
| 495 | void EmitGeneratorResume(Expression *generator, |
| 496 | Expression *value, |
| 497 | JSGeneratorObject::ResumeMode resume_mode); |
| 498 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 499 | // Platform-specific code for loading variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 500 | void EmitLoadGlobalCheckExtensions(Variable* var, |
| 501 | TypeofState typeof_state, |
| 502 | Label* slow); |
| 503 | MemOperand ContextSlotOperandCheckExtensions(Variable* var, Label* slow); |
| 504 | void EmitDynamicLookupFastCase(Variable* var, |
| 505 | TypeofState typeof_state, |
| 506 | Label* slow, |
| 507 | Label* done); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 508 | void EmitVariableLoad(VariableProxy* proxy); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 509 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 510 | void EmitAccessor(Expression* expression); |
| 511 | |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 512 | // Expects the arguments and the function already pushed. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 513 | void EmitResolvePossiblyDirectEval(int arg_count); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 514 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 515 | // Platform-specific support for allocating a new closure based on |
| 516 | // the given function info. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 517 | void EmitNewClosure(Handle<SharedFunctionInfo> info, bool pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 518 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 519 | // Platform-specific support for compiling assignments. |
| 520 | |
| 521 | // Load a value from a named property. |
| 522 | // The receiver is left on the stack by the IC. |
| 523 | void EmitNamedPropertyLoad(Property* expr); |
| 524 | |
| 525 | // Load a value from a keyed property. |
| 526 | // The receiver and the key is left on the stack by the IC. |
| 527 | void EmitKeyedPropertyLoad(Property* expr); |
| 528 | |
| 529 | // Apply the compound assignment operator. Expects the left operand on top |
| 530 | // of the stack and the right one in the accumulator. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 531 | void EmitBinaryOp(BinaryOperation* expr, |
| 532 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 533 | OverwriteMode mode); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 534 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 535 | // Helper functions for generating inlined smi code for certain |
| 536 | // binary operations. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 537 | void EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 538 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 539 | OverwriteMode mode, |
| 540 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 541 | Expression* right); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 542 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 543 | // Assign to the given expression as if via '='. The right-hand-side value |
| 544 | // is expected in the accumulator. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 545 | void EmitAssignment(Expression* expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 546 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 547 | // Complete a variable assignment. The right-hand-side value is expected |
| 548 | // in the accumulator. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 549 | void EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 550 | Token::Value op); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 551 | |
| 552 | // Complete a named property assignment. The receiver is expected on top |
| 553 | // of the stack and the right-hand-side value in the accumulator. |
| 554 | void EmitNamedPropertyAssignment(Assignment* expr); |
| 555 | |
| 556 | // Complete a keyed property assignment. The receiver and key are |
| 557 | // expected on top of the stack and the right-hand-side value in the |
| 558 | // accumulator. |
| 559 | void EmitKeyedPropertyAssignment(Assignment* expr); |
| 560 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 561 | void CallIC(Handle<Code> code, |
| 562 | RelocInfo::Mode rmode = RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 563 | TypeFeedbackId id = TypeFeedbackId::None()); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 564 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 565 | void SetFunctionPosition(FunctionLiteral* fun); |
| 566 | void SetReturnPosition(FunctionLiteral* fun); |
| 567 | void SetStatementPosition(Statement* stmt); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 568 | void SetExpressionPosition(Expression* expr, int pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 569 | void SetStatementPosition(int pos); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 570 | void SetSourcePosition(int pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 571 | |
| 572 | // Non-local control flow support. |
| 573 | void EnterFinallyBlock(); |
| 574 | void ExitFinallyBlock(); |
| 575 | |
| 576 | // Loop nesting counter. |
| 577 | int loop_depth() { return loop_depth_; } |
| 578 | void increment_loop_depth() { loop_depth_++; } |
| 579 | void decrement_loop_depth() { |
| 580 | ASSERT(loop_depth_ > 0); |
| 581 | loop_depth_--; |
| 582 | } |
| 583 | |
| 584 | MacroAssembler* masm() { return masm_; } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 585 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 586 | class ExpressionContext; |
| 587 | const ExpressionContext* context() { return context_; } |
| 588 | void set_new_context(const ExpressionContext* context) { context_ = context; } |
| 589 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 590 | Handle<Script> script() { return info_->script(); } |
| 591 | bool is_eval() { return info_->is_eval(); } |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 592 | bool is_native() { return info_->is_native(); } |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 593 | bool is_classic_mode() { return language_mode() == CLASSIC_MODE; } |
| 594 | LanguageMode language_mode() { return function()->language_mode(); } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 595 | FunctionLiteral* function() { return info_->function(); } |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 596 | Scope* scope() { return scope_; } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 597 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 598 | static Register result_register(); |
| 599 | static Register context_register(); |
| 600 | |
| 601 | // Set fields in the stack frame. Offsets are the frame pointer relative |
| 602 | // offsets defined in, e.g., StandardFrameConstants. |
| 603 | void StoreToFrameField(int frame_offset, Register value); |
| 604 | |
| 605 | // Load a value from the current context. Indices are defined as an enum |
| 606 | // in v8::internal::Context. |
| 607 | void LoadContextField(Register dst, int context_index); |
| 608 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 609 | // Push the function argument for the runtime functions PushWithContext |
| 610 | // and PushCatchContext. |
| 611 | void PushFunctionArgumentForContextAllocation(); |
| 612 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 613 | // AST node visit functions. |
| 614 | #define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
| 615 | AST_NODE_LIST(DECLARE_VISIT) |
| 616 | #undef DECLARE_VISIT |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 617 | |
| 618 | void EmitUnaryOperation(UnaryOperation* expr, const char* comment); |
| 619 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 620 | void VisitComma(BinaryOperation* expr); |
| 621 | void VisitLogicalExpression(BinaryOperation* expr); |
| 622 | void VisitArithmeticExpression(BinaryOperation* expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 623 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 624 | void VisitForTypeofValue(Expression* expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 625 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 626 | void Generate(); |
| 627 | void PopulateDeoptimizationData(Handle<Code> code); |
| 628 | void PopulateTypeFeedbackInfo(Handle<Code> code); |
| 629 | void PopulateTypeFeedbackCells(Handle<Code> code); |
| 630 | |
| 631 | Handle<FixedArray> handler_table() { return handler_table_; } |
| 632 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 633 | struct BailoutEntry { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 634 | BailoutId id; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 635 | unsigned pc_and_state; |
| 636 | }; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 637 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 638 | struct BackEdgeEntry { |
| 639 | BailoutId id; |
| 640 | unsigned pc; |
| 641 | uint8_t loop_depth; |
| 642 | }; |
| 643 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 644 | struct TypeFeedbackCellEntry { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 645 | TypeFeedbackId ast_id; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 646 | Handle<JSGlobalPropertyCell> cell; |
| 647 | }; |
| 648 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 649 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 650 | class ExpressionContext BASE_EMBEDDED { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 651 | public: |
| 652 | explicit ExpressionContext(FullCodeGenerator* codegen) |
| 653 | : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) { |
| 654 | codegen->set_new_context(this); |
| 655 | } |
| 656 | |
| 657 | virtual ~ExpressionContext() { |
| 658 | codegen_->set_new_context(old_); |
| 659 | } |
| 660 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 661 | Isolate* isolate() const { return codegen_->isolate(); } |
| 662 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 663 | // Convert constant control flow (true or false) to the result expected for |
| 664 | // this expression context. |
| 665 | virtual void Plug(bool flag) const = 0; |
| 666 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 667 | // Emit code to convert a pure value (in a register, known variable |
| 668 | // location, as a literal, or on top of the stack) into the result |
| 669 | // expected according to this expression context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 670 | virtual void Plug(Register reg) const = 0; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 671 | virtual void Plug(Variable* var) const = 0; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 672 | virtual void Plug(Handle<Object> lit) const = 0; |
| 673 | virtual void Plug(Heap::RootListIndex index) const = 0; |
| 674 | virtual void PlugTOS() const = 0; |
| 675 | |
| 676 | // Emit code to convert pure control flow to a pair of unbound labels into |
| 677 | // the result expected according to this expression context. The |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 678 | // implementation will bind both labels unless it's a TestContext, which |
| 679 | // won't bind them at this point. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 680 | virtual void Plug(Label* materialize_true, |
| 681 | Label* materialize_false) const = 0; |
| 682 | |
| 683 | // Emit code to discard count elements from the top of stack, then convert |
| 684 | // a pure value into the result expected according to this expression |
| 685 | // context. |
| 686 | virtual void DropAndPlug(int count, Register reg) const = 0; |
| 687 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 688 | // Set up branch labels for a test expression. The three Label** parameters |
| 689 | // are output parameters. |
| 690 | virtual void PrepareTest(Label* materialize_true, |
| 691 | Label* materialize_false, |
| 692 | Label** if_true, |
| 693 | Label** if_false, |
| 694 | Label** fall_through) const = 0; |
| 695 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 696 | // Returns true if we are evaluating only for side effects (i.e. if the |
| 697 | // result will be discarded). |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 698 | virtual bool IsEffect() const { return false; } |
| 699 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 700 | // Returns true if we are evaluating for the value (in accu/on stack). |
| 701 | virtual bool IsAccumulatorValue() const { return false; } |
| 702 | virtual bool IsStackValue() const { return false; } |
| 703 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 704 | // Returns true if we are branching on the value rather than materializing |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 705 | // it. Only used for asserts. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 706 | virtual bool IsTest() const { return false; } |
| 707 | |
| 708 | protected: |
| 709 | FullCodeGenerator* codegen() const { return codegen_; } |
| 710 | MacroAssembler* masm() const { return masm_; } |
| 711 | MacroAssembler* masm_; |
| 712 | |
| 713 | private: |
| 714 | const ExpressionContext* old_; |
| 715 | FullCodeGenerator* codegen_; |
| 716 | }; |
| 717 | |
| 718 | class AccumulatorValueContext : public ExpressionContext { |
| 719 | public: |
| 720 | explicit AccumulatorValueContext(FullCodeGenerator* codegen) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 721 | : ExpressionContext(codegen) { } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 722 | |
| 723 | virtual void Plug(bool flag) const; |
| 724 | virtual void Plug(Register reg) const; |
| 725 | virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 726 | virtual void Plug(Variable* var) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 727 | virtual void Plug(Handle<Object> lit) const; |
| 728 | virtual void Plug(Heap::RootListIndex) const; |
| 729 | virtual void PlugTOS() const; |
| 730 | virtual void DropAndPlug(int count, Register reg) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 731 | virtual void PrepareTest(Label* materialize_true, |
| 732 | Label* materialize_false, |
| 733 | Label** if_true, |
| 734 | Label** if_false, |
| 735 | Label** fall_through) const; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 736 | virtual bool IsAccumulatorValue() const { return true; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | class StackValueContext : public ExpressionContext { |
| 740 | public: |
| 741 | explicit StackValueContext(FullCodeGenerator* codegen) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 742 | : ExpressionContext(codegen) { } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 743 | |
| 744 | virtual void Plug(bool flag) const; |
| 745 | virtual void Plug(Register reg) const; |
| 746 | virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 747 | virtual void Plug(Variable* var) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 748 | virtual void Plug(Handle<Object> lit) const; |
| 749 | virtual void Plug(Heap::RootListIndex) const; |
| 750 | virtual void PlugTOS() const; |
| 751 | virtual void DropAndPlug(int count, Register reg) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 752 | virtual void PrepareTest(Label* materialize_true, |
| 753 | Label* materialize_false, |
| 754 | Label** if_true, |
| 755 | Label** if_false, |
| 756 | Label** fall_through) const; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 757 | virtual bool IsStackValue() const { return true; } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 758 | }; |
| 759 | |
| 760 | class TestContext : public ExpressionContext { |
| 761 | public: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 762 | TestContext(FullCodeGenerator* codegen, |
| 763 | Expression* condition, |
| 764 | Label* true_label, |
| 765 | Label* false_label, |
| 766 | Label* fall_through) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 767 | : ExpressionContext(codegen), |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 768 | condition_(condition), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 769 | true_label_(true_label), |
| 770 | false_label_(false_label), |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 771 | fall_through_(fall_through) { } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 772 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 773 | static const TestContext* cast(const ExpressionContext* context) { |
| 774 | ASSERT(context->IsTest()); |
| 775 | return reinterpret_cast<const TestContext*>(context); |
| 776 | } |
| 777 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 778 | Expression* condition() const { return condition_; } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 779 | Label* true_label() const { return true_label_; } |
| 780 | Label* false_label() const { return false_label_; } |
| 781 | Label* fall_through() const { return fall_through_; } |
| 782 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 783 | virtual void Plug(bool flag) const; |
| 784 | virtual void Plug(Register reg) const; |
| 785 | virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 786 | virtual void Plug(Variable* var) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 787 | virtual void Plug(Handle<Object> lit) const; |
| 788 | virtual void Plug(Heap::RootListIndex) const; |
| 789 | virtual void PlugTOS() const; |
| 790 | virtual void DropAndPlug(int count, Register reg) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 791 | virtual void PrepareTest(Label* materialize_true, |
| 792 | Label* materialize_false, |
| 793 | Label** if_true, |
| 794 | Label** if_false, |
| 795 | Label** fall_through) const; |
| 796 | virtual bool IsTest() const { return true; } |
| 797 | |
| 798 | private: |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 799 | Expression* condition_; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 800 | Label* true_label_; |
| 801 | Label* false_label_; |
| 802 | Label* fall_through_; |
| 803 | }; |
| 804 | |
| 805 | class EffectContext : public ExpressionContext { |
| 806 | public: |
| 807 | explicit EffectContext(FullCodeGenerator* codegen) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 808 | : ExpressionContext(codegen) { } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 809 | |
| 810 | virtual void Plug(bool flag) const; |
| 811 | virtual void Plug(Register reg) const; |
| 812 | virtual void Plug(Label* materialize_true, Label* materialize_false) const; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 813 | virtual void Plug(Variable* var) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 814 | virtual void Plug(Handle<Object> lit) const; |
| 815 | virtual void Plug(Heap::RootListIndex) const; |
| 816 | virtual void PlugTOS() const; |
| 817 | virtual void DropAndPlug(int count, Register reg) const; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 818 | virtual void PrepareTest(Label* materialize_true, |
| 819 | Label* materialize_false, |
| 820 | Label** if_true, |
| 821 | Label** if_false, |
| 822 | Label** fall_through) const; |
| 823 | virtual bool IsEffect() const { return true; } |
| 824 | }; |
| 825 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | MacroAssembler* masm_; |
| 827 | CompilationInfo* info_; |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 828 | Scope* scope_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 829 | Label return_label_; |
| 830 | NestedStatement* nesting_stack_; |
| 831 | int loop_depth_; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 832 | ZoneList<Handle<Object> >* globals_; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 833 | Handle<FixedArray> modules_; |
| 834 | int module_index_; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 835 | const ExpressionContext* context_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 836 | ZoneList<BailoutEntry> bailout_entries_; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 837 | GrowableBitVector prepared_bailout_ids_; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 838 | ZoneList<BackEdgeEntry> back_edges_; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 839 | ZoneList<TypeFeedbackCellEntry> type_feedback_cells_; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 840 | int ic_total_count_; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 841 | Handle<FixedArray> handler_table_; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 842 | Handle<JSGlobalPropertyCell> profiling_counter_; |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 843 | bool generate_debug_code_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 844 | Zone* zone_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 845 | |
| 846 | friend class NestedStatement; |
| 847 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 848 | DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 849 | DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator); |
| 850 | }; |
| 851 | |
| 852 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 853 | // A map from property names to getter/setter pairs allocated in the zone. |
| 854 | class AccessorTable: public TemplateHashMap<Literal, |
| 855 | ObjectLiteral::Accessors, |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 856 | ZoneAllocationPolicy> { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 857 | public: |
| 858 | explicit AccessorTable(Zone* zone) : |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 859 | TemplateHashMap<Literal, ObjectLiteral::Accessors, |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 860 | ZoneAllocationPolicy>(Literal::Match, |
| 861 | ZoneAllocationPolicy(zone)), |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 862 | zone_(zone) { } |
| 863 | |
| 864 | Iterator lookup(Literal* literal) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 865 | Iterator it = find(literal, true, ZoneAllocationPolicy(zone_)); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 866 | if (it->second == NULL) it->second = new(zone_) ObjectLiteral::Accessors(); |
| 867 | return it; |
| 868 | } |
| 869 | |
| 870 | private: |
| 871 | Zone* zone_; |
| 872 | }; |
| 873 | |
| 874 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 875 | } } // namespace v8::internal |
| 876 | |
| 877 | #endif // V8_FULL_CODEGEN_H_ |