| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 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 #include "v8.h" |
| 29 |
| 30 #include "codegen.h" |
| 31 #include "jump-target.h" |
| 32 |
| 33 namespace v8 { namespace internal { |
| 34 |
| 35 // ------------------------------------------------------------------------- |
| 36 // JumpTarget implementation. |
| 37 |
| 38 #define __ masm_-> |
| 39 |
| 40 JumpTarget::JumpTarget(CodeGenerator* cgen) { |
| 41 ASSERT(cgen != NULL); |
| 42 expected_frame_ = NULL; |
| 43 code_generator_ = cgen; |
| 44 masm_ = cgen->masm(); |
| 45 } |
| 46 |
| 47 |
| 48 JumpTarget::JumpTarget() |
| 49 : expected_frame_(NULL), |
| 50 code_generator_(NULL), |
| 51 masm_(NULL) { |
| 52 } |
| 53 |
| 54 |
| 55 void JumpTarget::set_code_generator(CodeGenerator* cgen) { |
| 56 ASSERT(cgen != NULL); |
| 57 ASSERT(code_generator_ == NULL); |
| 58 code_generator_ = cgen; |
| 59 masm_ = cgen->masm(); |
| 60 } |
| 61 |
| 62 |
| 63 bool JumpTarget::IsActualFunctionReturn() { |
| 64 return (this == &code_generator_->function_return_ && |
| 65 !code_generator_->function_return_is_shadowed_); |
| 66 } |
| 67 |
| 68 |
| 69 void JumpTarget::Jump() { |
| 70 // Precondition: there is a current frame. There may or may not be an |
| 71 // expected frame at the label. |
| 72 ASSERT(code_generator_ != NULL); |
| 73 ASSERT(masm_ != NULL); |
| 74 |
| 75 VirtualFrame* current_frame = code_generator_->frame(); |
| 76 ASSERT(current_frame != NULL); |
| 77 |
| 78 if (expected_frame_ == NULL) { |
| 79 expected_frame_ = current_frame; |
| 80 code_generator_->set_frame(NULL); |
| 81 // The frame at the actual function return will always have height |
| 82 // zero. |
| 83 if (IsActualFunctionReturn()) expected_frame_->height_ = 0; |
| 84 } else { |
| 85 // No code needs to be emitted to merge to the expected frame at the |
| 86 // actual function return. |
| 87 if (!IsActualFunctionReturn()) current_frame->MergeTo(expected_frame_); |
| 88 code_generator_->delete_frame(); |
| 89 } |
| 90 |
| 91 __ jmp(&label_); |
| 92 // Postcondition: there is no current frame but there is an expected frame |
| 93 // at the label. |
| 94 } |
| 95 |
| 96 |
| 97 void JumpTarget::Branch(Condition cc, Hint hint) { |
| 98 // Precondition: there is a current frame. There may or may not be an |
| 99 // expected frame at the label. |
| 100 ASSERT(code_generator_ != NULL); |
| 101 ASSERT(masm_ != NULL); |
| 102 |
| 103 VirtualFrame* current_frame = code_generator_->frame(); |
| 104 ASSERT(current_frame != NULL); |
| 105 |
| 106 if (expected_frame_ == NULL) { |
| 107 expected_frame_ = new VirtualFrame(current_frame); |
| 108 // The frame at the actual function return will always have height |
| 109 // zero. |
| 110 if (IsActualFunctionReturn()) expected_frame_->height_ = 0; |
| 111 } else { |
| 112 // No code needs to be emitted to merge to the expected frame at the |
| 113 // actual function return. |
| 114 if (!IsActualFunctionReturn()) current_frame->MergeTo(expected_frame_); |
| 115 } |
| 116 |
| 117 __ j(cc, &label_, hint); |
| 118 // Postcondition: there is both a current frame and an expected frame at |
| 119 // the label and they match. |
| 120 } |
| 121 |
| 122 |
| 123 void JumpTarget::Call() { |
| 124 // Precondition: there is a current frame, and there is no expected frame |
| 125 // at the label. |
| 126 ASSERT(code_generator_ != NULL); |
| 127 ASSERT(masm_ != NULL); |
| 128 ASSERT(!IsActualFunctionReturn()); |
| 129 |
| 130 VirtualFrame* current_frame = code_generator_->frame(); |
| 131 ASSERT(current_frame != NULL); |
| 132 ASSERT(expected_frame_ == NULL); |
| 133 |
| 134 expected_frame_ = new VirtualFrame(current_frame); |
| 135 // Adjust the expected frame's height to account for the return address |
| 136 // pushed by the call instruction. |
| 137 expected_frame_->height_++; |
| 138 |
| 139 __ call(&label_); |
| 140 |
| 141 // Postcondition: there is both a current frame and an expected frame at |
| 142 // the label. The current frame is one shorter than the one at the label |
| 143 // (which contains the 'return address', ie, the eip register and possibly |
| 144 // cs register). |
| 145 } |
| 146 |
| 147 |
| 148 void JumpTarget::Bind() { |
| 149 ASSERT(code_generator_ != NULL); |
| 150 ASSERT(masm_ != NULL); |
| 151 |
| 152 // Precondition: there is either a current frame or an expected frame at |
| 153 // the label (and possibly both). The label is unbound. |
| 154 VirtualFrame* current_frame = code_generator_->frame(); |
| 155 ASSERT(current_frame != NULL || expected_frame_ != NULL); |
| 156 ASSERT(!label_.is_bound()); |
| 157 |
| 158 if (expected_frame_ == NULL) { |
| 159 expected_frame_ = new VirtualFrame(current_frame); |
| 160 // The frame at the actual function return will always have height |
| 161 // zero. |
| 162 if (IsActualFunctionReturn()) expected_frame_->height_ = 0; |
| 163 } else if (current_frame == NULL) { |
| 164 code_generator_->set_frame(new VirtualFrame(expected_frame_)); |
| 165 } else { |
| 166 // No code needs to be emitted to merge to the expected frame at the |
| 167 // actual function return. |
| 168 if (!IsActualFunctionReturn()) current_frame->MergeTo(expected_frame_); |
| 169 } |
| 170 |
| 171 __ bind(&label_); |
| 172 // Postcondition: there is both a current frame and an expected frame at |
| 173 // the label and they match. The label is bound. |
| 174 } |
| 175 |
| 176 |
| 177 // ------------------------------------------------------------------------- |
| 178 // ShadowTarget implementation. |
| 179 |
| 180 ShadowTarget::ShadowTarget(JumpTarget* original) { |
| 181 ASSERT(original != NULL); |
| 182 original_target_ = original; |
| 183 original_pos_ = original->label()->pos_; |
| 184 original_expected_frame_ = original->expected_frame(); |
| 185 |
| 186 // We do not call Unuse() on the orginal jump target, because we do not |
| 187 // want to delete the expected frame. |
| 188 original->label()->pos_ = 0; |
| 189 original->set_expected_frame(NULL); |
| 190 #ifdef DEBUG |
| 191 is_shadowing_ = true; |
| 192 #endif |
| 193 } |
| 194 |
| 195 |
| 196 void ShadowTarget::StopShadowing() { |
| 197 ASSERT(is_shadowing_); |
| 198 ASSERT(is_unused()); |
| 199 |
| 200 set_code_generator(original_target_->code_generator()); |
| 201 label_.pos_ = original_target_->label()->pos_; |
| 202 expected_frame_ = original_target_->expected_frame(); |
| 203 |
| 204 original_target_->label()->pos_ = original_pos_; |
| 205 original_target_->set_expected_frame(original_expected_frame_); |
| 206 |
| 207 #ifdef DEBUG |
| 208 is_shadowing_ = false; |
| 209 #endif |
| 210 } |
| 211 |
| 212 #undef __ |
| 213 |
| 214 |
| 215 } } // namespace v8::internal |
| OLD | NEW |