macro-assembler.h revision 3ef787dbeca8a5fb1086949cda830dccee07bfbd
1// Copyright 2012 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_MACRO_ASSEMBLER_H_ 29#define V8_MACRO_ASSEMBLER_H_ 30 31 32// Helper types to make boolean flag easier to read at call-site. 33enum InvokeFlag { 34 CALL_FUNCTION, 35 JUMP_FUNCTION 36}; 37 38 39// Invalid depth in prototype chain. 40const int kInvalidProtoDepth = -1; 41 42#if V8_TARGET_ARCH_IA32 43#include "assembler.h" 44#include "ia32/assembler-ia32.h" 45#include "ia32/assembler-ia32-inl.h" 46#include "code.h" // must be after assembler_*.h 47#include "ia32/macro-assembler-ia32.h" 48#elif V8_TARGET_ARCH_X64 49#include "assembler.h" 50#include "x64/assembler-x64.h" 51#include "x64/assembler-x64-inl.h" 52#include "code.h" // must be after assembler_*.h 53#include "x64/macro-assembler-x64.h" 54#elif V8_TARGET_ARCH_ARM 55#include "arm/constants-arm.h" 56#include "assembler.h" 57#include "arm/assembler-arm.h" 58#include "arm/assembler-arm-inl.h" 59#include "code.h" // must be after assembler_*.h 60#include "arm/macro-assembler-arm.h" 61#elif V8_TARGET_ARCH_MIPS 62#include "mips/constants-mips.h" 63#include "assembler.h" 64#include "mips/assembler-mips.h" 65#include "mips/assembler-mips-inl.h" 66#include "code.h" // must be after assembler_*.h 67#include "mips/macro-assembler-mips.h" 68#else 69#error Unsupported target architecture. 70#endif 71 72namespace v8 { 73namespace internal { 74 75class FrameScope { 76 public: 77 explicit FrameScope(MacroAssembler* masm, StackFrame::Type type) 78 : masm_(masm), type_(type), old_has_frame_(masm->has_frame()) { 79 masm->set_has_frame(true); 80 if (type != StackFrame::MANUAL && type_ != StackFrame::NONE) { 81 masm->EnterFrame(type); 82 } 83 } 84 85 ~FrameScope() { 86 if (type_ != StackFrame::MANUAL && type_ != StackFrame::NONE) { 87 masm_->LeaveFrame(type_); 88 } 89 masm_->set_has_frame(old_has_frame_); 90 } 91 92 // Normally we generate the leave-frame code when this object goes 93 // out of scope. Sometimes we may need to generate the code somewhere else 94 // in addition. Calling this will achieve that, but the object stays in 95 // scope, the MacroAssembler is still marked as being in a frame scope, and 96 // the code will be generated again when it goes out of scope. 97 void GenerateLeaveFrame() { 98 masm_->LeaveFrame(type_); 99 } 100 101 private: 102 MacroAssembler* masm_; 103 StackFrame::Type type_; 104 bool old_has_frame_; 105}; 106 107 108class AllowExternalCallThatCantCauseGC: public FrameScope { 109 public: 110 explicit AllowExternalCallThatCantCauseGC(MacroAssembler* masm) 111 : FrameScope(masm, StackFrame::NONE) { } 112}; 113 114 115class NoCurrentFrameScope { 116 public: 117 explicit NoCurrentFrameScope(MacroAssembler* masm) 118 : masm_(masm), saved_(masm->has_frame()) { 119 masm->set_has_frame(false); 120 } 121 122 ~NoCurrentFrameScope() { 123 masm_->set_has_frame(saved_); 124 } 125 126 private: 127 MacroAssembler* masm_; 128 bool saved_; 129}; 130 131 132// Support for "structured" code comments. 133#ifdef DEBUG 134 135class Comment { 136 public: 137 Comment(MacroAssembler* masm, const char* msg); 138 ~Comment(); 139 140 private: 141 MacroAssembler* masm_; 142 const char* msg_; 143}; 144 145#else 146 147class Comment { 148 public: 149 Comment(MacroAssembler*, const char*) {} 150}; 151 152#endif // DEBUG 153 154} } // namespace v8::internal 155 156#endif // V8_MACRO_ASSEMBLER_H_ 157