OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/control-flow-builders.h" | 8 #include "src/interpreter/control-flow-builders.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 protected: | 188 protected: |
189 void set_result_identified() { | 189 void set_result_identified() { |
190 DCHECK(!result_identified()); | 190 DCHECK(!result_identified()); |
191 result_identified_ = true; | 191 result_identified_ = true; |
192 } | 192 } |
193 | 193 |
194 bool result_identified() const { return result_identified_; } | 194 bool result_identified() const { return result_identified_; } |
195 | 195 |
| 196 const TemporaryRegisterScope* allocator() const { return &allocator_; } |
| 197 |
196 private: | 198 private: |
197 BytecodeGenerator* generator_; | 199 BytecodeGenerator* generator_; |
198 Expression::Context kind_; | 200 Expression::Context kind_; |
199 ExpressionResultScope* outer_; | 201 ExpressionResultScope* outer_; |
200 TemporaryRegisterScope allocator_; | 202 TemporaryRegisterScope allocator_; |
201 bool result_identified_; | 203 bool result_identified_; |
202 | 204 |
203 DISALLOW_COPY_AND_ASSIGN(ExpressionResultScope); | 205 DISALLOW_COPY_AND_ASSIGN(ExpressionResultScope); |
204 }; | 206 }; |
205 | 207 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 : ExpressionResultScope(generator, Expression::kValue) {} | 247 : ExpressionResultScope(generator, Expression::kValue) {} |
246 | 248 |
247 virtual void SetResultInAccumulator() { | 249 virtual void SetResultInAccumulator() { |
248 result_register_ = outer()->NewRegister(); | 250 result_register_ = outer()->NewRegister(); |
249 builder()->StoreAccumulatorInRegister(result_register_); | 251 builder()->StoreAccumulatorInRegister(result_register_); |
250 set_result_identified(); | 252 set_result_identified(); |
251 } | 253 } |
252 | 254 |
253 virtual void SetResultInRegister(Register reg) { | 255 virtual void SetResultInRegister(Register reg) { |
254 DCHECK(builder()->RegisterIsParameterOrLocal(reg) || | 256 DCHECK(builder()->RegisterIsParameterOrLocal(reg) || |
255 builder()->RegisterIsTemporary(reg)); | 257 (builder()->RegisterIsTemporary(reg) && |
| 258 !allocator()->RegisterIsAllocatedInThisScope(reg))); |
256 result_register_ = reg; | 259 result_register_ = reg; |
257 set_result_identified(); | 260 set_result_identified(); |
258 } | 261 } |
259 | 262 |
260 Register ResultRegister() const { return result_register_; } | 263 Register ResultRegister() const { return result_register_; } |
261 | 264 |
262 private: | 265 private: |
263 Register result_register_; | 266 Register result_register_; |
264 }; | 267 }; |
265 | 268 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 builder()->LoadLiteral(Smi::FromInt(encoded_flags)); | 471 builder()->LoadLiteral(Smi::FromInt(encoded_flags)); |
469 builder()->StoreAccumulatorInRegister(flags); | 472 builder()->StoreAccumulatorInRegister(flags); |
470 DCHECK(flags.index() == pairs.index() + 1); | 473 DCHECK(flags.index() == pairs.index() + 1); |
471 | 474 |
472 builder()->CallRuntime(Runtime::kDeclareGlobals, pairs, 2); | 475 builder()->CallRuntime(Runtime::kDeclareGlobals, pairs, 2); |
473 globals()->clear(); | 476 globals()->clear(); |
474 } | 477 } |
475 | 478 |
476 | 479 |
477 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 480 void BytecodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 481 // TODO(rmcilroy): Replace this with a StatementResultScope when it exists. |
| 482 EffectResultScope effect_scope(this); |
478 VisitForEffect(stmt->expression()); | 483 VisitForEffect(stmt->expression()); |
479 } | 484 } |
480 | 485 |
481 | 486 |
482 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { | 487 void BytecodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
483 } | 488 } |
484 | 489 |
485 | 490 |
486 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { | 491 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { |
487 // TODO(oth): Spot easy cases where there code would not need to | 492 // TODO(oth): Spot easy cases where there code would not need to |
(...skipping 27 matching lines...) Expand all Loading... |
515 execution_control()->Continue(stmt->target()); | 520 execution_control()->Continue(stmt->target()); |
516 } | 521 } |
517 | 522 |
518 | 523 |
519 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { | 524 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
520 execution_control()->Break(stmt->target()); | 525 execution_control()->Break(stmt->target()); |
521 } | 526 } |
522 | 527 |
523 | 528 |
524 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 529 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 530 EffectResultScope effect_scope(this); |
525 VisitForAccumulatorValue(stmt->expression()); | 531 VisitForAccumulatorValue(stmt->expression()); |
526 builder()->Return(); | 532 builder()->Return(); |
527 } | 533 } |
528 | 534 |
529 | 535 |
530 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { | 536 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { |
531 UNIMPLEMENTED(); | 537 UNIMPLEMENTED(); |
532 } | 538 } |
533 | 539 |
534 | 540 |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 UNIMPLEMENTED(); | 1483 UNIMPLEMENTED(); |
1478 } | 1484 } |
1479 | 1485 |
1480 // Convert old value into a number. | 1486 // Convert old value into a number. |
1481 if (!is_strong(language_mode())) { | 1487 if (!is_strong(language_mode())) { |
1482 builder()->CastAccumulatorToNumber(); | 1488 builder()->CastAccumulatorToNumber(); |
1483 } | 1489 } |
1484 | 1490 |
1485 // Save result for postfix expressions. | 1491 // Save result for postfix expressions. |
1486 if (is_postfix) { | 1492 if (is_postfix) { |
1487 old_value = execution_result()->NewRegister(); | 1493 old_value = execution_result()->outer()->NewRegister(); |
1488 builder()->StoreAccumulatorInRegister(old_value); | 1494 builder()->StoreAccumulatorInRegister(old_value); |
1489 } | 1495 } |
1490 | 1496 |
1491 // Perform +1/-1 operation. | 1497 // Perform +1/-1 operation. |
1492 builder()->CountOperation(expr->binary_op(), language_mode_strength()); | 1498 builder()->CountOperation(expr->binary_op(), language_mode_strength()); |
1493 | 1499 |
1494 // Store the value. | 1500 // Store the value. |
1495 FeedbackVectorSlot feedback_slot = expr->CountSlot(); | 1501 FeedbackVectorSlot feedback_slot = expr->CountSlot(); |
1496 switch (assign_type) { | 1502 switch (assign_type) { |
1497 case VARIABLE: { | 1503 case VARIABLE: { |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 } | 1886 } |
1881 | 1887 |
1882 | 1888 |
1883 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 1889 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
1884 return info()->feedback_vector()->GetIndex(slot); | 1890 return info()->feedback_vector()->GetIndex(slot); |
1885 } | 1891 } |
1886 | 1892 |
1887 } // namespace interpreter | 1893 } // namespace interpreter |
1888 } // namespace internal | 1894 } // namespace internal |
1889 } // namespace v8 | 1895 } // namespace v8 |
OLD | NEW |