| OLD | NEW | 
|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 298   // compiler and needs to setup everything or the compiler is used as | 298   // compiler and needs to setup everything or the compiler is used as | 
| 299   // the secondary compiler for split compilation and has to handle | 299   // the secondary compiler for split compilation and has to handle | 
| 300   // bailouts. | 300   // bailouts. | 
| 301   enum Mode { | 301   enum Mode { | 
| 302     PRIMARY, | 302     PRIMARY, | 
| 303     SECONDARY | 303     SECONDARY | 
| 304   }; | 304   }; | 
| 305 | 305 | 
| 306   // Takes a function literal, generates code for it. This function should only | 306   // Takes a function literal, generates code for it. This function should only | 
| 307   // be called by compiler.cc. | 307   // be called by compiler.cc. | 
| 308   static Handle<Code> MakeCode(FunctionLiteral* fun, | 308   static Handle<Code> MakeCode(CompilationInfo* info); | 
| 309                                Handle<Script> script, |  | 
| 310                                bool is_eval, |  | 
| 311                                CompilationInfo* info); |  | 
| 312 | 309 | 
| 313   // Printing of AST, etc. as requested by flags. | 310   // Printing of AST, etc. as requested by flags. | 
| 314   static void MakeCodePrologue(FunctionLiteral* fun); | 311   static void MakeCodePrologue(CompilationInfo* info); | 
| 315 | 312 | 
| 316   // Allocate and install the code. | 313   // Allocate and install the code. | 
| 317   static Handle<Code> MakeCodeEpilogue(FunctionLiteral* fun, | 314   static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, | 
| 318                                        MacroAssembler* masm, |  | 
| 319                                        Code::Flags flags, | 315                                        Code::Flags flags, | 
| 320                                        Handle<Script> script); | 316                                        CompilationInfo* info); | 
| 321 | 317 | 
| 322 #ifdef ENABLE_LOGGING_AND_PROFILING | 318 #ifdef ENABLE_LOGGING_AND_PROFILING | 
| 323   static bool ShouldGenerateLog(Expression* type); | 319   static bool ShouldGenerateLog(Expression* type); | 
| 324 #endif | 320 #endif | 
| 325 | 321 | 
| 326   static void RecordPositions(MacroAssembler* masm, int pos); | 322   static void RecordPositions(MacroAssembler* masm, int pos); | 
| 327 | 323 | 
| 328   // Accessors | 324   // Accessors | 
| 329   MacroAssembler* masm() { return masm_; } | 325   MacroAssembler* masm() { return masm_; } | 
| 330   VirtualFrame* frame() const { return frame_; } | 326   VirtualFrame* frame() const { return frame_; } | 
| 331   Handle<Script> script() { return script_; } | 327   inline Handle<Script> script(); | 
| 332 | 328 | 
| 333   bool has_valid_frame() const { return frame_ != NULL; } | 329   bool has_valid_frame() const { return frame_ != NULL; } | 
| 334 | 330 | 
| 335   // Set the virtual frame to be new_frame, with non-frame register | 331   // Set the virtual frame to be new_frame, with non-frame register | 
| 336   // reference counts given by non_frame_registers.  The non-frame | 332   // reference counts given by non_frame_registers.  The non-frame | 
| 337   // register reference counts of the old frame are returned in | 333   // register reference counts of the old frame are returned in | 
| 338   // non_frame_registers. | 334   // non_frame_registers. | 
| 339   void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); | 335   void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); | 
| 340 | 336 | 
| 341   void DeleteFrame(); | 337   void DeleteFrame(); | 
| 342 | 338 | 
| 343   RegisterAllocator* allocator() const { return allocator_; } | 339   RegisterAllocator* allocator() const { return allocator_; } | 
| 344 | 340 | 
| 345   CodeGenState* state() { return state_; } | 341   CodeGenState* state() { return state_; } | 
| 346   void set_state(CodeGenState* state) { state_ = state; } | 342   void set_state(CodeGenState* state) { state_ = state; } | 
| 347 | 343 | 
| 348   void AddDeferred(DeferredCode* code) { deferred_.Add(code); } | 344   void AddDeferred(DeferredCode* code) { deferred_.Add(code); } | 
| 349 | 345 | 
| 350   bool in_spilled_code() const { return in_spilled_code_; } | 346   bool in_spilled_code() const { return in_spilled_code_; } | 
| 351   void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } | 347   void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } | 
| 352 | 348 | 
| 353  private: | 349  private: | 
| 354   // Construction/Destruction | 350   // Construction/Destruction | 
| 355   CodeGenerator(MacroAssembler* masm, Handle<Script> script, bool is_eval); | 351   CodeGenerator(MacroAssembler* masm); | 
| 356 | 352 | 
| 357   // Accessors | 353   // Accessors | 
| 358   Scope* scope() const { return scope_; } | 354   inline bool is_eval(); | 
|  | 355   Scope* scope(); | 
| 359 | 356 | 
| 360   // Generating deferred code. | 357   // Generating deferred code. | 
| 361   void ProcessDeferred(); | 358   void ProcessDeferred(); | 
| 362 | 359 | 
| 363   bool is_eval() { return is_eval_; } |  | 
| 364 |  | 
| 365   // State | 360   // State | 
| 366   ControlDestination* destination() const { return state_->destination(); } | 361   ControlDestination* destination() const { return state_->destination(); } | 
| 367 | 362 | 
| 368   // Track loop nesting level. | 363   // Track loop nesting level. | 
| 369   int loop_nesting() const { return loop_nesting_; } | 364   int loop_nesting() const { return loop_nesting_; } | 
| 370   void IncrementLoopNesting() { loop_nesting_++; } | 365   void IncrementLoopNesting() { loop_nesting_++; } | 
| 371   void DecrementLoopNesting() { loop_nesting_--; } | 366   void DecrementLoopNesting() { loop_nesting_--; } | 
| 372 | 367 | 
| 373 | 368 | 
| 374   // Node visitors. | 369   // Node visitors. | 
| 375   void VisitStatements(ZoneList<Statement*>* statements); | 370   void VisitStatements(ZoneList<Statement*>* statements); | 
| 376 | 371 | 
| 377 #define DEF_VISIT(type) \ | 372 #define DEF_VISIT(type) \ | 
| 378   void Visit##type(type* node); | 373   void Visit##type(type* node); | 
| 379   AST_NODE_LIST(DEF_VISIT) | 374   AST_NODE_LIST(DEF_VISIT) | 
| 380 #undef DEF_VISIT | 375 #undef DEF_VISIT | 
| 381 | 376 | 
| 382   // Visit a statement and then spill the virtual frame if control flow can | 377   // Visit a statement and then spill the virtual frame if control flow can | 
| 383   // reach the end of the statement (ie, it does not exit via break, | 378   // reach the end of the statement (ie, it does not exit via break, | 
| 384   // continue, return, or throw).  This function is used temporarily while | 379   // continue, return, or throw).  This function is used temporarily while | 
| 385   // the code generator is being transformed. | 380   // the code generator is being transformed. | 
| 386   void VisitAndSpill(Statement* statement); | 381   void VisitAndSpill(Statement* statement); | 
| 387 | 382 | 
| 388   // Visit a list of statements and then spill the virtual frame if control | 383   // Visit a list of statements and then spill the virtual frame if control | 
| 389   // flow can reach the end of the list. | 384   // flow can reach the end of the list. | 
| 390   void VisitStatementsAndSpill(ZoneList<Statement*>* statements); | 385   void VisitStatementsAndSpill(ZoneList<Statement*>* statements); | 
| 391 | 386 | 
| 392   // Main code generation function | 387   // Main code generation function | 
| 393   void Generate(FunctionLiteral* fun, Mode mode, CompilationInfo* info); | 388   void Generate(CompilationInfo* info, Mode mode); | 
| 394 | 389 | 
| 395   // Generate the return sequence code.  Should be called no more than | 390   // Generate the return sequence code.  Should be called no more than | 
| 396   // once per compiled function, immediately after binding the return | 391   // once per compiled function, immediately after binding the return | 
| 397   // target (which can not be done more than once). | 392   // target (which can not be done more than once). | 
| 398   void GenerateReturnSequence(Result* return_value); | 393   void GenerateReturnSequence(Result* return_value); | 
| 399 | 394 | 
| 400   // Returns the arguments allocation mode. | 395   // Returns the arguments allocation mode. | 
| 401   ArgumentsAllocationMode ArgumentsMode() const; | 396   ArgumentsAllocationMode ArgumentsMode(); | 
| 402 | 397 | 
| 403   // Store the arguments object and allocate it if necessary. | 398   // Store the arguments object and allocate it if necessary. | 
| 404   Result StoreArgumentsObject(bool initial); | 399   Result StoreArgumentsObject(bool initial); | 
| 405 | 400 | 
| 406   // The following are used by class Reference. | 401   // The following are used by class Reference. | 
| 407   void LoadReference(Reference* ref); | 402   void LoadReference(Reference* ref); | 
| 408   void UnloadReference(Reference* ref); | 403   void UnloadReference(Reference* ref); | 
| 409 | 404 | 
| 410   static Operand ContextOperand(Register context, int index) { | 405   static Operand ContextOperand(Register context, int index) { | 
| 411     return Operand(context, Context::SlotOffset(index)); | 406     return Operand(context, Context::SlotOffset(index)); | 
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 597   void CodeForStatementPosition(Statement* node); | 592   void CodeForStatementPosition(Statement* node); | 
| 598   void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); | 593   void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); | 
| 599   void CodeForSourcePosition(int pos); | 594   void CodeForSourcePosition(int pos); | 
| 600 | 595 | 
| 601 #ifdef DEBUG | 596 #ifdef DEBUG | 
| 602   // True if the registers are valid for entry to a block.  There should | 597   // True if the registers are valid for entry to a block.  There should | 
| 603   // be no frame-external references to (non-reserved) registers. | 598   // be no frame-external references to (non-reserved) registers. | 
| 604   bool HasValidEntryRegisters(); | 599   bool HasValidEntryRegisters(); | 
| 605 #endif | 600 #endif | 
| 606 | 601 | 
| 607   bool is_eval_;  // Tells whether code is generated for eval. |  | 
| 608   Handle<Script> script_; |  | 
| 609   ZoneList<DeferredCode*> deferred_; | 602   ZoneList<DeferredCode*> deferred_; | 
| 610 | 603 | 
| 611   // Assembler | 604   // Assembler | 
| 612   MacroAssembler* masm_;  // to generate code | 605   MacroAssembler* masm_;  // to generate code | 
| 613 | 606 | 
|  | 607   CompilationInfo* info_; | 
|  | 608 | 
| 614   // Code generation state | 609   // Code generation state | 
| 615   Scope* scope_; |  | 
| 616   VirtualFrame* frame_; | 610   VirtualFrame* frame_; | 
| 617   RegisterAllocator* allocator_; | 611   RegisterAllocator* allocator_; | 
| 618   CodeGenState* state_; | 612   CodeGenState* state_; | 
| 619   int loop_nesting_; | 613   int loop_nesting_; | 
| 620 | 614 | 
| 621   // Jump targets. | 615   // Jump targets. | 
| 622   // The target of the return from the function. | 616   // The target of the return from the function. | 
| 623   BreakTarget function_return_; | 617   BreakTarget function_return_; | 
| 624 | 618 | 
| 625   // True if the function return is shadowed (ie, jumping to the target | 619   // True if the function return is shadowed (ie, jumping to the target | 
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 823   Major MajorKey() { return StringCompare; } | 817   Major MajorKey() { return StringCompare; } | 
| 824   int MinorKey() { return 0; } | 818   int MinorKey() { return 0; } | 
| 825 | 819 | 
| 826   void Generate(MacroAssembler* masm); | 820   void Generate(MacroAssembler* masm); | 
| 827 }; | 821 }; | 
| 828 | 822 | 
| 829 | 823 | 
| 830 } }  // namespace v8::internal | 824 } }  // namespace v8::internal | 
| 831 | 825 | 
| 832 #endif  // V8_X64_CODEGEN_X64_H_ | 826 #endif  // V8_X64_CODEGEN_X64_H_ | 
| OLD | NEW | 
|---|