Commit 8bc526bc authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

Modify StubTester to test both code stubs and builtins

In the process, cleanup some of the maths and functionality used to setup
descriptors and compute parameters. Also cleanup and correct the context
passing.

Change-Id: I6b6629bc81ef1c03425332dd6eadf3085efec7c9
Reviewed-on: https://chromium-review.googlesource.com/588892Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Daniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46938}
parent e398bf81
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "src/bootstrapper.h"
#include "src/callable.h"
#include "src/code-stubs.h"
#include "src/compilation-info.h"
#include "src/compiler/common-operator.h"
......@@ -32,33 +33,52 @@ class StubTester {
Operator::kNoProperties)),
graph_(zone_),
common_(zone_),
tester_(InitializeFunctionTester(stub),
interface_descriptor_.GetParameterCount()) {}
tester_(InitializeFunctionTester(stub->GetCode()),
GetParameterCountWithContext()) {}
StubTester(Isolate* isolate, Zone* zone, Builtins::Name name)
: zone_(zone),
info_(ArrayVector("test"), isolate, zone,
Code::ComputeFlags(Code::HANDLER)),
interface_descriptor_(
Builtins::CallableFor(isolate, name).descriptor()),
descriptor_(Linkage::GetStubCallDescriptor(
isolate, zone, interface_descriptor_,
interface_descriptor_.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties)),
graph_(zone_),
common_(zone_),
tester_(InitializeFunctionTester(
Handle<Code>(isolate->builtins()->builtin(name))),
GetParameterCountWithContext()) {}
template <typename... Args>
Handle<Object> Call(Args... args) {
DCHECK_EQ(interface_descriptor_.GetParameterCount(), sizeof...(args));
MaybeHandle<Object> result = tester_.Call(args...).ToHandleChecked();
MaybeHandle<Object> result =
tester_.Call(args..., Handle<HeapObject>(tester_.function->context()))
.ToHandleChecked();
return result.ToHandleChecked();
}
FunctionTester& ft() { return tester_; }
private:
Graph* InitializeFunctionTester(CodeStub* stub) {
int parameter_count =
interface_descriptor_.GetParameterCount() + 1; // Add context
int node_count = parameter_count + 3;
Node* start = graph_.NewNode(common_.Start(parameter_count + 1));
Graph* InitializeFunctionTester(Handle<Code> stub) {
// Add target, effect and control.
int node_count = GetParameterCountWithContext() + 3;
// Add extra inputs for the JSFunction parameter and the receiver (which for
// the tester is always undefined) to the start node.
Node* start =
graph_.NewNode(common_.Start(GetParameterCountWithContext() + 2));
Node** node_array = zone_->NewArray<Node*>(node_count);
node_array[0] = graph_.NewNode(common_.HeapConstant(stub->GetCode()));
for (int i = 0; i < parameter_count - 1; ++i) {
node_array[0] = graph_.NewNode(common_.HeapConstant(stub));
for (int i = 0; i < GetParameterCountWithContext(); ++i) {
CHECK(IsAnyTagged(descriptor_->GetParameterType(i).representation()));
node_array[i + 1] = graph_.NewNode(common_.Parameter(i + 1), start);
}
node_array[parameter_count] = graph_.NewNode(common_.Parameter(0), start);
node_array[parameter_count + 1] = start;
node_array[parameter_count + 2] = start;
node_array[node_count - 2] = start;
node_array[node_count - 1] = start;
Node* call =
graph_.NewNode(common_.Call(descriptor_), node_count, &node_array[0]);
......@@ -70,6 +90,10 @@ class StubTester {
return &graph_;
}
int GetParameterCountWithContext() {
return interface_descriptor_.GetParameterCount() + 1;
}
Zone* zone_;
CompilationInfo info_;
CallInterfaceDescriptor interface_descriptor_;
......
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