Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/compiler.h" | 5 #include "vm/compiler.h" |
| 6 #include "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
| 7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 count++; | 88 count++; |
| 89 } | 89 } |
| 90 } else { | 90 } else { |
| 91 count++; | 91 count++; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 DUMP_ASSERT(count > 0); | 95 DUMP_ASSERT(count > 0); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Expect to find an instance call at |line| and |column|. | |
| 99 void InstanceCallAt(intptr_t line, | |
|
rmacnak
2016/01/14 00:28:08
Nit: the argument order here is different from Sta
Cutch
2016/01/14 15:25:10
Done.
| |
| 100 intptr_t column, | |
| 101 const char* needle) { | |
| 102 ZoneGrowableArray<Instruction*>* instructions = | |
| 103 FindInstructionsAt(line, column); | |
| 104 intptr_t count = 0; | |
| 105 for (intptr_t i = 0; i < instructions->length(); i++) { | |
| 106 Instruction* instr = instructions->At(i); | |
| 107 EXPECT(instr != NULL); | |
| 108 if (instr->IsInstanceCall()) { | |
| 109 const char* haystack = instr->ToCString(); | |
| 110 if (strstr(haystack, needle) != NULL) { | |
| 111 count++; | |
| 112 } | |
| 113 } | |
| 114 } | |
| 115 DUMP_ASSERT(count > 0); | |
| 116 } | |
| 117 | |
| 98 // Expect to find at least one static call at |line| and |column|. The | 118 // Expect to find at least one static call at |line| and |column|. The |
| 99 // static call will have |needle| in its |ToCString| representation. | 119 // static call will have |needle| in its |ToCString| representation. |
| 100 void StaticCallAt(const char* needle, | 120 void StaticCallAt(const char* needle, |
| 101 intptr_t line, | 121 intptr_t line, |
| 102 intptr_t column = -1) { | 122 intptr_t column = -1) { |
| 103 ZoneGrowableArray<Instruction*>* instructions = | 123 ZoneGrowableArray<Instruction*>* instructions = |
| 104 FindInstructionsAt(line, column); | 124 FindInstructionsAt(line, column); |
| 105 intptr_t count = 0; | 125 intptr_t count = 0; |
| 106 for (intptr_t i = 0; i < instructions->length(); i++) { | 126 for (intptr_t i = 0; i < instructions->length(); i++) { |
| 107 Instruction* instr = instructions->At(i); | 127 Instruction* instr = instructions->At(i); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 for (intptr_t i = 0; i < blocks_->length(); i++) { | 159 for (intptr_t i = 0; i < blocks_->length(); i++) { |
| 140 BlockEntryInstr* entry = (*blocks_)[i]; | 160 BlockEntryInstr* entry = (*blocks_)[i]; |
| 141 THR_Print("B%" Pd ":\n", entry->block_id()); | 161 THR_Print("B%" Pd ":\n", entry->block_id()); |
| 142 DumpInstruction(entry); | 162 DumpInstruction(entry); |
| 143 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 163 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 144 DumpInstruction(it.Current()); | 164 DumpInstruction(it.Current()); |
| 145 } | 165 } |
| 146 } | 166 } |
| 147 } | 167 } |
| 148 | 168 |
| 169 // Fails if any of the IR nodes has a token position of Scanner::kNoSourcePos. | |
| 170 void EnsureSourcePositions() { | |
| 171 for (intptr_t i = 0; i < blocks_->length(); i++) { | |
| 172 BlockEntryInstr* entry = (*blocks_)[i]; | |
| 173 DUMP_ASSERT(entry->token_pos() != Scanner::kNoSourcePos); | |
| 174 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | |
| 175 Instruction* instr = it.Current(); | |
| 176 DUMP_ASSERT(instr->token_pos() != Scanner::kNoSourcePos); | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 | |
| 149 private: | 181 private: |
| 150 void DumpInstruction(Instruction* instr) { | 182 void DumpInstruction(Instruction* instr) { |
| 151 const intptr_t token_pos = instr->token_pos(); | 183 const intptr_t token_pos = instr->token_pos(); |
| 152 if (token_pos < 0) { | 184 if (token_pos < 0) { |
| 153 const char* token_pos_string = | 185 const char* token_pos_string = |
| 154 ClassifyingTokenPositions::ToCString(token_pos); | 186 ClassifyingTokenPositions::ToCString(token_pos); |
| 155 THR_Print("%12s -- %s\n", token_pos_string, instr->ToCString()); | 187 THR_Print("%12s -- %s\n", token_pos_string, instr->ToCString()); |
| 156 return; | 188 return; |
| 157 } | 189 } |
| 158 intptr_t token_line = -1; | 190 intptr_t token_line = -1; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 " return z;\n" | 292 " return z;\n" |
| 261 "}\n"; | 293 "}\n"; |
| 262 | 294 |
| 263 SourcePositionTest spt(thread, kScript); | 295 SourcePositionTest spt(thread, kScript); |
| 264 spt.BuildGraphFor("main"); | 296 spt.BuildGraphFor("main"); |
| 265 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); | 297 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); |
| 266 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); | 298 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); |
| 267 spt.InstanceCallAt(4, 13, Token::kADD); | 299 spt.InstanceCallAt(4, 13, Token::kADD); |
| 268 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 3); | 300 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 3); |
| 269 spt.FuzzyInstructionMatchAt("Return", 5, 3); | 301 spt.FuzzyInstructionMatchAt("Return", 5, 3); |
| 302 | |
| 303 spt.EnsureSourcePositions(); | |
| 270 } | 304 } |
| 271 | 305 |
| 272 | 306 |
| 273 TEST_CASE(SourcePosition_If) { | 307 TEST_CASE(SourcePosition_If) { |
| 274 const char* kScript = | 308 const char* kScript = |
| 275 "var x = 5;\n" | 309 "var x = 5;\n" |
| 276 "var y = 5;\n" | 310 "var y = 5;\n" |
| 277 "main() {\n" | 311 "main() {\n" |
| 278 " if (x != 0) {\n" | 312 " if (x != 0) {\n" |
| 279 " return x;\n" | 313 " return x;\n" |
| 280 " }\n" | 314 " }\n" |
| 281 " return y;\n" | 315 " return y;\n" |
| 282 "}\n"; | 316 "}\n"; |
| 283 | 317 |
| 284 SourcePositionTest spt(thread, kScript); | 318 SourcePositionTest spt(thread, kScript); |
| 285 spt.BuildGraphFor("main"); | 319 spt.BuildGraphFor("main"); |
| 286 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); | 320 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); |
| 287 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); | 321 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); |
| 288 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); | 322 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); |
| 289 spt.InstanceCallAt(4, 9, Token::kEQ); | 323 spt.InstanceCallAt(4, 9, Token::kEQ); |
| 290 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); | 324 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); |
| 291 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); | 325 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); |
| 292 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); | 326 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); |
| 293 spt.FuzzyInstructionMatchAt("Return", 5, 5); | 327 spt.FuzzyInstructionMatchAt("Return", 5, 5); |
| 294 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); | 328 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); |
| 295 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); | 329 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); |
| 296 spt.FuzzyInstructionMatchAt("Return", 7, 3); | 330 spt.FuzzyInstructionMatchAt("Return", 7, 3); |
| 331 | |
| 332 spt.EnsureSourcePositions(); | |
| 297 } | 333 } |
| 298 | 334 |
| 299 | 335 |
| 300 TEST_CASE(SourcePosition_ForLoop) { | 336 TEST_CASE(SourcePosition_ForLoop) { |
| 301 const char* kScript = | 337 const char* kScript = |
| 302 "var x = 0;\n" | 338 "var x = 0;\n" |
| 303 "var y = 5;\n" | 339 "var y = 5;\n" |
| 304 "main() {\n" | 340 "main() {\n" |
| 305 " for (var i = 0; i < 10; i++) {\n" | 341 " for (var i = 0; i < 10; i++) {\n" |
| 306 " x += i;\n" | 342 " x += i;\n" |
| 307 " }\n" | 343 " }\n" |
| 308 " return x;\n" | 344 " return x;\n" |
| 309 "}\n"; | 345 "}\n"; |
| 310 | 346 |
| 311 SourcePositionTest spt(thread, kScript); | 347 SourcePositionTest spt(thread, kScript); |
| 312 spt.BuildGraphFor("main"); | 348 spt.BuildGraphFor("main"); |
| 313 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); | 349 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); |
| 314 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); | 350 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); |
| 315 spt.FuzzyInstructionMatchAt("StoreLocal", 4, 14); | 351 spt.FuzzyInstructionMatchAt("StoreLocal", 4, 14); |
| 316 spt.FuzzyInstructionMatchAt("LoadLocal", 4, 19); | 352 spt.FuzzyInstructionMatchAt("LoadLocal", 4, 19); |
| 317 spt.InstanceCallAt(4, 21, Token::kLT); | 353 spt.InstanceCallAt(4, 21, Token::kLT); |
| 318 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 21); | 354 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 21); |
| 319 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 5); | 355 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 5); |
| 320 spt.FuzzyInstructionMatchAt("StoreStaticField", 5, 5); | 356 spt.FuzzyInstructionMatchAt("StoreStaticField", 5, 5); |
| 321 spt.InstanceCallAt(5, 7, Token::kADD); | 357 spt.InstanceCallAt(5, 7, Token::kADD); |
| 322 spt.FuzzyInstructionMatchAt("LoadLocal", 5, 10); | 358 spt.FuzzyInstructionMatchAt("LoadLocal", 5, 10); |
| 323 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); | 359 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); |
| 324 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); | 360 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); |
| 325 spt.FuzzyInstructionMatchAt("Return", 7, 3); | 361 spt.FuzzyInstructionMatchAt("Return", 7, 3); |
| 362 | |
| 363 spt.EnsureSourcePositions(); | |
| 326 } | 364 } |
| 327 | 365 |
| 328 | 366 |
| 329 TEST_CASE(SourcePosition_While) { | 367 TEST_CASE(SourcePosition_While) { |
| 330 const char* kScript = | 368 const char* kScript = |
| 331 "var x = 0;\n" | 369 "var x = 0;\n" |
| 332 "var y = 5;\n" | 370 "var y = 5;\n" |
| 333 "main() {\n" | 371 "main() {\n" |
| 334 " while (x < 10) {\n" | 372 " while (x < 10) {\n" |
| 335 " if (y == 5) {\n" | 373 " if (y == 5) {\n" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 363 | 401 |
| 364 spt.FuzzyInstructionMatchAt("Constant", 8, 5); | 402 spt.FuzzyInstructionMatchAt("Constant", 8, 5); |
| 365 spt.FuzzyInstructionMatchAt("LoadStaticField", 8, 5); | 403 spt.FuzzyInstructionMatchAt("LoadStaticField", 8, 5); |
| 366 spt.FuzzyInstructionMatchAt("Constant(#1)", 8, 6); | 404 spt.FuzzyInstructionMatchAt("Constant(#1)", 8, 6); |
| 367 spt.InstanceCallAt(8, 6, Token::kADD); | 405 spt.InstanceCallAt(8, 6, Token::kADD); |
| 368 spt.FuzzyInstructionMatchAt("StoreStaticField", 8, 5); | 406 spt.FuzzyInstructionMatchAt("StoreStaticField", 8, 5); |
| 369 | 407 |
| 370 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); | 408 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); |
| 371 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); | 409 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); |
| 372 spt.FuzzyInstructionMatchAt("Return", 10, 3); | 410 spt.FuzzyInstructionMatchAt("Return", 10, 3); |
| 411 | |
| 412 spt.EnsureSourcePositions(); | |
| 373 } | 413 } |
| 374 | 414 |
| 375 | 415 |
| 376 TEST_CASE(SourcePosition_WhileContinueBreak) { | 416 TEST_CASE(SourcePosition_WhileContinueBreak) { |
| 377 const char* kScript = | 417 const char* kScript = |
| 378 "var x = 0;\n" | 418 "var x = 0;\n" |
| 379 "var y = 5;\n" | 419 "var y = 5;\n" |
| 380 "main() {\n" | 420 "main() {\n" |
| 381 " while (x < 10) {\n" | 421 " while (x < 10) {\n" |
| 382 " if (y == 5) {\n" | 422 " if (y == 5) {\n" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 401 | 441 |
| 402 spt.FuzzyInstructionMatchAt("Constant(#Field", 5, 9); | 442 spt.FuzzyInstructionMatchAt("Constant(#Field", 5, 9); |
| 403 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 9); | 443 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 9); |
| 404 spt.FuzzyInstructionMatchAt("Constant(#5", 5, 14); | 444 spt.FuzzyInstructionMatchAt("Constant(#5", 5, 14); |
| 405 spt.InstanceCallAt(5, 11, Token::kEQ); | 445 spt.InstanceCallAt(5, 11, Token::kEQ); |
| 406 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 5, 11); | 446 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 5, 11); |
| 407 | 447 |
| 408 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); | 448 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); |
| 409 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); | 449 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); |
| 410 spt.FuzzyInstructionMatchAt("Return", 10, 3); | 450 spt.FuzzyInstructionMatchAt("Return", 10, 3); |
| 451 | |
| 452 spt.EnsureSourcePositions(); | |
| 411 } | 453 } |
| 412 | 454 |
| 413 | 455 |
| 414 TEST_CASE(SourcePosition_LoadIndexed) { | 456 TEST_CASE(SourcePosition_LoadIndexed) { |
| 415 const char* kScript = | 457 const char* kScript = |
| 416 "var x = 0;\n" | 458 "var x = 0;\n" |
| 417 "var z = new List(3);\n" | 459 "var z = new List(3);\n" |
| 418 "main() {\n" | 460 "main() {\n" |
| 419 " z[0];\n" | 461 " z[0];\n" |
| 420 " var y = z[0] + z[1] + z[2];\n" | 462 " var y = z[0] + z[1] + z[2];\n" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 438 | 480 |
| 439 spt.StaticCallAt("get:z", 5, 25); | 481 spt.StaticCallAt("get:z", 5, 25); |
| 440 spt.FuzzyInstructionMatchAt("Constant(#2)", 5, 27); | 482 spt.FuzzyInstructionMatchAt("Constant(#2)", 5, 27); |
| 441 spt.InstanceCallAt(5, 26, Token::kINDEX); | 483 spt.InstanceCallAt(5, 26, Token::kINDEX); |
| 442 | 484 |
| 443 spt.InstanceCallAt(5, 23, Token::kADD); | 485 spt.InstanceCallAt(5, 23, Token::kADD); |
| 444 | 486 |
| 445 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); | 487 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); |
| 446 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); | 488 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); |
| 447 spt.FuzzyInstructionMatchAt("Return", 6, 1); | 489 spt.FuzzyInstructionMatchAt("Return", 6, 1); |
| 490 | |
| 491 spt.EnsureSourcePositions(); | |
| 448 } | 492 } |
| 449 | 493 |
| 450 | 494 |
| 451 TEST_CASE(SourcePosition_StoreIndexed) { | 495 TEST_CASE(SourcePosition_StoreIndexed) { |
| 452 const char* kScript = | 496 const char* kScript = |
| 453 "var x = 0;\n" | 497 "var x = 0;\n" |
| 454 "var z = new List(4);\n" | 498 "var z = new List(4);\n" |
| 455 "main() {\n" | 499 "main() {\n" |
| 456 " z[0];\n" | 500 " z[0];\n" |
| 457 " z[3] = z[0] + z[1] + z[2];\n" | 501 " z[3] = z[0] + z[1] + z[2];\n" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 480 | 524 |
| 481 spt.StaticCallAt("get:z", 5, 24); | 525 spt.StaticCallAt("get:z", 5, 24); |
| 482 spt.FuzzyInstructionMatchAt("Constant(#2)", 5, 26); | 526 spt.FuzzyInstructionMatchAt("Constant(#2)", 5, 26); |
| 483 spt.InstanceCallAt(5, 25, Token::kINDEX); | 527 spt.InstanceCallAt(5, 25, Token::kINDEX); |
| 484 | 528 |
| 485 spt.InstanceCallAt(5, 4, Token::kASSIGN_INDEX); | 529 spt.InstanceCallAt(5, 4, Token::kASSIGN_INDEX); |
| 486 | 530 |
| 487 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); | 531 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); |
| 488 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); | 532 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); |
| 489 spt.FuzzyInstructionMatchAt("Return", 6, 1); | 533 spt.FuzzyInstructionMatchAt("Return", 6, 1); |
| 534 | |
| 535 spt.EnsureSourcePositions(); | |
| 490 } | 536 } |
| 491 | 537 |
| 492 | 538 |
| 493 TEST_CASE(SourcePosition_BitwiseOperations) { | 539 TEST_CASE(SourcePosition_BitwiseOperations) { |
| 494 const char* kScript = | 540 const char* kScript = |
| 495 "var x = 0;\n" | 541 "var x = 0;\n" |
| 496 "var y = 1;\n" | 542 "var y = 1;\n" |
| 497 "main() {\n" | 543 "main() {\n" |
| 498 " var z;\n" | 544 " var z;\n" |
| 499 " z = x & y;\n" | 545 " z = x & y;\n" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 528 spt.InstanceCallAt(7, 9, Token::kBIT_XOR); | 574 spt.InstanceCallAt(7, 9, Token::kBIT_XOR); |
| 529 spt.FuzzyInstructionMatchAt("StoreLocal(z", 7, 3); | 575 spt.FuzzyInstructionMatchAt("StoreLocal(z", 7, 3); |
| 530 | 576 |
| 531 spt.FuzzyInstructionMatchAt("LoadLocal(z", 8, 8); | 577 spt.FuzzyInstructionMatchAt("LoadLocal(z", 8, 8); |
| 532 spt.InstanceCallAt(8, 7, Token::kBIT_NOT); | 578 spt.InstanceCallAt(8, 7, Token::kBIT_NOT); |
| 533 spt.FuzzyInstructionMatchAt("StoreLocal(z", 8, 3); | 579 spt.FuzzyInstructionMatchAt("StoreLocal(z", 8, 3); |
| 534 | 580 |
| 535 spt.FuzzyInstructionMatchAt("LoadLocal(z", 9, 10); | 581 spt.FuzzyInstructionMatchAt("LoadLocal(z", 9, 10); |
| 536 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3); | 582 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3); |
| 537 spt.FuzzyInstructionMatchAt("Return", 9, 3); | 583 spt.FuzzyInstructionMatchAt("Return", 9, 3); |
| 584 | |
| 585 spt.EnsureSourcePositions(); | |
| 538 } | 586 } |
| 539 | 587 |
| 540 | 588 |
| 541 TEST_CASE(SourcePosition_IfElse) { | 589 TEST_CASE(SourcePosition_IfElse) { |
| 542 const char* kScript = | 590 const char* kScript = |
| 543 "var x = 5;\n" | 591 "var x = 5;\n" |
| 544 "var y = 5;\n" | 592 "var y = 5;\n" |
| 545 "main() {\n" | 593 "main() {\n" |
| 546 " if (x != 0) {\n" | 594 " if (x != 0) {\n" |
| 547 " return x;\n" | 595 " return x;\n" |
| 548 " } else {\n" | 596 " } else {\n" |
| 549 " return y;\n" | 597 " return y;\n" |
| 550 " }\n" | 598 " }\n" |
| 551 "}\n"; | 599 "}\n"; |
| 552 | 600 |
| 553 SourcePositionTest spt(thread, kScript); | 601 SourcePositionTest spt(thread, kScript); |
| 554 spt.BuildGraphFor("main"); | 602 spt.BuildGraphFor("main"); |
| 555 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); | 603 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); |
| 556 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); | 604 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); |
| 557 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); | 605 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); |
| 558 spt.InstanceCallAt(4, 9, Token::kEQ); | 606 spt.InstanceCallAt(4, 9, Token::kEQ); |
| 559 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); | 607 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); |
| 560 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); | 608 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); |
| 561 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); | 609 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); |
| 562 spt.FuzzyInstructionMatchAt("Return", 5, 5); | 610 spt.FuzzyInstructionMatchAt("Return", 5, 5); |
| 563 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 12); | 611 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 12); |
| 564 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 5); | 612 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 5); |
| 565 spt.FuzzyInstructionMatchAt("Return", 7, 5); | 613 spt.FuzzyInstructionMatchAt("Return", 7, 5); |
| 614 | |
| 615 spt.EnsureSourcePositions(); | |
| 566 } | 616 } |
| 567 | 617 |
| 568 | 618 |
| 569 TEST_CASE(SourcePosition_Switch) { | 619 TEST_CASE(SourcePosition_Switch) { |
| 570 const char* kScript = | 620 const char* kScript = |
| 571 "var x = 5;\n" | 621 "var x = 5;\n" |
| 572 "var y = 5;\n" | 622 "var y = 5;\n" |
| 573 "main() {\n" | 623 "main() {\n" |
| 574 " switch (x) {\n" | 624 " switch (x) {\n" |
| 575 " case 1: return 3;\n" | 625 " case 1: return 3;\n" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 600 spt.FuzzyInstructionMatchAt("LoadLocal(:switch_expr", 6, 5); // 'c' | 650 spt.FuzzyInstructionMatchAt("LoadLocal(:switch_expr", 6, 5); // 'c' |
| 601 spt.InstanceCallAt(6, 10, Token::kEQ); // '2' | 651 spt.InstanceCallAt(6, 10, Token::kEQ); // '2' |
| 602 | 652 |
| 603 spt.FuzzyInstructionMatchAt("Constant(#4", 6, 20); // '4' | 653 spt.FuzzyInstructionMatchAt("Constant(#4", 6, 20); // '4' |
| 604 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 13); | 654 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 13); |
| 605 spt.FuzzyInstructionMatchAt("Return", 6, 13); | 655 spt.FuzzyInstructionMatchAt("Return", 6, 13); |
| 606 | 656 |
| 607 spt.FuzzyInstructionMatchAt("Constant(#5", 7, 21); // '5' | 657 spt.FuzzyInstructionMatchAt("Constant(#5", 7, 21); // '5' |
| 608 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 14); | 658 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 14); |
| 609 spt.FuzzyInstructionMatchAt("Return", 7, 14); | 659 spt.FuzzyInstructionMatchAt("Return", 7, 14); |
| 660 | |
| 661 spt.EnsureSourcePositions(); | |
| 610 } | 662 } |
| 611 | 663 |
| 612 | 664 |
| 613 TEST_CASE(SourcePosition_TryCatchFinally) { | 665 TEST_CASE(SourcePosition_TryCatchFinally) { |
| 614 const char* kScript = | 666 const char* kScript = |
| 615 "var x = 5;\n" | 667 "var x = 5;\n" |
| 616 "var y = 5;\n" | 668 "var y = 5;\n" |
| 617 "main() {\n" | 669 "main() {\n" |
| 618 " try {\n" | 670 " try {\n" |
| 619 " throw 'A';\n" | 671 " throw 'A';\n" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 650 spt.FuzzyInstructionMatchAt("StoreLocal(:finally_ret_val", 8, 5); // 'r' | 702 spt.FuzzyInstructionMatchAt("StoreLocal(:finally_ret_val", 8, 5); // 'r' |
| 651 | 703 |
| 652 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' | 704 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' |
| 653 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' | 705 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' |
| 654 | 706 |
| 655 spt.FuzzyInstructionMatchAt("LoadLocal(:saved_try_context", 9, 13); // '{' | 707 spt.FuzzyInstructionMatchAt("LoadLocal(:saved_try_context", 9, 13); // '{' |
| 656 spt.FuzzyInstructionMatchAt("StoreLocal(:current_context", 9, 13); // '{' | 708 spt.FuzzyInstructionMatchAt("StoreLocal(:current_context", 9, 13); // '{' |
| 657 | 709 |
| 658 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' | 710 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' |
| 659 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' | 711 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' |
| 712 | |
| 713 spt.EnsureSourcePositions(); | |
| 714 } | |
| 715 | |
| 716 | |
| 717 TEST_CASE(SourcePosition_InstanceFields) { | |
| 718 const char* kScript = | |
| 719 "class A {" | |
|
rmacnak
2016/01/14 00:28:08
missing new line...
Cutch
2016/01/14 15:25:10
Done.
| |
| 720 " var x;\n" | |
| 721 " var y;\n" | |
| 722 "}\n" | |
| 723 "main() {\n" | |
| 724 " var z = new A();\n" | |
| 725 " z.x = 99;\n" | |
| 726 " z.y = z.x;\n" | |
| 727 " return z.y;\n" | |
| 728 "}\n"; | |
| 729 | |
| 730 SourcePositionTest spt(thread, kScript); | |
| 731 spt.BuildGraphFor("main"); | |
| 732 spt.FuzzyInstructionMatchAt("AllocateObject(A)", 5, 15); // 'A' | |
|
rmacnak
2016/01/14 00:28:08
...Making these lines short by 1.
Cutch
2016/01/14 15:25:10
Done.
| |
| 733 spt.FuzzyInstructionMatchAt("StaticCall", 5, 15); // 'A' | |
| 734 spt.FuzzyInstructionMatchAt("StoreLocal(z", 5, 9); // '=' | |
| 735 spt.InstanceCallAt(6, 5, "set:x"); // 'x' | |
| 736 spt.InstanceCallAt(7, 11, "get:x"); // 'x' | |
| 737 spt.InstanceCallAt(7, 5, "set:y"); // 'y' | |
| 738 | |
| 739 spt.InstanceCallAt(8, 12, "get:y"); // 'y' | |
| 740 spt.FuzzyInstructionMatchAt("DebugStepCheck", 8, 3); | |
| 741 spt.FuzzyInstructionMatchAt("Return", 8, 3); | |
| 742 | |
| 743 spt.EnsureSourcePositions(); | |
| 744 } | |
| 745 | |
| 746 | |
| 747 TEST_CASE(SourcePosition_Await) { | |
| 748 const char* kScript = | |
| 749 "import 'dart:async';\n" | |
| 750 "var x = 5;\n" | |
| 751 "var y = 5;\n" | |
| 752 "foo(Future f1, Future f2) async {\n" | |
| 753 " await f1;\n" | |
| 754 " await f2;\n" | |
| 755 " return 55;\n" | |
| 756 "}\n" | |
| 757 "main() {\n" | |
| 758 " foo(new Future.value(33));\n" | |
| 759 "}\n"; | |
| 760 | |
| 761 SourcePositionTest spt(thread, kScript); | |
| 762 spt.BuildGraphFor("foo"); | |
|
rmacnak
2016/01/14 00:28:08
This doesn't actually test 'await'. All that trans
Cutch
2016/01/14 15:25:10
Correct, I've renamed this to be SourcePosition_As
| |
| 763 spt.EnsureSourcePositions(); | |
| 660 } | 764 } |
| 661 | 765 |
| 662 } // namespace dart | 766 } // namespace dart |
| 663 | 767 |
| OLD | NEW |