| 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 | 7 |
| 8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
| 11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
| 12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
| 13 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
| 14 #include "vm/parser.h" | 14 #include "vm/parser.h" |
| 15 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 16 #include "vm/thread.h" | 16 #include "vm/thread.h" |
| 17 #include "vm/unit_test.h" | 17 #include "vm/unit_test.h" |
| 18 | 18 |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 static const intptr_t kPos = Token::kNoSourcePos; | 21 static const TokenDescriptor kPos = TokenDescriptor::kNoSource; |
| 22 | 22 |
| 23 | 23 |
| 24 CODEGEN_TEST_GENERATE(StackmapCodegen, test) { | 24 CODEGEN_TEST_GENERATE(StackmapCodegen, test) { |
| 25 ParsedFunction* parsed_function = | 25 ParsedFunction* parsed_function = |
| 26 new ParsedFunction(Thread::Current(), test->function()); | 26 new ParsedFunction(Thread::Current(), test->function()); |
| 27 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1))); | 27 LiteralNode* l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(1))); |
| 28 test->node_sequence()->Add(new ReturnNode(kPos, l)); | 28 test->node_sequence()->Add(new ReturnNode(kPos, l)); |
| 29 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2))); | 29 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(2))); |
| 30 test->node_sequence()->Add(new ReturnNode(kPos, l)); | 30 test->node_sequence()->Add(new ReturnNode(kPos, l)); |
| 31 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); | 31 l = new LiteralNode(kPos, Smi::ZoneHandle(Smi::New(3))); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 // Now invoke 'A.moo' and it will trigger a GC when the native function | 263 // Now invoke 'A.moo' and it will trigger a GC when the native function |
| 264 // is called, this should then cause the stack map of function 'A.foo' | 264 // is called, this should then cause the stack map of function 'A.foo' |
| 265 // to be traversed and the appropriate objects visited. | 265 // to be traversed and the appropriate objects visited. |
| 266 const Object& result = Object::Handle( | 266 const Object& result = Object::Handle( |
| 267 DartEntry::InvokeFunction(function_foo, Object::empty_array())); | 267 DartEntry::InvokeFunction(function_foo, Object::empty_array())); |
| 268 EXPECT(!result.IsError()); | 268 EXPECT(!result.IsError()); |
| 269 } | 269 } |
| 270 | 270 |
| 271 | 271 |
| 272 TEST_CASE(DescriptorList_TokenPositions) { | 272 TEST_CASE(DescriptorList_TokenDescriptors) { |
| 273 DescriptorList* descriptors = new DescriptorList(64); | 273 DescriptorList* descriptors = new DescriptorList(64); |
| 274 ASSERT(descriptors != NULL); | 274 ASSERT(descriptors != NULL); |
| 275 const intptr_t token_positions[] = { | 275 const intptr_t token_positions[] = { |
| 276 kMinInt32, | 276 kMinInt32, |
| 277 5, | 277 5, |
| 278 13, | 278 13, |
| 279 13, | 279 13, |
| 280 13, | 280 13, |
| 281 13, | 281 13, |
| 282 31, | 282 31, |
| 283 23, | 283 23, |
| 284 23, | 284 23, |
| 285 23, | 285 23, |
| 286 33, | 286 33, |
| 287 33, | 287 33, |
| 288 5, | 288 5, |
| 289 5, | 289 5, |
| 290 Token::kMinSourcePos, | 290 TokenDescriptor::kMinSourcePos, |
| 291 Token::kMaxSourcePos, | 291 TokenDescriptor::kMaxSourcePos, |
| 292 }; | 292 }; |
| 293 const intptr_t num_token_positions = | 293 const intptr_t num_token_positions = |
| 294 sizeof(token_positions) / sizeof(token_positions[0]); | 294 sizeof(token_positions) / sizeof(token_positions[0]); |
| 295 | 295 |
| 296 for (intptr_t i = 0; i < num_token_positions; i++) { | 296 for (intptr_t i = 0; i < num_token_positions; i++) { |
| 297 descriptors->AddDescriptor(RawPcDescriptors::kRuntimeCall, 0, 0, | 297 descriptors->AddDescriptor(RawPcDescriptors::kRuntimeCall, 0, 0, |
| 298 token_positions[i], 0); | 298 TokenDescriptor(token_positions[i]), 0); |
| 299 } | 299 } |
| 300 | 300 |
| 301 const PcDescriptors& finalized_descriptors = | 301 const PcDescriptors& finalized_descriptors = |
| 302 PcDescriptors::Handle(descriptors->FinalizePcDescriptors(0)); | 302 PcDescriptors::Handle(descriptors->FinalizePcDescriptors(0)); |
| 303 | 303 |
| 304 ASSERT(!finalized_descriptors.IsNull()); | 304 ASSERT(!finalized_descriptors.IsNull()); |
| 305 PcDescriptors::Iterator it(finalized_descriptors, | 305 PcDescriptors::Iterator it(finalized_descriptors, |
| 306 RawPcDescriptors::kRuntimeCall); | 306 RawPcDescriptors::kRuntimeCall); |
| 307 | 307 |
| 308 intptr_t i = 0; | 308 intptr_t i = 0; |
| 309 while (it.MoveNext()) { | 309 while (it.MoveNext()) { |
| 310 if (token_positions[i] != it.TokenPos()) { | 310 if (token_positions[i] != it.TokenPos().value()) { |
| 311 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", | 311 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", |
| 312 i, token_positions[i], it.TokenPos()); | 312 i, token_positions[i], it.TokenPos().value()); |
| 313 } | 313 } |
| 314 EXPECT(token_positions[i] == it.TokenPos()); | 314 EXPECT(token_positions[i] == it.TokenPos().value()); |
| 315 i++; | 315 i++; |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 | 319 |
| 320 TEST_CASE(CodeSourceMap_TokenPositions) { | 320 TEST_CASE(CodeSourceMap_TokenDescriptors) { |
| 321 const intptr_t token_positions[] = { | 321 const intptr_t token_positions[] = { |
| 322 kMinInt32, | 322 kMinInt32, |
| 323 5, | 323 5, |
| 324 13, | 324 13, |
| 325 13, | 325 13, |
| 326 13, | 326 13, |
| 327 13, | 327 13, |
| 328 31, | 328 31, |
| 329 23, | 329 23, |
| 330 23, | 330 23, |
| 331 23, | 331 23, |
| 332 33, | 332 33, |
| 333 33, | 333 33, |
| 334 5, | 334 5, |
| 335 5, | 335 5, |
| 336 Token::kMinSourcePos, | 336 TokenDescriptor::kMinSourcePos, |
| 337 Token::kMaxSourcePos, | 337 TokenDescriptor::kMaxSourcePos, |
| 338 }; | 338 }; |
| 339 const intptr_t num_token_positions = | 339 const intptr_t num_token_positions = |
| 340 sizeof(token_positions) / sizeof(token_positions[0]); | 340 sizeof(token_positions) / sizeof(token_positions[0]); |
| 341 | 341 |
| 342 CodeSourceMapBuilder* builder = new CodeSourceMapBuilder(); | 342 CodeSourceMapBuilder* builder = new CodeSourceMapBuilder(); |
| 343 ASSERT(builder != NULL); | 343 ASSERT(builder != NULL); |
| 344 | 344 |
| 345 for (intptr_t i = 0; i < num_token_positions; i++) { | 345 for (intptr_t i = 0; i < num_token_positions; i++) { |
| 346 builder->AddEntry(i, token_positions[i]); | 346 builder->AddEntry(i, TokenDescriptor(token_positions[i])); |
| 347 } | 347 } |
| 348 | 348 |
| 349 const CodeSourceMap& code_Source_map = | 349 const CodeSourceMap& code_Source_map = |
| 350 CodeSourceMap::Handle(builder->Finalize()); | 350 CodeSourceMap::Handle(builder->Finalize()); |
| 351 | 351 |
| 352 ASSERT(!code_Source_map.IsNull()); | 352 ASSERT(!code_Source_map.IsNull()); |
| 353 CodeSourceMap::Iterator it(code_Source_map); | 353 CodeSourceMap::Iterator it(code_Source_map); |
| 354 | 354 |
| 355 uintptr_t i = 0; | 355 uintptr_t i = 0; |
| 356 while (it.MoveNext()) { | 356 while (it.MoveNext()) { |
| 357 EXPECT(it.PcOffset() == i); | 357 EXPECT(it.PcOffset() == i); |
| 358 if (token_positions[i] != it.TokenPos()) { | 358 if (token_positions[i] != it.TokenPos().value()) { |
| 359 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", | 359 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", |
| 360 i, token_positions[i], it.TokenPos()); | 360 i, token_positions[i], it.TokenPos().value()); |
| 361 } | 361 } |
| 362 EXPECT(token_positions[i] == it.TokenPos()); | 362 EXPECT(token_positions[i] == it.TokenPos().value()); |
| 363 i++; | 363 i++; |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace dart | 367 } // namespace dart |
| OLD | NEW |