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" |
11 | 11 |
12 #include "include/libplatform/libplatform.h" | 12 #include "include/libplatform/libplatform.h" |
13 #include "include/v8.h" | 13 #include "include/v8.h" |
14 | 14 |
15 #include "src/base/logging.h" | 15 #include "src/base/logging.h" |
16 #include "src/interpreter/interpreter.h" | 16 #include "src/interpreter/interpreter.h" |
17 | 17 |
18 #ifdef V8_OS_POSIX | 18 #ifdef V8_OS_POSIX |
19 #include <dirent.h> | 19 #include <dirent.h> |
20 #endif | 20 #endif |
21 | 21 |
22 using v8::internal::interpreter::BytecodeExpectationsPrinter; | 22 using v8::internal::interpreter::BytecodeExpectationsPrinter; |
23 | 23 |
24 #define REPORT_ERROR(MESSAGE) (((std::cerr << "ERROR: ") << MESSAGE) << '\n') | 24 #define REPORT_ERROR(MESSAGE) (((std::cerr << "ERROR: ") << MESSAGE) << '\n') |
25 #define REPORT_WARNING(MESSAGE) \ | |
26 (((std::cerr << "WARNING: ") << MESSAGE) << '\n') | |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 #ifdef V8_OS_POSIX | 30 #ifdef V8_OS_POSIX |
29 const char* kGoldenFilesPath = "test/cctest/interpreter/bytecode_expectations/"; | 31 const char* kGoldenFilesPath = "test/cctest/interpreter/bytecode_expectations/"; |
30 #endif | 32 #endif |
31 | 33 |
32 class ProgramOptions final { | 34 class ProgramOptions final { |
33 public: | 35 public: |
34 static ProgramOptions FromCommandLine(int argc, char** argv); | 36 static ProgramOptions FromCommandLine(int argc, char** argv); |
35 | 37 |
36 ProgramOptions() | 38 ProgramOptions() |
37 : parsing_failed_(false), | 39 : parsing_failed_(false), |
38 print_help_(false), | 40 print_help_(false), |
39 read_raw_js_snippet_(false), | 41 read_raw_js_snippet_(false), |
40 read_from_stdin_(false), | 42 read_from_stdin_(false), |
41 rebaseline_(false), | 43 rebaseline_(false), |
42 wrap_(true), | 44 wrap_(true), |
43 execute_(true), | 45 execute_(true), |
44 top_level_(false), | 46 top_level_(false), |
45 do_expressions_(false), | 47 do_expressions_(false), |
46 verbose_(false), | 48 verbose_(false) {} |
47 const_pool_type_( | |
48 BytecodeExpectationsPrinter::ConstantPoolType::kMixed) {} | |
49 | 49 |
50 bool Validate() const; | 50 bool Validate() const; |
51 void UpdateFromHeader(std::istream& stream); // NOLINT | 51 void UpdateFromHeader(std::istream& stream); // NOLINT |
52 void PrintHeader(std::ostream& stream) const; // NOLINT | 52 void PrintHeader(std::ostream& stream) const; // NOLINT |
53 | 53 |
54 bool parsing_failed() const { return parsing_failed_; } | 54 bool parsing_failed() const { return parsing_failed_; } |
55 bool print_help() const { return print_help_; } | 55 bool print_help() const { return print_help_; } |
56 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } | 56 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } |
57 bool read_from_stdin() const { return read_from_stdin_; } | 57 bool read_from_stdin() const { return read_from_stdin_; } |
58 bool write_to_stdout() const { | 58 bool write_to_stdout() const { |
59 return output_filename_.empty() && !rebaseline_; | 59 return output_filename_.empty() && !rebaseline_; |
60 } | 60 } |
61 bool rebaseline() const { return rebaseline_; } | 61 bool rebaseline() const { return rebaseline_; } |
62 bool wrap() const { return wrap_; } | 62 bool wrap() const { return wrap_; } |
63 bool execute() const { return execute_; } | 63 bool execute() const { return execute_; } |
64 bool top_level() const { return top_level_; } | 64 bool top_level() const { return top_level_; } |
65 bool do_expressions() const { return do_expressions_; } | 65 bool do_expressions() const { return do_expressions_; } |
66 bool verbose() const { return verbose_; } | 66 bool verbose() const { return verbose_; } |
67 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } | 67 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } |
68 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type() const { | |
69 return const_pool_type_; | |
70 } | |
71 std::vector<std::string> input_filenames() const { return input_filenames_; } | 68 std::vector<std::string> input_filenames() const { return input_filenames_; } |
72 std::string output_filename() const { return output_filename_; } | 69 std::string output_filename() const { return output_filename_; } |
73 std::string test_function_name() const { return test_function_name_; } | 70 std::string test_function_name() const { return test_function_name_; } |
74 | 71 |
75 private: | 72 private: |
76 bool parsing_failed_; | 73 bool parsing_failed_; |
77 bool print_help_; | 74 bool print_help_; |
78 bool read_raw_js_snippet_; | 75 bool read_raw_js_snippet_; |
79 bool read_from_stdin_; | 76 bool read_from_stdin_; |
80 bool rebaseline_; | 77 bool rebaseline_; |
81 bool wrap_; | 78 bool wrap_; |
82 bool execute_; | 79 bool execute_; |
83 bool top_level_; | 80 bool top_level_; |
84 bool do_expressions_; | 81 bool do_expressions_; |
85 bool verbose_; | 82 bool verbose_; |
86 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type_; | |
87 std::vector<std::string> input_filenames_; | 83 std::vector<std::string> input_filenames_; |
88 std::string output_filename_; | 84 std::string output_filename_; |
89 std::string test_function_name_; | 85 std::string test_function_name_; |
90 }; | 86 }; |
91 | 87 |
92 class V8InitializationScope final { | 88 class V8InitializationScope final { |
93 public: | 89 public: |
94 explicit V8InitializationScope(const char* exec_path); | 90 explicit V8InitializationScope(const char* exec_path); |
95 ~V8InitializationScope(); | 91 ~V8InitializationScope(); |
96 | 92 |
97 v8::Platform* platform() const { return platform_.get(); } | 93 v8::Platform* platform() const { return platform_.get(); } |
98 v8::Isolate* isolate() const { return isolate_; } | 94 v8::Isolate* isolate() const { return isolate_; } |
99 | 95 |
100 private: | 96 private: |
101 std::unique_ptr<v8::Platform> platform_; | 97 std::unique_ptr<v8::Platform> platform_; |
102 std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_; | 98 std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_; |
103 v8::Isolate* isolate_; | 99 v8::Isolate* isolate_; |
104 | 100 |
105 DISALLOW_COPY_AND_ASSIGN(V8InitializationScope); | 101 DISALLOW_COPY_AND_ASSIGN(V8InitializationScope); |
106 }; | 102 }; |
107 | 103 |
108 BytecodeExpectationsPrinter::ConstantPoolType ParseConstantPoolType( | |
109 const char* type_string) { | |
110 if (strcmp(type_string, "number") == 0) { | |
111 return BytecodeExpectationsPrinter::ConstantPoolType::kNumber; | |
112 } else if (strcmp(type_string, "string") == 0) { | |
113 return BytecodeExpectationsPrinter::ConstantPoolType::kString; | |
114 } else if (strcmp(type_string, "mixed") == 0) { | |
115 return BytecodeExpectationsPrinter::ConstantPoolType::kMixed; | |
116 } | |
117 return BytecodeExpectationsPrinter::ConstantPoolType::kUnknown; | |
118 } | |
119 | |
120 const char* ConstantPoolTypeToString( | |
121 BytecodeExpectationsPrinter::ConstantPoolType type) { | |
122 switch (type) { | |
123 case BytecodeExpectationsPrinter::ConstantPoolType::kNumber: | |
124 return "number"; | |
125 case BytecodeExpectationsPrinter::ConstantPoolType::kMixed: | |
126 return "mixed"; | |
127 case BytecodeExpectationsPrinter::ConstantPoolType::kString: | |
128 return "string"; | |
129 default: | |
130 UNREACHABLE(); | |
131 return nullptr; | |
132 } | |
133 } | |
134 | |
135 bool ParseBoolean(const char* string) { | 104 bool ParseBoolean(const char* string) { |
136 if (strcmp(string, "yes") == 0) { | 105 if (strcmp(string, "yes") == 0) { |
137 return true; | 106 return true; |
138 } else if (strcmp(string, "no") == 0) { | 107 } else if (strcmp(string, "no") == 0) { |
139 return false; | 108 return false; |
140 } else { | 109 } else { |
141 UNREACHABLE(); | 110 UNREACHABLE(); |
142 return false; | 111 return false; |
143 } | 112 } |
144 } | 113 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 | 149 |
181 // static | 150 // static |
182 ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) { | 151 ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) { |
183 ProgramOptions options; | 152 ProgramOptions options; |
184 | 153 |
185 for (int i = 1; i < argc; ++i) { | 154 for (int i = 1; i < argc; ++i) { |
186 if (strcmp(argv[i], "--help") == 0) { | 155 if (strcmp(argv[i], "--help") == 0) { |
187 options.print_help_ = true; | 156 options.print_help_ = true; |
188 } else if (strcmp(argv[i], "--raw-js") == 0) { | 157 } else if (strcmp(argv[i], "--raw-js") == 0) { |
189 options.read_raw_js_snippet_ = true; | 158 options.read_raw_js_snippet_ = true; |
190 } else if (strncmp(argv[i], "--pool-type=", 12) == 0) { | |
191 options.const_pool_type_ = ParseConstantPoolType(argv[i] + 12); | |
192 } else if (strcmp(argv[i], "--stdin") == 0) { | 159 } else if (strcmp(argv[i], "--stdin") == 0) { |
193 options.read_from_stdin_ = true; | 160 options.read_from_stdin_ = true; |
194 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 161 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
195 options.rebaseline_ = true; | 162 options.rebaseline_ = true; |
196 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 163 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
197 options.wrap_ = false; | 164 options.wrap_ = false; |
198 } else if (strcmp(argv[i], "--no-execute") == 0) { | 165 } else if (strcmp(argv[i], "--no-execute") == 0) { |
199 options.execute_ = false; | 166 options.execute_ = false; |
200 } else if (strcmp(argv[i], "--top-level") == 0) { | 167 } else if (strcmp(argv[i], "--top-level") == 0) { |
201 options.top_level_ = true; | 168 options.top_level_ = true; |
(...skipping 29 matching lines...) Expand all Loading... | |
231 #endif | 198 #endif |
232 } | 199 } |
233 | 200 |
234 return options; | 201 return options; |
235 } | 202 } |
236 | 203 |
237 bool ProgramOptions::Validate() const { | 204 bool ProgramOptions::Validate() const { |
238 if (parsing_failed_) return false; | 205 if (parsing_failed_) return false; |
239 if (print_help_) return true; | 206 if (print_help_) return true; |
240 | 207 |
241 if (const_pool_type_ == | |
242 BytecodeExpectationsPrinter::ConstantPoolType::kUnknown) { | |
243 REPORT_ERROR("Unknown constant pool type."); | |
244 return false; | |
245 } | |
246 | |
247 if (!read_from_stdin_ && input_filenames_.empty()) { | 208 if (!read_from_stdin_ && input_filenames_.empty()) { |
248 REPORT_ERROR("No input file specified."); | 209 REPORT_ERROR("No input file specified."); |
249 return false; | 210 return false; |
250 } | 211 } |
251 | 212 |
252 if (read_from_stdin_ && !input_filenames_.empty()) { | 213 if (read_from_stdin_ && !input_filenames_.empty()) { |
253 REPORT_ERROR("Reading from stdin, but input files supplied."); | 214 REPORT_ERROR("Reading from stdin, but input files supplied."); |
254 return false; | 215 return false; |
255 } | 216 } |
256 | 217 |
(...skipping 30 matching lines...) Expand all Loading... | |
287 void ProgramOptions::UpdateFromHeader(std::istream& stream) { | 248 void ProgramOptions::UpdateFromHeader(std::istream& stream) { |
288 std::string line; | 249 std::string line; |
289 | 250 |
290 // Skip to the beginning of the options header | 251 // Skip to the beginning of the options header |
291 while (std::getline(stream, line)) { | 252 while (std::getline(stream, line)) { |
292 if (line == "---") break; | 253 if (line == "---") break; |
293 } | 254 } |
294 | 255 |
295 while (std::getline(stream, line)) { | 256 while (std::getline(stream, line)) { |
296 if (line.compare(0, 11, "pool type: ") == 0) { | 257 if (line.compare(0, 11, "pool type: ") == 0) { |
297 const_pool_type_ = ParseConstantPoolType(line.c_str() + 11); | 258 REPORT_WARNING("Pool types are deprecated"); |
rmcilroy
2016/09/06 15:28:57
Just drop this branch entirely - there shouldn't b
| |
298 } else if (line.compare(0, 9, "execute: ") == 0) { | 259 } else if (line.compare(0, 9, "execute: ") == 0) { |
299 execute_ = ParseBoolean(line.c_str() + 9); | 260 execute_ = ParseBoolean(line.c_str() + 9); |
300 } else if (line.compare(0, 6, "wrap: ") == 0) { | 261 } else if (line.compare(0, 6, "wrap: ") == 0) { |
301 wrap_ = ParseBoolean(line.c_str() + 6); | 262 wrap_ = ParseBoolean(line.c_str() + 6); |
302 } else if (line.compare(0, 20, "test function name: ") == 0) { | 263 } else if (line.compare(0, 20, "test function name: ") == 0) { |
303 test_function_name_ = line.c_str() + 20; | 264 test_function_name_ = line.c_str() + 20; |
304 } else if (line.compare(0, 11, "top level: ") == 0) { | 265 } else if (line.compare(0, 11, "top level: ") == 0) { |
305 top_level_ = ParseBoolean(line.c_str() + 11); | 266 top_level_ = ParseBoolean(line.c_str() + 11); |
306 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 267 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
307 do_expressions_ = ParseBoolean(line.c_str() + 16); | 268 do_expressions_ = ParseBoolean(line.c_str() + 16); |
308 } else if (line == "---") { | 269 } else if (line == "---") { |
309 break; | 270 break; |
310 } else if (line.empty()) { | 271 } else if (line.empty()) { |
311 continue; | 272 continue; |
312 } else { | 273 } else { |
313 UNREACHABLE(); | 274 UNREACHABLE(); |
314 return; | 275 return; |
315 } | 276 } |
316 } | 277 } |
317 } | 278 } |
318 | 279 |
319 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 280 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
320 stream << "---" | 281 stream << "---" |
321 "\npool type: " | |
322 << ConstantPoolTypeToString(const_pool_type_) | |
323 << "\nexecute: " << BooleanToString(execute_) | 282 << "\nexecute: " << BooleanToString(execute_) |
324 << "\nwrap: " << BooleanToString(wrap_); | 283 << "\nwrap: " << BooleanToString(wrap_); |
325 | 284 |
326 if (!test_function_name_.empty()) { | 285 if (!test_function_name_.empty()) { |
327 stream << "\ntest function name: " << test_function_name_; | 286 stream << "\ntest function name: " << test_function_name_; |
328 } | 287 } |
329 | 288 |
330 if (top_level_) stream << "\ntop level: yes"; | 289 if (top_level_) stream << "\ntop level: yes"; |
331 if (do_expressions_) stream << "\ndo expressions: yes"; | 290 if (do_expressions_) stream << "\ndo expressions: yes"; |
332 | 291 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 376 |
418 void GenerateExpectationsFile(std::ostream& stream, // NOLINT | 377 void GenerateExpectationsFile(std::ostream& stream, // NOLINT |
419 const std::vector<std::string>& snippet_list, | 378 const std::vector<std::string>& snippet_list, |
420 const V8InitializationScope& platform, | 379 const V8InitializationScope& platform, |
421 const ProgramOptions& options) { | 380 const ProgramOptions& options) { |
422 v8::Isolate::Scope isolate_scope(platform.isolate()); | 381 v8::Isolate::Scope isolate_scope(platform.isolate()); |
423 v8::HandleScope handle_scope(platform.isolate()); | 382 v8::HandleScope handle_scope(platform.isolate()); |
424 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); | 383 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); |
425 v8::Context::Scope context_scope(context); | 384 v8::Context::Scope context_scope(context); |
426 | 385 |
427 BytecodeExpectationsPrinter printer(platform.isolate(), | 386 BytecodeExpectationsPrinter printer(platform.isolate()); |
428 options.const_pool_type()); | |
429 printer.set_wrap(options.wrap()); | 387 printer.set_wrap(options.wrap()); |
430 printer.set_execute(options.execute()); | 388 printer.set_execute(options.execute()); |
431 printer.set_top_level(options.top_level()); | 389 printer.set_top_level(options.top_level()); |
432 if (!options.test_function_name().empty()) { | 390 if (!options.test_function_name().empty()) { |
433 printer.set_test_function_name(options.test_function_name()); | 391 printer.set_test_function_name(options.test_function_name()); |
434 } | 392 } |
435 | 393 |
436 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 394 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
437 | 395 |
438 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 396 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 } | 512 } |
555 } | 513 } |
556 | 514 |
557 if (!options.rebaseline()) { | 515 if (!options.rebaseline()) { |
558 if (!WriteExpectationsFile(snippet_list, platform, options, | 516 if (!WriteExpectationsFile(snippet_list, platform, options, |
559 options.output_filename())) { | 517 options.output_filename())) { |
560 return 3; | 518 return 3; |
561 } | 519 } |
562 } | 520 } |
563 } | 521 } |
OLD | NEW |