OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "lib/error.h" | 10 #include "lib/error.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 | 117 |
118 void FlowGraphCompiler::CopyParameters() { | 118 void FlowGraphCompiler::CopyParameters() { |
119 const Function& function = parsed_function().function(); | 119 const Function& function = parsed_function().function(); |
120 const bool is_native_instance_closure = | 120 const bool is_native_instance_closure = |
121 function.is_native() && function.IsImplicitInstanceClosureFunction(); | 121 function.is_native() && function.IsImplicitInstanceClosureFunction(); |
122 LocalScope* scope = parsed_function().node_sequence()->scope(); | 122 LocalScope* scope = parsed_function().node_sequence()->scope(); |
123 const int num_fixed_params = function.num_fixed_parameters(); | 123 const int num_fixed_params = function.num_fixed_parameters(); |
124 const int num_opt_params = function.num_optional_parameters(); | 124 const int num_opt_params = function.num_optional_parameters(); |
| 125 int implicit_this_param_pos = is_native_instance_closure ? -1 : 0; |
125 ASSERT(parsed_function().first_parameter_index() == | 126 ASSERT(parsed_function().first_parameter_index() == |
126 ParsedFunction::kFirstLocalSlotIndex); | 127 ParsedFunction::kFirstLocalSlotIndex + implicit_this_param_pos); |
127 // Copy positional arguments. | 128 // Copy positional arguments. |
128 // Check that no fewer than num_fixed_params positional arguments are passed | 129 // Check that no fewer than num_fixed_params positional arguments are passed |
129 // in and that no more than num_params arguments are passed in. | 130 // in and that no more than num_params arguments are passed in. |
130 // Passed argument i at fp[1 + argc - i] | 131 // Passed argument i at fp[1 + argc - i] |
131 // copied to fp[ParsedFunction::kFirstLocalSlotIndex - i]. | 132 // copied to fp[ParsedFunction::kFirstLocalSlotIndex - i]. |
132 const int num_params = num_fixed_params + num_opt_params; | 133 const int num_params = num_fixed_params + num_opt_params; |
133 | 134 |
134 // Total number of args is the first Smi in args descriptor array (EDX). | 135 // Total number of args is the first Smi in args descriptor array (EDX). |
135 __ movl(EBX, FieldAddress(EDX, Array::data_offset())); | 136 __ movl(EBX, FieldAddress(EDX, Array::data_offset())); |
136 // Check that num_args <= num_params. | 137 // Check that num_args <= num_params. |
137 Label wrong_num_arguments; | 138 Label wrong_num_arguments; |
138 __ cmpl(EBX, Immediate(Smi::RawValue(num_params))); | 139 __ cmpl(EBX, Immediate(Smi::RawValue(num_params))); |
139 __ j(GREATER, &wrong_num_arguments); | 140 __ j(GREATER, &wrong_num_arguments); |
140 // Number of positional args is the second Smi in descriptor array (EDX). | 141 // Number of positional args is the second Smi in descriptor array (EDX). |
141 __ movl(ECX, FieldAddress(EDX, Array::data_offset() + (1 * kWordSize))); | 142 __ movl(ECX, FieldAddress(EDX, Array::data_offset() + (1 * kWordSize))); |
142 // Check that num_pos_args >= num_fixed_params. | 143 // Check that num_pos_args >= num_fixed_params. |
143 __ cmpl(ECX, Immediate(Smi::RawValue(num_fixed_params))); | 144 __ cmpl(ECX, Immediate(Smi::RawValue(num_fixed_params))); |
144 __ j(LESS, &wrong_num_arguments); | 145 __ j(LESS, &wrong_num_arguments); |
145 // Since EBX and ECX are Smi, use TIMES_2 instead of TIMES_4. | 146 // Since EBX and ECX are Smi, use TIMES_2 instead of TIMES_4. |
146 // Let EBX point to the last passed positional argument, i.e. to | 147 // Let EBX point to the last passed positional argument, i.e. to |
147 // fp[1 + num_args - (num_pos_args - 1)]. | 148 // fp[1 + num_args - (num_pos_args - 1)]. |
148 __ subl(EBX, ECX); | 149 __ subl(EBX, ECX); |
149 __ leal(EBX, Address(EBP, EBX, TIMES_2, 2 * kWordSize)); | 150 __ leal(EBX, Address(EBP, EBX, TIMES_2, 2 * kWordSize)); |
150 | 151 |
151 // Let EDI point to the last copied positional argument, i.e. to | 152 // Let EDI point to the last copied positional argument, i.e. to |
152 // fp[ParsedFunction::kFirstLocalSlotIndex - (num_pos_args - 1)]. | 153 // fp[ParsedFunction::kFirstLocalSlotIndex - (num_pos_args - 1)]. |
153 int implicit_this_param_pos = is_native_instance_closure ? -1 : 0; | |
154 const int index = | 154 const int index = |
155 ParsedFunction::kFirstLocalSlotIndex + 1 + implicit_this_param_pos; | 155 ParsedFunction::kFirstLocalSlotIndex + 1 + implicit_this_param_pos; |
156 // First copy captured receiver if function is an implicit native closure. | 156 // First copy captured receiver if function is an implicit native closure. |
157 if (is_native_instance_closure) { | 157 if (is_native_instance_closure) { |
158 __ movl(EAX, FieldAddress(CTX, Context::variable_offset(0))); | 158 __ movl(EAX, FieldAddress(CTX, Context::variable_offset(0))); |
159 __ movl(Address(EBP, (index * kWordSize)), EAX); | 159 __ movl(Address(EBP, (index * kWordSize)), EAX); |
160 } | 160 } |
161 __ leal(EDI, Address(EBP, (index * kWordSize))); | 161 __ leal(EDI, Address(EBP, (index * kWordSize))); |
162 __ subl(EDI, ECX); // ECX is a Smi, subtract twice for TIMES_4 scaling. | 162 __ subl(EDI, ECX); // ECX is a Smi, subtract twice for TIMES_4 scaling. |
163 __ subl(EDI, ECX); | 163 __ subl(EDI, ECX); |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 __ cvtsi2sd(result, temp); | 1046 __ cvtsi2sd(result, temp); |
1047 __ Bind(&done); | 1047 __ Bind(&done); |
1048 } | 1048 } |
1049 | 1049 |
1050 | 1050 |
1051 #undef __ | 1051 #undef __ |
1052 | 1052 |
1053 } // namespace dart | 1053 } // namespace dart |
1054 | 1054 |
1055 #endif // defined TARGET_ARCH_IA32 | 1055 #endif // defined TARGET_ARCH_IA32 |
OLD | NEW |