2016-02-10 11:26:14 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
#include <algorithm>
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
#include <cstring>
|
2016-02-10 11:26:14 +00:00
|
|
|
#include <fstream>
|
2016-07-25 11:12:42 +00:00
|
|
|
#include <memory>
|
2019-07-19 09:38:43 +00:00
|
|
|
#include <sstream>
|
2016-02-26 12:04:03 +00:00
|
|
|
#include <vector>
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
|
2016-02-10 11:26:14 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "include/v8-array-buffer.h"
|
|
|
|
#include "include/v8-context.h"
|
|
|
|
#include "include/v8-initialization.h"
|
|
|
|
#include "include/v8-local-handle.h"
|
|
|
|
#include "include/v8-message.h"
|
2016-02-10 11:26:14 +00:00
|
|
|
#include "src/base/logging.h"
|
|
|
|
#include "src/interpreter/interpreter.h"
|
2021-08-23 13:01:06 +00:00
|
|
|
#include "test/cctest/interpreter/bytecode-expectations-printer.h"
|
2016-02-10 11:26:14 +00:00
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
#ifdef V8_OS_POSIX
|
|
|
|
#include <dirent.h>
|
2021-07-27 15:35:59 +00:00
|
|
|
#elif V8_OS_WIN
|
|
|
|
#include <windows.h>
|
2016-02-26 12:04:03 +00:00
|
|
|
#endif
|
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
using v8::internal::interpreter::BytecodeExpectationsPrinter;
|
2016-02-10 11:26:14 +00:00
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
#define REPORT_ERROR(MESSAGE) (((std::cerr << "ERROR: ") << MESSAGE) << '\n')
|
|
|
|
|
2016-02-10 11:26:14 +00:00
|
|
|
namespace {
|
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
const char* kGoldenFilesPath = "test/cctest/interpreter/bytecode_expectations/";
|
|
|
|
|
2016-02-19 12:36:26 +00:00
|
|
|
class ProgramOptions final {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
public:
|
|
|
|
static ProgramOptions FromCommandLine(int argc, char** argv);
|
|
|
|
|
|
|
|
ProgramOptions()
|
|
|
|
: parsing_failed_(false),
|
|
|
|
print_help_(false),
|
|
|
|
read_raw_js_snippet_(false),
|
|
|
|
read_from_stdin_(false),
|
2016-02-19 12:36:26 +00:00
|
|
|
rebaseline_(false),
|
2019-07-19 09:38:43 +00:00
|
|
|
check_baseline_(false),
|
2016-02-19 12:36:26 +00:00
|
|
|
wrap_(true),
|
2016-10-04 18:42:13 +00:00
|
|
|
module_(false),
|
2016-02-19 12:36:26 +00:00
|
|
|
top_level_(false),
|
2018-08-07 13:14:23 +00:00
|
|
|
print_callee_(false),
|
2017-02-24 17:48:49 +00:00
|
|
|
async_iteration_(false),
|
2016-09-06 16:10:19 +00:00
|
|
|
verbose_(false) {}
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
|
|
|
|
bool Validate() const;
|
2019-09-10 01:19:59 +00:00
|
|
|
void UpdateFromHeader(std::istream* stream);
|
|
|
|
void PrintHeader(std::ostream* stream) const;
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
|
|
|
|
bool parsing_failed() const { return parsing_failed_; }
|
|
|
|
bool print_help() const { return print_help_; }
|
|
|
|
bool read_raw_js_snippet() const { return read_raw_js_snippet_; }
|
|
|
|
bool read_from_stdin() const { return read_from_stdin_; }
|
2016-02-19 12:36:26 +00:00
|
|
|
bool write_to_stdout() const {
|
|
|
|
return output_filename_.empty() && !rebaseline_;
|
|
|
|
}
|
|
|
|
bool rebaseline() const { return rebaseline_; }
|
2019-07-19 09:38:43 +00:00
|
|
|
bool check_baseline() const { return check_baseline_; }
|
|
|
|
bool baseline() const { return rebaseline_ || check_baseline_; }
|
2016-02-19 12:36:26 +00:00
|
|
|
bool wrap() const { return wrap_; }
|
2016-10-04 18:42:13 +00:00
|
|
|
bool module() const { return module_; }
|
2016-02-19 12:36:26 +00:00
|
|
|
bool top_level() const { return top_level_; }
|
2018-08-07 13:14:23 +00:00
|
|
|
bool print_callee() const { return print_callee_; }
|
2017-02-24 17:48:49 +00:00
|
|
|
bool async_iteration() const { return async_iteration_; }
|
2016-02-26 12:04:03 +00:00
|
|
|
bool verbose() const { return verbose_; }
|
2019-07-19 09:38:43 +00:00
|
|
|
bool suppress_runtime_errors() const { return baseline() && !verbose_; }
|
2016-02-26 12:04:03 +00:00
|
|
|
std::vector<std::string> input_filenames() const { return input_filenames_; }
|
2016-02-19 12:36:26 +00:00
|
|
|
std::string output_filename() const { return output_filename_; }
|
|
|
|
std::string test_function_name() const { return test_function_name_; }
|
2016-02-10 11:26:14 +00:00
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
private:
|
|
|
|
bool parsing_failed_;
|
|
|
|
bool print_help_;
|
|
|
|
bool read_raw_js_snippet_;
|
|
|
|
bool read_from_stdin_;
|
2016-02-19 12:36:26 +00:00
|
|
|
bool rebaseline_;
|
2019-07-19 09:38:43 +00:00
|
|
|
bool check_baseline_;
|
2016-02-19 12:36:26 +00:00
|
|
|
bool wrap_;
|
2016-10-04 18:42:13 +00:00
|
|
|
bool module_;
|
2016-02-19 12:36:26 +00:00
|
|
|
bool top_level_;
|
2018-08-07 13:14:23 +00:00
|
|
|
bool print_callee_;
|
2017-02-24 17:48:49 +00:00
|
|
|
bool async_iteration_;
|
2016-02-26 12:04:03 +00:00
|
|
|
bool verbose_;
|
|
|
|
std::vector<std::string> input_filenames_;
|
2016-02-19 12:36:26 +00:00
|
|
|
std::string output_filename_;
|
|
|
|
std::string test_function_name_;
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
};
|
|
|
|
|
2020-11-26 10:08:27 +00:00
|
|
|
class V8_NODISCARD V8InitializationScope final {
|
2016-02-10 11:26:14 +00:00
|
|
|
public:
|
|
|
|
explicit V8InitializationScope(const char* exec_path);
|
|
|
|
~V8InitializationScope();
|
2020-11-06 02:39:19 +00:00
|
|
|
V8InitializationScope(const V8InitializationScope&) = delete;
|
|
|
|
V8InitializationScope& operator=(const V8InitializationScope&) = delete;
|
2016-02-10 11:26:14 +00:00
|
|
|
|
|
|
|
v8::Platform* platform() const { return platform_.get(); }
|
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
|
|
|
|
private:
|
2016-07-25 11:12:42 +00:00
|
|
|
std::unique_ptr<v8::Platform> platform_;
|
|
|
|
std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_;
|
2016-02-10 11:26:14 +00:00
|
|
|
v8::Isolate* isolate_;
|
|
|
|
};
|
|
|
|
|
2016-02-19 12:36:26 +00:00
|
|
|
bool ParseBoolean(const char* string) {
|
|
|
|
if (strcmp(string, "yes") == 0) {
|
|
|
|
return true;
|
|
|
|
} else if (strcmp(string, "no") == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* BooleanToString(bool value) { return value ? "yes" : "no"; }
|
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
bool CollectGoldenFiles(std::vector<std::string>* golden_file_list,
|
|
|
|
const char* directory_path) {
|
2019-02-04 18:50:09 +00:00
|
|
|
#ifdef V8_OS_POSIX
|
2016-02-26 12:04:03 +00:00
|
|
|
DIR* directory = opendir(directory_path);
|
|
|
|
if (!directory) return false;
|
|
|
|
|
2019-02-04 18:50:09 +00:00
|
|
|
auto str_ends_with = [](const char* string, const char* suffix) {
|
2019-04-29 14:56:08 +00:00
|
|
|
size_t string_size = strlen(string);
|
|
|
|
size_t suffix_size = strlen(suffix);
|
2019-02-04 18:50:09 +00:00
|
|
|
if (string_size < suffix_size) return false;
|
|
|
|
|
|
|
|
return strcmp(string + (string_size - suffix_size), suffix) == 0;
|
|
|
|
};
|
|
|
|
|
2016-09-30 11:05:17 +00:00
|
|
|
dirent* entry = readdir(directory);
|
|
|
|
while (entry) {
|
2019-02-04 18:50:09 +00:00
|
|
|
if (str_ends_with(entry->d_name, ".golden")) {
|
2016-02-26 12:04:03 +00:00
|
|
|
std::string golden_filename(kGoldenFilesPath);
|
|
|
|
golden_filename += entry->d_name;
|
|
|
|
golden_file_list->push_back(golden_filename);
|
|
|
|
}
|
2016-09-30 11:05:17 +00:00
|
|
|
entry = readdir(directory);
|
2016-02-26 12:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(directory);
|
2019-02-04 18:50:09 +00:00
|
|
|
#elif V8_OS_WIN
|
|
|
|
std::string search_path(directory_path + std::string("/*.golden"));
|
|
|
|
WIN32_FIND_DATAA fd;
|
|
|
|
HANDLE find_handle = FindFirstFileA(search_path.c_str(), &fd);
|
|
|
|
if (find_handle == INVALID_HANDLE_VALUE) return false;
|
|
|
|
do {
|
|
|
|
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
|
|
std::string golden_filename(kGoldenFilesPath);
|
|
|
|
std::string temp_filename(fd.cFileName);
|
|
|
|
golden_filename += temp_filename;
|
|
|
|
golden_file_list->push_back(golden_filename);
|
|
|
|
}
|
|
|
|
} while (FindNextFileA(find_handle, &fd));
|
|
|
|
FindClose(find_handle);
|
|
|
|
#endif // V8_OS_POSIX
|
2016-02-26 12:04:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
// static
|
|
|
|
ProgramOptions ProgramOptions::FromCommandLine(int argc, char** argv) {
|
|
|
|
ProgramOptions options;
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
if (strcmp(argv[i], "--help") == 0) {
|
|
|
|
options.print_help_ = true;
|
|
|
|
} else if (strcmp(argv[i], "--raw-js") == 0) {
|
|
|
|
options.read_raw_js_snippet_ = true;
|
|
|
|
} else if (strcmp(argv[i], "--stdin") == 0) {
|
|
|
|
options.read_from_stdin_ = true;
|
2016-02-19 12:36:26 +00:00
|
|
|
} else if (strcmp(argv[i], "--rebaseline") == 0) {
|
|
|
|
options.rebaseline_ = true;
|
2019-07-19 09:38:43 +00:00
|
|
|
} else if (strcmp(argv[i], "--check-baseline") == 0) {
|
|
|
|
options.check_baseline_ = true;
|
2016-02-19 12:36:26 +00:00
|
|
|
} else if (strcmp(argv[i], "--no-wrap") == 0) {
|
|
|
|
options.wrap_ = false;
|
2016-10-04 18:42:13 +00:00
|
|
|
} else if (strcmp(argv[i], "--module") == 0) {
|
|
|
|
options.module_ = true;
|
2016-02-19 12:36:26 +00:00
|
|
|
} else if (strcmp(argv[i], "--top-level") == 0) {
|
|
|
|
options.top_level_ = true;
|
2018-08-07 13:14:23 +00:00
|
|
|
} else if (strcmp(argv[i], "--print-callee") == 0) {
|
|
|
|
options.print_callee_ = true;
|
2017-02-24 17:48:49 +00:00
|
|
|
} else if (strcmp(argv[i], "--async-iteration") == 0) {
|
|
|
|
options.async_iteration_ = true;
|
2016-02-26 12:04:03 +00:00
|
|
|
} else if (strcmp(argv[i], "--verbose") == 0) {
|
|
|
|
options.verbose_ = true;
|
2016-02-19 12:36:26 +00:00
|
|
|
} else if (strncmp(argv[i], "--output=", 9) == 0) {
|
|
|
|
options.output_filename_ = argv[i] + 9;
|
|
|
|
} else if (strncmp(argv[i], "--test-function-name=", 21) == 0) {
|
|
|
|
options.test_function_name_ = argv[i] + 21;
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
} else if (strncmp(argv[i], "--", 2) != 0) { // It doesn't start with --
|
2016-02-26 12:04:03 +00:00
|
|
|
options.input_filenames_.push_back(argv[i]);
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
} else {
|
2016-03-16 14:41:05 +00:00
|
|
|
REPORT_ERROR("Unknown option " << argv[i]);
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
options.parsing_failed_ = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (options.rebaseline() && options.check_baseline()) {
|
|
|
|
REPORT_ERROR("Can't check baseline and rebaseline at the same time.");
|
|
|
|
std::exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((options.check_baseline_ || options.rebaseline_) &&
|
|
|
|
options.input_filenames_.empty()) {
|
2019-02-04 18:50:09 +00:00
|
|
|
#if defined(V8_OS_POSIX) || defined(V8_OS_WIN)
|
2016-02-26 12:04:03 +00:00
|
|
|
if (options.verbose_) {
|
|
|
|
std::cout << "Looking for golden files in " << kGoldenFilesPath << '\n';
|
|
|
|
}
|
|
|
|
if (!CollectGoldenFiles(&options.input_filenames_, kGoldenFilesPath)) {
|
|
|
|
REPORT_ERROR("Golden files autodiscovery failed.");
|
|
|
|
options.parsing_failed_ = true;
|
|
|
|
}
|
|
|
|
#else
|
2019-02-04 18:50:09 +00:00
|
|
|
REPORT_ERROR(
|
|
|
|
"Golden files autodiscovery requires a POSIX or Window OS, sorry.");
|
2016-02-26 12:04:03 +00:00
|
|
|
options.parsing_failed_ = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ProgramOptions::Validate() const {
|
|
|
|
if (parsing_failed_) return false;
|
|
|
|
if (print_help_) return true;
|
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
if (!read_from_stdin_ && input_filenames_.empty()) {
|
|
|
|
REPORT_ERROR("No input file specified.");
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
if (read_from_stdin_ && !input_filenames_.empty()) {
|
|
|
|
REPORT_ERROR("Reading from stdin, but input files supplied.");
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (baseline() && read_raw_js_snippet_) {
|
|
|
|
REPORT_ERROR(
|
|
|
|
"Cannot use --rebaseline or --check-baseline on a raw JS snippet.");
|
2016-02-26 12:04:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (baseline() && !output_filename_.empty()) {
|
|
|
|
REPORT_ERROR(
|
|
|
|
"Output file cannot be specified together with --rebaseline or "
|
|
|
|
"--check-baseline.");
|
2016-02-26 12:04:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (baseline() && read_from_stdin_) {
|
|
|
|
REPORT_ERROR(
|
|
|
|
"Cannot --rebaseline or --check-baseline when input is --stdin.");
|
2016-02-26 12:04:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (input_filenames_.size() > 1 && !baseline() && !read_raw_js_snippet()) {
|
2016-02-26 12:04:03 +00:00
|
|
|
REPORT_ERROR(
|
2019-07-19 09:38:43 +00:00
|
|
|
"Multiple input files, but no --rebaseline, --check-baseline or "
|
|
|
|
"--raw-js specified.");
|
2016-02-19 12:36:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (top_level_ && !test_function_name_.empty()) {
|
2016-02-26 12:04:03 +00:00
|
|
|
REPORT_ERROR(
|
|
|
|
"Test function name specified while processing top level code.");
|
2016-02-19 12:36:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-04 18:42:13 +00:00
|
|
|
if (module_ && (!top_level_ || wrap_)) {
|
|
|
|
REPORT_ERROR(
|
|
|
|
"The flag --module currently requires --top-level and --no-wrap.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return true;
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void ProgramOptions::UpdateFromHeader(std::istream* stream) {
|
2016-02-19 12:36:26 +00:00
|
|
|
std::string line;
|
2018-08-07 13:14:23 +00:00
|
|
|
const char* kPrintCallee = "print callee: ";
|
2016-02-19 12:36:26 +00:00
|
|
|
|
|
|
|
// Skip to the beginning of the options header
|
2019-09-10 01:19:59 +00:00
|
|
|
while (std::getline(*stream, line)) {
|
2016-02-19 12:36:26 +00:00
|
|
|
if (line == "---") break;
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
while (std::getline(*stream, line)) {
|
2016-10-04 18:42:13 +00:00
|
|
|
if (line.compare(0, 8, "module: ") == 0) {
|
|
|
|
module_ = ParseBoolean(line.c_str() + 8);
|
|
|
|
} else if (line.compare(0, 6, "wrap: ") == 0) {
|
2016-02-19 12:36:26 +00:00
|
|
|
wrap_ = ParseBoolean(line.c_str() + 6);
|
|
|
|
} else if (line.compare(0, 20, "test function name: ") == 0) {
|
|
|
|
test_function_name_ = line.c_str() + 20;
|
|
|
|
} else if (line.compare(0, 11, "top level: ") == 0) {
|
|
|
|
top_level_ = ParseBoolean(line.c_str() + 11);
|
2018-08-07 13:14:23 +00:00
|
|
|
} else if (line.compare(0, strlen(kPrintCallee), kPrintCallee) == 0) {
|
|
|
|
print_callee_ = ParseBoolean(line.c_str() + strlen(kPrintCallee));
|
2017-02-24 17:48:49 +00:00
|
|
|
} else if (line.compare(0, 17, "async iteration: ") == 0) {
|
|
|
|
async_iteration_ = ParseBoolean(line.c_str() + 17);
|
2016-02-19 12:36:26 +00:00
|
|
|
} else if (line == "---") {
|
|
|
|
break;
|
|
|
|
} else if (line.empty()) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void ProgramOptions::PrintHeader(std::ostream* stream) const {
|
|
|
|
*stream << "---"
|
|
|
|
<< "\nwrap: " << BooleanToString(wrap_);
|
2016-02-19 12:36:26 +00:00
|
|
|
|
|
|
|
if (!test_function_name_.empty()) {
|
2019-09-10 01:19:59 +00:00
|
|
|
*stream << "\ntest function name: " << test_function_name_;
|
2016-02-19 12:36:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
if (module_) *stream << "\nmodule: yes";
|
|
|
|
if (top_level_) *stream << "\ntop level: yes";
|
|
|
|
if (print_callee_) *stream << "\nprint callee: yes";
|
|
|
|
if (async_iteration_) *stream << "\nasync iteration: yes";
|
2016-02-19 12:36:26 +00:00
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
*stream << "\n\n";
|
2016-02-19 12:36:26 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 11:26:14 +00:00
|
|
|
V8InitializationScope::V8InitializationScope(const char* exec_path)
|
2017-11-13 13:16:49 +00:00
|
|
|
: platform_(v8::platform::NewDefaultPlatform()) {
|
2016-02-10 11:26:14 +00:00
|
|
|
i::FLAG_always_opt = false;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2019-07-19 09:38:43 +00:00
|
|
|
i::FLAG_enable_lazy_source_positions = false;
|
2016-02-10 11:26:14 +00:00
|
|
|
|
2016-06-08 12:09:25 +00:00
|
|
|
v8::V8::InitializeICUDefaultLocation(exec_path);
|
2016-02-10 11:26:14 +00:00
|
|
|
v8::V8::InitializeExternalStartupData(exec_path);
|
|
|
|
v8::V8::InitializePlatform(platform_.get());
|
|
|
|
v8::V8::Initialize();
|
|
|
|
|
|
|
|
v8::Isolate::CreateParams create_params;
|
2016-07-25 11:12:42 +00:00
|
|
|
allocator_.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator());
|
2016-06-29 07:39:45 +00:00
|
|
|
create_params.array_buffer_allocator = allocator_.get();
|
2016-02-10 11:26:14 +00:00
|
|
|
|
|
|
|
isolate_ = v8::Isolate::New(create_params);
|
|
|
|
}
|
|
|
|
|
|
|
|
V8InitializationScope::~V8InitializationScope() {
|
|
|
|
isolate_->Dispose();
|
|
|
|
v8::V8::Dispose();
|
2021-11-30 13:38:10 +00:00
|
|
|
v8::V8::DisposePlatform();
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
std::string ReadRawJSSnippet(std::istream* stream) {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
std::stringstream body_buffer;
|
2019-09-10 01:19:59 +00:00
|
|
|
CHECK(body_buffer << stream->rdbuf());
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return body_buffer.str();
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
bool ReadNextSnippet(std::istream* stream, std::string* string_out) {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
std::string line;
|
|
|
|
bool found_begin_snippet = false;
|
|
|
|
string_out->clear();
|
2019-09-10 01:19:59 +00:00
|
|
|
while (std::getline(*stream, line)) {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
if (line == "snippet: \"") {
|
|
|
|
found_begin_snippet = true;
|
|
|
|
continue;
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
if (!found_begin_snippet) continue;
|
|
|
|
if (line == "\"") return true;
|
2018-08-07 13:14:23 +00:00
|
|
|
if (line.size() == 0) {
|
|
|
|
string_out->append("\n"); // consume empty line
|
|
|
|
continue;
|
|
|
|
}
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
CHECK_GE(line.size(), 2u); // We should have the indent
|
|
|
|
string_out->append(line.begin() + 2, line.end());
|
|
|
|
*string_out += '\n';
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return false;
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 12:36:26 +00:00
|
|
|
std::string UnescapeString(const std::string& escaped_string) {
|
|
|
|
std::string unescaped_string;
|
|
|
|
bool previous_was_backslash = false;
|
|
|
|
for (char c : escaped_string) {
|
|
|
|
if (previous_was_backslash) {
|
|
|
|
// If it was not an escape sequence, emit the previous backslash
|
|
|
|
if (c != '\\' && c != '"') unescaped_string += '\\';
|
|
|
|
unescaped_string += c;
|
|
|
|
previous_was_backslash = false;
|
|
|
|
} else {
|
|
|
|
if (c == '\\') {
|
|
|
|
previous_was_backslash = true;
|
|
|
|
// Defer emission to the point where we can check if it was an escape.
|
|
|
|
} else {
|
|
|
|
unescaped_string += c;
|
|
|
|
}
|
2016-02-10 18:35:31 +00:00
|
|
|
}
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
2016-02-19 12:36:26 +00:00
|
|
|
return unescaped_string;
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 12:36:26 +00:00
|
|
|
void ExtractSnippets(std::vector<std::string>* snippet_list,
|
2019-09-10 01:19:59 +00:00
|
|
|
std::istream* body_stream, bool read_raw_js_snippet) {
|
2016-02-19 12:36:26 +00:00
|
|
|
if (read_raw_js_snippet) {
|
|
|
|
snippet_list->push_back(ReadRawJSSnippet(body_stream));
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
} else {
|
2016-02-19 12:36:26 +00:00
|
|
|
std::string snippet;
|
|
|
|
while (ReadNextSnippet(body_stream, &snippet)) {
|
|
|
|
snippet_list->push_back(UnescapeString(snippet));
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
void GenerateExpectationsFile(std::ostream* stream,
|
2016-02-19 12:36:26 +00:00
|
|
|
const std::vector<std::string>& snippet_list,
|
2016-02-26 12:04:03 +00:00
|
|
|
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);
|
|
|
|
|
2016-09-06 16:10:19 +00:00
|
|
|
BytecodeExpectationsPrinter printer(platform.isolate());
|
2016-02-26 12:04:03 +00:00
|
|
|
printer.set_wrap(options.wrap());
|
2016-10-04 18:42:13 +00:00
|
|
|
printer.set_module(options.module());
|
2016-02-26 12:04:03 +00:00
|
|
|
printer.set_top_level(options.top_level());
|
2018-08-07 13:14:23 +00:00
|
|
|
printer.set_print_callee(options.print_callee());
|
2016-02-26 12:04:03 +00:00
|
|
|
if (!options.test_function_name().empty()) {
|
|
|
|
printer.set_test_function_name(options.test_function_name());
|
|
|
|
}
|
2016-02-10 11:26:14 +00:00
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
*stream << "#\n# Autogenerated by generate-bytecode-expectations.\n#\n\n";
|
2016-02-26 12:04:03 +00:00
|
|
|
options.PrintHeader(stream);
|
|
|
|
for (const std::string& snippet : snippet_list) {
|
|
|
|
printer.PrintExpectation(stream, snippet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WriteExpectationsFile(const std::vector<std::string>& snippet_list,
|
|
|
|
const V8InitializationScope& platform,
|
|
|
|
const ProgramOptions& options,
|
|
|
|
const std::string& output_filename) {
|
|
|
|
std::ofstream output_file_handle;
|
|
|
|
if (!options.write_to_stdout()) {
|
2021-02-17 14:36:58 +00:00
|
|
|
output_file_handle.open(output_filename.c_str(), std::ios::binary);
|
2016-02-26 12:04:03 +00:00
|
|
|
if (!output_file_handle.is_open()) {
|
|
|
|
REPORT_ERROR("Could not open " << output_filename << " for writing.");
|
|
|
|
return false;
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
}
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
2016-02-26 12:04:03 +00:00
|
|
|
std::ostream& output_stream =
|
|
|
|
options.write_to_stdout() ? std::cout : output_file_handle;
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
GenerateExpectationsFile(&output_stream, snippet_list, platform, options);
|
2016-02-26 12:04:03 +00:00
|
|
|
|
|
|
|
return true;
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
std::string WriteExpectationsToString(
|
|
|
|
const std::vector<std::string>& snippet_list,
|
|
|
|
const V8InitializationScope& platform, const ProgramOptions& options) {
|
|
|
|
std::stringstream output_string;
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
GenerateExpectationsFile(&output_string, snippet_list, platform, options);
|
2019-07-19 09:38:43 +00:00
|
|
|
|
|
|
|
return output_string.str();
|
|
|
|
}
|
|
|
|
|
2016-03-01 10:41:56 +00:00
|
|
|
void PrintMessage(v8::Local<v8::Message> message, v8::Local<v8::Value>) {
|
2017-08-29 00:17:03 +00:00
|
|
|
std::cerr << "INFO: "
|
2019-06-21 13:32:50 +00:00
|
|
|
<< *v8::String::Utf8Value(message->GetIsolate(), message->Get())
|
2017-08-29 00:17:03 +00:00
|
|
|
<< '\n';
|
2016-03-01 10:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiscardMessage(v8::Local<v8::Message>, v8::Local<v8::Value>) {}
|
|
|
|
|
2016-02-10 11:26:14 +00:00
|
|
|
void PrintUsage(const char* exec_path) {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
std::cerr
|
|
|
|
<< "\nUsage: " << exec_path
|
2016-02-26 12:04:03 +00:00
|
|
|
<< " [OPTIONS]... [INPUT FILES]...\n\n"
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
"Options:\n"
|
2019-07-19 09:38:43 +00:00
|
|
|
" --help Print this help message.\n"
|
|
|
|
" --verbose Emit messages about the progress of the tool.\n"
|
|
|
|
" --raw-js Read raw JavaScript, instead of the output format.\n"
|
|
|
|
" --stdin Read from standard input instead of file.\n"
|
2016-02-19 12:36:26 +00:00
|
|
|
" --rebaseline Rebaseline input snippet file.\n"
|
2019-07-19 09:38:43 +00:00
|
|
|
" --check-baseline Checks the current baseline is valid.\n"
|
2016-02-19 12:36:26 +00:00
|
|
|
" --no-wrap Do not wrap the snippet in a function.\n"
|
2018-08-07 13:14:23 +00:00
|
|
|
" --print-callee Print bytecode of callee, function should "
|
|
|
|
"return arguments.callee.\n"
|
2016-10-04 18:42:13 +00:00
|
|
|
" --module Compile as JavaScript module.\n"
|
2016-02-19 12:36:26 +00:00
|
|
|
" --test-function-name=foo "
|
|
|
|
"Specify the name of the test function.\n"
|
2016-02-26 12:04:03 +00:00
|
|
|
" --top-level Process top level code, not the top-level function.\n"
|
2016-02-19 12:36:26 +00:00
|
|
|
" --output=file.name\n"
|
|
|
|
" Specify the output file. If not specified, output goes to "
|
|
|
|
"stdout.\n"
|
2016-02-19 16:14:07 +00:00
|
|
|
" --pool-type=(number|string|mixed)\n"
|
2016-02-19 12:36:26 +00:00
|
|
|
" Specify the type of the entries in the constant pool "
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
"(default: mixed).\n"
|
|
|
|
"\n"
|
2019-07-19 09:38:43 +00:00
|
|
|
"When using --rebaseline or --check-baseline, flags --no-wrap,\n"
|
|
|
|
"--test-function-name and --pool-type will be overridden by the\n"
|
|
|
|
"options specified in the input file header.\n\n"
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
"Each raw JavaScript file is interpreted as a single snippet.\n\n"
|
|
|
|
"This tool is intended as a help in writing tests.\n"
|
|
|
|
"Please, DO NOT blindly copy and paste the output "
|
|
|
|
"into the test suite.\n";
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
bool CheckBaselineExpectations(const std::string& input_filename,
|
|
|
|
const std::vector<std::string>& snippet_list,
|
|
|
|
const V8InitializationScope& platform,
|
|
|
|
const ProgramOptions& options) {
|
|
|
|
std::string actual =
|
|
|
|
WriteExpectationsToString(snippet_list, platform, options);
|
|
|
|
|
|
|
|
std::ifstream input_stream(input_filename);
|
|
|
|
if (!input_stream.is_open()) {
|
|
|
|
REPORT_ERROR("Could not open " << input_filename << " for reading.");
|
2019-07-19 15:30:21 +00:00
|
|
|
std::exit(2);
|
2019-07-19 09:38:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool check_failed = false;
|
|
|
|
std::string expected((std::istreambuf_iterator<char>(input_stream)),
|
|
|
|
std::istreambuf_iterator<char>());
|
|
|
|
if (expected != actual) {
|
|
|
|
REPORT_ERROR("Mismatch: " << input_filename);
|
|
|
|
check_failed = true;
|
|
|
|
if (expected.size() != actual.size()) {
|
|
|
|
REPORT_ERROR(" Expected size (" << expected.size()
|
|
|
|
<< ") != actual size (" << actual.size()
|
|
|
|
<< ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
int line = 1;
|
|
|
|
for (size_t i = 0; i < std::min(expected.size(), actual.size()); ++i) {
|
|
|
|
if (expected[i] != actual[i]) {
|
|
|
|
// Find the start of the line that has the mismatch carefully
|
|
|
|
// handling the case where it's the first line that mismatches.
|
|
|
|
size_t start = expected[i] != '\n' ? expected.rfind("\n", i)
|
|
|
|
: actual.rfind("\n", i);
|
|
|
|
if (start == std::string::npos) {
|
|
|
|
start = 0;
|
|
|
|
} else {
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no new line, then these two lines will consume the
|
|
|
|
// remaining characters in the string, because npos - start will
|
|
|
|
// always be longer than the string itself.
|
|
|
|
std::string expected_line =
|
|
|
|
expected.substr(start, expected.find("\n", i) - start);
|
|
|
|
std::string actual_line =
|
|
|
|
actual.substr(start, actual.find("\n", i) - start);
|
|
|
|
REPORT_ERROR(" First mismatch on line " << line << ")");
|
|
|
|
REPORT_ERROR(" Expected : '" << expected_line << "'");
|
|
|
|
REPORT_ERROR(" Actual : '" << actual_line << "'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (expected[i] == '\n') line++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return check_failed;
|
|
|
|
}
|
|
|
|
|
2016-02-10 11:26:14 +00:00
|
|
|
int main(int argc, char** argv) {
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
ProgramOptions options = ProgramOptions::FromCommandLine(argc, argv);
|
[Interpreter] Print constant pool in generate-bytecode-expectations
This is a follow-up to https://crrev.com/1671863002, adding the
capability to print the contents of the constant pool. The expected
type of the pool is taken from command line, and it's either:
* string/int/double: assume all constants have the specified type.
This way, we can emit a meaningful representation, e.g. a quoted
string for type string and so on. All the constants in the pool must
have the same type, otherwise one or more CHECK() will fail and the
program will eventually crash.
* mixed: print the InstanceType tag instead of the actual value.
This is the choice for those tests where the type of the constants in
the pool is not uniform, however only a type tag is printed, not the
actual value of the entries. SMIs are an exception, since they do not
have an InstanceType tag, so kInstanceTypeDontCare is printed instead.
In addition to that, functions Print{ExpectedSnippet,BytecodeSequence}
have been extracted with no functional change. It's just for improving
readability, since the code is becoming quite long.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1686963002
Cr-Commit-Position: refs/heads/master@{#33888}
2016-02-11 11:26:41 +00:00
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
if (!options.Validate() || options.print_help()) {
|
2016-02-10 11:26:14 +00:00
|
|
|
PrintUsage(argv[0]);
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
return options.print_help() ? 0 : 1;
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
V8InitializationScope platform(argv[0]);
|
2016-03-01 10:41:56 +00:00
|
|
|
platform.isolate()->AddMessageListener(
|
|
|
|
options.suppress_runtime_errors() ? DiscardMessage : PrintMessage);
|
2016-02-19 12:36:26 +00:00
|
|
|
|
[Interpreter] Change the output format of generate-bytecode-expectations.
Now the tool produces a far more readable output format, which bears a
lot of resemblance to YAML. In fact, the output should be machine
parseable as such, one document per testcase. However, the output format
may be subject to changes in future, so don't rely on this property.
In general, the output format has been optimized for producing a meaningful
textual diff, while keeping a decent readability as well. Therefore, not
everything is as compact as it could be, e.g. for an empty const pool we get:
constant pool: [
]
instead of:
constant pool: []
Also, trailing commas are always inserted in lists.
Additionally, now the tool accepts its output format as input. When
operating in this mode, all the snippets are extracted, processed and
the output is then emitted as usual. If nothing has changed, the output
should match the input. This is very useful for catching bugs in the
bytecode generation by running a textual diff against a known-good file.
The core (namely bytecode-expectations.cc) has been extracted from the
original cc file, which provides the utility as usual. The definitions
in the matching header of the library have been moved into the
v8::internal::interpreter namespace.
The library exposes a class ExpectationPrinter, with a method
PrintExpectation, which takes a test snippet as input, and writes the
formatted expectation to the supplied stream. One might then use a
std::stringstream to retrieve the results as a string and run it through
a diff utility.
BUG=v8:4280
LOG=N
Review URL: https://codereview.chromium.org/1688383003
Cr-Commit-Position: refs/heads/master@{#33997}
2016-02-15 15:20:19 +00:00
|
|
|
std::vector<std::string> snippet_list;
|
2016-02-19 12:36:26 +00:00
|
|
|
|
2016-02-26 12:04:03 +00:00
|
|
|
if (options.read_from_stdin()) {
|
|
|
|
// Rebaseline will never get here, so we will always take the
|
|
|
|
// GenerateExpectationsFile at the end of this function.
|
2019-07-19 09:38:43 +00:00
|
|
|
DCHECK(!options.rebaseline() && !options.check_baseline());
|
2019-09-10 01:19:59 +00:00
|
|
|
ExtractSnippets(&snippet_list, &std::cin, options.read_raw_js_snippet());
|
2016-02-26 12:04:03 +00:00
|
|
|
} else {
|
2019-07-19 09:38:43 +00:00
|
|
|
bool check_failed = false;
|
2016-02-26 12:04:03 +00:00
|
|
|
for (const std::string& input_filename : options.input_filenames()) {
|
|
|
|
if (options.verbose()) {
|
|
|
|
std::cerr << "Processing " << input_filename << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ifstream input_stream(input_filename.c_str());
|
|
|
|
if (!input_stream.is_open()) {
|
|
|
|
REPORT_ERROR("Could not open " << input_filename << " for reading.");
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgramOptions updated_options = options;
|
2019-07-19 09:38:43 +00:00
|
|
|
if (options.baseline()) {
|
2019-09-10 01:19:59 +00:00
|
|
|
updated_options.UpdateFromHeader(&input_stream);
|
2016-02-26 12:04:03 +00:00
|
|
|
CHECK(updated_options.Validate());
|
|
|
|
}
|
|
|
|
|
2019-09-10 01:19:59 +00:00
|
|
|
ExtractSnippets(&snippet_list, &input_stream,
|
2016-02-26 12:04:03 +00:00
|
|
|
options.read_raw_js_snippet());
|
2019-07-19 09:38:43 +00:00
|
|
|
input_stream.close();
|
2016-02-26 12:04:03 +00:00
|
|
|
|
|
|
|
if (options.rebaseline()) {
|
|
|
|
if (!WriteExpectationsFile(snippet_list, platform, updated_options,
|
|
|
|
input_filename)) {
|
|
|
|
return 3;
|
|
|
|
}
|
2019-07-19 09:38:43 +00:00
|
|
|
} else if (options.check_baseline()) {
|
|
|
|
check_failed |= CheckBaselineExpectations(input_filename, snippet_list,
|
|
|
|
platform, updated_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.baseline()) {
|
2016-02-26 12:04:03 +00:00
|
|
|
snippet_list.clear();
|
|
|
|
}
|
2016-02-19 12:36:26 +00:00
|
|
|
}
|
2019-07-19 09:38:43 +00:00
|
|
|
if (check_failed) {
|
|
|
|
return 4;
|
|
|
|
}
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:38:43 +00:00
|
|
|
if (!options.baseline()) {
|
2016-02-26 12:04:03 +00:00
|
|
|
if (!WriteExpectationsFile(snippet_list, platform, options,
|
|
|
|
options.output_filename())) {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 11:26:14 +00:00
|
|
|
}
|