| 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 25 matching lines...) Expand all Loading... |
| 36 ProgramOptions() | 36 ProgramOptions() |
| 37 : parsing_failed_(false), | 37 : parsing_failed_(false), |
| 38 print_help_(false), | 38 print_help_(false), |
| 39 read_raw_js_snippet_(false), | 39 read_raw_js_snippet_(false), |
| 40 read_from_stdin_(false), | 40 read_from_stdin_(false), |
| 41 rebaseline_(false), | 41 rebaseline_(false), |
| 42 wrap_(true), | 42 wrap_(true), |
| 43 execute_(true), | 43 execute_(true), |
| 44 top_level_(false), | 44 top_level_(false), |
| 45 do_expressions_(false), | 45 do_expressions_(false), |
| 46 class_fields_(false), |
| 46 verbose_(false) {} | 47 verbose_(false) {} |
| 47 | 48 |
| 48 bool Validate() const; | 49 bool Validate() const; |
| 49 void UpdateFromHeader(std::istream& stream); // NOLINT | 50 void UpdateFromHeader(std::istream& stream); // NOLINT |
| 50 void PrintHeader(std::ostream& stream) const; // NOLINT | 51 void PrintHeader(std::ostream& stream) const; // NOLINT |
| 51 | 52 |
| 52 bool parsing_failed() const { return parsing_failed_; } | 53 bool parsing_failed() const { return parsing_failed_; } |
| 53 bool print_help() const { return print_help_; } | 54 bool print_help() const { return print_help_; } |
| 54 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } | 55 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } |
| 55 bool read_from_stdin() const { return read_from_stdin_; } | 56 bool read_from_stdin() const { return read_from_stdin_; } |
| 56 bool write_to_stdout() const { | 57 bool write_to_stdout() const { |
| 57 return output_filename_.empty() && !rebaseline_; | 58 return output_filename_.empty() && !rebaseline_; |
| 58 } | 59 } |
| 59 bool rebaseline() const { return rebaseline_; } | 60 bool rebaseline() const { return rebaseline_; } |
| 60 bool wrap() const { return wrap_; } | 61 bool wrap() const { return wrap_; } |
| 61 bool execute() const { return execute_; } | 62 bool execute() const { return execute_; } |
| 62 bool top_level() const { return top_level_; } | 63 bool top_level() const { return top_level_; } |
| 63 bool do_expressions() const { return do_expressions_; } | 64 bool do_expressions() const { return do_expressions_; } |
| 65 bool class_fields() const { return class_fields_; } |
| 64 bool verbose() const { return verbose_; } | 66 bool verbose() const { return verbose_; } |
| 65 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } | 67 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } |
| 66 std::vector<std::string> input_filenames() const { return input_filenames_; } | 68 std::vector<std::string> input_filenames() const { return input_filenames_; } |
| 67 std::string output_filename() const { return output_filename_; } | 69 std::string output_filename() const { return output_filename_; } |
| 68 std::string test_function_name() const { return test_function_name_; } | 70 std::string test_function_name() const { return test_function_name_; } |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 bool parsing_failed_; | 73 bool parsing_failed_; |
| 72 bool print_help_; | 74 bool print_help_; |
| 73 bool read_raw_js_snippet_; | 75 bool read_raw_js_snippet_; |
| 74 bool read_from_stdin_; | 76 bool read_from_stdin_; |
| 75 bool rebaseline_; | 77 bool rebaseline_; |
| 76 bool wrap_; | 78 bool wrap_; |
| 77 bool execute_; | 79 bool execute_; |
| 78 bool top_level_; | 80 bool top_level_; |
| 79 bool do_expressions_; | 81 bool do_expressions_; |
| 82 bool class_fields_; |
| 80 bool verbose_; | 83 bool verbose_; |
| 81 std::vector<std::string> input_filenames_; | 84 std::vector<std::string> input_filenames_; |
| 82 std::string output_filename_; | 85 std::string output_filename_; |
| 83 std::string test_function_name_; | 86 std::string test_function_name_; |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 class V8InitializationScope final { | 89 class V8InitializationScope final { |
| 87 public: | 90 public: |
| 88 explicit V8InitializationScope(const char* exec_path); | 91 explicit V8InitializationScope(const char* exec_path); |
| 89 ~V8InitializationScope(); | 92 ~V8InitializationScope(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 162 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
| 160 options.rebaseline_ = true; | 163 options.rebaseline_ = true; |
| 161 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 164 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
| 162 options.wrap_ = false; | 165 options.wrap_ = false; |
| 163 } else if (strcmp(argv[i], "--no-execute") == 0) { | 166 } else if (strcmp(argv[i], "--no-execute") == 0) { |
| 164 options.execute_ = false; | 167 options.execute_ = false; |
| 165 } else if (strcmp(argv[i], "--top-level") == 0) { | 168 } else if (strcmp(argv[i], "--top-level") == 0) { |
| 166 options.top_level_ = true; | 169 options.top_level_ = true; |
| 167 } else if (strcmp(argv[i], "--do-expressions") == 0) { | 170 } else if (strcmp(argv[i], "--do-expressions") == 0) { |
| 168 options.do_expressions_ = true; | 171 options.do_expressions_ = true; |
| 172 } else if (strcmp(argv[i], "--class-fields") == 0) { |
| 173 options.class_fields_ = true; |
| 169 } else if (strcmp(argv[i], "--verbose") == 0) { | 174 } else if (strcmp(argv[i], "--verbose") == 0) { |
| 170 options.verbose_ = true; | 175 options.verbose_ = true; |
| 171 } else if (strncmp(argv[i], "--output=", 9) == 0) { | 176 } else if (strncmp(argv[i], "--output=", 9) == 0) { |
| 172 options.output_filename_ = argv[i] + 9; | 177 options.output_filename_ = argv[i] + 9; |
| 173 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { | 178 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { |
| 174 options.test_function_name_ = argv[i] + 21; | 179 options.test_function_name_ = argv[i] + 21; |
| 175 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- | 180 } else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- |
| 176 options.input_filenames_.push_back(argv[i]); | 181 options.input_filenames_.push_back(argv[i]); |
| 177 } else { | 182 } else { |
| 178 REPORT_ERROR("Unknown option " << argv[i]); | 183 REPORT_ERROR("Unknown option " << argv[i]); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (line.compare(0, 9, "execute: ") == 0) { | 260 if (line.compare(0, 9, "execute: ") == 0) { |
| 256 execute_ = ParseBoolean(line.c_str() + 9); | 261 execute_ = ParseBoolean(line.c_str() + 9); |
| 257 } else if (line.compare(0, 6, "wrap: ") == 0) { | 262 } else if (line.compare(0, 6, "wrap: ") == 0) { |
| 258 wrap_ = ParseBoolean(line.c_str() + 6); | 263 wrap_ = ParseBoolean(line.c_str() + 6); |
| 259 } else if (line.compare(0, 20, "test function name: ") == 0) { | 264 } else if (line.compare(0, 20, "test function name: ") == 0) { |
| 260 test_function_name_ = line.c_str() + 20; | 265 test_function_name_ = line.c_str() + 20; |
| 261 } else if (line.compare(0, 11, "top level: ") == 0) { | 266 } else if (line.compare(0, 11, "top level: ") == 0) { |
| 262 top_level_ = ParseBoolean(line.c_str() + 11); | 267 top_level_ = ParseBoolean(line.c_str() + 11); |
| 263 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 268 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
| 264 do_expressions_ = ParseBoolean(line.c_str() + 16); | 269 do_expressions_ = ParseBoolean(line.c_str() + 16); |
| 270 } else if (line.compare(0, 14, "class fields: ") == 0) { |
| 271 class_fields_ = ParseBoolean(line.c_str() + 14); |
| 265 } else if (line == "---") { | 272 } else if (line == "---") { |
| 266 break; | 273 break; |
| 267 } else if (line.empty()) { | 274 } else if (line.empty()) { |
| 268 continue; | 275 continue; |
| 269 } else { | 276 } else { |
| 270 UNREACHABLE(); | 277 UNREACHABLE(); |
| 271 return; | 278 return; |
| 272 } | 279 } |
| 273 } | 280 } |
| 274 } | 281 } |
| 275 | 282 |
| 276 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 283 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
| 277 stream << "---" | 284 stream << "---" |
| 278 << "\nexecute: " << BooleanToString(execute_) | 285 << "\nexecute: " << BooleanToString(execute_) |
| 279 << "\nwrap: " << BooleanToString(wrap_); | 286 << "\nwrap: " << BooleanToString(wrap_); |
| 280 | 287 |
| 281 if (!test_function_name_.empty()) { | 288 if (!test_function_name_.empty()) { |
| 282 stream << "\ntest function name: " << test_function_name_; | 289 stream << "\ntest function name: " << test_function_name_; |
| 283 } | 290 } |
| 284 | 291 |
| 285 if (top_level_) stream << "\ntop level: yes"; | 292 if (top_level_) stream << "\ntop level: yes"; |
| 286 if (do_expressions_) stream << "\ndo expressions: yes"; | 293 if (do_expressions_) stream << "\ndo expressions: yes"; |
| 294 if (class_fields_) stream << "\nclass fields: yes"; |
| 287 | 295 |
| 288 stream << "\n\n"; | 296 stream << "\n\n"; |
| 289 } | 297 } |
| 290 | 298 |
| 291 V8InitializationScope::V8InitializationScope(const char* exec_path) | 299 V8InitializationScope::V8InitializationScope(const char* exec_path) |
| 292 : platform_(v8::platform::CreateDefaultPlatform()) { | 300 : platform_(v8::platform::CreateDefaultPlatform()) { |
| 293 i::FLAG_ignition = true; | 301 i::FLAG_ignition = true; |
| 294 i::FLAG_always_opt = false; | 302 i::FLAG_always_opt = false; |
| 295 i::FLAG_allow_natives_syntax = true; | 303 i::FLAG_allow_natives_syntax = true; |
| 296 | 304 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 389 |
| 382 BytecodeExpectationsPrinter printer(platform.isolate()); | 390 BytecodeExpectationsPrinter printer(platform.isolate()); |
| 383 printer.set_wrap(options.wrap()); | 391 printer.set_wrap(options.wrap()); |
| 384 printer.set_execute(options.execute()); | 392 printer.set_execute(options.execute()); |
| 385 printer.set_top_level(options.top_level()); | 393 printer.set_top_level(options.top_level()); |
| 386 if (!options.test_function_name().empty()) { | 394 if (!options.test_function_name().empty()) { |
| 387 printer.set_test_function_name(options.test_function_name()); | 395 printer.set_test_function_name(options.test_function_name()); |
| 388 } | 396 } |
| 389 | 397 |
| 390 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 398 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
| 399 if (options.class_fields()) i::FLAG_harmony_class_fields = true; |
| 391 | 400 |
| 392 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 401 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
| 393 options.PrintHeader(stream); | 402 options.PrintHeader(stream); |
| 394 for (const std::string& snippet : snippet_list) { | 403 for (const std::string& snippet : snippet_list) { |
| 395 printer.PrintExpectation(stream, snippet); | 404 printer.PrintExpectation(stream, snippet); |
| 396 } | 405 } |
| 397 | 406 |
| 398 i::FLAG_harmony_do_expressions = false; | 407 i::FLAG_harmony_do_expressions = false; |
| 408 i::FLAG_harmony_class_fields = false; |
| 399 } | 409 } |
| 400 | 410 |
| 401 bool WriteExpectationsFile(const std::vector<std::string>& snippet_list, | 411 bool WriteExpectationsFile(const std::vector<std::string>& snippet_list, |
| 402 const V8InitializationScope& platform, | 412 const V8InitializationScope& platform, |
| 403 const ProgramOptions& options, | 413 const ProgramOptions& options, |
| 404 const std::string& output_filename) { | 414 const std::string& output_filename) { |
| 405 std::ofstream output_file_handle; | 415 std::ofstream output_file_handle; |
| 406 if (!options.write_to_stdout()) { | 416 if (!options.write_to_stdout()) { |
| 407 output_file_handle.open(output_filename.c_str()); | 417 output_file_handle.open(output_filename.c_str()); |
| 408 if (!output_file_handle.is_open()) { | 418 if (!output_file_handle.is_open()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 433 " --verbose Emit messages about the progress of the tool.\n" | 443 " --verbose Emit messages about the progress of the tool.\n" |
| 434 " --raw-js Read raw JavaScript, instead of the output format.\n" | 444 " --raw-js Read raw JavaScript, instead of the output format.\n" |
| 435 " --stdin Read from standard input instead of file.\n" | 445 " --stdin Read from standard input instead of file.\n" |
| 436 " --rebaseline Rebaseline input snippet file.\n" | 446 " --rebaseline Rebaseline input snippet file.\n" |
| 437 " --no-wrap Do not wrap the snippet in a function.\n" | 447 " --no-wrap Do not wrap the snippet in a function.\n" |
| 438 " --no-execute Do not execute after compilation.\n" | 448 " --no-execute Do not execute after compilation.\n" |
| 439 " --test-function-name=foo " | 449 " --test-function-name=foo " |
| 440 "Specify the name of the test function.\n" | 450 "Specify the name of the test function.\n" |
| 441 " --top-level Process top level code, not the top-level function.\n" | 451 " --top-level Process top level code, not the top-level function.\n" |
| 442 " --do-expressions Enable harmony_do_expressions flag.\n" | 452 " --do-expressions Enable harmony_do_expressions flag.\n" |
| 453 " --class-fields Enable harmony_class-fields flag.\n" |
| 443 " --output=file.name\n" | 454 " --output=file.name\n" |
| 444 " Specify the output file. If not specified, output goes to " | 455 " Specify the output file. If not specified, output goes to " |
| 445 "stdout.\n" | 456 "stdout.\n" |
| 446 " --pool-type=(number|string|mixed)\n" | 457 " --pool-type=(number|string|mixed)\n" |
| 447 " Specify the type of the entries in the constant pool " | 458 " Specify the type of the entries in the constant pool " |
| 448 "(default: mixed).\n" | 459 "(default: mixed).\n" |
| 449 "\n" | 460 "\n" |
| 450 "When using --rebaseline, flags --no-wrap, --no-execute, " | 461 "When using --rebaseline, flags --no-wrap, --no-execute, " |
| 451 "--test-function-name\nand --pool-type will be overridden by the " | 462 "--test-function-name\nand --pool-type will be overridden by the " |
| 452 "options specified in the input file\nheader.\n\n" | 463 "options specified in the input file\nheader.\n\n" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 519 } |
| 509 } | 520 } |
| 510 | 521 |
| 511 if (!options.rebaseline()) { | 522 if (!options.rebaseline()) { |
| 512 if (!WriteExpectationsFile(snippet_list, platform, options, | 523 if (!WriteExpectationsFile(snippet_list, platform, options, |
| 513 options.output_filename())) { | 524 options.output_filename())) { |
| 514 return 3; | 525 return 3; |
| 515 } | 526 } |
| 516 } | 527 } |
| 517 } | 528 } |
| OLD | NEW |