| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 | 94 |
| 95 enum Encoding { | 95 enum Encoding { |
| 96 LATIN1, | 96 LATIN1, |
| 97 UTF8, | 97 UTF8, |
| 98 UTF16, | 98 UTF16, |
| 99 UTF8TO16 // Read as UTF8, convert to UTF16 before giving it to the lexers. | 99 UTF8TO16 // Read as UTF8, convert to UTF16 before giving it to the lexers. |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 | 102 |
| 103 struct HarmonySettings { | 103 struct LexerShellSettings { |
| 104 bool numeric_literals; | 104 Encoding encoding; |
| 105 bool modules; | 105 bool print_tokens; |
| 106 bool scoping; | 106 bool run_baseline; |
| 107 HarmonySettings() : numeric_literals(false), modules(false), scoping(false) {} | 107 bool run_experimental; |
| 108 bool check_tokens; |
| 109 bool dump_tokens; |
| 110 bool break_after_illegal; |
| 111 bool eos_test; |
| 112 int repeat; |
| 113 bool harmony_numeric_literals; |
| 114 bool harmony_modules; |
| 115 bool harmony_scoping; |
| 116 LexerShellSettings() |
| 117 : encoding(LATIN1), |
| 118 print_tokens(false), |
| 119 run_baseline(true), |
| 120 run_experimental(true), |
| 121 check_tokens(true), |
| 122 dump_tokens(false), |
| 123 break_after_illegal(false), |
| 124 eos_test(false), |
| 125 repeat(1), |
| 126 harmony_numeric_literals(false), |
| 127 harmony_modules(false), |
| 128 harmony_scoping(false) {} |
| 108 }; | 129 }; |
| 109 | 130 |
| 110 class BaselineScanner { | 131 class BaselineScanner { |
| 111 public: | 132 public: |
| 112 BaselineScanner(const byte* source, | 133 BaselineScanner(const byte* source, |
| 113 const byte* source_end, | 134 const byte* source_end, |
| 114 Isolate* isolate, | 135 Isolate* isolate, |
| 115 Encoding encoding, | |
| 116 ElapsedTimer* timer, | 136 ElapsedTimer* timer, |
| 117 int repeat, | 137 const LexerShellSettings& settings) |
| 118 HarmonySettings harmony_settings) | |
| 119 : source_(source), stream_(NULL) { | 138 : source_(source), stream_(NULL) { |
| 120 unicode_cache_ = new UnicodeCache(); | 139 unicode_cache_ = new UnicodeCache(); |
| 121 scanner_ = new Scanner(unicode_cache_); | 140 scanner_ = new Scanner(unicode_cache_); |
| 122 scanner_->SetHarmonyNumericLiterals(harmony_settings.numeric_literals); | 141 scanner_->SetHarmonyNumericLiterals(settings.harmony_numeric_literals); |
| 123 scanner_->SetHarmonyModules(harmony_settings.modules); | 142 scanner_->SetHarmonyModules(settings.harmony_modules); |
| 124 scanner_->SetHarmonyScoping(harmony_settings.scoping); | 143 scanner_->SetHarmonyScoping(settings.harmony_scoping); |
| 125 switch (encoding) { | 144 switch (settings.encoding) { |
| 126 case UTF8: | 145 case UTF8: |
| 127 case UTF8TO16: | 146 case UTF8TO16: |
| 128 stream_ = new Utf8ToUtf16CharacterStream(source_, source_end - source_); | 147 stream_ = new Utf8ToUtf16CharacterStream(source_, source_end - source_); |
| 129 break; | 148 break; |
| 130 case UTF16: { | 149 case UTF16: { |
| 131 Handle<String> result = isolate->factory()->NewStringFromTwoByte( | 150 Handle<String> result = isolate->factory()->NewStringFromTwoByte( |
| 132 Vector<const uint16_t>( | 151 Vector<const uint16_t>( |
| 133 reinterpret_cast<const uint16_t*>(source_), | 152 reinterpret_cast<const uint16_t*>(source_), |
| 134 (source_end - source_) / 2)); | 153 (source_end - source_) / 2)); |
| 135 stream_ = | 154 stream_ = |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 result.literal = ToStdVector(scanner->literal_utf16_string()); | 250 result.literal = ToStdVector(scanner->literal_utf16_string()); |
| 232 } | 251 } |
| 233 } | 252 } |
| 234 return result; | 253 return result; |
| 235 } | 254 } |
| 236 | 255 |
| 237 | 256 |
| 238 TimeDelta RunBaselineScanner(const byte* source, | 257 TimeDelta RunBaselineScanner(const byte* source, |
| 239 const byte* source_end, | 258 const byte* source_end, |
| 240 Isolate* isolate, | 259 Isolate* isolate, |
| 241 Encoding encoding, | |
| 242 bool dump_tokens, | |
| 243 std::vector<TokenWithLocation>* tokens, | 260 std::vector<TokenWithLocation>* tokens, |
| 244 int repeat, | 261 const LexerShellSettings& settings) { |
| 245 HarmonySettings harmony_settings) { | |
| 246 ElapsedTimer timer; | 262 ElapsedTimer timer; |
| 247 BaselineScanner scanner(source, | 263 BaselineScanner scanner(source, |
| 248 source_end, | 264 source_end, |
| 249 isolate, | 265 isolate, |
| 250 encoding, | |
| 251 &timer, | 266 &timer, |
| 252 repeat, | 267 settings); |
| 253 harmony_settings); | |
| 254 Token::Value token; | 268 Token::Value token; |
| 255 do { | 269 do { |
| 256 token = scanner.scanner_->Next(); | 270 token = scanner.scanner_->Next(); |
| 257 if (dump_tokens) { | 271 if (settings.dump_tokens) { |
| 258 tokens->push_back(GetTokenWithLocation(scanner.scanner_, token)); | 272 tokens->push_back(GetTokenWithLocation(scanner.scanner_, token)); |
| 259 } else if (HasLiteral(token)) { | 273 } else if (HasLiteral(token)) { |
| 260 if (scanner.scanner_->is_literal_ascii()) { | 274 if (scanner.scanner_->is_literal_ascii()) { |
| 261 scanner.scanner_->literal_ascii_string(); | 275 scanner.scanner_->literal_ascii_string(); |
| 262 } else { | 276 } else { |
| 263 scanner.scanner_->literal_utf16_string(); | 277 scanner.scanner_->literal_utf16_string(); |
| 264 } | 278 } |
| 265 } | 279 } |
| 266 } while (token != Token::EOS); | 280 } while (token != Token::EOS); |
| 267 return timer.Elapsed(); | 281 return timer.Elapsed(); |
| 268 } | 282 } |
| 269 | 283 |
| 270 | 284 |
| 271 template<typename Char> | 285 template<typename Char> |
| 272 TimeDelta RunExperimentalScanner(Handle<String> source, | 286 TimeDelta RunExperimentalScanner(Handle<String> source, |
| 273 Isolate* isolate, | 287 Isolate* isolate, |
| 274 Encoding encoding, | |
| 275 bool dump_tokens, | |
| 276 std::vector<TokenWithLocation>* tokens, | 288 std::vector<TokenWithLocation>* tokens, |
| 277 int repeat, | 289 LexerShellSettings settings) { |
| 278 HarmonySettings harmony_settings) { | |
| 279 ElapsedTimer timer; | 290 ElapsedTimer timer; |
| 280 ExperimentalScanner<Char> scanner(source, isolate); | 291 ExperimentalScanner<Char> scanner(source, isolate); |
| 281 scanner.SetHarmonyNumericLiterals(harmony_settings.numeric_literals); | 292 scanner.SetHarmonyNumericLiterals(settings.harmony_numeric_literals); |
| 282 scanner.SetHarmonyModules(harmony_settings.modules); | 293 scanner.SetHarmonyModules(settings.harmony_modules); |
| 283 scanner.SetHarmonyScoping(harmony_settings.scoping); | 294 scanner.SetHarmonyScoping(settings.harmony_scoping); |
| 284 | 295 |
| 285 timer.Start(); | 296 timer.Start(); |
| 286 scanner.Init(); | 297 scanner.Init(); |
| 287 Token::Value token; | 298 Token::Value token; |
| 288 do { | 299 do { |
| 289 token = scanner.Next(); | 300 token = scanner.Next(); |
| 290 if (dump_tokens) { | 301 if (settings.dump_tokens) { |
| 291 tokens->push_back(GetTokenWithLocation(&scanner, token)); | 302 tokens->push_back(GetTokenWithLocation(&scanner, token)); |
| 292 } else if (HasLiteral(token)) { | 303 } else if (HasLiteral(token)) { |
| 293 if (scanner.is_literal_ascii()) { | 304 if (scanner.is_literal_ascii()) { |
| 294 scanner.literal_ascii_string(); | 305 scanner.literal_ascii_string(); |
| 295 } else { | 306 } else { |
| 296 scanner.literal_utf16_string(); | 307 scanner.literal_utf16_string(); |
| 297 } | 308 } |
| 298 } | 309 } |
| 299 } while (token != Token::EOS); | 310 } while (token != Token::EOS); |
| 300 return timer.Elapsed(); | 311 return timer.Elapsed(); |
| 301 } | 312 } |
| 302 | 313 |
| 303 | 314 |
| 304 void PrintTokens(const char* name, | 315 void PrintTokens(const char* name, |
| 305 const std::vector<TokenWithLocation>& tokens) { | 316 const std::vector<TokenWithLocation>& tokens) { |
| 306 printf("No of tokens: %d\n", | 317 printf("No of tokens: %d\n", |
| 307 static_cast<int>(tokens.size())); | 318 static_cast<int>(tokens.size())); |
| 308 printf("%s:\n", name); | 319 printf("%s:\n", name); |
| 309 for (size_t i = 0; i < tokens.size(); ++i) { | 320 for (size_t i = 0; i < tokens.size(); ++i) { |
| 310 tokens[i].Print("=>"); | 321 tokens[i].Print("=>"); |
| 311 } | 322 } |
| 312 } | 323 } |
| 313 | 324 |
| 314 | 325 |
| 315 std::pair<TimeDelta, TimeDelta> ProcessFile( | 326 std::pair<TimeDelta, TimeDelta> ProcessFile( |
| 316 const char* fname, | 327 const char* fname, |
| 317 Encoding encoding, | |
| 318 Isolate* isolate, | 328 Isolate* isolate, |
| 319 bool run_baseline, | 329 const LexerShellSettings& settings, |
| 320 bool run_experimental, | |
| 321 bool print_tokens, | |
| 322 bool check_tokens, | |
| 323 bool break_after_illegal, | |
| 324 int repeat, | |
| 325 HarmonySettings harmony_settings, | |
| 326 int truncate_by, | 330 int truncate_by, |
| 327 bool* can_truncate) { | 331 bool* can_truncate) { |
| 332 const bool print_tokens = settings.print_tokens; |
| 333 const bool run_baseline = settings.run_baseline; |
| 334 const bool run_experimental = settings.run_experimental; |
| 328 if (print_tokens) { | 335 if (print_tokens) { |
| 329 printf("Processing file %s, truncating by %d bytes\n", fname, truncate_by); | 336 printf("Processing file %s, truncating by %d bytes\n", fname, truncate_by); |
| 330 } | 337 } |
| 331 HandleScope handle_scope(isolate); | 338 HandleScope handle_scope(isolate); |
| 332 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; | 339 std::vector<TokenWithLocation> baseline_tokens, experimental_tokens; |
| 333 TimeDelta baseline_time, experimental_time; | 340 TimeDelta baseline_time, experimental_time; |
| 334 if (run_baseline) { | 341 if (settings.run_baseline) { |
| 335 const byte* buffer_end = 0; | 342 const byte* buffer_end = 0; |
| 336 const byte* buffer = ReadFile(fname, &buffer_end, repeat, false); | 343 const byte* buffer = ReadFile(fname, &buffer_end, settings.repeat, false); |
| 337 if (truncate_by > buffer_end - buffer) { | 344 if (truncate_by > buffer_end - buffer) { |
| 338 *can_truncate = false; | 345 *can_truncate = false; |
| 339 } else { | 346 } else { |
| 340 buffer_end -= truncate_by; | 347 buffer_end -= truncate_by; |
| 341 baseline_time = RunBaselineScanner( | 348 baseline_time = RunBaselineScanner( |
| 342 buffer, buffer_end, isolate, encoding, print_tokens || check_tokens, | 349 buffer, buffer_end, isolate, &baseline_tokens, settings); |
| 343 &baseline_tokens, repeat, harmony_settings); | |
| 344 } | 350 } |
| 345 delete[] buffer; | 351 delete[] buffer; |
| 346 } | 352 } |
| 347 if (run_experimental) { | 353 if (run_experimental) { |
| 348 Handle<String> source; | 354 Handle<String> source; |
| 349 const byte* buffer_end = 0; | 355 const byte* buffer_end = 0; |
| 350 const byte* buffer = ReadFile(fname, &buffer_end, repeat, | 356 const byte* buffer = ReadFile(fname, &buffer_end, settings.repeat, |
| 351 encoding == UTF8TO16); | 357 settings.encoding == UTF8TO16); |
| 352 if (truncate_by > buffer_end - buffer) { | 358 if (truncate_by > buffer_end - buffer) { |
| 353 *can_truncate = false; | 359 *can_truncate = false; |
| 354 } else { | 360 } else { |
| 355 buffer_end -= truncate_by; | 361 buffer_end -= truncate_by; |
| 356 switch (encoding) { | 362 switch (settings.encoding) { |
| 357 case UTF8: | 363 case UTF8: |
| 358 case LATIN1: | 364 case LATIN1: |
| 359 source = isolate->factory()->NewStringFromAscii( | 365 source = isolate->factory()->NewStringFromAscii( |
| 360 Vector<const char>(reinterpret_cast<const char*>(buffer), | 366 Vector<const char>(reinterpret_cast<const char*>(buffer), |
| 361 buffer_end - buffer)); | 367 buffer_end - buffer)); |
| 362 experimental_time = RunExperimentalScanner<uint8_t>( | 368 experimental_time = RunExperimentalScanner<uint8_t>( |
| 363 source, isolate, encoding, print_tokens || check_tokens, | 369 source, isolate, &experimental_tokens, settings); |
| 364 &experimental_tokens, repeat, harmony_settings); | |
| 365 break; | 370 break; |
| 366 case UTF16: | 371 case UTF16: |
| 367 case UTF8TO16: { | 372 case UTF8TO16: { |
| 368 const uc16* buffer_16 = reinterpret_cast<const uc16*>(buffer); | 373 const uc16* buffer_16 = reinterpret_cast<const uc16*>(buffer); |
| 369 const uc16* buffer_end_16 = reinterpret_cast<const uc16*>(buffer_end); | 374 const uc16* buffer_end_16 = reinterpret_cast<const uc16*>(buffer_end); |
| 370 source = isolate->factory()->NewStringFromTwoByte( | 375 source = isolate->factory()->NewStringFromTwoByte( |
| 371 Vector<const uc16>(buffer_16, buffer_end_16 - buffer_16)); | 376 Vector<const uc16>(buffer_16, buffer_end_16 - buffer_16)); |
| 372 // If the string was just an expaneded one byte string, V8 detects it | 377 // If the string was just an expaneded one byte string, V8 detects it |
| 373 // and doesn't store it as two byte. | 378 // and doesn't store it as two byte. |
| 374 if (!source->IsTwoByteRepresentation()) { | 379 if (!source->IsTwoByteRepresentation()) { |
| 375 experimental_time = RunExperimentalScanner<uint8_t>( | 380 experimental_time = RunExperimentalScanner<uint8_t>( |
| 376 source, isolate, encoding, print_tokens || check_tokens, | 381 source, isolate, &experimental_tokens, settings); |
| 377 &experimental_tokens, repeat, harmony_settings); | |
| 378 } else { | 382 } else { |
| 379 experimental_time = RunExperimentalScanner<uint16_t>( | 383 experimental_time = RunExperimentalScanner<uint16_t>( |
| 380 source, isolate, encoding, print_tokens || check_tokens, | 384 source, isolate, &experimental_tokens, settings); |
| 381 &experimental_tokens, repeat, harmony_settings); | |
| 382 } | 385 } |
| 383 break; | 386 break; |
| 384 } | 387 } |
| 385 default: | 388 default: |
| 386 printf("Encoding not supported by the experimental scanner\n"); | 389 printf("Encoding not supported by the experimental scanner\n"); |
| 387 exit(1); | 390 exit(1); |
| 388 break; | 391 break; |
| 389 } | 392 } |
| 390 } | 393 } |
| 391 delete[] buffer; | 394 delete[] buffer; |
| 392 } | 395 } |
| 393 if (print_tokens && !run_experimental) { | 396 if (print_tokens && !run_experimental) { |
| 394 PrintTokens("Baseline", baseline_tokens); | 397 PrintTokens("Baseline", baseline_tokens); |
| 395 } | 398 } |
| 396 if (print_tokens && !run_baseline) { | 399 if (print_tokens && !run_baseline) { |
| 397 PrintTokens("Experimental", experimental_tokens); | 400 PrintTokens("Experimental", experimental_tokens); |
| 398 } | 401 } |
| 399 if ((print_tokens || check_tokens) && run_baseline && run_experimental) { | 402 if ((print_tokens || settings.check_tokens) && |
| 403 run_baseline && run_experimental) { |
| 400 if (print_tokens) { | 404 if (print_tokens) { |
| 401 printf("No of tokens in Baseline: %d\n", | 405 printf("No of tokens in Baseline: %d\n", |
| 402 static_cast<int>(baseline_tokens.size())); | 406 static_cast<int>(baseline_tokens.size())); |
| 403 printf("No of tokens in Experimental: %d\n", | 407 printf("No of tokens in Experimental: %d\n", |
| 404 static_cast<int>(experimental_tokens.size())); | 408 static_cast<int>(experimental_tokens.size())); |
| 405 printf("Baseline and Experimental:\n"); | 409 printf("Baseline and Experimental:\n"); |
| 406 } | 410 } |
| 407 for (size_t i = 0; i < experimental_tokens.size(); ++i) { | 411 for (size_t i = 0; i < experimental_tokens.size(); ++i) { |
| 408 if (print_tokens) experimental_tokens[i].Print("=>"); | 412 if (print_tokens) experimental_tokens[i].Print("=>"); |
| 409 if (baseline_tokens[i].value == Token::ILLEGAL) { | 413 if (baseline_tokens[i].value == Token::ILLEGAL) { |
| 410 if (experimental_tokens[i].value != Token::ILLEGAL || | 414 if (experimental_tokens[i].value != Token::ILLEGAL || |
| 411 experimental_tokens[i].beg != baseline_tokens[i].beg) { | 415 experimental_tokens[i].beg != baseline_tokens[i].beg) { |
| 412 printf("MISMATCH:\n"); | 416 printf("MISMATCH:\n"); |
| 413 baseline_tokens[i].Print("Expected: "); | 417 baseline_tokens[i].Print("Expected: "); |
| 414 experimental_tokens[i].Print("Actual: "); | 418 experimental_tokens[i].Print("Actual: "); |
| 415 exit(1); | 419 exit(1); |
| 416 } | 420 } |
| 417 if (break_after_illegal) | 421 if (settings.break_after_illegal) |
| 418 break; | 422 break; |
| 419 continue; | 423 continue; |
| 420 } | 424 } |
| 421 if (experimental_tokens[i] != baseline_tokens[i]) { | 425 if (experimental_tokens[i] != baseline_tokens[i]) { |
| 422 printf("MISMATCH:\n"); | 426 printf("MISMATCH:\n"); |
| 423 baseline_tokens[i].Print("Expected: "); | 427 baseline_tokens[i].Print("Expected: "); |
| 424 experimental_tokens[i].Print("Actual: "); | 428 experimental_tokens[i].Print("Actual: "); |
| 425 exit(1); | 429 exit(1); |
| 426 } | 430 } |
| 427 } | 431 } |
| 428 } | 432 } |
| 429 return std::make_pair(baseline_time, experimental_time); | 433 return std::make_pair(baseline_time, experimental_time); |
| 430 } | 434 } |
| 431 | 435 |
| 432 | 436 |
| 433 int main(int argc, char* argv[]) { | 437 int main(int argc, char* argv[]) { |
| 434 v8::V8::InitializeICU(); | 438 v8::V8::InitializeICU(); |
| 435 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 439 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 436 Encoding encoding = LATIN1; | |
| 437 bool print_tokens = false; | |
| 438 bool run_baseline = true; | |
| 439 bool run_experimental = true; | |
| 440 bool check_tokens = true; | |
| 441 bool break_after_illegal = false; | |
| 442 bool eos_test = false; | |
| 443 std::vector<std::string> fnames; | 440 std::vector<std::string> fnames; |
| 444 std::string benchmark; | 441 std::string benchmark; |
| 445 int repeat = 1; | 442 LexerShellSettings settings; |
| 446 HarmonySettings harmony_settings; | |
| 447 for (int i = 0; i < argc; ++i) { | 443 for (int i = 0; i < argc; ++i) { |
| 448 if (strcmp(argv[i], "--latin1") == 0) { | 444 if (strcmp(argv[i], "--latin1") == 0) { |
| 449 encoding = LATIN1; | 445 settings.encoding = LATIN1; |
| 450 } else if (strcmp(argv[i], "--utf8") == 0) { | 446 } else if (strcmp(argv[i], "--utf8") == 0) { |
| 451 encoding = UTF8; | 447 settings.encoding = UTF8; |
| 452 } else if (strcmp(argv[i], "--utf16") == 0) { | 448 } else if (strcmp(argv[i], "--utf16") == 0) { |
| 453 encoding = UTF16; | 449 settings.encoding = UTF16; |
| 454 } else if (strcmp(argv[i], "--utf8to16") == 0) { | 450 } else if (strcmp(argv[i], "--utf8to16") == 0) { |
| 455 encoding = UTF8TO16; | 451 settings.encoding = UTF8TO16; |
| 456 } else if (strcmp(argv[i], "--print-tokens") == 0) { | 452 } else if (strcmp(argv[i], "--print-tokens") == 0) { |
| 457 print_tokens = true; | 453 settings.print_tokens = true; |
| 458 } else if (strcmp(argv[i], "--no-baseline") == 0) { | 454 } else if (strcmp(argv[i], "--no-baseline") == 0) { |
| 459 run_baseline = false; | 455 settings.run_baseline = false; |
| 460 } else if (strcmp(argv[i], "--no-experimental") == 0) { | 456 } else if (strcmp(argv[i], "--no-experimental") == 0) { |
| 461 run_experimental = false; | 457 settings.run_experimental = false; |
| 462 } else if (strcmp(argv[i], "--no-check") == 0) { | 458 } else if (strcmp(argv[i], "--no-check") == 0) { |
| 463 check_tokens = false; | 459 settings.check_tokens = false; |
| 464 } else if (strcmp(argv[i], "--break-after-illegal") == 0) { | 460 } else if (strcmp(argv[i], "--break-after-illegal") == 0) { |
| 465 break_after_illegal = true; | 461 settings.break_after_illegal = true; |
| 466 } else if (strcmp(argv[i], "--use-harmony") == 0) { | 462 } else if (strcmp(argv[i], "--use-harmony") == 0) { |
| 467 harmony_settings.numeric_literals = true; | 463 settings.harmony_numeric_literals = true; |
| 468 harmony_settings.modules = true; | 464 settings.harmony_modules = true; |
| 469 harmony_settings.scoping = true; | 465 settings.harmony_scoping = true; |
| 470 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { | 466 } else if (strncmp(argv[i], "--benchmark=", 12) == 0) { |
| 471 benchmark = std::string(argv[i]).substr(12); | 467 benchmark = std::string(argv[i]).substr(12); |
| 472 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { | 468 } else if (strncmp(argv[i], "--repeat=", 9) == 0) { |
| 473 std::string repeat_str = std::string(argv[i]).substr(9); | 469 std::string repeat_str = std::string(argv[i]).substr(9); |
| 474 repeat = atoi(repeat_str.c_str()); | 470 settings.repeat = atoi(repeat_str.c_str()); |
| 475 } else if (strcmp(argv[i], "--eos-test") == 0) { | 471 } else if (strcmp(argv[i], "--eos-test") == 0) { |
| 476 eos_test = true; | 472 settings.eos_test = true; |
| 477 } else if (i > 0 && argv[i][0] != '-') { | 473 } else if (i > 0 && argv[i][0] != '-') { |
| 478 fnames.push_back(std::string(argv[i])); | 474 fnames.push_back(std::string(argv[i])); |
| 479 } | 475 } |
| 480 } | 476 } |
| 481 check_tokens = check_tokens && run_baseline && run_experimental; | 477 settings.check_tokens = |
| 478 settings.check_tokens && |
| 479 settings.run_baseline && |
| 480 settings.run_experimental; |
| 481 settings.dump_tokens = settings.check_tokens || settings.print_tokens; |
| 482 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 482 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 483 { | 483 { |
| 484 v8::HandleScope handle_scope(isolate); | 484 v8::HandleScope handle_scope(isolate); |
| 485 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); | 485 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); |
| 486 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); | 486 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
| 487 ASSERT(!context.IsEmpty()); | 487 ASSERT(!context.IsEmpty()); |
| 488 { | 488 { |
| 489 v8::Context::Scope scope(context); | 489 v8::Context::Scope scope(context); |
| 490 Isolate* internal_isolate = Isolate::Current(); | 490 Isolate* internal_isolate = Isolate::Current(); |
| 491 double baseline_total = 0, experimental_total = 0; | 491 double baseline_total = 0, experimental_total = 0; |
| 492 for (size_t i = 0; i < fnames.size(); i++) { | 492 for (size_t i = 0; i < fnames.size(); i++) { |
| 493 std::pair<TimeDelta, TimeDelta> times; | 493 std::pair<TimeDelta, TimeDelta> times; |
| 494 bool can_truncate = eos_test; | 494 bool can_truncate = settings.eos_test; |
| 495 int truncate_by = 0; | 495 int truncate_by = 0; |
| 496 do { | 496 do { |
| 497 times = ProcessFile(fnames[i].c_str(), | 497 times = ProcessFile(fnames[i].c_str(), |
| 498 encoding, | |
| 499 internal_isolate, | 498 internal_isolate, |
| 500 run_baseline, | 499 settings, |
| 501 run_experimental, | |
| 502 print_tokens, | |
| 503 check_tokens, | |
| 504 break_after_illegal, | |
| 505 repeat, | |
| 506 harmony_settings, | |
| 507 truncate_by, | 500 truncate_by, |
| 508 &can_truncate); | 501 &can_truncate); |
| 509 baseline_total += times.first.InMillisecondsF(); | 502 baseline_total += times.first.InMillisecondsF(); |
| 510 experimental_total += times.second.InMillisecondsF(); | 503 experimental_total += times.second.InMillisecondsF(); |
| 511 ++truncate_by; | 504 ++truncate_by; |
| 512 } while (can_truncate); | 505 } while (can_truncate); |
| 513 } | 506 } |
| 514 if (run_baseline) { | 507 if (settings.run_baseline) { |
| 515 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(), | 508 printf("Baseline%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 516 baseline_total); | 509 baseline_total); |
| 517 } | 510 } |
| 518 if (run_experimental) { | 511 if (settings.run_experimental) { |
| 519 if (benchmark.empty()) benchmark = "Experimental"; | 512 if (benchmark.empty()) benchmark = "Experimental"; |
| 520 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), | 513 printf("%s(RunTime): %.f ms\n", benchmark.c_str(), |
| 521 experimental_total); | 514 experimental_total); |
| 522 } | 515 } |
| 523 } | 516 } |
| 524 } | 517 } |
| 525 v8::V8::Dispose(); | 518 v8::V8::Dispose(); |
| 526 return 0; | 519 return 0; |
| 527 } | 520 } |
| OLD | NEW |