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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // formal parameter count expected by the function. | 47 // formal parameter count expected by the function. |
48 // | 48 // |
49 // The live registers are: | 49 // The live registers are: |
50 // o edi: the JS function object being called (ie, ourselves) | 50 // o edi: the JS function object being called (ie, ourselves) |
51 // o esi: our context | 51 // o esi: our context |
52 // o ebp: our caller's frame pointer | 52 // o ebp: our caller's frame pointer |
53 // o esp: stack pointer (pointing to return address) | 53 // o esp: stack pointer (pointing to return address) |
54 // | 54 // |
55 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 55 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
56 // frames-ia32.h for its layout. | 56 // frames-ia32.h for its layout. |
57 void FullCodeGenerator::Generate(CompilationInfo* info, Mode mode) { | 57 void FullCodeGenerator::Generate(CompilationInfo* info) { |
58 ASSERT(info_ == NULL); | 58 ASSERT(info_ == NULL); |
59 info_ = info; | 59 info_ = info; |
60 SetFunctionPosition(function()); | 60 SetFunctionPosition(function()); |
61 Comment cmnt(masm_, "[ function compiled by full code generator"); | 61 Comment cmnt(masm_, "[ function compiled by full code generator"); |
62 | 62 |
63 if (mode == PRIMARY) { | 63 __ push(ebp); // Caller's frame pointer. |
64 __ push(ebp); // Caller's frame pointer. | 64 __ mov(ebp, esp); |
65 __ mov(ebp, esp); | 65 __ push(esi); // Callee's context. |
66 __ push(esi); // Callee's context. | 66 __ push(edi); // Callee's JS Function. |
67 __ push(edi); // Callee's JS Function. | |
68 | 67 |
69 { Comment cmnt(masm_, "[ Allocate locals"); | 68 { Comment cmnt(masm_, "[ Allocate locals"); |
70 int locals_count = scope()->num_stack_slots(); | 69 int locals_count = scope()->num_stack_slots(); |
71 if (locals_count == 1) { | 70 if (locals_count == 1) { |
72 __ push(Immediate(Factory::undefined_value())); | 71 __ push(Immediate(Factory::undefined_value())); |
73 } else if (locals_count > 1) { | 72 } else if (locals_count > 1) { |
74 __ mov(eax, Immediate(Factory::undefined_value())); | 73 __ mov(eax, Immediate(Factory::undefined_value())); |
75 for (int i = 0; i < locals_count; i++) { | 74 for (int i = 0; i < locals_count; i++) { |
76 __ push(eax); | 75 __ push(eax); |
77 } | |
78 } | 76 } |
79 } | 77 } |
80 | |
81 bool function_in_register = true; | |
82 | |
83 // Possibly allocate a local context. | |
84 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | |
85 if (heap_slots > 0) { | |
86 Comment cmnt(masm_, "[ Allocate local context"); | |
87 // Argument to NewContext is the function, which is still in edi. | |
88 __ push(edi); | |
89 if (heap_slots <= FastNewContextStub::kMaximumSlots) { | |
90 FastNewContextStub stub(heap_slots); | |
91 __ CallStub(&stub); | |
92 } else { | |
93 __ CallRuntime(Runtime::kNewContext, 1); | |
94 } | |
95 function_in_register = false; | |
96 // Context is returned in both eax and esi. It replaces the context | |
97 // passed to us. It's saved in the stack and kept live in esi. | |
98 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); | |
99 | |
100 // Copy parameters into context if necessary. | |
101 int num_parameters = scope()->num_parameters(); | |
102 for (int i = 0; i < num_parameters; i++) { | |
103 Slot* slot = scope()->parameter(i)->slot(); | |
104 if (slot != NULL && slot->type() == Slot::CONTEXT) { | |
105 int parameter_offset = StandardFrameConstants::kCallerSPOffset + | |
106 (num_parameters - 1 - i) * kPointerSize; | |
107 // Load parameter from stack. | |
108 __ mov(eax, Operand(ebp, parameter_offset)); | |
109 // Store it in the context. | |
110 int context_offset = Context::SlotOffset(slot->index()); | |
111 __ mov(Operand(esi, context_offset), eax); | |
112 // Update the write barrier. This clobbers all involved | |
113 // registers, so we have use a third register to avoid | |
114 // clobbering esi. | |
115 __ mov(ecx, esi); | |
116 __ RecordWrite(ecx, context_offset, eax, ebx); | |
117 } | |
118 } | |
119 } | |
120 | |
121 Variable* arguments = scope()->arguments()->AsVariable(); | |
122 if (arguments != NULL) { | |
123 // Function uses arguments object. | |
124 Comment cmnt(masm_, "[ Allocate arguments object"); | |
125 if (function_in_register) { | |
126 __ push(edi); | |
127 } else { | |
128 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
129 } | |
130 // Receiver is just before the parameters on the caller's stack. | |
131 int offset = scope()->num_parameters() * kPointerSize; | |
132 __ lea(edx, | |
133 Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); | |
134 __ push(edx); | |
135 __ push(Immediate(Smi::FromInt(scope()->num_parameters()))); | |
136 // Arguments to ArgumentsAccessStub: | |
137 // function, receiver address, parameter count. | |
138 // The stub will rewrite receiver and parameter count if the previous | |
139 // stack frame was an arguments adapter frame. | |
140 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); | |
141 __ CallStub(&stub); | |
142 __ mov(ecx, eax); // Duplicate result. | |
143 Move(arguments->slot(), eax, ebx, edx); | |
144 Slot* dot_arguments_slot = | |
145 scope()->arguments_shadow()->AsVariable()->slot(); | |
146 Move(dot_arguments_slot, ecx, ebx, edx); | |
147 } | |
148 } | 78 } |
149 | 79 |
| 80 bool function_in_register = true; |
| 81 |
| 82 // Possibly allocate a local context. |
| 83 int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 84 if (heap_slots > 0) { |
| 85 Comment cmnt(masm_, "[ Allocate local context"); |
| 86 // Argument to NewContext is the function, which is still in edi. |
| 87 __ push(edi); |
| 88 if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 89 FastNewContextStub stub(heap_slots); |
| 90 __ CallStub(&stub); |
| 91 } else { |
| 92 __ CallRuntime(Runtime::kNewContext, 1); |
| 93 } |
| 94 function_in_register = false; |
| 95 // Context is returned in both eax and esi. It replaces the context |
| 96 // passed to us. It's saved in the stack and kept live in esi. |
| 97 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 98 |
| 99 // Copy parameters into context if necessary. |
| 100 int num_parameters = scope()->num_parameters(); |
| 101 for (int i = 0; i < num_parameters; i++) { |
| 102 Slot* slot = scope()->parameter(i)->slot(); |
| 103 if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 104 int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 105 (num_parameters - 1 - i) * kPointerSize; |
| 106 // Load parameter from stack. |
| 107 __ mov(eax, Operand(ebp, parameter_offset)); |
| 108 // Store it in the context. |
| 109 int context_offset = Context::SlotOffset(slot->index()); |
| 110 __ mov(Operand(esi, context_offset), eax); |
| 111 // Update the write barrier. This clobbers all involved |
| 112 // registers, so we have use a third register to avoid |
| 113 // clobbering esi. |
| 114 __ mov(ecx, esi); |
| 115 __ RecordWrite(ecx, context_offset, eax, ebx); |
| 116 } |
| 117 } |
| 118 } |
| 119 |
| 120 Variable* arguments = scope()->arguments()->AsVariable(); |
| 121 if (arguments != NULL) { |
| 122 // Function uses arguments object. |
| 123 Comment cmnt(masm_, "[ Allocate arguments object"); |
| 124 if (function_in_register) { |
| 125 __ push(edi); |
| 126 } else { |
| 127 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 128 } |
| 129 // Receiver is just before the parameters on the caller's stack. |
| 130 int offset = scope()->num_parameters() * kPointerSize; |
| 131 __ lea(edx, |
| 132 Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 133 __ push(edx); |
| 134 __ push(Immediate(Smi::FromInt(scope()->num_parameters()))); |
| 135 // Arguments to ArgumentsAccessStub: |
| 136 // function, receiver address, parameter count. |
| 137 // The stub will rewrite receiver and parameter count if the previous |
| 138 // stack frame was an arguments adapter frame. |
| 139 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 140 __ CallStub(&stub); |
| 141 __ mov(ecx, eax); // Duplicate result. |
| 142 Move(arguments->slot(), eax, ebx, edx); |
| 143 Slot* dot_arguments_slot = |
| 144 scope()->arguments_shadow()->AsVariable()->slot(); |
| 145 Move(dot_arguments_slot, ecx, ebx, edx); |
| 146 } |
| 147 |
150 { Comment cmnt(masm_, "[ Declarations"); | 148 { Comment cmnt(masm_, "[ Declarations"); |
151 // For named function expressions, declare the function name as a | 149 // For named function expressions, declare the function name as a |
152 // constant. | 150 // constant. |
153 if (scope()->is_function_scope() && scope()->function() != NULL) { | 151 if (scope()->is_function_scope() && scope()->function() != NULL) { |
154 EmitDeclaration(scope()->function(), Variable::CONST, NULL); | 152 EmitDeclaration(scope()->function(), Variable::CONST, NULL); |
155 } | 153 } |
156 // Visit all the explicit declarations unless there is an illegal | 154 // Visit all the explicit declarations unless there is an illegal |
157 // redeclaration. | 155 // redeclaration. |
158 if (scope()->HasIllegalRedeclaration()) { | 156 if (scope()->HasIllegalRedeclaration()) { |
159 scope()->VisitIllegalRedeclaration(this); | 157 scope()->VisitIllegalRedeclaration(this); |
(...skipping 3195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3355 // And return. | 3353 // And return. |
3356 __ ret(0); | 3354 __ ret(0); |
3357 } | 3355 } |
3358 | 3356 |
3359 | 3357 |
3360 #undef __ | 3358 #undef __ |
3361 | 3359 |
3362 } } // namespace v8::internal | 3360 } } // namespace v8::internal |
3363 | 3361 |
3364 #endif // V8_TARGET_ARCH_IA32 | 3362 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |