| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // formal parameter count expected by the function. | 44 // formal parameter count expected by the function. |
| 45 // | 45 // |
| 46 // The live registers are: | 46 // The live registers are: |
| 47 // o rdi: the JS function object being called (ie, ourselves) | 47 // o rdi: the JS function object being called (ie, ourselves) |
| 48 // o rsi: our context | 48 // o rsi: our context |
| 49 // o rbp: our caller's frame pointer | 49 // o rbp: our caller's frame pointer |
| 50 // o rsp: stack pointer (pointing to return address) | 50 // o rsp: stack pointer (pointing to return address) |
| 51 // | 51 // |
| 52 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 52 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 53 // frames-x64.h for its layout. | 53 // frames-x64.h for its layout. |
| 54 void FullCodeGenerator::Generate(FunctionLiteral* fun) { | 54 void FullCodeGenerator::Generate(FunctionLiteral* fun, Mode mode) { |
| 55 function_ = fun; | 55 function_ = fun; |
| 56 SetFunctionPosition(fun); | 56 SetFunctionPosition(fun); |
| 57 | 57 |
| 58 __ push(rbp); // Caller's frame pointer. | 58 if (mode == PRIMARY) { |
| 59 __ movq(rbp, rsp); | 59 __ push(rbp); // Caller's frame pointer. |
| 60 __ push(rsi); // Callee's context. | 60 __ movq(rbp, rsp); |
| 61 __ push(rdi); // Callee's JS Function. | 61 __ push(rsi); // Callee's context. |
| 62 __ push(rdi); // Callee's JS Function. |
| 62 | 63 |
| 63 { Comment cmnt(masm_, "[ Allocate locals"); | 64 { Comment cmnt(masm_, "[ Allocate locals"); |
| 64 int locals_count = fun->scope()->num_stack_slots(); | 65 int locals_count = fun->scope()->num_stack_slots(); |
| 65 if (locals_count == 1) { | 66 if (locals_count == 1) { |
| 66 __ PushRoot(Heap::kUndefinedValueRootIndex); | 67 __ PushRoot(Heap::kUndefinedValueRootIndex); |
| 67 } else if (locals_count > 1) { | 68 } else if (locals_count > 1) { |
| 68 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 69 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 69 for (int i = 0; i < locals_count; i++) { | 70 for (int i = 0; i < locals_count; i++) { |
| 70 __ push(rdx); | 71 __ push(rdx); |
| 72 } |
| 71 } | 73 } |
| 72 } | 74 } |
| 75 |
| 76 bool function_in_register = true; |
| 77 |
| 78 // Possibly allocate a local context. |
| 79 if (fun->scope()->num_heap_slots() > 0) { |
| 80 Comment cmnt(masm_, "[ Allocate local context"); |
| 81 // Argument to NewContext is the function, which is still in rdi. |
| 82 __ push(rdi); |
| 83 __ CallRuntime(Runtime::kNewContext, 1); |
| 84 function_in_register = false; |
| 85 // Context is returned in both rax and rsi. It replaces the context |
| 86 // passed to us. It's saved in the stack and kept live in rsi. |
| 87 __ movq(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); |
| 88 |
| 89 // Copy any necessary parameters into the context. |
| 90 int num_parameters = fun->scope()->num_parameters(); |
| 91 for (int i = 0; i < num_parameters; i++) { |
| 92 Slot* slot = fun->scope()->parameter(i)->slot(); |
| 93 if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 94 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 95 (num_parameters - 1 - i) * kPointerSize; |
| 96 // Load parameter from stack. |
| 97 __ movq(rax, Operand(rbp, parameter_offset)); |
| 98 // Store it in the context |
| 99 __ movq(Operand(rsi, Context::SlotOffset(slot->index())), rax); |
| 100 } |
| 101 } |
| 102 } |
| 103 |
| 104 // Possibly allocate an arguments object. |
| 105 Variable* arguments = fun->scope()->arguments()->AsVariable(); |
| 106 if (arguments != NULL) { |
| 107 // Arguments object must be allocated after the context object, in |
| 108 // case the "arguments" or ".arguments" variables are in the context. |
| 109 Comment cmnt(masm_, "[ Allocate arguments object"); |
| 110 if (function_in_register) { |
| 111 __ push(rdi); |
| 112 } else { |
| 113 __ push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 114 } |
| 115 // The receiver is just before the parameters on the caller's stack. |
| 116 __ lea(rdx, Operand(rbp, StandardFrameConstants::kCallerSPOffset + |
| 117 fun->num_parameters() * kPointerSize)); |
| 118 __ push(rdx); |
| 119 __ Push(Smi::FromInt(fun->num_parameters())); |
| 120 // Arguments to ArgumentsAccessStub: |
| 121 // function, receiver address, parameter count. |
| 122 // The stub will rewrite receiver and parameter count if the previous |
| 123 // stack frame was an arguments adapter frame. |
| 124 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 125 __ CallStub(&stub); |
| 126 // Store new arguments object in both "arguments" and ".arguments" slots. |
| 127 __ movq(rcx, rax); |
| 128 Move(arguments->slot(), rax, rbx, rdx); |
| 129 Slot* dot_arguments_slot = |
| 130 fun->scope()->arguments_shadow()->AsVariable()->slot(); |
| 131 Move(dot_arguments_slot, rcx, rbx, rdx); |
| 132 } |
| 73 } | 133 } |
| 74 | 134 |
| 75 bool function_in_register = true; | |
| 76 | |
| 77 // Possibly allocate a local context. | |
| 78 if (fun->scope()->num_heap_slots() > 0) { | |
| 79 Comment cmnt(masm_, "[ Allocate local context"); | |
| 80 // Argument to NewContext is the function, which is still in rdi. | |
| 81 __ push(rdi); | |
| 82 __ CallRuntime(Runtime::kNewContext, 1); | |
| 83 function_in_register = false; | |
| 84 // Context is returned in both rax and rsi. It replaces the context | |
| 85 // passed to us. It's saved in the stack and kept live in rsi. | |
| 86 __ movq(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); | |
| 87 | |
| 88 // Copy any necessary parameters into the context. | |
| 89 int num_parameters = fun->scope()->num_parameters(); | |
| 90 for (int i = 0; i < num_parameters; i++) { | |
| 91 Slot* slot = fun->scope()->parameter(i)->slot(); | |
| 92 if (slot != NULL && slot->type() == Slot::CONTEXT) { | |
| 93 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | |
| 94 (num_parameters - 1 - i) * kPointerSize; | |
| 95 // Load parameter from stack. | |
| 96 __ movq(rax, Operand(rbp, parameter_offset)); | |
| 97 // Store it in the context | |
| 98 __ movq(Operand(rsi, Context::SlotOffset(slot->index())), rax); | |
| 99 } | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 // Possibly allocate an arguments object. | |
| 104 Variable* arguments = fun->scope()->arguments()->AsVariable(); | |
| 105 if (arguments != NULL) { | |
| 106 // Arguments object must be allocated after the context object, in | |
| 107 // case the "arguments" or ".arguments" variables are in the context. | |
| 108 Comment cmnt(masm_, "[ Allocate arguments object"); | |
| 109 if (function_in_register) { | |
| 110 __ push(rdi); | |
| 111 } else { | |
| 112 __ push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | |
| 113 } | |
| 114 // The receiver is just before the parameters on the caller's stack. | |
| 115 __ lea(rdx, Operand(rbp, StandardFrameConstants::kCallerSPOffset + | |
| 116 fun->num_parameters() * kPointerSize)); | |
| 117 __ push(rdx); | |
| 118 __ Push(Smi::FromInt(fun->num_parameters())); | |
| 119 // Arguments to ArgumentsAccessStub: | |
| 120 // function, receiver address, parameter count. | |
| 121 // The stub will rewrite receiver and parameter count if the previous | |
| 122 // stack frame was an arguments adapter frame. | |
| 123 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); | |
| 124 __ CallStub(&stub); | |
| 125 // Store new arguments object in both "arguments" and ".arguments" slots. | |
| 126 __ movq(rcx, rax); | |
| 127 Move(arguments->slot(), rax, rbx, rdx); | |
| 128 Slot* dot_arguments_slot = | |
| 129 fun->scope()->arguments_shadow()->AsVariable()->slot(); | |
| 130 Move(dot_arguments_slot, rcx, rbx, rdx); | |
| 131 } | |
| 132 | |
| 133 { Comment cmnt(masm_, "[ Declarations"); | 135 { Comment cmnt(masm_, "[ Declarations"); |
| 134 VisitDeclarations(fun->scope()->declarations()); | 136 VisitDeclarations(fun->scope()->declarations()); |
| 135 } | 137 } |
| 136 | 138 |
| 137 { Comment cmnt(masm_, "[ Stack check"); | 139 { Comment cmnt(masm_, "[ Stack check"); |
| 138 Label ok; | 140 Label ok; |
| 139 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); | 141 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 140 __ j(above_equal, &ok); | 142 __ j(above_equal, &ok); |
| 141 StackCheckStub stub; | 143 StackCheckStub stub; |
| 142 __ CallStub(&stub); | 144 __ CallStub(&stub); |
| (...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 __ movq(Operand(rsp, 0), rdx); | 1887 __ movq(Operand(rsp, 0), rdx); |
| 1886 // And return. | 1888 // And return. |
| 1887 __ ret(0); | 1889 __ ret(0); |
| 1888 } | 1890 } |
| 1889 | 1891 |
| 1890 | 1892 |
| 1891 #undef __ | 1893 #undef __ |
| 1892 | 1894 |
| 1893 | 1895 |
| 1894 } } // namespace v8::internal | 1896 } } // namespace v8::internal |
| OLD | NEW |