| 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 #ifndef V8_JUMP_TARGET_IA32_H_ |
| 29 #define V8_JUMP_TARGET_IA32_H_ |
| 30 |
| 31 #include "virtual-frame.h" |
| 32 |
| 33 namespace v8 { namespace internal { |
| 34 |
| 35 // ------------------------------------------------------------------------- |
| 36 // Jump targets |
| 37 // |
| 38 // A jump target is an abstraction of a control-flow target in generated |
| 39 // code. It encapsulates an assembler label and an expected virtual frame |
| 40 // layout at that label. The first time control flow reaches the target, |
| 41 // either via jumping or branching or by binding the target, the expected |
| 42 // frame is set. If control flow subsequently reaches the target, code may |
| 43 // be emitted to ensure that the current frame matches the expected frame. |
| 44 // |
| 45 // A jump target must have been reached via control flow (either by jumping, |
| 46 // branching, or falling through) when it is bound. In particular, this |
| 47 // means that at least one of the control-flow graph edges reaching the |
| 48 // target must be a forward edge and must be compiled before any backward |
| 49 // edges. |
| 50 |
| 51 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. |
| 52 public: |
| 53 // Construct a jump target with a given code generator used to generate |
| 54 // code and to provide access to a current frame. |
| 55 explicit JumpTarget(CodeGenerator* cgen); |
| 56 |
| 57 // Construct a jump target without a code generator. A code generator |
| 58 // must be supplied before using the jump target as a label. This is |
| 59 // useful, eg, when jump targets are embedded in AST nodes. |
| 60 JumpTarget(); |
| 61 |
| 62 virtual ~JumpTarget() { delete expected_frame_; } |
| 63 |
| 64 // Supply a code generator. This function expects to be given a non-null |
| 65 // code generator, and to be called only when the code generator is not |
| 66 // yet set. |
| 67 void set_code_generator(CodeGenerator* cgen); |
| 68 |
| 69 // Accessors. |
| 70 CodeGenerator* code_generator() const { return code_generator_; } |
| 71 |
| 72 MacroAssembler* masm() const { return masm_; } |
| 73 |
| 74 Label* label() { return &label_; } |
| 75 |
| 76 VirtualFrame* expected_frame() const { return expected_frame_; } |
| 77 void set_expected_frame(VirtualFrame* frame) { |
| 78 expected_frame_ = frame; |
| 79 } |
| 80 |
| 81 // Predicates testing the state of the encapsulated label. |
| 82 bool is_bound() const { return label_.is_bound(); } |
| 83 bool is_linked() const { return label_.is_linked(); } |
| 84 bool is_unused() const { return label_.is_unused(); } |
| 85 |
| 86 // Treat the jump target as a fresh one---the label is unused and the |
| 87 // expected frame if any is reset. |
| 88 void Unuse() { |
| 89 label_.Unuse(); |
| 90 delete expected_frame_; |
| 91 expected_frame_ = NULL; |
| 92 } |
| 93 |
| 94 // True if this jump target is the (non-shadowed) target of the return |
| 95 // from the code generator's current function. |
| 96 bool IsActualFunctionReturn(); |
| 97 |
| 98 // Emit a jump to the target. If there is no expected frame, the code |
| 99 // generator's current frame becomes the expected one. If there is |
| 100 // already an expected frame, code may be emitted to merge the current |
| 101 // frame to the expected one. After the jump, the code generate has no |
| 102 // current frame (because control flow does not fall through from a jump). |
| 103 // A new current frame can be picked up by, eg, binding a jump target with |
| 104 // an expected frame. |
| 105 void Jump(); |
| 106 |
| 107 // Emit a conditional branch to the target. If there is no expected |
| 108 // frame, a clone of the code generator's current frame becomes the |
| 109 // expected one. If there is already an expected frame, code may be |
| 110 // emitted to merge the current frame to the expected one. |
| 111 void Branch(Condition cc, Hint hint = no_hint); |
| 112 |
| 113 // Bind a jump target. If there is no expected frame and there is a |
| 114 // current frame (ie, control flow is falling through to the target), then |
| 115 // a clone of the current frame becomes the expected one. If there is a |
| 116 // current frame and an expected one (eg, control flow is falling through |
| 117 // to a target that has already been reached via a jump or branch), then |
| 118 // code may be emitted to merge the frames. A jump target that already |
| 119 // has an expected frame can be bound even if there is no current |
| 120 // frame---in that case, the new current frame is picked up from the jump |
| 121 // target. |
| 122 void Bind(); |
| 123 |
| 124 // Call a jump target. A clone of the current frame, with a return |
| 125 // address pushed on top of it, becomes the expected frame at the target. |
| 126 // The current frame after the site of the call (ie, after the return) is |
| 127 // expected to be the same as before the call. This operation is only |
| 128 // supported when there is a current frame and when there is no expected |
| 129 // frame at the label. |
| 130 void Call(); |
| 131 |
| 132 protected: |
| 133 // The encapsulated assembler label. |
| 134 Label label_; |
| 135 |
| 136 // The expected frame where the label is bound, or NULL. |
| 137 VirtualFrame* expected_frame_; |
| 138 |
| 139 private: |
| 140 // The code generator gives access to the current frame. |
| 141 CodeGenerator* code_generator_; |
| 142 |
| 143 // Used to emit code. |
| 144 MacroAssembler* masm_; |
| 145 }; |
| 146 |
| 147 |
| 148 // ------------------------------------------------------------------------- |
| 149 // Shadow jump targets |
| 150 // |
| 151 // Shadow jump targets represent a jump target that is temporarily shadowed |
| 152 // by another one (represented by the original during shadowing). They are |
| 153 // used to catch jumps to labels in certain contexts, e.g. try blocks. |
| 154 // After shadowing ends, the formerly shadowed target is again represented |
| 155 // by the original and the ShadowTarget can be used as a jump target in its |
| 156 // own right, representing the formerly shadowing target. |
| 157 |
| 158 class ShadowTarget : public JumpTarget { |
| 159 public: |
| 160 // Construct a shadow a jump target. After construction, the original |
| 161 // jump target shadows the former target, which is hidden as the |
| 162 // newly-constructed shadow target. |
| 163 explicit ShadowTarget(JumpTarget* original); |
| 164 |
| 165 virtual ~ShadowTarget() { |
| 166 ASSERT(!is_shadowing_); |
| 167 } |
| 168 |
| 169 // End shadowing. After shadowing ends, the original jump target gives |
| 170 // access to the formerly shadowed target and the shadow target object |
| 171 // gives access to the formerly shadowing target. |
| 172 void StopShadowing(); |
| 173 |
| 174 // During shadowing, the currently shadowing target. After shadowing, the |
| 175 // target that was shadowed. |
| 176 JumpTarget* original_target() const { return original_target_; } |
| 177 |
| 178 private: |
| 179 // During shadowing, the currently shadowing target. After shadowing, the |
| 180 // target that was shadowed. |
| 181 JumpTarget* original_target_; |
| 182 |
| 183 // During shadowing, the saved state of the shadowed target's label. |
| 184 int original_pos_; |
| 185 |
| 186 // During shadowing, the saved state of the shadowed target's expected |
| 187 // frame. |
| 188 VirtualFrame* original_expected_frame_; |
| 189 |
| 190 #ifdef DEBUG |
| 191 bool is_shadowing_; |
| 192 #endif |
| 193 }; |
| 194 |
| 195 |
| 196 } } // namespace v8::internal |
| 197 |
| 198 #endif // V8_JUMP_TARGET_IA32_H_ |
| OLD | NEW |