| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
| 7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 7 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 8 | 8 |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/assembler.h" | 10 #include "vm/assembler.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { | 56 CODEGEN_TEST_GENERATE(ReturnParameterCodegen, test) { |
| 57 SequenceNode* node_seq = test->node_sequence(); | 57 SequenceNode* node_seq = test->node_sequence(); |
| 58 const int num_params = 1; | 58 const int num_params = 1; |
| 59 LocalVariable* parameter = NewTestLocalVariable("parameter"); | 59 LocalVariable* parameter = NewTestLocalVariable("parameter"); |
| 60 LocalScope* local_scope = node_seq->scope(); | 60 LocalScope* local_scope = node_seq->scope(); |
| 61 local_scope->AddVariable(parameter); | 61 local_scope->AddVariable(parameter); |
| 62 ASSERT(local_scope->num_variables() == num_params); | 62 ASSERT(local_scope->num_variables() == num_params); |
| 63 const Function& function = test->function(); | 63 const Function& function = test->function(); |
| 64 function.set_num_fixed_parameters(num_params); | 64 function.set_num_fixed_parameters(num_params); |
| 65 ASSERT(function.num_optional_parameters() == 0); | 65 ASSERT(function.num_optional_parameters() == 0); |
| 66 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, *parameter))); | 66 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, parameter))); |
| 67 } | 67 } |
| 68 | 68 |
| 69 | 69 |
| 70 CODEGEN_TEST2_GENERATE(StaticCallReturnParameterCodegen, function, test) { | 70 CODEGEN_TEST2_GENERATE(StaticCallReturnParameterCodegen, function, test) { |
| 71 // Wrap and call the ReturnParameterCodegen test above as a static function. | 71 // Wrap and call the ReturnParameterCodegen test above as a static function. |
| 72 SequenceNode* node_seq = test->node_sequence(); | 72 SequenceNode* node_seq = test->node_sequence(); |
| 73 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 73 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 74 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); | 74 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); |
| 75 node_seq->Add(new ReturnNode(kPos, | 75 node_seq->Add(new ReturnNode(kPos, |
| 76 new StaticCallNode(kPos, function, arguments))); | 76 new StaticCallNode(kPos, function, arguments))); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 LocalScope* local_scope = node_seq->scope(); | 90 LocalScope* local_scope = node_seq->scope(); |
| 91 local_scope->AddVariable(param1); | 91 local_scope->AddVariable(param1); |
| 92 local_scope->AddVariable(param2); | 92 local_scope->AddVariable(param2); |
| 93 local_scope->AddVariable(sum); | 93 local_scope->AddVariable(sum); |
| 94 ASSERT(local_scope->num_variables() == num_params + num_locals); | 94 ASSERT(local_scope->num_variables() == num_params + num_locals); |
| 95 const Function& function = test->function(); | 95 const Function& function = test->function(); |
| 96 function.set_num_fixed_parameters(num_params); | 96 function.set_num_fixed_parameters(num_params); |
| 97 ASSERT(function.num_optional_parameters() == 0); | 97 ASSERT(function.num_optional_parameters() == 0); |
| 98 BinaryOpNode* add = new BinaryOpNode(kPos, | 98 BinaryOpNode* add = new BinaryOpNode(kPos, |
| 99 Token::kADD, | 99 Token::kADD, |
| 100 new LoadLocalNode(kPos, *param1), | 100 new LoadLocalNode(kPos, param1), |
| 101 new LoadLocalNode(kPos, *param2)); | 101 new LoadLocalNode(kPos, param2)); |
| 102 node_seq->Add(new StoreLocalNode(kPos, *sum, add)); | 102 node_seq->Add(new StoreLocalNode(kPos, sum, add)); |
| 103 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, *sum))); | 103 node_seq->Add(new ReturnNode(kPos, new LoadLocalNode(kPos, sum))); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 CODEGEN_TEST2_GENERATE(StaticCallSmiParamSumCodegen, function, test) { | 107 CODEGEN_TEST2_GENERATE(StaticCallSmiParamSumCodegen, function, test) { |
| 108 // Wrap and call the SmiParamSumCodegen test above as a static function. | 108 // Wrap and call the SmiParamSumCodegen test above as a static function. |
| 109 SequenceNode* node_seq = test->node_sequence(); | 109 SequenceNode* node_seq = test->node_sequence(); |
| 110 ArgumentListNode* arguments = new ArgumentListNode(kPos); | 110 ArgumentListNode* arguments = new ArgumentListNode(kPos); |
| 111 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); | 111 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3)))); |
| 112 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2)))); | 112 arguments->Add(new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2)))); |
| 113 node_seq->Add(new ReturnNode(kPos, | 113 node_seq->Add(new ReturnNode(kPos, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 345 |
| 346 String& constructor_name = String::Handle(String::New("A.")); | 346 String& constructor_name = String::Handle(String::New("A.")); |
| 347 Function& constructor = | 347 Function& constructor = |
| 348 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); | 348 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); |
| 349 EXPECT(!constructor.IsNull()); | 349 EXPECT(!constructor.IsNull()); |
| 350 | 350 |
| 351 // The unit test creates an instance of class A and calls function 'bar'. | 351 // The unit test creates an instance of class A and calls function 'bar'. |
| 352 String& function_bar_name = String::ZoneHandle(Symbols::New("bar")); | 352 String& function_bar_name = String::ZoneHandle(Symbols::New("bar")); |
| 353 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 353 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
| 354 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); | 354 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); |
| 355 const LocalVariable& allocated = *test->CreateTempConstVariable("alloc"); | 355 const LocalVariable* allocated = test->CreateTempConstVariable("alloc"); |
| 356 InstanceCallNode* call_bar = new InstanceCallNode( | 356 InstanceCallNode* call_bar = new InstanceCallNode( |
| 357 kPos, | 357 kPos, |
| 358 new ConstructorCallNode( | 358 new ConstructorCallNode( |
| 359 kPos, no_type_arguments, constructor, no_arguments, allocated), | 359 kPos, no_type_arguments, constructor, no_arguments, allocated), |
| 360 function_bar_name, | 360 function_bar_name, |
| 361 no_arguments); | 361 no_arguments); |
| 362 | 362 |
| 363 test->node_sequence()->Add(new ReturnNode(kPos, call_bar)); | 363 test->node_sequence()->Add(new ReturnNode(kPos, call_bar)); |
| 364 } | 364 } |
| 365 CODEGEN_TEST_RUN(InstanceCallCodegen, Smi::New(42)) | 365 CODEGEN_TEST_RUN(InstanceCallCodegen, Smi::New(42)) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); | 483 Class& cls = Class::ZoneHandle(LookupClass(lib, "A")); |
| 484 EXPECT(!cls.IsNull()); | 484 EXPECT(!cls.IsNull()); |
| 485 | 485 |
| 486 String& constructor_name = String::Handle(String::New("A.")); | 486 String& constructor_name = String::Handle(String::New("A.")); |
| 487 Function& constructor = | 487 Function& constructor = |
| 488 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); | 488 Function::ZoneHandle(cls.LookupConstructor(constructor_name)); |
| 489 EXPECT(!constructor.IsNull()); | 489 EXPECT(!constructor.IsNull()); |
| 490 | 490 |
| 491 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); | 491 const TypeArguments& no_type_arguments = TypeArguments::ZoneHandle(); |
| 492 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); | 492 ArgumentListNode* no_arguments = new ArgumentListNode(kPos); |
| 493 const LocalVariable& allocated = *test->CreateTempConstVariable("alloc"); | 493 const LocalVariable* allocated = test->CreateTempConstVariable("alloc"); |
| 494 test->node_sequence()->Add(new ReturnNode(kPos, new ConstructorCallNode( | 494 test->node_sequence()->Add(new ReturnNode(kPos, new ConstructorCallNode( |
| 495 kPos, no_type_arguments, constructor, no_arguments, allocated))); | 495 kPos, no_type_arguments, constructor, no_arguments, allocated))); |
| 496 } | 496 } |
| 497 | 497 |
| 498 | 498 |
| 499 CODEGEN_TEST_RAW_RUN(AllocateNewObjectCodegen, function) { | 499 CODEGEN_TEST_RAW_RUN(AllocateNewObjectCodegen, function) { |
| 500 GrowableArray<const Object*> arguments; | 500 GrowableArray<const Object*> arguments; |
| 501 const Array& kNoArgumentNames = Array::Handle(); | 501 const Array& kNoArgumentNames = Array::Handle(); |
| 502 Object& result = Object::Handle(); | 502 Object& result = Object::Handle(); |
| 503 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); | 503 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); |
| 504 EXPECT(!result.IsError()); | 504 EXPECT(!result.IsError()); |
| 505 const GrowableObjectArray& libs = GrowableObjectArray::Handle( | 505 const GrowableObjectArray& libs = GrowableObjectArray::Handle( |
| 506 Isolate::Current()->object_store()->libraries()); | 506 Isolate::Current()->object_store()->libraries()); |
| 507 ASSERT(!libs.IsNull()); | 507 ASSERT(!libs.IsNull()); |
| 508 // App lib is the last one that was loaded. | 508 // App lib is the last one that was loaded. |
| 509 intptr_t num_libs = libs.Length(); | 509 intptr_t num_libs = libs.Length(); |
| 510 Library& app_lib = Library::Handle(); | 510 Library& app_lib = Library::Handle(); |
| 511 app_lib ^= libs.At(num_libs - 1); | 511 app_lib ^= libs.At(num_libs - 1); |
| 512 ASSERT(!app_lib.IsNull()); | 512 ASSERT(!app_lib.IsNull()); |
| 513 const Class& cls = Class::Handle( | 513 const Class& cls = Class::Handle( |
| 514 app_lib.LookupClass(String::Handle(Symbols::New("A")))); | 514 app_lib.LookupClass(String::Handle(Symbols::New("A")))); |
| 515 EXPECT_EQ(cls.raw(), result.clazz()); | 515 EXPECT_EQ(cls.raw(), result.clazz()); |
| 516 } | 516 } |
| 517 | 517 |
| 518 } // namespace dart | 518 } // namespace dart |
| 519 | 519 |
| 520 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) | 520 #endif // defined TARGET_ARCH_IA32 || defined(TARGET_ARCH_X64) |
| OLD | NEW |