Index: test/cctest/interpreter/generate-bytecode-expectations.cc |
diff --git a/test/cctest/interpreter/generate-bytecode-expectations.cc b/test/cctest/interpreter/generate-bytecode-expectations.cc |
index db55a6cbabfe7e7cf7f2c6412fb1aa9a2d46d3a3..238ddc0a618a262ae7f43741980fe67e20b2265a 100644 |
--- a/test/cctest/interpreter/generate-bytecode-expectations.cc |
+++ b/test/cctest/interpreter/generate-bytecode-expectations.cc |
@@ -4,6 +4,7 @@ |
#include <cstring> |
#include <fstream> |
+#include <vector> |
#include "test/cctest/interpreter/bytecode-expectations-printer.h" |
@@ -57,7 +58,7 @@ class ProgramOptions final { |
BytecodeExpectationsPrinter::ConstantPoolType const_pool_type() const { |
return const_pool_type_; |
} |
- std::string input_filename() const { return input_filename_; } |
+ std::vector<std::string> input_filenames() const { return input_filenames_; } |
std::string output_filename() const { return output_filename_; } |
std::string test_function_name() const { return test_function_name_; } |
@@ -73,7 +74,7 @@ class ProgramOptions final { |
bool legacy_const_; |
bool do_expressions_; |
BytecodeExpectationsPrinter::ConstantPoolType const_pool_type_; |
- std::string input_filename_; |
+ std::vector<std::string> input_filenames_; |
std::string output_filename_; |
std::string test_function_name_; |
}; |
@@ -174,12 +175,7 @@ ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) { |
} else if (strncmp(argv[i], "--test-function-name=", 21) == 0) { |
options.test_function_name_ = argv[i] + 21; |
} else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with -- |
- if (!options.input_filename_.empty()) { |
- std::cerr << "ERROR: More than one input file specified\n"; |
- options.parsing_failed_ = true; |
- break; |
- } |
- options.input_filename_ = argv[i]; |
+ options.input_filenames_.push_back(argv[i]); |
} else { |
std::cerr << "ERROR: Unknonwn option " << argv[i] << "\n"; |
options.parsing_failed_ = true; |
@@ -200,12 +196,12 @@ bool ProgramOptions::Validate() const { |
return false; |
} |
- if (!read_from_stdin_ && input_filename_.empty()) { |
+ if (!read_from_stdin_ && input_filenames_.empty()) { |
std::cerr << "ERROR: No input file specified.\n"; |
return false; |
} |
- if (read_from_stdin_ && !input_filename_.empty()) { |
+ if (read_from_stdin_ && !input_filenames_.empty()) { |
std::cerr << "ERROR: Reading from stdin, but input files supplied.\n"; |
return false; |
} |
@@ -215,6 +211,23 @@ bool ProgramOptions::Validate() const { |
return false; |
} |
+ if (rebaseline_ && !output_filename_.empty()) { |
+ std::cerr << "ERROR: Output file cannot be specified together with " |
+ "--rebaseline.\n"; |
+ return false; |
+ } |
+ |
+ if (rebaseline_ && read_from_stdin_) { |
+ std::cerr << "ERROR: Cannot --rebaseline when input is --stdin.\n"; |
+ return false; |
+ } |
+ |
+ if (input_filenames_.size() > 1 && !rebaseline_ && !read_raw_js_snippet()) { |
+ std::cerr << "ERROR: Multiple input files, but no --rebaseline or --raw-js " |
+ "specified.\n"; |
+ return false; |
+ } |
+ |
if (top_level_ && !test_function_name_.empty()) { |
std::cerr << "ERROR: test function name specified while processing " |
"top level code.\n"; |
@@ -360,39 +373,36 @@ void ExtractSnippets(std::vector<std::string>* snippet_list, |
void GenerateExpectationsFile(std::ostream& stream, // NOLINT |
const std::vector<std::string>& snippet_list, |
- const ProgramOptions& options, |
- const char* exec_path) { |
- V8InitializationScope platform(exec_path); |
- { |
- v8::Isolate::Scope isolate_scope(platform.isolate()); |
- v8::HandleScope handle_scope(platform.isolate()); |
- v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); |
- v8::Context::Scope context_scope(context); |
- |
- BytecodeExpectationsPrinter printer(platform.isolate(), |
- options.const_pool_type()); |
- printer.set_wrap(options.wrap()); |
- printer.set_execute(options.execute()); |
- printer.set_top_level(options.top_level()); |
- if (!options.test_function_name().empty()) { |
- printer.set_test_function_name(options.test_function_name()); |
- } |
+ const V8InitializationScope& platform, |
+ const ProgramOptions& options) { |
+ v8::Isolate::Scope isolate_scope(platform.isolate()); |
+ v8::HandleScope handle_scope(platform.isolate()); |
+ v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); |
+ v8::Context::Scope context_scope(context); |
+ |
+ BytecodeExpectationsPrinter printer(platform.isolate(), |
+ options.const_pool_type()); |
+ printer.set_wrap(options.wrap()); |
+ printer.set_execute(options.execute()); |
+ printer.set_top_level(options.top_level()); |
+ if (!options.test_function_name().empty()) { |
+ printer.set_test_function_name(options.test_function_name()); |
+ } |
- if (options.legacy_const()) i::FLAG_legacy_const = true; |
- if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
+ if (options.legacy_const()) i::FLAG_legacy_const = true; |
+ if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
- stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
- options.PrintHeader(stream); |
- for (const std::string& snippet : snippet_list) { |
- printer.PrintExpectation(stream, snippet); |
- } |
+ stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
+ options.PrintHeader(stream); |
+ for (const std::string& snippet : snippet_list) { |
+ printer.PrintExpectation(stream, snippet); |
} |
} |
void PrintUsage(const char* exec_path) { |
std::cerr |
<< "\nUsage: " << exec_path |
- << " [OPTIONS]... [INPUT FILE]\n\n" |
+ << " [OPTIONS]... [INPUT FILES]...\n\n" |
"Options:\n" |
" --help Print this help message.\n" |
" --raw-js Read raw JavaScript, instead of the output format.\n" |
@@ -402,7 +412,7 @@ void PrintUsage(const char* exec_path) { |
" --no-execute Do not execute after compilation.\n" |
" --test-function-name=foo " |
"Specify the name of the test function.\n" |
- " --top-level Process top level code, not the top-level function." |
+ " --top-level Process top level code, not the top-level function.\n" |
" --legacy-const Enable legacy_const flag.\n" |
" --do-expressions Enable harmony_do_expressions flag.\n" |
" --output=file.name\n" |
@@ -421,21 +431,86 @@ void PrintUsage(const char* exec_path) { |
"into the test suite.\n"; |
} |
-} // namespace |
+int DoRebaseline(const V8InitializationScope& platform, |
rmcilroy
2016/02/25 14:12:28
As discussed offline, let's try to merge these thr
Stefano Sanfilippo
2016/02/25 14:23:50
I'm working on it right now.
|
+ const ProgramOptions& base_options) { |
+ DCHECK(base_options.rebaseline()); |
+ for (const std::string& input_filename : base_options.input_filenames()) { |
+ std::cerr << "Updating " << input_filename << '\n'; |
-int main(int argc, char** argv) { |
- ProgramOptions options = ProgramOptions::FromCommandLine(argc, argv); |
+ std::ifstream input_stream(input_filename); |
+ if (!input_stream.is_open()) { |
+ std::cerr << "ERROR: Could not open '" << input_filename |
+ << "' for reading.\n"; |
+ return 2; |
+ } |
- if (!options.Validate() || options.print_help()) { |
- PrintUsage(argv[0]); |
- return options.print_help() ? 0 : 1; |
+ ProgramOptions options = base_options; |
+ options.UpdateFromHeader(input_stream); |
+ CHECK(options.Validate()); |
+ |
+ std::vector<std::string> snippet_list; |
+ ExtractSnippets(&snippet_list, input_stream, false); |
+ |
+ std::ofstream output_stream(input_filename); |
+ if (!output_stream.is_open()) { |
+ std::cerr << "ERROR: Could not open '" << input_filename |
oth
2016/02/25 13:12:38
These ERROR messages could all be reported by a co
Stefano Sanfilippo
2016/02/25 13:23:56
Done.
|
+ << "' for writing.\n"; |
+ return 3; |
+ } |
+ |
+ GenerateExpectationsFile(output_stream, snippet_list, platform, options); |
+ } |
+ return 0; |
+} |
+ |
+int DoRawJS(const V8InitializationScope& platform, |
+ const ProgramOptions& options) { |
+ DCHECK(options.read_raw_js_snippet()); |
+ |
+ std::vector<std::string> snippet_list; |
+ |
+ if (options.read_from_stdin()) { |
+ snippet_list.push_back(ReadRawJSSnippet(std::cin)); |
+ } else { |
+ for (const std::string& input_filename : options.input_filenames()) { |
+ std::cerr << "Reading " << input_filename << '\n'; |
oth
2016/02/25 13:12:38
This looks like left over debugging.
Stefano Sanfilippo
2016/02/25 13:23:56
Actually it's not, I thought it could give some fe
rmcilroy
2016/02/25 14:12:28
I think just remove this, the tool should be as si
Stefano Sanfilippo
2016/02/25 14:23:50
Added a verbose flag. Done.
|
+ |
+ std::ifstream input_stream(input_filename.c_str()); |
+ if (!input_stream.is_open()) { |
+ std::cerr << "ERROR: Could not open '" << input_filename |
+ << "' for reading.\n"; |
+ return 2; |
+ } |
+ |
+ snippet_list.push_back(ReadRawJSSnippet(input_stream)); |
+ } |
} |
+ std::ofstream output_file_handle; |
+ if (!options.write_to_stdout()) { |
+ output_file_handle.open(options.output_filename().c_str()); |
+ if (!output_file_handle.is_open()) { |
+ std::cerr << "ERROR: Could not open '" << options.output_filename() |
+ << "' for writing.\n"; |
+ return 3; |
+ } |
+ } |
+ std::ostream& output_stream = |
+ options.write_to_stdout() ? std::cout : output_file_handle; |
+ |
+ GenerateExpectationsFile(output_stream, snippet_list, platform, options); |
+ |
+ return 0; |
+} |
+ |
+int DoDefault(const V8InitializationScope& platform, |
+ const ProgramOptions& options) { |
std::ifstream input_file_handle; |
if (!options.read_from_stdin()) { |
- input_file_handle.open(options.input_filename().c_str()); |
+ const char* input_filename = options.input_filenames().front().c_str(); |
+ input_file_handle.open(input_filename); |
if (!input_file_handle.is_open()) { |
- std::cerr << "ERROR: Could not open '" << options.input_filename() |
+ std::cerr << "ERROR: Could not open '" << input_filename |
<< "' for reading.\n"; |
return 2; |
} |
@@ -443,19 +518,12 @@ int main(int argc, char** argv) { |
std::istream& input_stream = |
options.read_from_stdin() ? std::cin : input_file_handle; |
- if (options.rebaseline()) { |
- options.UpdateFromHeader(input_stream); |
- CHECK(options.Validate()); |
- } |
- |
std::vector<std::string> snippet_list; |
- ExtractSnippets(&snippet_list, input_stream, options.read_raw_js_snippet()); |
+ ExtractSnippets(&snippet_list, input_stream, false); |
std::ofstream output_file_handle; |
if (!options.write_to_stdout()) { |
- output_file_handle.open(options.rebaseline() |
- ? options.input_filename().c_str() |
- : options.output_filename().c_str()); |
+ output_file_handle.open(options.output_filename().c_str()); |
if (!output_file_handle.is_open()) { |
std::cerr << "ERROR: Could not open '" << options.output_filename() |
<< "' for writing.\n"; |
@@ -465,5 +533,28 @@ int main(int argc, char** argv) { |
std::ostream& output_stream = |
options.write_to_stdout() ? std::cout : output_file_handle; |
- GenerateExpectationsFile(output_stream, snippet_list, options, argv[0]); |
+ GenerateExpectationsFile(output_stream, snippet_list, platform, options); |
+ |
+ return 0; |
+} |
+ |
+} // namespace |
+ |
+int main(int argc, char** argv) { |
+ ProgramOptions options = ProgramOptions::FromCommandLine(argc, argv); |
+ |
+ if (!options.Validate() || options.print_help()) { |
+ PrintUsage(argv[0]); |
+ return options.print_help() ? 0 : 1; |
+ } |
+ |
+ V8InitializationScope platform(argv[0]); |
+ |
+ if (options.read_raw_js_snippet()) { |
+ return DoRawJS(platform, options); |
+ } else if (options.rebaseline()) { |
+ return DoRebaseline(platform, options); |
+ } else { |
+ return DoDefault(platform, options); |
+ } |
} |