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 verbose_(false), | 46 verbose_(false) {} |
47 const_pool_type_( | |
48 BytecodeExpectationsPrinter::ConstantPoolType::kMixed) {} | |
49 | 47 |
50 bool Validate() const; | 48 bool Validate() const; |
51 void UpdateFromHeader(std::istream& stream); // NOLINT | 49 void UpdateFromHeader(std::istream& stream); // NOLINT |
52 void PrintHeader(std::ostream& stream) const; // NOLINT | 50 void PrintHeader(std::ostream& stream) const; // NOLINT |
53 | 51 |
54 bool parsing_failed() const { return parsing_failed_; } | 52 bool parsing_failed() const { return parsing_failed_; } |
55 bool print_help() const { return print_help_; } | 53 bool print_help() const { return print_help_; } |
56 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } | 54 bool read_raw_js_snippet() const { return read_raw_js_snippet_; } |
57 bool read_from_stdin() const { return read_from_stdin_; } | 55 bool read_from_stdin() const { return read_from_stdin_; } |
58 bool write_to_stdout() const { | 56 bool write_to_stdout() const { |
59 return output_filename_.empty() && !rebaseline_; | 57 return output_filename_.empty() && !rebaseline_; |
60 } | 58 } |
61 bool rebaseline() const { return rebaseline_; } | 59 bool rebaseline() const { return rebaseline_; } |
62 bool wrap() const { return wrap_; } | 60 bool wrap() const { return wrap_; } |
63 bool execute() const { return execute_; } | 61 bool execute() const { return execute_; } |
64 bool top_level() const { return top_level_; } | 62 bool top_level() const { return top_level_; } |
65 bool do_expressions() const { return do_expressions_; } | 63 bool do_expressions() const { return do_expressions_; } |
66 bool verbose() const { return verbose_; } | 64 bool verbose() const { return verbose_; } |
67 bool suppress_runtime_errors() const { return rebaseline_ && !verbose_; } | 65 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_; } | 66 std::vector<std::string> input_filenames() const { return input_filenames_; } |
72 std::string output_filename() const { return output_filename_; } | 67 std::string output_filename() const { return output_filename_; } |
73 std::string test_function_name() const { return test_function_name_; } | 68 std::string test_function_name() const { return test_function_name_; } |
74 | 69 |
75 private: | 70 private: |
76 bool parsing_failed_; | 71 bool parsing_failed_; |
77 bool print_help_; | 72 bool print_help_; |
78 bool read_raw_js_snippet_; | 73 bool read_raw_js_snippet_; |
79 bool read_from_stdin_; | 74 bool read_from_stdin_; |
80 bool rebaseline_; | 75 bool rebaseline_; |
81 bool wrap_; | 76 bool wrap_; |
82 bool execute_; | 77 bool execute_; |
83 bool top_level_; | 78 bool top_level_; |
84 bool do_expressions_; | 79 bool do_expressions_; |
85 bool verbose_; | 80 bool verbose_; |
86 BytecodeExpectationsPrinter::ConstantPoolType const_pool_type_; | |
87 std::vector<std::string> input_filenames_; | 81 std::vector<std::string> input_filenames_; |
88 std::string output_filename_; | 82 std::string output_filename_; |
89 std::string test_function_name_; | 83 std::string test_function_name_; |
90 }; | 84 }; |
91 | 85 |
92 class V8InitializationScope final { | 86 class V8InitializationScope final { |
93 public: | 87 public: |
94 explicit V8InitializationScope(const char* exec_path); | 88 explicit V8InitializationScope(const char* exec_path); |
95 ~V8InitializationScope(); | 89 ~V8InitializationScope(); |
96 | 90 |
97 v8::Platform* platform() const { return platform_.get(); } | 91 v8::Platform* platform() const { return platform_.get(); } |
98 v8::Isolate* isolate() const { return isolate_; } | 92 v8::Isolate* isolate() const { return isolate_; } |
99 | 93 |
100 private: | 94 private: |
101 std::unique_ptr<v8::Platform> platform_; | 95 std::unique_ptr<v8::Platform> platform_; |
102 std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_; | 96 std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_; |
103 v8::Isolate* isolate_; | 97 v8::Isolate* isolate_; |
104 | 98 |
105 DISALLOW_COPY_AND_ASSIGN(V8InitializationScope); | 99 DISALLOW_COPY_AND_ASSIGN(V8InitializationScope); |
106 }; | 100 }; |
107 | 101 |
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) { | 102 bool ParseBoolean(const char* string) { |
136 if (strcmp(string, "yes") == 0) { | 103 if (strcmp(string, "yes") == 0) { |
137 return true; | 104 return true; |
138 } else if (strcmp(string, "no") == 0) { | 105 } else if (strcmp(string, "no") == 0) { |
139 return false; | 106 return false; |
140 } else { | 107 } else { |
141 UNREACHABLE(); | 108 UNREACHABLE(); |
142 return false; | 109 return false; |
143 } | 110 } |
144 } | 111 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 147 |
181 // static | 148 // static |
182 ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) { | 149 ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) { |
183 ProgramOptions options; | 150 ProgramOptions options; |
184 | 151 |
185 for (int i = 1; i < argc; ++i) { | 152 for (int i = 1; i < argc; ++i) { |
186 if (strcmp(argv[i], "--help") == 0) { | 153 if (strcmp(argv[i], "--help") == 0) { |
187 options.print_help_ = true; | 154 options.print_help_ = true; |
188 } else if (strcmp(argv[i], "--raw-js") == 0) { | 155 } else if (strcmp(argv[i], "--raw-js") == 0) { |
189 options.read_raw_js_snippet_ = true; | 156 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) { | 157 } else if (strcmp(argv[i], "--stdin") == 0) { |
193 options.read_from_stdin_ = true; | 158 options.read_from_stdin_ = true; |
194 } else if (strcmp(argv[i], "--rebaseline") == 0) { | 159 } else if (strcmp(argv[i], "--rebaseline") == 0) { |
195 options.rebaseline_ = true; | 160 options.rebaseline_ = true; |
196 } else if (strcmp(argv[i], "--no-wrap") == 0) { | 161 } else if (strcmp(argv[i], "--no-wrap") == 0) { |
197 options.wrap_ = false; | 162 options.wrap_ = false; |
198 } else if (strcmp(argv[i], "--no-execute") == 0) { | 163 } else if (strcmp(argv[i], "--no-execute") == 0) { |
199 options.execute_ = false; | 164 options.execute_ = false; |
200 } else if (strcmp(argv[i], "--top-level") == 0) { | 165 } else if (strcmp(argv[i], "--top-level") == 0) { |
201 options.top_level_ = true; | 166 options.top_level_ = true; |
(...skipping 29 matching lines...) Expand all Loading... |
231 #endif | 196 #endif |
232 } | 197 } |
233 | 198 |
234 return options; | 199 return options; |
235 } | 200 } |
236 | 201 |
237 bool ProgramOptions::Validate() const { | 202 bool ProgramOptions::Validate() const { |
238 if (parsing_failed_) return false; | 203 if (parsing_failed_) return false; |
239 if (print_help_) return true; | 204 if (print_help_) return true; |
240 | 205 |
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()) { | 206 if (!read_from_stdin_ && input_filenames_.empty()) { |
248 REPORT_ERROR("No input file specified."); | 207 REPORT_ERROR("No input file specified."); |
249 return false; | 208 return false; |
250 } | 209 } |
251 | 210 |
252 if (read_from_stdin_ && !input_filenames_.empty()) { | 211 if (read_from_stdin_ && !input_filenames_.empty()) { |
253 REPORT_ERROR("Reading from stdin, but input files supplied."); | 212 REPORT_ERROR("Reading from stdin, but input files supplied."); |
254 return false; | 213 return false; |
255 } | 214 } |
256 | 215 |
(...skipping 29 matching lines...) Expand all Loading... |
286 | 245 |
287 void ProgramOptions::UpdateFromHeader(std::istream& stream) { | 246 void ProgramOptions::UpdateFromHeader(std::istream& stream) { |
288 std::string line; | 247 std::string line; |
289 | 248 |
290 // Skip to the beginning of the options header | 249 // Skip to the beginning of the options header |
291 while (std::getline(stream, line)) { | 250 while (std::getline(stream, line)) { |
292 if (line == "---") break; | 251 if (line == "---") break; |
293 } | 252 } |
294 | 253 |
295 while (std::getline(stream, line)) { | 254 while (std::getline(stream, line)) { |
296 if (line.compare(0, 11, "pool type: ") == 0) { | 255 if (line.compare(0, 9, "execute: ") == 0) { |
297 const_pool_type_ = ParseConstantPoolType(line.c_str() + 11); | |
298 } else if (line.compare(0, 9, "execute: ") == 0) { | |
299 execute_ = ParseBoolean(line.c_str() + 9); | 256 execute_ = ParseBoolean(line.c_str() + 9); |
300 } else if (line.compare(0, 6, "wrap: ") == 0) { | 257 } else if (line.compare(0, 6, "wrap: ") == 0) { |
301 wrap_ = ParseBoolean(line.c_str() + 6); | 258 wrap_ = ParseBoolean(line.c_str() + 6); |
302 } else if (line.compare(0, 20, "test function name: ") == 0) { | 259 } else if (line.compare(0, 20, "test function name: ") == 0) { |
303 test_function_name_ = line.c_str() + 20; | 260 test_function_name_ = line.c_str() + 20; |
304 } else if (line.compare(0, 11, "top level: ") == 0) { | 261 } else if (line.compare(0, 11, "top level: ") == 0) { |
305 top_level_ = ParseBoolean(line.c_str() + 11); | 262 top_level_ = ParseBoolean(line.c_str() + 11); |
306 } else if (line.compare(0, 16, "do expressions: ") == 0) { | 263 } else if (line.compare(0, 16, "do expressions: ") == 0) { |
307 do_expressions_ = ParseBoolean(line.c_str() + 16); | 264 do_expressions_ = ParseBoolean(line.c_str() + 16); |
308 } else if (line == "---") { | 265 } else if (line == "---") { |
309 break; | 266 break; |
310 } else if (line.empty()) { | 267 } else if (line.empty()) { |
311 continue; | 268 continue; |
312 } else { | 269 } else { |
313 UNREACHABLE(); | 270 UNREACHABLE(); |
314 return; | 271 return; |
315 } | 272 } |
316 } | 273 } |
317 } | 274 } |
318 | 275 |
319 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT | 276 void ProgramOptions::PrintHeader(std::ostream& stream) const { // NOLINT |
320 stream << "---" | 277 stream << "---" |
321 "\npool type: " | |
322 << ConstantPoolTypeToString(const_pool_type_) | |
323 << "\nexecute: " << BooleanToString(execute_) | 278 << "\nexecute: " << BooleanToString(execute_) |
324 << "\nwrap: " << BooleanToString(wrap_); | 279 << "\nwrap: " << BooleanToString(wrap_); |
325 | 280 |
326 if (!test_function_name_.empty()) { | 281 if (!test_function_name_.empty()) { |
327 stream << "\ntest function name: " << test_function_name_; | 282 stream << "\ntest function name: " << test_function_name_; |
328 } | 283 } |
329 | 284 |
330 if (top_level_) stream << "\ntop level: yes"; | 285 if (top_level_) stream << "\ntop level: yes"; |
331 if (do_expressions_) stream << "\ndo expressions: yes"; | 286 if (do_expressions_) stream << "\ndo expressions: yes"; |
332 | 287 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 372 |
418 void GenerateExpectationsFile(std::ostream& stream, // NOLINT | 373 void GenerateExpectationsFile(std::ostream& stream, // NOLINT |
419 const std::vector<std::string>& snippet_list, | 374 const std::vector<std::string>& snippet_list, |
420 const V8InitializationScope& platform, | 375 const V8InitializationScope& platform, |
421 const ProgramOptions& options) { | 376 const ProgramOptions& options) { |
422 v8::Isolate::Scope isolate_scope(platform.isolate()); | 377 v8::Isolate::Scope isolate_scope(platform.isolate()); |
423 v8::HandleScope handle_scope(platform.isolate()); | 378 v8::HandleScope handle_scope(platform.isolate()); |
424 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); | 379 v8::Local<v8::Context> context = v8::Context::New(platform.isolate()); |
425 v8::Context::Scope context_scope(context); | 380 v8::Context::Scope context_scope(context); |
426 | 381 |
427 BytecodeExpectationsPrinter printer(platform.isolate(), | 382 BytecodeExpectationsPrinter printer(platform.isolate()); |
428 options.const_pool_type()); | |
429 printer.set_wrap(options.wrap()); | 383 printer.set_wrap(options.wrap()); |
430 printer.set_execute(options.execute()); | 384 printer.set_execute(options.execute()); |
431 printer.set_top_level(options.top_level()); | 385 printer.set_top_level(options.top_level()); |
432 if (!options.test_function_name().empty()) { | 386 if (!options.test_function_name().empty()) { |
433 printer.set_test_function_name(options.test_function_name()); | 387 printer.set_test_function_name(options.test_function_name()); |
434 } | 388 } |
435 | 389 |
436 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; | 390 if (options.do_expressions()) i::FLAG_harmony_do_expressions = true; |
437 | 391 |
438 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; | 392 stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n"; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 508 } |
555 } | 509 } |
556 | 510 |
557 if (!options.rebaseline()) { | 511 if (!options.rebaseline()) { |
558 if (!WriteExpectationsFile(snippet_list, platform, options, | 512 if (!WriteExpectationsFile(snippet_list, platform, options, |
559 options.output_filename())) { | 513 options.output_filename())) { |
560 return 3; | 514 return 3; |
561 } | 515 } |
562 } | 516 } |
563 } | 517 } |
OLD | NEW |