| 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 22 matching lines...) Expand all Loading... |
| 33 public: | 33 public: |
| 34 static ProgramOptions FromCommandLine(int argc, char** argv); | 34 static ProgramOptions FromCommandLine(int argc, char** argv); |
| 35 | 35 |
| 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 module_(false), |
| 43 top_level_(false), | 44 top_level_(false), |
| 44 do_expressions_(false), | 45 do_expressions_(false), |
| 45 verbose_(false) {} | 46 verbose_(false) {} |
| 46 | 47 |
| 47 bool Validate() const; | 48 bool Validate() const; |
| 48 void UpdateFromHeader(std::istream& stream); // NOLINT | 49 void UpdateFromHeader(std::istream& stream); // NOLINT |
| 49 void PrintHeader(std::ostream& stream) const; // NOLINT | 50 void PrintHeader(std::ostream& stream) const; // NOLINT |
| 50 | 51 |
| 51 bool parsing_failed() const { return parsing_failed_; } | 52 bool parsing_failed() const { return parsing_failed_; } |
| 52 bool print_help() const { return print_help_; } | 53 bool print_help() const { return print_help_; } |
| 53 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } | 54 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } |
| 54 bool read_from_stdin() const { return read_from_stdin_; } | 55 bool read_from_stdin() const { return read_from_stdin_; } |
| 55 bool write_to_stdout() const { | 56 bool write_to_stdout() const { |
| 56 return output_filename_.empty() && !rebaseline_; | 57 return output_filename_.empty() && !rebaseline_; |
| 57 } | 58 } |
| 58 bool rebaseline() const { return rebaseline_; } | 59 bool rebaseline() const { return rebaseline_; } |
| 59 bool wrap() const { return wrap_; } | 60 bool wrap() const { return wrap_; } |
| 61 bool module() const { return module_; } |
| 60 bool top_level() const { return top_level_; } | 62 bool top_level() const { return top_level_; } |
| 61 bool do_expressions() const { return do_expressions_; } | 63 bool do_expressions() const { return do_expressions_; } |
| 62 bool verbose() const { return verbose_; } | 64 bool verbose() const { return verbose_; } |
| 63 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } | 65 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } |
| 64 std::vector<std::string> input_filenames() const { return input_filenames_; } | 66 std::vector<std::string> input_filenames() const { return input_filenames_; } |
| 65 std::string output_filename() const { return output_filename_; } | 67 std::string output_filename() const { return output_filename_; } |
| 66 std::string test_function_name() const { return test_function_name_; } | 68 std::string test_function_name() const { return test_function_name_; } |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 bool parsing_failed_; | 71 bool parsing_failed_; |
| 70 bool print_help_; | 72 bool print_help_; |
| 71 bool read_raw_js_snippet_; | 73 bool read_raw_js_snippet_; |
| 72 bool read_from_stdin_; | 74 bool read_from_stdin_; |
| 73 bool rebaseline_; | 75 bool rebaseline_; |
| 74 bool wrap_; | 76 bool wrap_; |
| 77 bool module_; |
| 75 bool top_level_; | 78 bool top_level_; |
| 76 bool do_expressions_; | 79 bool do_expressions_; |
| 77 bool verbose_; | 80 bool verbose_; |
| 78 std::vector<std::string> input_filenames_; | 81 std::vector<std::string> input_filenames_; |
| 79 std::string output_filename_; | 82 std::string output_filename_; |
| 80 std::string test_function_name_; | 83 std::string test_function_name_; |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 class V8InitializationScope final { | 86 class V8InitializationScope final { |
| 84 public: | 87 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (strcmp(argv[i], "--help") == 0) { | 153 if (strcmp(argv[i], "--help") == 0) { |
| 151 options.print_help_ = true; | 154 options.print_help_ = true; |
| 152 } else if (strcmp(argv[i], "--raw-js") == 0) { | 155 } else if (strcmp(argv[i], "--raw-js") == 0) { |
| 153 options.read_raw_js_snippet_ = true; | 156 options.read_raw_js_snippet_ = true; |
| 154 } else if (strcmp(argv[i], "--stdin") == 0) { | 157 } else if (strcmp(argv[i], "--stdin") == 0) { |
| 155 options.read_from_stdin_ = true; | 158 options.read_from_stdin_ = true; |
| 156 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 159 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
| 157 options.rebaseline_ = true; | 160 options.rebaseline_ = true; |
| 158 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 161 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
| 159 options.wrap_ = false; | 162 options.wrap_ = false; |
| 163 } else if (strcmp(argv[i], "--module") == 0) { |
| 164 options.module_ = true; |
| 160 } else if (strcmp(argv[i], "--top-level") == 0) { | 165 } else if (strcmp(argv[i], "--top-level") == 0) { |
| 161 options.top_level_ = true; | 166 options.top_level_ = true; |
| 162 } else if (strcmp(argv[i], "--do-expressions") == 0) { | 167 } else if (strcmp(argv[i], "--do-expressions") == 0) { |
| 163 options.do_expressions_ = true; | 168 options.do_expressions_ = true; |
| 164 } else if (strcmp(argv[i], "--verbose") == 0) { | 169 } else if (strcmp(argv[i], "--verbose") == 0) { |
| 165 options.verbose_ = true; | 170 options.verbose_ = true; |
| 166 } else if (strncmp(argv[i], "--output=", 9) == 0) { | 171 } else if (strncmp(argv[i], "--output=", 9) == 0) { |
| 167 options.output_filename_ = argv[i] + 9; | 172 options.output_filename_ = argv[i] + 9; |
| 168 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { | 173 } else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { |
| 169 options.test_function_name_ = argv[i] + 21; | 174 options.test_function_name_ = argv[i] + 21; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 "Multiple input files, but no --rebaseline or --raw-js specified."); | 233 "Multiple input files, but no --rebaseline or --raw-js specified."); |
| 229 return false; | 234 return false; |
| 230 } | 235 } |
| 231 | 236 |
| 232 if (top_level_ && !test_function_name_.empty()) { | 237 if (top_level_ && !test_function_name_.empty()) { |
| 233 REPORT_ERROR( | 238 REPORT_ERROR( |
| 234 "Test function name specified while processing top level code."); | 239 "Test function name specified while processing top level code."); |
| 235 return false; | 240 return false; |
| 236 } | 241 } |
| 237 | 242 |
| 243 if (module_ && (!top_level_ || wrap_)) { |
| 244 REPORT_ERROR( |
| 245 "The flag --module currently requires --top-level and --no-wrap."); |
| 246 return false; |
| 247 } |
| 248 |
| 238 return true; | 249 return true; |
| 239 } | 250 } |
| 240 | 251 |
| 241 void ProgramOptions::UpdateFromHeader(std::istream& stream) { | 252 void ProgramOptions::UpdateFromHeader(std::istream& stream) { |
| 242 std::string line; | 253 std::string line; |
| 243 | 254 |
| 244 // Skip to the beginning of the options header | 255 // Skip to the beginning of the options header |
| 245 while (std::getline(stream, line)) { | 256 while (std::getline(stream, line)) { |
| 246 if (line == "---") break; | 257 if (line == "---") break; |
| 247 } | 258 } |
| 248 | 259 |
| 249 while (std::getline(stream, line)) { | 260 while (std::getline(stream, line)) { |
| 250 if (line.compare(0, 6, "wrap: ") == 0) { | 261 if (line.compare(0, 8, "module: ") == 0) { |
| 262 module_ = ParseBoolean(line.c_str() + 8); |
| 263 } else if (line.compare(0, 6, "wrap: ") == 0) { |
| 251 wrap_ = ParseBoolean(line.c_str() + 6); | 264 wrap_ = ParseBoolean(line.c_str() + 6); |
| 252 } else if (line.compare(0, 20, "test function name: ") == 0) { | 265 } else if (line.compare(0, 20, "test function name: ") == 0) { |
| 253 test_function_name_ = line.c_str() + 20; | 266 test_function_name_ = line.c_str() + 20; |
| 254 } else if (line.compare(0, 11, "top level: ") == 0) { | 267 } else if (line.compare(0, 11, "top level: ") == 0) { |
| 255 top_level_ = ParseBoolean(line.c_str() + 11); | 268 top_level_ = ParseBoolean(line.c_str() + 11); |
| 256 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 269 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
| 257 do_expressions_ = ParseBoolean(line.c_str() + 16); | 270 do_expressions_ = ParseBoolean(line.c_str() + 16); |
| 258 } else if (line == "---") { | 271 } else if (line == "---") { |
| 259 break; | 272 break; |
| 260 } else if (line.empty()) { | 273 } else if (line.empty()) { |
| 261 continue; | 274 continue; |
| 262 } else { | 275 } else { |
| 263 UNREACHABLE(); | 276 UNREACHABLE(); |
| 264 return; | 277 return; |
| 265 } | 278 } |
| 266 } | 279 } |
| 267 } | 280 } |
| 268 | 281 |
| 269 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 282 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
| 270 stream << "---" | 283 stream << "---" |
| 271 << "\nwrap: " << BooleanToString(wrap_); | 284 << "\nwrap: " << BooleanToString(wrap_); |
| 272 | 285 |
| 273 if (!test_function_name_.empty()) { | 286 if (!test_function_name_.empty()) { |
| 274 stream << "\ntest function name: " << test_function_name_; | 287 stream << "\ntest function name: " << test_function_name_; |
| 275 } | 288 } |
| 276 | 289 |
| 290 if (module_) stream << "\nmodule: yes"; |
| 277 if (top_level_) stream << "\ntop level: yes"; | 291 if (top_level_) stream << "\ntop level: yes"; |
| 278 if (do_expressions_) stream << "\ndo expressions: yes"; | 292 if (do_expressions_) stream << "\ndo expressions: yes"; |
| 279 | 293 |
| 280 stream << "\n\n"; | 294 stream << "\n\n"; |
| 281 } | 295 } |
| 282 | 296 |
| 283 V8InitializationScope::V8InitializationScope(const char* exec_path) | 297 V8InitializationScope::V8InitializationScope(const char* exec_path) |
| 284 : platform_(v8::platform::CreateDefaultPlatform()) { | 298 : platform_(v8::platform::CreateDefaultPlatform()) { |
| 285 i::FLAG_ignition = true; | 299 i::FLAG_ignition = true; |
| 286 i::FLAG_always_opt = false; | 300 i::FLAG_always_opt = false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 const std::vector<std::string>& snippet_list, | 380 const std::vector<std::string>& snippet_list, |
| 367 const V8InitializationScope& platform, | 381 const V8InitializationScope& platform, |
| 368 const ProgramOptions& options) { | 382 const ProgramOptions& options) { |
| 369 v8::Isolate::Scope isolate_scope(platform.isolate()); | 383 v8::Isolate::Scope isolate_scope(platform.isolate()); |
| 370 v8::HandleScope handle_scope(platform.isolate()); | 384 v8::HandleScope handle_scope(platform.isolate()); |
| 371 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); | 385 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); |
| 372 v8::Context::Scope context_scope(context); | 386 v8::Context::Scope context_scope(context); |
| 373 | 387 |
| 374 BytecodeExpectationsPrinter printer(platform.isolate()); | 388 BytecodeExpectationsPrinter printer(platform.isolate()); |
| 375 printer.set_wrap(options.wrap()); | 389 printer.set_wrap(options.wrap()); |
| 390 printer.set_module(options.module()); |
| 376 printer.set_top_level(options.top_level()); | 391 printer.set_top_level(options.top_level()); |
| 377 if (!options.test_function_name().empty()) { | 392 if (!options.test_function_name().empty()) { |
| 378 printer.set_test_function_name(options.test_function_name()); | 393 printer.set_test_function_name(options.test_function_name()); |
| 379 } | 394 } |
| 380 | 395 |
| 381 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 396 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
| 382 | 397 |
| 383 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 398 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
| 384 options.PrintHeader(stream); | 399 options.PrintHeader(stream); |
| 385 for (const std::string& snippet : snippet_list) { | 400 for (const std::string& snippet : snippet_list) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 std::cerr | 434 std::cerr |
| 420 << "\nUsage: " << exec_path | 435 << "\nUsage: " << exec_path |
| 421 << " [OPTIONS]... [INPUT FILES]...\n\n" | 436 << " [OPTIONS]... [INPUT FILES]...\n\n" |
| 422 "Options:\n" | 437 "Options:\n" |
| 423 " --help Print this help message.\n" | 438 " --help Print this help message.\n" |
| 424 " --verbose Emit messages about the progress of the tool.\n" | 439 " --verbose Emit messages about the progress of the tool.\n" |
| 425 " --raw-js Read raw JavaScript, instead of the output format.\n" | 440 " --raw-js Read raw JavaScript, instead of the output format.\n" |
| 426 " --stdin Read from standard input instead of file.\n" | 441 " --stdin Read from standard input instead of file.\n" |
| 427 " --rebaseline Rebaseline input snippet file.\n" | 442 " --rebaseline Rebaseline input snippet file.\n" |
| 428 " --no-wrap Do not wrap the snippet in a function.\n" | 443 " --no-wrap Do not wrap the snippet in a function.\n" |
| 444 " --module Compile as JavaScript module.\n" |
| 429 " --test-function-name=foo " | 445 " --test-function-name=foo " |
| 430 "Specify the name of the test function.\n" | 446 "Specify the name of the test function.\n" |
| 431 " --top-level Process top level code, not the top-level function.\n" | 447 " --top-level Process top level code, not the top-level function.\n" |
| 432 " --do-expressions Enable harmony_do_expressions flag.\n" | 448 " --do-expressions Enable harmony_do_expressions flag.\n" |
| 433 " --output=file.name\n" | 449 " --output=file.name\n" |
| 434 " Specify the output file. If not specified, output goes to " | 450 " Specify the output file. If not specified, output goes to " |
| 435 "stdout.\n" | 451 "stdout.\n" |
| 436 " --pool-type=(number|string|mixed)\n" | 452 " --pool-type=(number|string|mixed)\n" |
| 437 " Specify the type of the entries in the constant pool " | 453 " Specify the type of the entries in the constant pool " |
| 438 "(default: mixed).\n" | 454 "(default: mixed).\n" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } | 514 } |
| 499 } | 515 } |
| 500 | 516 |
| 501 if (!options.rebaseline()) { | 517 if (!options.rebaseline()) { |
| 502 if (!WriteExpectationsFile(snippet_list, platform, options, | 518 if (!WriteExpectationsFile(snippet_list, platform, options, |
| 503 options.output_filename())) { | 519 options.output_filename())) { |
| 504 return 3; | 520 return 3; |
| 505 } | 521 } |
| 506 } | 522 } |
| 507 } | 523 } |
| OLD | NEW |