| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 19 matching lines...) Expand all Loading... |
| 30 #include "codegen.h" | 30 #include "codegen.h" |
| 31 #include "jump-target.h" | 31 #include "jump-target.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // JumpTarget implementation. | 36 // JumpTarget implementation. |
| 37 | 37 |
| 38 #define __ masm_-> | 38 #define __ masm_-> |
| 39 | 39 |
| 40 JumpTarget::JumpTarget(CodeGenerator* cgen) { | 40 JumpTarget::JumpTarget(CodeGenerator* cgen) |
| 41 ASSERT(cgen != NULL); | 41 : expected_frame_(NULL), |
| 42 expected_frame_ = NULL; | 42 code_generator_(cgen), |
| 43 code_generator_ = cgen; | 43 masm_(cgen->masm()) { |
| 44 masm_ = cgen->masm(); | |
| 45 } | 44 } |
| 46 | 45 |
| 47 | 46 |
| 48 JumpTarget::JumpTarget() | 47 JumpTarget::JumpTarget() |
| 49 : expected_frame_(NULL), | 48 : expected_frame_(NULL), |
| 50 code_generator_(NULL), | 49 code_generator_(NULL), |
| 51 masm_(NULL) { | 50 masm_(NULL) { |
| 52 } | 51 } |
| 53 | 52 |
| 54 | 53 |
| 55 void JumpTarget::set_code_generator(CodeGenerator* cgen) { | 54 void JumpTarget::set_code_generator(CodeGenerator* cgen) { |
| 56 ASSERT(cgen != NULL); | 55 ASSERT(cgen != NULL); |
| 57 ASSERT(code_generator_ == NULL); | 56 ASSERT(code_generator_ == NULL); |
| 58 code_generator_ = cgen; | 57 code_generator_ = cgen; |
| 59 masm_ = cgen->masm(); | 58 masm_ = cgen->masm(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 | 61 |
| 63 void JumpTarget::Jump() { | 62 void JumpTarget::Jump() { |
| 63 // Precondition: there is a current frame. There may or may not be an |
| 64 // expected frame at the label. |
| 65 ASSERT(code_generator_ != NULL); |
| 66 |
| 67 VirtualFrame* current_frame = code_generator_->frame(); |
| 68 ASSERT(current_frame != NULL); |
| 69 |
| 70 if (expected_frame_ == NULL) { |
| 71 expected_frame_ = current_frame; |
| 72 code_generator_->set_frame(NULL); |
| 73 } else { |
| 74 current_frame->MergeTo(expected_frame_); |
| 75 code_generator_->delete_frame(); |
| 76 } |
| 77 |
| 64 __ b(&label_); | 78 __ b(&label_); |
| 65 } | 79 // Postcondition: there is no current frame but there is an expected frame |
| 66 | 80 // at the label. |
| 67 void JumpTarget::Branch(Condition cc, Hint ignored) { | |
| 68 __ b(cc, &label_); | |
| 69 } | |
| 70 | |
| 71 void JumpTarget::Bind() { | |
| 72 __ bind(&label_); | |
| 73 } | 81 } |
| 74 | 82 |
| 75 | 83 |
| 84 void JumpTarget::Branch(Condition cc, Hint ignored) { |
| 85 // Precondition: there is a current frame. There may or may not be an |
| 86 // expected frame at the label. |
| 87 ASSERT(code_generator_ != NULL); |
| 88 ASSERT(masm_ != NULL); |
| 89 |
| 90 VirtualFrame* current_frame = code_generator_->frame(); |
| 91 ASSERT(current_frame != NULL); |
| 92 |
| 93 if (expected_frame_ == NULL) { |
| 94 expected_frame_ = new VirtualFrame(current_frame); |
| 95 } else { |
| 96 current_frame->MergeTo(expected_frame_); |
| 97 } |
| 98 |
| 99 __ b(cc, &label_); |
| 100 // Postcondition: there is both a current frame and an expected frame at |
| 101 // the label and they match. |
| 102 } |
| 103 |
| 104 |
| 105 void JumpTarget::Call() { |
| 106 // Precondition: there is a current frame, and there is no expected frame |
| 107 // at the label. |
| 108 ASSERT(code_generator_ != NULL); |
| 109 ASSERT(masm_ != NULL); |
| 110 |
| 111 VirtualFrame* current_frame = code_generator_->frame(); |
| 112 ASSERT(current_frame != NULL); |
| 113 ASSERT(expected_frame_ == NULL); |
| 114 |
| 115 expected_frame_ = new VirtualFrame(current_frame); |
| 116 // Adjust the expected frame's height to account for the return address |
| 117 // pushed by the call instruction. |
| 118 expected_frame_->Adjust(1); |
| 119 |
| 120 __ bl(&label_); |
| 121 // Postcondition: there is both a current frame and an expected frame at |
| 122 // the label. The current frame is one shorter than the one at the label |
| 123 // (which contains the return address in memory). |
| 124 } |
| 125 |
| 126 |
| 127 void JumpTarget::Bind() { |
| 128 // Precondition: there is either a current frame or an expected frame at |
| 129 // the label (and possibly both). The label is unbound. |
| 130 ASSERT(code_generator_ != NULL); |
| 131 ASSERT(masm_ != NULL); |
| 132 |
| 133 VirtualFrame* current_frame = code_generator_->frame(); |
| 134 ASSERT(current_frame != NULL || expected_frame_ != NULL); |
| 135 ASSERT(!label_.is_bound()); |
| 136 |
| 137 if (expected_frame_ == NULL) { |
| 138 expected_frame_ = new VirtualFrame(current_frame); |
| 139 } else if (current_frame == NULL) { |
| 140 code_generator_->set_frame(new VirtualFrame(expected_frame_)); |
| 141 } else { |
| 142 current_frame->MergeTo(expected_frame_); |
| 143 } |
| 144 |
| 145 __ bind(&label_); |
| 146 // Postcondition: there is both a current frame and an expected frame at |
| 147 // the label and they match. The label is bound. |
| 148 } |
| 149 |
| 150 |
| 76 // ------------------------------------------------------------------------- | 151 // ------------------------------------------------------------------------- |
| 77 // ShadowTarget implementation. | 152 // ShadowTarget implementation. |
| 78 | 153 |
| 79 ShadowTarget::ShadowTarget(JumpTarget* original) { | 154 ShadowTarget::ShadowTarget(JumpTarget* original) { |
| 80 ASSERT(original != NULL); | 155 ASSERT(original != NULL); |
| 81 original_target_ = original; | 156 original_target_ = original; |
| 82 original_pos_ = original->label()->pos_; | 157 original_pos_ = original->label()->pos_; |
| 83 original_expected_frame_ = original->expected_frame(); | 158 original_expected_frame_ = original->expected_frame(); |
| 84 | 159 |
| 85 // We do not call Unuse() on the orginal jump target, because we do not | 160 // We do not call Unuse() on the orginal jump target, because we do not |
| (...skipping 19 matching lines...) Expand all Loading... |
| 105 | 180 |
| 106 #ifdef DEBUG | 181 #ifdef DEBUG |
| 107 is_shadowing_ = false; | 182 is_shadowing_ = false; |
| 108 #endif | 183 #endif |
| 109 } | 184 } |
| 110 | 185 |
| 111 #undef __ | 186 #undef __ |
| 112 | 187 |
| 113 | 188 |
| 114 } } // namespace v8::internal | 189 } } // namespace v8::internal |
| OLD | NEW |