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 TokenPosition kPos = TokenPosition::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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 13, | 286 13, |
287 13, | 287 13, |
288 31, | 288 31, |
289 23, | 289 23, |
290 23, | 290 23, |
291 23, | 291 23, |
292 33, | 292 33, |
293 33, | 293 33, |
294 5, | 294 5, |
295 5, | 295 5, |
296 Token::kMinSourcePos, | 296 TokenPosition::kMinSourcePos, |
297 Token::kMaxSourcePos, | 297 TokenPosition::kMaxSourcePos, |
298 }; | 298 }; |
299 const intptr_t num_token_positions = | 299 const intptr_t num_token_positions = |
300 sizeof(token_positions) / sizeof(token_positions[0]); | 300 sizeof(token_positions) / sizeof(token_positions[0]); |
301 | 301 |
302 for (intptr_t i = 0; i < num_token_positions; i++) { | 302 for (intptr_t i = 0; i < num_token_positions; i++) { |
303 descriptors->AddDescriptor(RawPcDescriptors::kRuntimeCall, 0, 0, | 303 descriptors->AddDescriptor(RawPcDescriptors::kRuntimeCall, 0, 0, |
304 token_positions[i], 0); | 304 TokenPosition(token_positions[i]), 0); |
305 } | 305 } |
306 | 306 |
307 const PcDescriptors& finalized_descriptors = | 307 const PcDescriptors& finalized_descriptors = |
308 PcDescriptors::Handle(descriptors->FinalizePcDescriptors(0)); | 308 PcDescriptors::Handle(descriptors->FinalizePcDescriptors(0)); |
309 | 309 |
310 ASSERT(!finalized_descriptors.IsNull()); | 310 ASSERT(!finalized_descriptors.IsNull()); |
311 PcDescriptors::Iterator it(finalized_descriptors, | 311 PcDescriptors::Iterator it(finalized_descriptors, |
312 RawPcDescriptors::kRuntimeCall); | 312 RawPcDescriptors::kRuntimeCall); |
313 | 313 |
314 intptr_t i = 0; | 314 intptr_t i = 0; |
315 while (it.MoveNext()) { | 315 while (it.MoveNext()) { |
316 if (token_positions[i] != it.TokenPos()) { | 316 if (token_positions[i] != it.TokenPos().value()) { |
317 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", | 317 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", |
318 i, token_positions[i], it.TokenPos()); | 318 i, token_positions[i], it.TokenPos().value()); |
319 } | 319 } |
320 EXPECT(token_positions[i] == it.TokenPos()); | 320 EXPECT(token_positions[i] == it.TokenPos().value()); |
321 i++; | 321 i++; |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 | 325 |
326 TEST_CASE(CodeSourceMap_TokenPositions) { | 326 TEST_CASE(CodeSourceMap_TokenPositions) { |
327 const intptr_t token_positions[] = { | 327 const intptr_t token_positions[] = { |
328 kMinInt32, | 328 kMinInt32, |
329 5, | 329 5, |
330 13, | 330 13, |
331 13, | 331 13, |
332 13, | 332 13, |
333 13, | 333 13, |
334 31, | 334 31, |
335 23, | 335 23, |
336 23, | 336 23, |
337 23, | 337 23, |
338 33, | 338 33, |
339 33, | 339 33, |
340 5, | 340 5, |
341 5, | 341 5, |
342 Token::kMinSourcePos, | 342 TokenPosition::kMinSourcePos, |
343 Token::kMaxSourcePos, | 343 TokenPosition::kMaxSourcePos, |
344 }; | 344 }; |
345 const intptr_t num_token_positions = | 345 const intptr_t num_token_positions = |
346 sizeof(token_positions) / sizeof(token_positions[0]); | 346 sizeof(token_positions) / sizeof(token_positions[0]); |
347 | 347 |
348 CodeSourceMapBuilder* builder = new CodeSourceMapBuilder(); | 348 CodeSourceMapBuilder* builder = new CodeSourceMapBuilder(); |
349 ASSERT(builder != NULL); | 349 ASSERT(builder != NULL); |
350 | 350 |
351 for (intptr_t i = 0; i < num_token_positions; i++) { | 351 for (intptr_t i = 0; i < num_token_positions; i++) { |
352 builder->AddEntry(i, token_positions[i]); | 352 builder->AddEntry(i, TokenPosition(token_positions[i])); |
353 } | 353 } |
354 | 354 |
355 const CodeSourceMap& code_Source_map = | 355 const CodeSourceMap& code_Source_map = |
356 CodeSourceMap::Handle(builder->Finalize()); | 356 CodeSourceMap::Handle(builder->Finalize()); |
357 | 357 |
358 ASSERT(!code_Source_map.IsNull()); | 358 ASSERT(!code_Source_map.IsNull()); |
359 CodeSourceMap::Iterator it(code_Source_map); | 359 CodeSourceMap::Iterator it(code_Source_map); |
360 | 360 |
361 uintptr_t i = 0; | 361 uintptr_t i = 0; |
362 while (it.MoveNext()) { | 362 while (it.MoveNext()) { |
363 EXPECT(it.PcOffset() == i); | 363 EXPECT(it.PcOffset() == i); |
364 if (token_positions[i] != it.TokenPos()) { | 364 if (token_positions[i] != it.TokenPos().value()) { |
365 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", | 365 OS::Print("[%" Pd "]: Expected: %" Pd " != %" Pd "\n", |
366 i, token_positions[i], it.TokenPos()); | 366 i, token_positions[i], it.TokenPos().value()); |
367 } | 367 } |
368 EXPECT(token_positions[i] == it.TokenPos()); | 368 EXPECT(token_positions[i] == it.TokenPos().value()); |
369 i++; | 369 i++; |
370 } | 370 } |
371 } | 371 } |
372 | 372 |
373 } // namespace dart | 373 } // namespace dart |
OLD | NEW |