OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_CODEGEN_IA32_H_ | 28 #ifndef V8_CODEGEN_IA32_H_ |
29 #define V8_CODEGEN_IA32_H_ | 29 #define V8_CODEGEN_IA32_H_ |
30 | 30 |
31 #include "scopes.h" | |
32 #include "register-allocator.h" | |
33 | |
34 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
35 | 32 |
36 // Forward declarations | 33 // Forward declarations |
37 class DeferredCode; | 34 class DeferredCode; |
| 35 class RegisterAllocator; |
| 36 class RegisterFile; |
38 | 37 |
39 // Mode to overwrite BinaryExpression values. | 38 // Mode to overwrite BinaryExpression values. |
40 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; | 39 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT }; |
41 | 40 |
42 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 41 enum InitState { CONST_INIT, NOT_CONST_INIT }; |
43 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; | 42 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
44 | 43 |
45 | 44 |
46 // ------------------------------------------------------------------------- | 45 // ------------------------------------------------------------------------- |
47 // Reference support | 46 // Reference support |
(...skipping 27 matching lines...) Expand all Loading... |
75 bool is_property() const { return type_ == NAMED || type_ == KEYED; } | 74 bool is_property() const { return type_ == NAMED || type_ == KEYED; } |
76 | 75 |
77 // Return the name. Only valid for named property references. | 76 // Return the name. Only valid for named property references. |
78 Handle<String> GetName(); | 77 Handle<String> GetName(); |
79 | 78 |
80 // Generate code to push the value of the reference on top of the | 79 // Generate code to push the value of the reference on top of the |
81 // expression stack. The reference is expected to be already on top of | 80 // expression stack. The reference is expected to be already on top of |
82 // the expression stack, and it is left in place with its value above it. | 81 // the expression stack, and it is left in place with its value above it. |
83 void GetValue(TypeofState typeof_state); | 82 void GetValue(TypeofState typeof_state); |
84 | 83 |
85 // Generate code to push the value of a reference on top of the expression | |
86 // stack and then spill the stack frame. This function is used temporarily | |
87 // while the code generator is being transformed. | |
88 inline void GetValueAndSpill(TypeofState typeof_state); | |
89 | |
90 // Like GetValue except that the slot is expected to be written to before | 84 // Like GetValue except that the slot is expected to be written to before |
91 // being read from again. Thae value of the reference may be invalidated, | 85 // being read from again. Thae value of the reference may be invalidated, |
92 // causing subsequent attempts to read it to fail. | 86 // causing subsequent attempts to read it to fail. |
93 void TakeValue(TypeofState typeof_state); | 87 void TakeValue(TypeofState typeof_state); |
94 | 88 |
95 // Generate code to store the value on top of the expression stack in the | 89 // Generate code to store the value on top of the expression stack in the |
96 // reference. The reference is expected to be immediately below the value | 90 // reference. The reference is expected to be immediately below the value |
97 // on the expression stack. The stored value is left in place (with the | 91 // on the expression stack. The stored value is left in place (with the |
98 // reference intact below it) to support chained assignments. | 92 // reference intact below it) to support chained assignments. |
99 void SetValue(InitState init_state); | 93 void SetValue(InitState init_state); |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 355 |
362 #define DEF_VISIT(type) \ | 356 #define DEF_VISIT(type) \ |
363 void Visit##type(type* node); | 357 void Visit##type(type* node); |
364 NODE_LIST(DEF_VISIT) | 358 NODE_LIST(DEF_VISIT) |
365 #undef DEF_VISIT | 359 #undef DEF_VISIT |
366 | 360 |
367 // Visit a statement and then spill the virtual frame if control flow can | 361 // Visit a statement and then spill the virtual frame if control flow can |
368 // reach the end of the statement (ie, it does not exit via break, | 362 // reach the end of the statement (ie, it does not exit via break, |
369 // continue, return, or throw). This function is used temporarily while | 363 // continue, return, or throw). This function is used temporarily while |
370 // the code generator is being transformed. | 364 // the code generator is being transformed. |
371 void VisitAndSpill(Statement* statement) { | 365 void VisitAndSpill(Statement* statement); |
372 ASSERT(in_spilled_code()); | |
373 set_in_spilled_code(false); | |
374 Visit(statement); | |
375 if (frame_ != NULL) { | |
376 frame_->SpillAll(); | |
377 } | |
378 set_in_spilled_code(true); | |
379 } | |
380 | 366 |
381 // Visit a list of statements and then spill the virtual frame if control | 367 // Visit a list of statements and then spill the virtual frame if control |
382 // flow can reach the end of the list. | 368 // flow can reach the end of the list. |
383 void VisitStatementsAndSpill(ZoneList<Statement*>* statements) { | 369 void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
384 ASSERT(in_spilled_code()); | |
385 set_in_spilled_code(false); | |
386 VisitStatements(statements); | |
387 if (frame_ != NULL) { | |
388 frame_->SpillAll(); | |
389 } | |
390 set_in_spilled_code(true); | |
391 } | |
392 | 370 |
393 // Main code generation function | 371 // Main code generation function |
394 void GenCode(FunctionLiteral* fun); | 372 void GenCode(FunctionLiteral* fun); |
395 | 373 |
396 // Generate the return sequence code. Should be called no more than once | 374 // Generate the return sequence code. Should be called no more than once |
397 // per compiled function (it binds the return target, which can not be | 375 // per compiled function (it binds the return target, which can not be |
398 // done more than once). The return value is assumed to be in eax by the | 376 // done more than once). The return value is assumed to be in eax by the |
399 // code generated. | 377 // code generated. |
400 void GenerateReturnSequence(); | 378 void GenerateReturnSequence(); |
401 | 379 |
(...skipping 21 matching lines...) Expand all Loading... |
423 ControlDestination* destination, | 401 ControlDestination* destination, |
424 bool force_control); | 402 bool force_control); |
425 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF); | 403 void Load(Expression* x, TypeofState typeof_state = NOT_INSIDE_TYPEOF); |
426 void LoadGlobal(); | 404 void LoadGlobal(); |
427 void LoadGlobalReceiver(); | 405 void LoadGlobalReceiver(); |
428 | 406 |
429 // Generate code to push the value of an expression on top of the frame | 407 // Generate code to push the value of an expression on top of the frame |
430 // and then spill the frame fully to memory. This function is used | 408 // and then spill the frame fully to memory. This function is used |
431 // temporarily while the code generator is being transformed. | 409 // temporarily while the code generator is being transformed. |
432 void LoadAndSpill(Expression* expression, | 410 void LoadAndSpill(Expression* expression, |
433 TypeofState typeof_state = NOT_INSIDE_TYPEOF) { | 411 TypeofState typeof_state = NOT_INSIDE_TYPEOF); |
434 ASSERT(in_spilled_code()); | |
435 set_in_spilled_code(false); | |
436 Load(expression, typeof_state); | |
437 frame_->SpillAll(); | |
438 set_in_spilled_code(true); | |
439 } | |
440 | |
441 // Call LoadCondition and then spill the virtual frame unless control flow | |
442 // cannot reach the end of the expression (ie, by emitting only | |
443 // unconditional jumps to the control targets). | |
444 void LoadConditionAndSpill(Expression* expression, | |
445 TypeofState typeof_state, | |
446 ControlDestination* destination, | |
447 bool force_control) { | |
448 ASSERT(in_spilled_code()); | |
449 set_in_spilled_code(false); | |
450 LoadCondition(expression, typeof_state, destination, force_control); | |
451 if (frame_ != NULL) { | |
452 frame_->SpillAll(); | |
453 } | |
454 set_in_spilled_code(true); | |
455 } | |
456 | 412 |
457 // Read a value from a slot and leave it on top of the expression stack. | 413 // Read a value from a slot and leave it on top of the expression stack. |
458 void LoadFromSlot(Slot* slot, TypeofState typeof_state); | 414 void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
459 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, | 415 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, |
460 TypeofState typeof_state, | 416 TypeofState typeof_state, |
461 JumpTarget* slow); | 417 JumpTarget* slow); |
462 | 418 |
463 // Store the value on top of the expression stack into a slot, leaving the | 419 // Store the value on top of the expression stack into a slot, leaving the |
464 // value in place. | 420 // value in place. |
465 void StoreToSlot(Slot* slot, InitState init_state); | 421 void StoreToSlot(Slot* slot, InitState init_state); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 | 593 |
638 friend class VirtualFrame; | 594 friend class VirtualFrame; |
639 friend class JumpTarget; | 595 friend class JumpTarget; |
640 friend class Reference; | 596 friend class Reference; |
641 friend class Result; | 597 friend class Result; |
642 | 598 |
643 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); | 599 DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
644 }; | 600 }; |
645 | 601 |
646 | 602 |
647 void Reference::GetValueAndSpill(TypeofState typeof_state) { | |
648 ASSERT(cgen_->in_spilled_code()); | |
649 cgen_->set_in_spilled_code(false); | |
650 GetValue(typeof_state); | |
651 cgen_->frame()->SpillAll(); | |
652 cgen_->set_in_spilled_code(true); | |
653 } | |
654 | |
655 | |
656 } } // namespace v8::internal | 603 } } // namespace v8::internal |
657 | 604 |
658 #endif // V8_CODEGEN_IA32_H_ | 605 #endif // V8_CODEGEN_IA32_H_ |
OLD | NEW |