OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_ARM. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // Clobbers R2. | 266 // Clobbers R2. |
267 RawSubtypeTestCache* | 267 RawSubtypeTestCache* |
268 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( | 268 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( |
269 intptr_t token_pos, | 269 intptr_t token_pos, |
270 const AbstractType& type, | 270 const AbstractType& type, |
271 Label* is_instance_lbl, | 271 Label* is_instance_lbl, |
272 Label* is_not_instance_lbl) { | 272 Label* is_not_instance_lbl) { |
273 __ Comment("InstantiatedTypeWithArgumentsTest"); | 273 __ Comment("InstantiatedTypeWithArgumentsTest"); |
274 ASSERT(type.IsInstantiated()); | 274 ASSERT(type.IsInstantiated()); |
275 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); | 275 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); |
276 ASSERT((type_class.NumTypeArguments() > 0) || type_class.IsSignatureClass()); | 276 ASSERT(type.IsFunctionType() || (type_class.NumTypeArguments() > 0)); |
277 const Register kInstanceReg = R0; | 277 const Register kInstanceReg = R0; |
278 Error& bound_error = Error::Handle(zone()); | 278 Error& bound_error = Error::Handle(zone()); |
279 const Type& int_type = Type::Handle(zone(), Type::IntType()); | 279 const Type& int_type = Type::Handle(zone(), Type::IntType()); |
280 const bool smi_is_ok = int_type.IsSubtypeOf(type, &bound_error, Heap::kOld); | 280 const bool smi_is_ok = int_type.IsSubtypeOf(type, &bound_error, Heap::kOld); |
281 // Malformed type should have been handled at graph construction time. | 281 // Malformed type should have been handled at graph construction time. |
282 ASSERT(smi_is_ok || bound_error.IsNull()); | 282 ASSERT(smi_is_ok || bound_error.IsNull()); |
283 __ tst(kInstanceReg, Operand(kSmiTagMask)); | 283 __ tst(kInstanceReg, Operand(kSmiTagMask)); |
284 if (smi_is_ok) { | 284 if (smi_is_ok) { |
285 __ b(is_instance_lbl, EQ); | 285 __ b(is_instance_lbl, EQ); |
286 } else { | 286 } else { |
287 __ b(is_not_instance_lbl, EQ); | 287 __ b(is_not_instance_lbl, EQ); |
288 } | 288 } |
289 const intptr_t num_type_args = type_class.NumTypeArguments(); | 289 // A function type test requires checking the function signature. |
290 const intptr_t num_type_params = type_class.NumTypeParameters(); | 290 if (!type.IsFunctionType()) { |
291 const intptr_t from_index = num_type_args - num_type_params; | 291 const intptr_t num_type_args = type_class.NumTypeArguments(); |
292 const TypeArguments& type_arguments = | 292 const intptr_t num_type_params = type_class.NumTypeParameters(); |
293 TypeArguments::ZoneHandle(zone(), type.arguments()); | 293 const intptr_t from_index = num_type_args - num_type_params; |
294 const bool is_raw_type = type_arguments.IsNull() || | 294 const TypeArguments& type_arguments = |
295 type_arguments.IsRaw(from_index, num_type_params); | 295 TypeArguments::ZoneHandle(zone(), type.arguments()); |
296 // Signature class is an instantiated parameterized type. | 296 const bool is_raw_type = type_arguments.IsNull() || |
297 if (!type_class.IsSignatureClass()) { | 297 type_arguments.IsRaw(from_index, num_type_params); |
298 if (is_raw_type) { | 298 if (is_raw_type) { |
299 const Register kClassIdReg = R2; | 299 const Register kClassIdReg = R2; |
300 // dynamic type argument, check only classes. | 300 // dynamic type argument, check only classes. |
301 __ LoadClassId(kClassIdReg, kInstanceReg); | 301 __ LoadClassId(kClassIdReg, kInstanceReg); |
302 __ CompareImmediate(kClassIdReg, type_class.id()); | 302 __ CompareImmediate(kClassIdReg, type_class.id()); |
303 __ b(is_instance_lbl, EQ); | 303 __ b(is_instance_lbl, EQ); |
304 // List is a very common case. | 304 // List is a very common case. |
305 if (IsListClass(type_class)) { | 305 if (IsListClass(type_class)) { |
306 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); | 306 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); |
307 } | 307 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // R0: instance being type checked (preserved). | 355 // R0: instance being type checked (preserved). |
356 // Clobbers R2, R3. | 356 // Clobbers R2, R3. |
357 // Returns true if there is a fallthrough. | 357 // Returns true if there is a fallthrough. |
358 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( | 358 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( |
359 intptr_t token_pos, | 359 intptr_t token_pos, |
360 const AbstractType& type, | 360 const AbstractType& type, |
361 Label* is_instance_lbl, | 361 Label* is_instance_lbl, |
362 Label* is_not_instance_lbl) { | 362 Label* is_not_instance_lbl) { |
363 __ Comment("InstantiatedTypeNoArgumentsTest"); | 363 __ Comment("InstantiatedTypeNoArgumentsTest"); |
364 ASSERT(type.IsInstantiated()); | 364 ASSERT(type.IsInstantiated()); |
| 365 if (type.IsFunctionType()) { |
| 366 // Fallthrough. |
| 367 return true; |
| 368 } |
365 const Class& type_class = Class::Handle(zone(), type.type_class()); | 369 const Class& type_class = Class::Handle(zone(), type.type_class()); |
366 ASSERT(type_class.NumTypeArguments() == 0); | 370 ASSERT(type_class.NumTypeArguments() == 0); |
367 | 371 |
368 const Register kInstanceReg = R0; | 372 const Register kInstanceReg = R0; |
369 __ tst(kInstanceReg, Operand(kSmiTagMask)); | 373 __ tst(kInstanceReg, Operand(kSmiTagMask)); |
370 // If instance is Smi, check directly. | 374 // If instance is Smi, check directly. |
371 const Class& smi_class = Class::Handle(zone(), Smi::Class()); | 375 const Class& smi_class = Class::Handle(zone(), Smi::Class()); |
372 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), | 376 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), |
373 type_class, | 377 type_class, |
374 TypeArguments::Handle(zone()), | 378 TypeArguments::Handle(zone()), |
(...skipping 10 matching lines...) Expand all Loading... |
385 __ b(is_instance_lbl, EQ); | 389 __ b(is_instance_lbl, EQ); |
386 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted | 390 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted |
387 // interfaces. | 391 // interfaces. |
388 // Bool interface can be implemented only by core class Bool. | 392 // Bool interface can be implemented only by core class Bool. |
389 if (type.IsBoolType()) { | 393 if (type.IsBoolType()) { |
390 __ CompareImmediate(kClassIdReg, kBoolCid); | 394 __ CompareImmediate(kClassIdReg, kBoolCid); |
391 __ b(is_instance_lbl, EQ); | 395 __ b(is_instance_lbl, EQ); |
392 __ b(is_not_instance_lbl); | 396 __ b(is_not_instance_lbl); |
393 return false; | 397 return false; |
394 } | 398 } |
395 if (type.IsFunctionType()) { | 399 if (type.IsDartFunctionType()) { |
396 // Check if instance is a closure. | 400 // Check if instance is a closure. |
397 __ LoadClassById(R3, kClassIdReg); | 401 __ CompareImmediate(kClassIdReg, kClosureCid); |
398 __ ldr(R3, FieldAddress(R3, Class::signature_function_offset())); | 402 __ b(is_instance_lbl, EQ); |
399 __ CompareObject(R3, Object::null_object()); | |
400 __ b(is_instance_lbl, NE); | |
401 } | 403 } |
402 // Custom checking for numbers (Smi, Mint, Bigint and Double). | 404 // Custom checking for numbers (Smi, Mint, Bigint and Double). |
403 // Note that instance is not Smi (checked above). | 405 // Note that instance is not Smi (checked above). |
404 if (type.IsSubtypeOf( | 406 if (type.IsSubtypeOf( |
405 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { | 407 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { |
406 GenerateNumberTypeCheck( | 408 GenerateNumberTypeCheck( |
407 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); | 409 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); |
408 return false; | 410 return false; |
409 } | 411 } |
410 if (type.IsStringType()) { | 412 if (type.IsStringType()) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 Label* is_instance_lbl, | 542 Label* is_instance_lbl, |
541 Label* is_not_instance_lbl) { | 543 Label* is_not_instance_lbl) { |
542 __ Comment("InlineInstanceof"); | 544 __ Comment("InlineInstanceof"); |
543 if (type.IsVoidType()) { | 545 if (type.IsVoidType()) { |
544 // A non-null value is returned from a void function, which will result in a | 546 // A non-null value is returned from a void function, which will result in a |
545 // type error. A null value is handled prior to executing this inline code. | 547 // type error. A null value is handled prior to executing this inline code. |
546 return SubtypeTestCache::null(); | 548 return SubtypeTestCache::null(); |
547 } | 549 } |
548 if (type.IsInstantiated()) { | 550 if (type.IsInstantiated()) { |
549 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); | 551 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); |
550 // A class equality check is only applicable with a dst type of a | 552 // A class equality check is only applicable with a dst type (not a |
551 // non-parameterized class, non-signature class, or with a raw dst type of | 553 // function type) of a non-parameterized class or with a raw dst type of |
552 // a parameterized class. | 554 // a parameterized class. |
553 if (type_class.IsSignatureClass() || (type_class.NumTypeArguments() > 0)) { | 555 if (type.IsFunctionType() || (type_class.NumTypeArguments() > 0)) { |
554 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, | 556 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, |
555 type, | 557 type, |
556 is_instance_lbl, | 558 is_instance_lbl, |
557 is_not_instance_lbl); | 559 is_not_instance_lbl); |
558 // Fall through to runtime call. | 560 // Fall through to runtime call. |
559 } | 561 } |
560 const bool has_fall_through = | 562 const bool has_fall_through = |
561 GenerateInstantiatedTypeNoArgumentsTest(token_pos, | 563 GenerateInstantiatedTypeNoArgumentsTest(token_pos, |
562 type, | 564 type, |
563 is_instance_lbl, | 565 is_instance_lbl, |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 DRegister dreg = EvenDRegisterOf(reg); | 1934 DRegister dreg = EvenDRegisterOf(reg); |
1933 __ vldrd(dreg, Address(SP, kDoubleSize, Address::PostIndex)); | 1935 __ vldrd(dreg, Address(SP, kDoubleSize, Address::PostIndex)); |
1934 } | 1936 } |
1935 | 1937 |
1936 | 1938 |
1937 #undef __ | 1939 #undef __ |
1938 | 1940 |
1939 } // namespace dart | 1941 } // namespace dart |
1940 | 1942 |
1941 #endif // defined TARGET_ARCH_ARM | 1943 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |