// Copyright 2010 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef V8_ARM_CODEGEN_ARM_H_ #define V8_ARM_CODEGEN_ARM_H_ #include "ic-inl.h" #include "ast.h" namespace v8 { namespace internal { // Forward declarations class CompilationInfo; class DeferredCode; class JumpTarget; class RegisterAllocator; class RegisterFile; enum InitState { CONST_INIT, NOT_CONST_INIT }; enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI }; enum WriteBarrierCharacter { UNLIKELY_SMI, LIKELY_SMI, NEVER_NEWSPACE }; // ------------------------------------------------------------------------- // Reference support // A reference is a C++ stack-allocated object that puts a // reference on the virtual frame. The reference may be consumed // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. // When the lifetime (scope) of a valid reference ends, it must have // been consumed, and be in state UNLOADED. class Reference BASE_EMBEDDED { public: // The values of the types is important, see size(). enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; Reference(CodeGenerator* cgen, Expression* expression, bool persist_after_get = false); ~Reference(); Expression* expression() const { return expression_; } Type type() const { return type_; } void set_type(Type value) { ASSERT_EQ(ILLEGAL, type_); type_ = value; } void set_unloaded() { ASSERT_NE(ILLEGAL, type_); ASSERT_NE(UNLOADED, type_); type_ = UNLOADED; } // The size the reference takes up on the stack. int size() const { return (type_ < SLOT) ? 0 : type_; } bool is_illegal() const { return type_ == ILLEGAL; } bool is_slot() const { return type_ == SLOT; } bool is_property() const { return type_ == NAMED || type_ == KEYED; } bool is_unloaded() const { return type_ == UNLOADED; } // Return the name. Only valid for named property references. Handle GetName(); // Generate code to push the value of the reference on top of the // expression stack. The reference is expected to be already on top of // the expression stack, and it is consumed by the call unless the // reference is for a compound assignment. // If the reference is not consumed, it is left in place under its value. void GetValue(); // Generate code to store the value on top of the expression stack in the // reference. The reference is expected to be immediately below the value // on the expression stack. The value is stored in the location specified // by the reference, and is left on top of the stack, after the reference // is popped from beneath it (unloaded). void SetValue(InitState init_state, WriteBarrierCharacter wb); // This is in preparation for something that uses the reference on the stack. // If we need this reference afterwards get then dup it now. Otherwise mark // it as used. inline void DupIfPersist(); private: CodeGenerator* cgen_; Expression* expression_; Type type_; // Keep the reference on the stack after get, so it can be used by set later. bool persist_after_get_; }; // ------------------------------------------------------------------------- // Code generation state // The state is passed down the AST by the code generator (and back up, in // the form of the state of the label pair). It is threaded through the // call stack. Constructing a state implicitly pushes it on the owning code // generator's stack of states, and destroying one implicitly pops it. class CodeGenState BASE_EMBEDDED { public: // Create an initial code generator state. Destroying the initial state // leaves the code generator with a NULL state. explicit CodeGenState(CodeGenerator* owner); // Destroy a code generator state and restore the owning code generator's // previous state. virtual ~CodeGenState(); virtual JumpTarget* true_target() const { return NULL; } virtual JumpTarget* false_target() const { return NULL; } protected: inline CodeGenerator* owner() { return owner_; } inline CodeGenState* previous() const { return previous_; } private: CodeGenerator* owner_; CodeGenState* previous_; }; class ConditionCodeGenState : public CodeGenState { public: // Create a code generator state based on a code generator's current // state. The new state has its own pair of branch labels. ConditionCodeGenState(CodeGenerator* owner, JumpTarget* true_target, JumpTarget* false_target); virtual JumpTarget* true_target() const { return true_target_; } virtual JumpTarget* false_target() const { return false_target_; } private: JumpTarget* true_target_; JumpTarget* false_target_; }; class TypeInfoCodeGenState : public CodeGenState { public: TypeInfoCodeGenState(CodeGenerator* owner, Slot* slot_number, TypeInfo info); ~TypeInfoCodeGenState(); virtual JumpTarget* true_target() const { return previous()->true_target(); } virtual JumpTarget* false_target() const { return previous()->false_target(); } private: Slot* slot_; TypeInfo old_type_info_; }; // ------------------------------------------------------------------------- // Arguments allocation mode enum ArgumentsAllocationMode { NO_ARGUMENTS_ALLOCATION, EAGER_ARGUMENTS_ALLOCATION, LAZY_ARGUMENTS_ALLOCATION }; // Different nop operations are used by the code generator to detect certain // states of the generated code. enum NopMarkerTypes { NON_MARKING_NOP = 0, PROPERTY_ACCESS_INLINED }; // ------------------------------------------------------------------------- // CodeGenerator class CodeGenerator: public AstVisitor { public: // Takes a function literal, generates code for it. This function should only // be called by compiler.cc. static Handle MakeCode(CompilationInfo* info); // Printing of AST, etc. as requested by flags. static void MakeCodePrologue(CompilationInfo* info); // Allocate and install the code. static Handle MakeCodeEpilogue(MacroAssembler* masm, Code::Flags flags, CompilationInfo* info); #ifdef ENABLE_LOGGING_AND_PROFILING static bool ShouldGenerateLog(Expression* type); #endif static void SetFunctionInfo(Handle fun, FunctionLiteral* lit, bool is_toplevel, Handle