Commit 5dd3122c authored by mythria's avatar mythria Committed by Commit bot

[Interpreter] Adds support for CreateArguments to BytecodeGraphBuilder.

Adds implementation and tests for CreateMappedArguments and
CreateUnmappedArguments to bytecode graph builder.

BUG=v8:4280
LOG=N

Review URL: https://codereview.chromium.org/1490283003

Cr-Commit-Position: refs/heads/master@{#33004}
parent 155cbad5
...@@ -928,15 +928,25 @@ void BytecodeGraphBuilder::VisitCreateClosureWide( ...@@ -928,15 +928,25 @@ void BytecodeGraphBuilder::VisitCreateClosureWide(
} }
void BytecodeGraphBuilder::BuildCreateArguments(
CreateArgumentsParameters::Type type,
const interpreter::BytecodeArrayIterator& iterator) {
FrameStateBeforeAndAfter states(this, iterator);
const Operator* op = javascript()->CreateArguments(type, 0);
Node* object = NewNode(op, GetFunctionClosure());
environment()->BindAccumulator(object, &states);
}
void BytecodeGraphBuilder::VisitCreateMappedArguments( void BytecodeGraphBuilder::VisitCreateMappedArguments(
const interpreter::BytecodeArrayIterator& iterator) { const interpreter::BytecodeArrayIterator& iterator) {
UNIMPLEMENTED(); BuildCreateArguments(CreateArgumentsParameters::kMappedArguments, iterator);
} }
void BytecodeGraphBuilder::VisitCreateUnmappedArguments( void BytecodeGraphBuilder::VisitCreateUnmappedArguments(
const interpreter::BytecodeArrayIterator& iterator) { const interpreter::BytecodeArrayIterator& iterator) {
UNIMPLEMENTED(); BuildCreateArguments(CreateArgumentsParameters::kUnmappedArguments, iterator);
} }
......
...@@ -138,6 +138,8 @@ class BytecodeGraphBuilder { ...@@ -138,6 +138,8 @@ class BytecodeGraphBuilder {
const interpreter::BytecodeArrayIterator& iterator); const interpreter::BytecodeArrayIterator& iterator);
void BuildCreateObjectLiteral( void BuildCreateObjectLiteral(
const interpreter::BytecodeArrayIterator& iterator); const interpreter::BytecodeArrayIterator& iterator);
void BuildCreateArguments(CreateArgumentsParameters::Type type,
const interpreter::BytecodeArrayIterator& iterator);
void BuildLoadGlobal(const interpreter::BytecodeArrayIterator& iterator, void BuildLoadGlobal(const interpreter::BytecodeArrayIterator& iterator,
TypeofMode typeof_mode); TypeofMode typeof_mode);
void BuildStoreGlobal(const interpreter::BytecodeArrayIterator& iterator); void BuildStoreGlobal(const interpreter::BytecodeArrayIterator& iterator);
......
...@@ -1306,6 +1306,82 @@ TEST(BytecodeGraphBuilderLoadContext) { ...@@ -1306,6 +1306,82 @@ TEST(BytecodeGraphBuilderLoadContext) {
} }
TEST(BytecodeGraphBuilderCreateArgumentsNoParameters) {
HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate();
Zone* zone = scope.main_zone();
Factory* factory = isolate->factory();
ExpectedSnippet<0> snippets[] = {
{"function f() {return arguments[0];}", {factory->undefined_value()}},
{"function f(a) {return arguments[0];}", {factory->undefined_value()}},
{"function f() {'use strict'; return arguments[0];}",
{factory->undefined_value()}},
{"function f(a) {'use strict'; return arguments[0];}",
{factory->undefined_value()}},
};
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
for (size_t i = 0; i < num_snippets; i++) {
ScopedVector<char> script(1024);
SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName);
BytecodeGraphTester tester(isolate, zone, script.start());
auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked();
CHECK(return_value->SameValue(*snippets[i].return_value()));
}
}
TEST(BytecodeGraphBuilderCreateArguments) {
HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate();
Zone* zone = scope.main_zone();
Factory* factory = isolate->factory();
ExpectedSnippet<3> snippets[] = {
{"function f(a, b, c) {return arguments[0];}",
{factory->NewNumberFromInt(1), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function f(a, b, c) {return arguments[3];}",
{factory->undefined_value(), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function f(a, b, c) { b = c; return arguments[1];}",
{factory->NewNumberFromInt(3), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function f(a, b, c) {'use strict'; return arguments[0];}",
{factory->NewNumberFromInt(1), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function f(a, b, c) {'use strict'; return arguments[3];}",
{factory->undefined_value(), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function f(a, b, c) {'use strict'; b = c; return arguments[1];}",
{factory->NewNumberFromInt(2), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
{"function inline_func(a, b) { return arguments[0] }"
"function f(a, b, c) {return inline_func(b, c) + arguments[0];}",
{factory->NewNumberFromInt(3), factory->NewNumberFromInt(1),
factory->NewNumberFromInt(2), factory->NewNumberFromInt(30)}},
};
size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
for (size_t i = 0; i < num_snippets; i++) {
ScopedVector<char> script(1024);
SNPrintF(script, "%s\n%s();", snippets[i].code_snippet, kFunctionName);
BytecodeGraphTester tester(isolate, zone, script.start());
auto callable =
tester.GetCallable<Handle<Object>, Handle<Object>, Handle<Object>>();
Handle<Object> return_value =
callable(snippets[i].parameter(0), snippets[i].parameter(1),
snippets[i].parameter(2))
.ToHandleChecked();
CHECK(return_value->SameValue(*snippets[i].return_value()));
}
}
TEST(BytecodeGraphBuilderRegExpLiterals) { TEST(BytecodeGraphBuilderRegExpLiterals) {
HandleAndZoneScope scope; HandleAndZoneScope scope;
Isolate* isolate = scope.main_isolate(); Isolate* isolate = scope.main_isolate();
...@@ -1441,7 +1517,6 @@ TEST(BytecodeGraphBuilderObjectLiterals) { ...@@ -1441,7 +1517,6 @@ TEST(BytecodeGraphBuilderObjectLiterals) {
ScopedVector<char> script(4096); ScopedVector<char> script(4096);
SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName, SNPrintF(script, "function %s() { %s }\n%s();", kFunctionName,
snippets[i].code_snippet, kFunctionName); snippets[i].code_snippet, kFunctionName);
BytecodeGraphTester tester(isolate, zone, script.start()); BytecodeGraphTester tester(isolate, zone, script.start());
auto callable = tester.GetCallable<>(); auto callable = tester.GetCallable<>();
Handle<Object> return_value = callable().ToHandleChecked(); Handle<Object> return_value = callable().ToHandleChecked();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment