code); class StateField : public BitField { }; class PcField : public BitField { }; static const char* State2String(State state) { switch (state) { case NO_REGISTERS: return "NO_REGISTERS"; case TOS_REG: return "TOS_REG"; } UNREACHABLE(); return NULL; } private: class Breakable; class Iteration; class TryCatch; class TryFinally; class Finally; class ForIn; class NestedStatement BASE_EMBEDDED { public: explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) { // Link into codegen's nesting stack. previous_ = codegen->nesting_stack_; codegen->nesting_stack_ = this; } virtual ~NestedStatement() { // Unlink from codegen's nesting stack. ASSERT_EQ(this, codegen_->nesting_stack_); codegen_->nesting_stack_ = previous_; } virtual Breakable* AsBreakable() { return NULL; } virtual Iteration* AsIteration() { return NULL; } virtual TryCatch* AsTryCatch() { return NULL; } virtual TryFinally* AsTryFinally() { return NULL; } virtual Finally* AsFinally() { return NULL; } virtual ForIn* AsForIn() { return NULL; } virtual bool IsContinueTarget(Statement* target) { return false; } virtual bool IsBreakTarget(Statement* target) { return false; } // Generate code to leave the nested statement. This includes // cleaning up any stack elements in use and restoring the // stack to the expectations of the surrounding statements. // Takes a number of stack elements currently on top of the // nested statement's stack, and returns a number of stack // elements left on top of the surrounding statement's stack. // The generated code must preserve the result register (which // contains the value in case of a return). virtual int Exit(int stack_depth) { // Default implementation for the case where there is // nothing to clean up. return stack_depth; } NestedStatement* outer() { return previous_; } protected: MacroAssembler* masm() { return codegen_->masm(); } private: FullCodeGenerator* codegen_; NestedStatement* previous_; DISALLOW_COPY_AND_ASSIGN(NestedStatement); }; class Breakable : public NestedStatement { public: Breakable(FullCodeGenerator* codegen, BreakableStatement* break_target) : NestedStatement(codegen), target_(break_target) {} virtual ~Breakable() {} virtual Breakable* AsBreakable() { return this; } virtual bool IsBreakTarget(Statement* statement) { return target_ == statement; } BreakableStatement* statement() { return target_; } Label* break_target() { return &break_target_label_; } private: BreakableStatement* target_; Label break_target_label_; DISALLOW_COPY_AND_ASSIGN(Breakable); }; class Iteration : public Breakable { public: Iteration(FullCodeGenerator* codegen, IterationStatement* iteration_statement) : Breakable(codegen, iteration_statement) {} virtual ~Iteration() {} virtual Iteration* AsIteration() { return this; } virtual bool IsContinueTarget(Statement* statement) { return this->statement() == statement; } Label* continue_target() { return &continue_target_label_; } private: Label continue_target_label_; DISALLOW_COPY_AND_ASSIGN(Iteration); }; // The environment inside the try block of a try/catch statement. class TryCatch : public NestedStatement { public: explicit TryCatch(FullCodeGenerator* codegen, Label* catch_entry) : NestedStatement(codegen), catch_entry_(catch_entry) { } virtual ~TryCatch() {} virtual TryCatch* AsTryCatch() { return this; } Label* catch_entry() { return catch_entry_; } virtual int Exit(int stack_depth); private: Label* catch_entry_; DISALLOW_COPY_AND_ASSIGN(TryCatch); }; // The environment inside the try block of a try/finally statement. class TryFinally : public NestedStatement { public: explicit TryFinally(FullCodeGenerator* codegen, Label* finally_entry) : NestedStatement(codegen), finally_entry_(finally_entry) { } virtual ~TryFinally() {} virtual TryFinally* AsTryFinally() { return this; } Label* finally_entry() { return finally_entry_; } virtual int Exit(int stack_depth); private: Label* finally_entry_; DISALLOW_COPY_AND_ASSIGN(TryFinally); }; // A FinallyEnvironment represents being inside a finally block. // Abnormal termination of the finally block needs to clean up // the block's parameters from the stack. class Finally : public NestedStatement { public: explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { } virtual ~Finally() {} virtual Finally* AsFinally() { return this; } virtual int Exit(int stack_depth) { return stack_depth + kFinallyStackElementCount; } private: // Number of extra stack slots occupied during a finally block. static const int kFinallyStackElementCount = 2; DISALLOW_COPY_AND_ASSIGN(Finally); }; // A ForInEnvironment represents being inside a for-in loop. // Abnormal termination of the for-in block needs to clean up // the block's temporary storage from the stack. class ForIn : public Iteration { public: ForIn(FullCodeGenerator* codegen, ForInStatement* statement) : Iteration(codegen, statement) { } virtual ~ForIn() {} virtual ForIn* AsForIn() { return this; } virtual int Exit(int stack_depth) { return stack_depth + kForInStackElementCount; } private: static const int kForInStackElementCount = 5; DISALLOW_COPY_AND_ASSIGN(ForIn); }; // The forward bailout stack keeps track of the expressions that can // bail out to just before the control flow is split in a child // node. The stack elements are linked together through the parent // link when visiting expressions in test contexts after requesting // bailout in child forwarding. class ForwardBailoutStack BASE_EMBEDDED { public: ForwardBailoutStack(Expression* expr, ForwardBailoutStack* parent) : expr_(expr), parent_(parent) { } Expression* expr() const { return expr_; } ForwardBailoutStack* parent() const { return parent_; } private: Expression* const expr_; ForwardBailoutStack* const parent_; }; // Type of a member function that generates inline code for a native function. typedef void (FullCodeGenerator::*InlineFunctionGenerator) (ZoneList*); static const InlineFunctionGenerator kInlineFunctionGenerators[]; // A platform-specific utility to overwrite the accumulator register // with a GC-safe value. void ClearAccumulator(); // Compute the frame pointer relative offset for a given local or // parameter slot. int SlotOffset(Slot* slot); // Determine whether or not to inline the smi case for the given // operation. bool ShouldInlineSmiCase(Token::Value op); // Helper function to convert a pure value into a test context. The value // is expected on the stack or the accumulator, depending on the platform. // See the platform-specific implementation for details. void DoTest(Label* if_true, Label* if_false, Label* fall_through); // Helper function to split control flow and avoid a branch to the // fall-through label if it is set up. void Split(Condition cc, Label* if_true, Label* if_false, Label* fall_through); void Move(Slot* dst, Register source, Register scratch1, Register scratch2); void Move(Register dst, Slot* source); // Return an operand used to read/write to a known (ie, non-LOOKUP) slot. // May emit code to traverse the context chain, destroying the scratch // register. MemOperand EmitSlotSearch(Slot* slot, Register scratch); // Forward the bailout responsibility for the given expression to // the next child visited (which must be in a test context). void ForwardBailoutToChild(Expression* expr); void VisitForEffect(Expression* expr) { EffectContext context(this); HandleInNonTestContext(expr, NO_REGISTERS); } void VisitForAccumulatorValue(Expression* expr) { AccumulatorValueContext context(this); HandleInNonTestContext(expr, TOS_REG); } void VisitForStackValue(Expression* expr) { StackValueContext context(this); HandleInNonTestContext(expr, NO_REGISTERS); } void VisitForControl(Expression* expr, Label* if_true, Label* if_false, Label* fall_through) { TestContext context(this, if_true, if_false, fall_through); VisitInTestContext(expr); // Forwarding bailouts to children is a one shot operation. It // should have been processed at this point. ASSERT(forward_bailout_pending_ == NULL); } void HandleInNonTestContext(Expression* expr, State state); void VisitInTestContext(Expression* expr); void VisitDeclarations(ZoneList* declarations); void DeclareGlobals(Handle pairs); // Try to perform a comparison as a fast inlined literal compare if // the operands allow it. Returns true if the compare operations // has been matched and all code generated; false otherwise. bool TryLiteralCompare(Token::Value op, Expression* left, Expression* right, Label* if_true, Label* if_false, Label* fall_through); // Bailout support. void PrepareForBailout(AstNode* node, State state); void PrepareForBailoutForId(int id, State state); // Record a call's return site offset, used to rebuild the frame if the // called function was inlined at the site. void RecordJSReturnSite(Call* call); // Prepare for bailout before a test (or compare) and branch. If // should_normalize, then the following comparison will not handle the // canonical JS true value so we will insert a (dead) test against true at // the actual bailout target from the optimized code. If not // should_normalize, the true and false labels are ignored. void PrepareForBailoutBeforeSplit(State state, bool should_normalize, Label* if_true, Label* if_false); // Platform-specific code for a variable, constant, or function // declaration. Functions have an initial value. void EmitDeclaration(Variable* variable, Variable::Mode mode, FunctionLiteral* function); // Platform-specific code for checking the stack limit at the back edge of // a loop. void EmitStackCheck(IterationStatement* stmt); // Record the OSR AST id corresponding to a stack check in the code. void RecordStackCheck(int osr_ast_id); // Emit a table of stack check ids and pcs into the code stream. Return // the offset of the start of the table. unsigned EmitStackCheckTable(); // Platform-specific return sequence void EmitReturnSequence(); // Platform-specific code sequences for calls void EmitCallWithStub(Call* expr); void EmitCallWithIC(Call* expr, Handle name, RelocInfo::Mode mode); void EmitKeyedCallWithIC(Call* expr, Expression* key, RelocInfo::Mode mode); // Platform-specific code for inline runtime calls. InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id); void EmitInlineRuntimeCall(CallRuntime* expr); #define EMIT_INLINE_RUNTIME_CALL(name, x, y) \ void Emit##name(ZoneList* arguments); INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) INLINE_RUNTIME_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL) #undef EMIT_INLINE_RUNTIME_CALL // Platform-specific code for loading variables. void EmitLoadGlobalSlotCheckExtensions(Slot* slot, TypeofState typeof_state, Label* slow); MemOperand ContextSlotOperandCheckExtensions(Slot* slot, Label* slow); void EmitDynamicLoadFromSlotFastCase(Slot* slot, TypeofState typeof_state, Label* slow, Label* done); void EmitVariableLoad(Variable* expr); enum ResolveEvalFlag { SKIP_CONTEXT_LOOKUP, PERFORM_CONTEXT_LOOKUP }; // Expects the arguments and the function already pushed. void EmitResolvePossiblyDirectEval(ResolveEvalFlag flag, int arg_count); // Platform-specific support for allocating a new closure based on // the given function info. void EmitNewClosure(Handle info, bool pretenure); // Platform-specific support for compiling assignments. // Load a value from a named property. // The receiver is left on the stack by the IC. void EmitNamedPropertyLoad(Property* expr); // Load a value from a keyed property. // The receiver and the key is left on the stack by the IC. void EmitKeyedPropertyLoad(Property* expr); // Apply the compound assignment operator. Expects the left operand on top // of the stack and the right one in the accumulator. void EmitBinaryOp(Token::Value op, OverwriteMode mode); // Helper functions for generating inlined smi code for certain // binary operations. void EmitInlineSmiBinaryOp(Expression* expr, Token::Value op, OverwriteMode mode, Expression* left, Expression* right); // Assign to the given expression as if via '='. The right-hand-side value // is expected in the accumulator. void EmitAssignment(Expression* expr, int bailout_ast_id); // Complete a variable assignment. The right-hand-side value is expected // in the accumulator. void EmitVariableAssignment(Variable* var, Token::Value op); // Complete a named property assignment. The receiver is expected on top // of the stack and the right-hand-side value in the accumulator. void EmitNamedPropertyAssignment(Assignment* expr); // Complete a keyed property assignment. The receiver and key are // expected on top of the stack and the right-hand-side value in the // accumulator. void EmitKeyedPropertyAssignment(Assignment* expr); void SetFunctionPosition(FunctionLiteral* fun); void SetReturnPosition(FunctionLiteral* fun); void SetStatementPosition(Statement* stmt); void SetExpressionPosition(Expression* expr, int pos); void SetStatementPosition(int pos); void SetSourcePosition(int pos); // Non-local control flow support. void EnterFinallyBlock(); void ExitFinallyBlock(); // Loop nesting counter. int loop_depth() { return loop_depth_; } void increment_loop_depth() { loop_depth_++; } void decrement_loop_depth() { ASSERT(loop_depth_ > 0); loop_depth_--; } MacroAssembler* masm() { return masm_; } class ExpressionContext; const ExpressionContext* context() { return context_; } void set_new_context(const ExpressionContext* context) { context_ = context; } Handle 登录后可以享受更多权益 您还没有登录,登录后您可以: 收藏Android系统代码 收藏喜欢的文章 多个平台共享账号 去登录 首次使用?从这里 注册
您还没有登录,登录后您可以:
首次使用?从这里 注册