OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cstring> | 5 #include <cstring> |
6 #include <fstream> | 6 #include <fstream> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "test/cctest/interpreter/bytecode-expectations-printer.h" | 9 #include "test/cctest/interpreter/bytecode-expectations-printer.h" |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 ProgramOptions() | 37 ProgramOptions() |
38 : parsing_failed_(false), | 38 : parsing_failed_(false), |
39 print_help_(false), | 39 print_help_(false), |
40 read_raw_js_snippet_(false), | 40 read_raw_js_snippet_(false), |
41 read_from_stdin_(false), | 41 read_from_stdin_(false), |
42 rebaseline_(false), | 42 rebaseline_(false), |
43 wrap_(true), | 43 wrap_(true), |
44 execute_(true), | 44 execute_(true), |
45 top_level_(false), | 45 top_level_(false), |
46 legacy_const_(false), | |
47 do_expressions_(false), | 46 do_expressions_(false), |
48 verbose_(false), | 47 verbose_(false), |
49 const_pool_type_( | 48 const_pool_type_( |
50 BytecodeExpectationsPrinter::ConstantPoolType::kMixed) {} | 49 BytecodeExpectationsPrinter::ConstantPoolType::kMixed) {} |
51 | 50 |
52 bool Validate() const; | 51 bool Validate() const; |
53 void UpdateFromHeader(std::istream& stream); // NOLINT | 52 void UpdateFromHeader(std::istream& stream); // NOLINT |
54 void PrintHeader(std::ostream& stream) const; // NOLINT | 53 void PrintHeader(std::ostream& stream) const; // NOLINT |
55 | 54 |
56 bool parsing_failed() const { return parsing_failed_; } | 55 bool parsing_failed() const { return parsing_failed_; } |
57 bool print_help() const { return print_help_; } | 56 bool print_help() const { return print_help_; } |
58 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } | 57 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } |
59 bool read_from_stdin() const { return read_from_stdin_; } | 58 bool read_from_stdin() const { return read_from_stdin_; } |
60 bool write_to_stdout() const { | 59 bool write_to_stdout() const { |
61 return output_filename_.empty() && !rebaseline_; | 60 return output_filename_.empty() && !rebaseline_; |
62 } | 61 } |
63 bool rebaseline() const { return rebaseline_; } | 62 bool rebaseline() const { return rebaseline_; } |
64 bool wrap() const { return wrap_; } | 63 bool wrap() const { return wrap_; } |
65 bool execute() const { return execute_; } | 64 bool execute() const { return execute_; } |
66 bool top_level() const { return top_level_; } | 65 bool top_level() const { return top_level_; } |
67 bool legacy_const() const { return legacy_const_; } | |
68 bool do_expressions() const { return do_expressions_; } | 66 bool do_expressions() const { return do_expressions_; } |
69 bool verbose() const { return verbose_; } | 67 bool verbose() const { return verbose_; } |
70 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } | 68 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } |
71 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type() const { | 69 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type() const { |
72 return const_pool_type_; | 70 return const_pool_type_; |
73 } | 71 } |
74 std::vector<std::string> input_filenames() const { return input_filenames_; } | 72 std::vector<std::string> input_filenames() const { return input_filenames_; } |
75 std::string output_filename() const { return output_filename_; } | 73 std::string output_filename() const { return output_filename_; } |
76 std::string test_function_name() const { return test_function_name_; } | 74 std::string test_function_name() const { return test_function_name_; } |
77 | 75 |
78 private: | 76 private: |
79 bool parsing_failed_; | 77 bool parsing_failed_; |
80 bool print_help_; | 78 bool print_help_; |
81 bool read_raw_js_snippet_; | 79 bool read_raw_js_snippet_; |
82 bool read_from_stdin_; | 80 bool read_from_stdin_; |
83 bool rebaseline_; | 81 bool rebaseline_; |
84 bool wrap_; | 82 bool wrap_; |
85 bool execute_; | 83 bool execute_; |
86 bool top_level_; | 84 bool top_level_; |
87 bool legacy_const_; | |
88 bool do_expressions_; | 85 bool do_expressions_; |
89 bool verbose_; | 86 bool verbose_; |
90 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type_; | 87 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type_; |
91 std::vector<std::string> input_filenames_; | 88 std::vector<std::string> input_filenames_; |
92 std::string output_filename_; | 89 std::string output_filename_; |
93 std::string test_function_name_; | 90 std::string test_function_name_; |
94 }; | 91 }; |
95 | 92 |
96 class ArrayBufferAllocator final : public v8::ArrayBuffer::Allocator { | 93 class ArrayBufferAllocator final : public v8::ArrayBuffer::Allocator { |
97 public: | 94 public: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } else if (strcmp(argv[i], "--stdin") == 0) { | 203 } else if (strcmp(argv[i], "--stdin") == 0) { |
207 options.read_from_stdin_ = true; | 204 options.read_from_stdin_ = true; |
208 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 205 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
209 options.rebaseline_ = true; | 206 options.rebaseline_ = true; |
210 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 207 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
211 options.wrap_ = false; | 208 options.wrap_ = false; |
212 } else if (strcmp(argv[i], "--no-execute") == 0) { | 209 } else if (strcmp(argv[i], "--no-execute") == 0) { |
213 options.execute_ = false; | 210 options.execute_ = false; |
214 } else if (strcmp(argv[i], "--top-level") == 0) { | 211 } else if (strcmp(argv[i], "--top-level") == 0) { |
215 options.top_level_ = true; | 212 options.top_level_ = true; |
216 } else if (strcmp(argv[i], "--legacy-const") == 0) { | |
217 options.legacy_const_ = true; | |
218 } else if (strcmp(argv[i], "--do-expressions") == 0) { | 213 } else if (strcmp(argv[i], "--do-expressions") == 0) { |
219 options.do_expressions_ = true; | 214 options.do_expressions_ = true; |
220 } else if (strcmp(argv[i], "--verbose") == 0) { | 215 } else if (strcmp(argv[i], "--verbose") == 0) { |
221 options.verbose_ = true; | 216 options.verbose_ = true; |
222 } else if (strncmp(argv[i], "--output=", 9) == 0) { | 217 } else if (strncmp(argv[i], "--output=", 9) == 0) { |
223 options.output_filename_ = argv[i] + 9; | 218 options.output_filename_ = argv[i] + 9; |
224 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { | 219 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { |
225 options.test_function_name_ = argv[i] + 21; | 220 options.test_function_name_ = argv[i] + 21; |
226 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- | 221 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- |
227 options.input_filenames_.push_back(argv[i]); | 222 options.input_filenames_.push_back(argv[i]); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (line.compare(0, 11, "pool type: ") == 0) { | 307 if (line.compare(0, 11, "pool type: ") == 0) { |
313 const_pool_type_ = ParseConstantPoolType(line.c_str() + 11); | 308 const_pool_type_ = ParseConstantPoolType(line.c_str() + 11); |
314 } else if (line.compare(0, 9, "execute: ") == 0) { | 309 } else if (line.compare(0, 9, "execute: ") == 0) { |
315 execute_ = ParseBoolean(line.c_str() + 9); | 310 execute_ = ParseBoolean(line.c_str() + 9); |
316 } else if (line.compare(0, 6, "wrap: ") == 0) { | 311 } else if (line.compare(0, 6, "wrap: ") == 0) { |
317 wrap_ = ParseBoolean(line.c_str() + 6); | 312 wrap_ = ParseBoolean(line.c_str() + 6); |
318 } else if (line.compare(0, 20, "test function name: ") == 0) { | 313 } else if (line.compare(0, 20, "test function name: ") == 0) { |
319 test_function_name_ = line.c_str() + 20; | 314 test_function_name_ = line.c_str() + 20; |
320 } else if (line.compare(0, 11, "top level: ") == 0) { | 315 } else if (line.compare(0, 11, "top level: ") == 0) { |
321 top_level_ = ParseBoolean(line.c_str() + 11); | 316 top_level_ = ParseBoolean(line.c_str() + 11); |
322 } else if (line.compare(0, 14, "legacy const: ") == 0) { | |
323 legacy_const_ = ParseBoolean(line.c_str() + 14); | |
324 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 317 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
325 do_expressions_ = ParseBoolean(line.c_str() + 16); | 318 do_expressions_ = ParseBoolean(line.c_str() + 16); |
326 } else if (line == "---") { | 319 } else if (line == "---") { |
327 break; | 320 break; |
328 } else if (line.empty()) { | 321 } else if (line.empty()) { |
329 continue; | 322 continue; |
330 } else { | 323 } else { |
331 UNREACHABLE(); | 324 UNREACHABLE(); |
332 return; | 325 return; |
333 } | 326 } |
334 } | 327 } |
335 } | 328 } |
336 | 329 |
337 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 330 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
338 stream << "---" | 331 stream << "---" |
339 "\npool type: " | 332 "\npool type: " |
340 << ConstantPoolTypeToString(const_pool_type_) | 333 << ConstantPoolTypeToString(const_pool_type_) |
341 << "\nexecute: " << BooleanToString(execute_) | 334 << "\nexecute: " << BooleanToString(execute_) |
342 << "\nwrap: " << BooleanToString(wrap_); | 335 << "\nwrap: " << BooleanToString(wrap_); |
343 | 336 |
344 if (!test_function_name_.empty()) { | 337 if (!test_function_name_.empty()) { |
345 stream << "\ntest function name: " << test_function_name_; | 338 stream << "\ntest function name: " << test_function_name_; |
346 } | 339 } |
347 | 340 |
348 if (top_level_) stream << "\ntop level: yes"; | 341 if (top_level_) stream << "\ntop level: yes"; |
349 if (legacy_const_) stream << "\nlegacy const: yes"; | |
350 if (do_expressions_) stream << "\ndo expressions: yes"; | 342 if (do_expressions_) stream << "\ndo expressions: yes"; |
351 | 343 |
352 stream << "\n\n"; | 344 stream << "\n\n"; |
353 } | 345 } |
354 | 346 |
355 V8InitializationScope::V8InitializationScope(const char* exec_path) | 347 V8InitializationScope::V8InitializationScope(const char* exec_path) |
356 : platform_(v8::platform::CreateDefaultPlatform()) { | 348 : platform_(v8::platform::CreateDefaultPlatform()) { |
357 i::FLAG_ignition = true; | 349 i::FLAG_ignition = true; |
358 i::FLAG_always_opt = false; | 350 i::FLAG_always_opt = false; |
359 i::FLAG_allow_natives_syntax = true; | 351 i::FLAG_allow_natives_syntax = true; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 437 |
446 BytecodeExpectationsPrinter printer(platform.isolate(), | 438 BytecodeExpectationsPrinter printer(platform.isolate(), |
447 options.const_pool_type()); | 439 options.const_pool_type()); |
448 printer.set_wrap(options.wrap()); | 440 printer.set_wrap(options.wrap()); |
449 printer.set_execute(options.execute()); | 441 printer.set_execute(options.execute()); |
450 printer.set_top_level(options.top_level()); | 442 printer.set_top_level(options.top_level()); |
451 if (!options.test_function_name().empty()) { | 443 if (!options.test_function_name().empty()) { |
452 printer.set_test_function_name(options.test_function_name()); | 444 printer.set_test_function_name(options.test_function_name()); |
453 } | 445 } |
454 | 446 |
455 if (options.legacy_const()) i::FLAG_legacy_const = true; | |
456 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 447 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
457 | 448 |
458 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 449 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
459 options.PrintHeader(stream); | 450 options.PrintHeader(stream); |
460 for (const std::string& snippet : snippet_list) { | 451 for (const std::string& snippet : snippet_list) { |
461 printer.PrintExpectation(stream, snippet); | 452 printer.PrintExpectation(stream, snippet); |
462 } | 453 } |
463 | 454 |
464 i::FLAG_legacy_const = false; | |
465 i::FLAG_harmony_do_expressions = false; | 455 i::FLAG_harmony_do_expressions = false; |
466 } | 456 } |
467 | 457 |
468 bool WriteExpectationsFile(const std::vector<std::string>& snippet_list, | 458 bool WriteExpectationsFile(const std::vector<std::string>& snippet_list, |
469 const V8InitializationScope& platform, | 459 const V8InitializationScope& platform, |
470 const ProgramOptions& options, | 460 const ProgramOptions& options, |
471 const std::string& output_filename) { | 461 const std::string& output_filename) { |
472 std::ofstream output_file_handle; | 462 std::ofstream output_file_handle; |
473 if (!options.write_to_stdout()) { | 463 if (!options.write_to_stdout()) { |
474 output_file_handle.open(output_filename.c_str()); | 464 output_file_handle.open(output_filename.c_str()); |
(...skipping 24 matching lines...) Expand all Loading... |
499 " --help Print this help message.\n" | 489 " --help Print this help message.\n" |
500 " --verbose Emit messages about the progress of the tool.\n" | 490 " --verbose Emit messages about the progress of the tool.\n" |
501 " --raw-js Read raw JavaScript, instead of the output format.\n" | 491 " --raw-js Read raw JavaScript, instead of the output format.\n" |
502 " --stdin Read from standard input instead of file.\n" | 492 " --stdin Read from standard input instead of file.\n" |
503 " --rebaseline Rebaseline input snippet file.\n" | 493 " --rebaseline Rebaseline input snippet file.\n" |
504 " --no-wrap Do not wrap the snippet in a function.\n" | 494 " --no-wrap Do not wrap the snippet in a function.\n" |
505 " --no-execute Do not execute after compilation.\n" | 495 " --no-execute Do not execute after compilation.\n" |
506 " --test-function-name=foo " | 496 " --test-function-name=foo " |
507 "Specify the name of the test function.\n" | 497 "Specify the name of the test function.\n" |
508 " --top-level Process top level code, not the top-level function.\n" | 498 " --top-level Process top level code, not the top-level function.\n" |
509 " --legacy-const Enable legacy_const flag.\n" | |
510 " --do-expressions Enable harmony_do_expressions flag.\n" | 499 " --do-expressions Enable harmony_do_expressions flag.\n" |
511 " --output=file.name\n" | 500 " --output=file.name\n" |
512 " Specify the output file. If not specified, output goes to " | 501 " Specify the output file. If not specified, output goes to " |
513 "stdout.\n" | 502 "stdout.\n" |
514 " --pool-type=(number|string|mixed)\n" | 503 " --pool-type=(number|string|mixed)\n" |
515 " Specify the type of the entries in the constant pool " | 504 " Specify the type of the entries in the constant pool " |
516 "(default: mixed).\n" | 505 "(default: mixed).\n" |
517 "\n" | 506 "\n" |
518 "When using --rebaseline, flags --no-wrap, --no-execute, " | 507 "When using --rebaseline, flags --no-wrap, --no-execute, " |
519 "--test-function-name\nand --pool-type will be overridden by the " | 508 "--test-function-name\nand --pool-type will be overridden by the " |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 565 } |
577 } | 566 } |
578 | 567 |
579 if (!options.rebaseline()) { | 568 if (!options.rebaseline()) { |
580 if (!WriteExpectationsFile(snippet_list, platform, options, | 569 if (!WriteExpectationsFile(snippet_list, platform, options, |
581 options.output_filename())) { | 570 options.output_filename())) { |
582 return 3; | 571 return 3; |
583 } | 572 } |
584 } | 573 } |
585 } | 574 } |
OLD | NEW |