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 edi: the JS function object being called (ie, ourselves) | 47 // o edi: the JS function object being called (ie, ourselves) |
48 // o esi: our context | 48 // o esi: our context |
49 // o ebp: our caller's frame pointer | 49 // o ebp: our caller's frame pointer |
50 // o esp: stack pointer (pointing to return address) | 50 // o esp: 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-ia32.h for its layout. | 53 // frames-ia32.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(ebp); // Caller's frame pointer. | 58 if (mode == PRIMARY) { |
59 __ mov(ebp, esp); | 59 __ push(ebp); // Caller's frame pointer. |
60 __ push(esi); // Callee's context. | 60 __ mov(ebp, esp); |
61 __ push(edi); // Callee's JS Function. | 61 __ push(esi); // Callee's context. |
| 62 __ push(edi); // 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 __ push(Immediate(Factory::undefined_value())); | 67 __ push(Immediate(Factory::undefined_value())); |
67 } else if (locals_count > 1) { | 68 } else if (locals_count > 1) { |
68 __ mov(eax, Immediate(Factory::undefined_value())); | 69 __ mov(eax, Immediate(Factory::undefined_value())); |
69 for (int i = 0; i < locals_count; i++) { | 70 for (int i = 0; i < locals_count; i++) { |
70 __ push(eax); | 71 __ push(eax); |
| 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 edi. |
| 82 __ push(edi); |
| 83 __ CallRuntime(Runtime::kNewContext, 1); |
| 84 function_in_register = false; |
| 85 // Context is returned in both eax and esi. It replaces the context |
| 86 // passed to us. It's saved in the stack and kept live in esi. |
| 87 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 88 |
| 89 // Copy parameters into context if necessary. |
| 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 __ mov(eax, Operand(ebp, parameter_offset)); |
| 98 // Store it in the context |
| 99 __ mov(Operand(esi, Context::SlotOffset(slot->index())), eax); |
| 100 } |
| 101 } |
| 102 } |
| 103 |
| 104 Variable* arguments = fun->scope()->arguments()->AsVariable(); |
| 105 if (arguments != NULL) { |
| 106 // Function uses arguments object. |
| 107 Comment cmnt(masm_, "[ Allocate arguments object"); |
| 108 if (function_in_register) { |
| 109 __ push(edi); |
| 110 } else { |
| 111 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 112 } |
| 113 // Receiver is just before the parameters on the caller's stack. |
| 114 __ lea(edx, Operand(ebp, StandardFrameConstants::kCallerSPOffset + |
| 115 fun->num_parameters() * kPointerSize)); |
| 116 __ push(edx); |
| 117 __ push(Immediate(Smi::FromInt(fun->num_parameters()))); |
| 118 // Arguments to ArgumentsAccessStub: |
| 119 // function, receiver address, parameter count. |
| 120 // The stub will rewrite receiver and parameter count if the previous |
| 121 // stack frame was an arguments adapter frame. |
| 122 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 123 __ CallStub(&stub); |
| 124 __ mov(ecx, eax); // Duplicate result. |
| 125 Move(arguments->slot(), eax, ebx, edx); |
| 126 Slot* dot_arguments_slot = |
| 127 fun->scope()->arguments_shadow()->AsVariable()->slot(); |
| 128 Move(dot_arguments_slot, ecx, ebx, edx); |
| 129 } |
73 } | 130 } |
74 | 131 |
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 edi. | |
81 __ push(edi); | |
82 __ CallRuntime(Runtime::kNewContext, 1); | |
83 function_in_register = false; | |
84 // Context is returned in both eax and esi. It replaces the context | |
85 // passed to us. It's saved in the stack and kept live in esi. | |
86 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); | |
87 | |
88 // Copy parameters into context if necessary. | |
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 __ mov(eax, Operand(ebp, parameter_offset)); | |
97 // Store it in the context | |
98 __ mov(Operand(esi, Context::SlotOffset(slot->index())), eax); | |
99 } | |
100 } | |
101 } | |
102 | |
103 Variable* arguments = fun->scope()->arguments()->AsVariable(); | |
104 if (arguments != NULL) { | |
105 // Function uses arguments object. | |
106 Comment cmnt(masm_, "[ Allocate arguments object"); | |
107 if (function_in_register) { | |
108 __ push(edi); | |
109 } else { | |
110 __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | |
111 } | |
112 // Receiver is just before the parameters on the caller's stack. | |
113 __ lea(edx, Operand(ebp, StandardFrameConstants::kCallerSPOffset + | |
114 fun->num_parameters() * kPointerSize)); | |
115 __ push(edx); | |
116 __ push(Immediate(Smi::FromInt(fun->num_parameters()))); | |
117 // Arguments to ArgumentsAccessStub: | |
118 // function, receiver address, parameter count. | |
119 // The stub will rewrite receiver and parameter count if the previous | |
120 // stack frame was an arguments adapter frame. | |
121 ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); | |
122 __ CallStub(&stub); | |
123 __ mov(ecx, eax); // Duplicate result. | |
124 Move(arguments->slot(), eax, ebx, edx); | |
125 Slot* dot_arguments_slot = | |
126 fun->scope()->arguments_shadow()->AsVariable()->slot(); | |
127 Move(dot_arguments_slot, ecx, ebx, edx); | |
128 } | |
129 | |
130 { Comment cmnt(masm_, "[ Declarations"); | 132 { Comment cmnt(masm_, "[ Declarations"); |
131 VisitDeclarations(fun->scope()->declarations()); | 133 VisitDeclarations(fun->scope()->declarations()); |
132 } | 134 } |
133 | 135 |
134 { Comment cmnt(masm_, "[ Stack check"); | 136 { Comment cmnt(masm_, "[ Stack check"); |
135 Label ok; | 137 Label ok; |
136 ExternalReference stack_limit = | 138 ExternalReference stack_limit = |
137 ExternalReference::address_of_stack_limit(); | 139 ExternalReference::address_of_stack_limit(); |
138 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 140 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
139 __ j(above_equal, &ok, taken); | 141 __ j(above_equal, &ok, taken); |
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 __ add(Operand(edx), Immediate(masm_->CodeObject())); | 1885 __ add(Operand(edx), Immediate(masm_->CodeObject())); |
1884 __ mov(Operand(esp, 0), edx); | 1886 __ mov(Operand(esp, 0), edx); |
1885 // And return. | 1887 // And return. |
1886 __ ret(0); | 1888 __ ret(0); |
1887 } | 1889 } |
1888 | 1890 |
1889 | 1891 |
1890 #undef __ | 1892 #undef __ |
1891 | 1893 |
1892 } } // namespace v8::internal | 1894 } } // namespace v8::internal |
OLD | NEW |