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 <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "test/cctest/interpreter/bytecode-expectations-printer.h" | 10 #include "test/cctest/interpreter/bytecode-expectations-printer.h" |
(...skipping 26 matching lines...) Expand all Loading... |
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 do_expressions_(false), | 46 do_expressions_(false), |
47 ignition_generators_(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 do_expressions() const { return do_expressions_; } | 66 bool do_expressions() const { return do_expressions_; } |
68 bool ignition_generators() const { return ignition_generators_; } | |
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 do_expressions_; | 85 bool do_expressions_; |
88 bool ignition_generators_; | |
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 V8InitializationScope final { | 93 class V8InitializationScope final { |
97 public: | 94 public: |
98 explicit V8InitializationScope(const char* exec_path); | 95 explicit V8InitializationScope(const char* exec_path); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 195 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
199 options.rebaseline_ = true; | 196 options.rebaseline_ = true; |
200 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 197 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
201 options.wrap_ = false; | 198 options.wrap_ = false; |
202 } else if (strcmp(argv[i], "--no-execute") == 0) { | 199 } else if (strcmp(argv[i], "--no-execute") == 0) { |
203 options.execute_ = false; | 200 options.execute_ = false; |
204 } else if (strcmp(argv[i], "--top-level") == 0) { | 201 } else if (strcmp(argv[i], "--top-level") == 0) { |
205 options.top_level_ = true; | 202 options.top_level_ = true; |
206 } else if (strcmp(argv[i], "--do-expressions") == 0) { | 203 } else if (strcmp(argv[i], "--do-expressions") == 0) { |
207 options.do_expressions_ = true; | 204 options.do_expressions_ = true; |
208 } else if (strcmp(argv[i], "--ignition-generators") == 0) { | |
209 options.ignition_generators_ = true; | |
210 } else if (strcmp(argv[i], "--verbose") == 0) { | 205 } else if (strcmp(argv[i], "--verbose") == 0) { |
211 options.verbose_ = true; | 206 options.verbose_ = true; |
212 } else if (strncmp(argv[i], "--output=", 9) == 0) { | 207 } else if (strncmp(argv[i], "--output=", 9) == 0) { |
213 options.output_filename_ = argv[i] + 9; | 208 options.output_filename_ = argv[i] + 9; |
214 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { | 209 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { |
215 options.test_function_name_ = argv[i] + 21; | 210 options.test_function_name_ = argv[i] + 21; |
216 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- | 211 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- |
217 options.input_filenames_.push_back(argv[i]); | 212 options.input_filenames_.push_back(argv[i]); |
218 } else { | 213 } else { |
219 REPORT_ERROR("Unknown option " << argv[i]); | 214 REPORT_ERROR("Unknown option " << argv[i]); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } else if (line.compare(0, 9, "execute: ") == 0) { | 299 } else if (line.compare(0, 9, "execute: ") == 0) { |
305 execute_ = ParseBoolean(line.c_str() + 9); | 300 execute_ = ParseBoolean(line.c_str() + 9); |
306 } else if (line.compare(0, 6, "wrap: ") == 0) { | 301 } else if (line.compare(0, 6, "wrap: ") == 0) { |
307 wrap_ = ParseBoolean(line.c_str() + 6); | 302 wrap_ = ParseBoolean(line.c_str() + 6); |
308 } else if (line.compare(0, 20, "test function name: ") == 0) { | 303 } else if (line.compare(0, 20, "test function name: ") == 0) { |
309 test_function_name_ = line.c_str() + 20; | 304 test_function_name_ = line.c_str() + 20; |
310 } else if (line.compare(0, 11, "top level: ") == 0) { | 305 } else if (line.compare(0, 11, "top level: ") == 0) { |
311 top_level_ = ParseBoolean(line.c_str() + 11); | 306 top_level_ = ParseBoolean(line.c_str() + 11); |
312 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 307 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
313 do_expressions_ = ParseBoolean(line.c_str() + 16); | 308 do_expressions_ = ParseBoolean(line.c_str() + 16); |
314 } else if (line.compare(0, 21, "ignition generators: ") == 0) { | |
315 ignition_generators_ = ParseBoolean(line.c_str() + 21); | |
316 } else if (line == "---") { | 309 } else if (line == "---") { |
317 break; | 310 break; |
318 } else if (line.empty()) { | 311 } else if (line.empty()) { |
319 continue; | 312 continue; |
320 } else { | 313 } else { |
321 UNREACHABLE(); | 314 UNREACHABLE(); |
322 return; | 315 return; |
323 } | 316 } |
324 } | 317 } |
325 } | 318 } |
326 | 319 |
327 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 320 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
328 stream << "---" | 321 stream << "---" |
329 "\npool type: " | 322 "\npool type: " |
330 << ConstantPoolTypeToString(const_pool_type_) | 323 << ConstantPoolTypeToString(const_pool_type_) |
331 << "\nexecute: " << BooleanToString(execute_) | 324 << "\nexecute: " << BooleanToString(execute_) |
332 << "\nwrap: " << BooleanToString(wrap_); | 325 << "\nwrap: " << BooleanToString(wrap_); |
333 | 326 |
334 if (!test_function_name_.empty()) { | 327 if (!test_function_name_.empty()) { |
335 stream << "\ntest function name: " << test_function_name_; | 328 stream << "\ntest function name: " << test_function_name_; |
336 } | 329 } |
337 | 330 |
338 if (top_level_) stream << "\ntop level: yes"; | 331 if (top_level_) stream << "\ntop level: yes"; |
339 if (do_expressions_) stream << "\ndo expressions: yes"; | 332 if (do_expressions_) stream << "\ndo expressions: yes"; |
340 if (ignition_generators_) stream << "\nignition generators: yes"; | |
341 | 333 |
342 stream << "\n\n"; | 334 stream << "\n\n"; |
343 } | 335 } |
344 | 336 |
345 V8InitializationScope::V8InitializationScope(const char* exec_path) | 337 V8InitializationScope::V8InitializationScope(const char* exec_path) |
346 : platform_(v8::platform::CreateDefaultPlatform()) { | 338 : platform_(v8::platform::CreateDefaultPlatform()) { |
347 i::FLAG_ignition = true; | 339 i::FLAG_ignition = true; |
348 i::FLAG_always_opt = false; | 340 i::FLAG_always_opt = false; |
349 i::FLAG_allow_natives_syntax = true; | 341 i::FLAG_allow_natives_syntax = true; |
350 | 342 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 BytecodeExpectationsPrinter printer(platform.isolate(), | 428 BytecodeExpectationsPrinter printer(platform.isolate(), |
437 options.const_pool_type()); | 429 options.const_pool_type()); |
438 printer.set_wrap(options.wrap()); | 430 printer.set_wrap(options.wrap()); |
439 printer.set_execute(options.execute()); | 431 printer.set_execute(options.execute()); |
440 printer.set_top_level(options.top_level()); | 432 printer.set_top_level(options.top_level()); |
441 if (!options.test_function_name().empty()) { | 433 if (!options.test_function_name().empty()) { |
442 printer.set_test_function_name(options.test_function_name()); | 434 printer.set_test_function_name(options.test_function_name()); |
443 } | 435 } |
444 | 436 |
445 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 437 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
446 if (options.ignition_generators()) i::FLAG_ignition_generators = true; | |
447 | 438 |
448 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 439 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
449 options.PrintHeader(stream); | 440 options.PrintHeader(stream); |
450 for (const std::string& snippet : snippet_list) { | 441 for (const std::string& snippet : snippet_list) { |
451 printer.PrintExpectation(stream, snippet); | 442 printer.PrintExpectation(stream, snippet); |
452 } | 443 } |
453 | 444 |
454 i::FLAG_harmony_do_expressions = false; | 445 i::FLAG_harmony_do_expressions = false; |
455 } | 446 } |
456 | 447 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 " --verbose Emit messages about the progress of the tool.\n" | 480 " --verbose Emit messages about the progress of the tool.\n" |
490 " --raw-js Read raw JavaScript, instead of the output format.\n" | 481 " --raw-js Read raw JavaScript, instead of the output format.\n" |
491 " --stdin Read from standard input instead of file.\n" | 482 " --stdin Read from standard input instead of file.\n" |
492 " --rebaseline Rebaseline input snippet file.\n" | 483 " --rebaseline Rebaseline input snippet file.\n" |
493 " --no-wrap Do not wrap the snippet in a function.\n" | 484 " --no-wrap Do not wrap the snippet in a function.\n" |
494 " --no-execute Do not execute after compilation.\n" | 485 " --no-execute Do not execute after compilation.\n" |
495 " --test-function-name=foo " | 486 " --test-function-name=foo " |
496 "Specify the name of the test function.\n" | 487 "Specify the name of the test function.\n" |
497 " --top-level Process top level code, not the top-level function.\n" | 488 " --top-level Process top level code, not the top-level function.\n" |
498 " --do-expressions Enable harmony_do_expressions flag.\n" | 489 " --do-expressions Enable harmony_do_expressions flag.\n" |
499 " --ignition-generators Enable ignition_generators flag.\n" | |
500 " --output=file.name\n" | 490 " --output=file.name\n" |
501 " Specify the output file. If not specified, output goes to " | 491 " Specify the output file. If not specified, output goes to " |
502 "stdout.\n" | 492 "stdout.\n" |
503 " --pool-type=(number|string|mixed)\n" | 493 " --pool-type=(number|string|mixed)\n" |
504 " Specify the type of the entries in the constant pool " | 494 " Specify the type of the entries in the constant pool " |
505 "(default: mixed).\n" | 495 "(default: mixed).\n" |
506 "\n" | 496 "\n" |
507 "When using --rebaseline, flags --no-wrap, --no-execute, " | 497 "When using --rebaseline, flags --no-wrap, --no-execute, " |
508 "--test-function-name\nand --pool-type will be overridden by the " | 498 "--test-function-name\nand --pool-type will be overridden by the " |
509 "options specified in the input file\nheader.\n\n" | 499 "options specified in the input file\nheader.\n\n" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 555 } |
566 } | 556 } |
567 | 557 |
568 if (!options.rebaseline()) { | 558 if (!options.rebaseline()) { |
569 if (!WriteExpectationsFile(snippet_list, platform, options, | 559 if (!WriteExpectationsFile(snippet_list, platform, options, |
570 options.output_filename())) { | 560 options.output_filename())) { |
571 return 3; | 561 return 3; |
572 } | 562 } |
573 } | 563 } |
574 } | 564 } |
OLD | NEW |