2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
|
|
|
#ifndef V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_
|
|
|
|
#define V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_
|
|
|
|
|
|
|
|
#include "src/v8.h"
|
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
#include "src/compiler/common-operator.h"
|
|
|
|
#include "src/compiler/graph-builder.h"
|
2015-04-30 14:51:50 +00:00
|
|
|
#include "src/compiler/linkage.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/machine-operator.h"
|
2015-04-30 14:51:50 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
|
|
|
#include "test/cctest/compiler/call-tester.h"
|
|
|
|
#include "test/cctest/compiler/simplified-graph-builder.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
class GraphAndBuilders {
|
|
|
|
public:
|
|
|
|
explicit GraphAndBuilders(Zone* zone)
|
|
|
|
: main_graph_(new (zone) Graph(zone)),
|
|
|
|
main_common_(zone),
|
2014-11-10 14:28:09 +00:00
|
|
|
main_machine_(zone),
|
2014-07-30 13:54:45 +00:00
|
|
|
main_simplified_(zone) {}
|
|
|
|
|
|
|
|
protected:
|
2015-04-30 14:51:50 +00:00
|
|
|
// Prefixed with main_ to avoid naming conflicts.
|
2014-08-11 09:40:02 +00:00
|
|
|
Graph* main_graph_;
|
2014-07-30 13:54:45 +00:00
|
|
|
CommonOperatorBuilder main_common_;
|
|
|
|
MachineOperatorBuilder main_machine_;
|
|
|
|
SimplifiedOperatorBuilder main_simplified_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename ReturnType>
|
2015-05-29 14:05:39 +00:00
|
|
|
class GraphBuilderTester : public HandleAndZoneScope,
|
|
|
|
private GraphAndBuilders,
|
|
|
|
public CallHelper<ReturnType>,
|
|
|
|
public SimplifiedGraphBuilder {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
2014-08-14 09:19:54 +00:00
|
|
|
explicit GraphBuilderTester(MachineType p0 = kMachNone,
|
|
|
|
MachineType p1 = kMachNone,
|
|
|
|
MachineType p2 = kMachNone,
|
|
|
|
MachineType p3 = kMachNone,
|
|
|
|
MachineType p4 = kMachNone)
|
2014-07-30 13:54:45 +00:00
|
|
|
: GraphAndBuilders(main_zone()),
|
2015-05-29 14:05:39 +00:00
|
|
|
CallHelper<ReturnType>(
|
2015-01-23 15:19:34 +00:00
|
|
|
main_isolate(),
|
2015-06-01 15:54:53 +00:00
|
|
|
MakeMachineSignature(main_zone(), MachineTypeForC<ReturnType>(), p0,
|
|
|
|
p1, p2, p3, p4)),
|
2015-01-23 15:19:34 +00:00
|
|
|
SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_,
|
2015-04-30 14:51:50 +00:00
|
|
|
&main_machine_, &main_simplified_),
|
|
|
|
parameters_(main_zone()->template NewArray<Node*>(parameter_count())) {
|
2014-09-03 10:13:21 +00:00
|
|
|
Begin(static_cast<int>(parameter_count()));
|
2015-04-30 14:51:50 +00:00
|
|
|
InitParameters();
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
virtual ~GraphBuilderTester() {}
|
|
|
|
|
2015-04-30 14:51:50 +00:00
|
|
|
void GenerateCode() { Generate(); }
|
|
|
|
Node* Parameter(size_t index) {
|
|
|
|
DCHECK(index < parameter_count());
|
|
|
|
return parameters_[index];
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
Factory* factory() const { return isolate()->factory(); }
|
2015-04-30 14:51:50 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual byte* Generate() {
|
|
|
|
if (!Pipeline::SupportedBackend()) return NULL;
|
|
|
|
if (code_.is_null()) {
|
|
|
|
Zone* zone = graph()->zone();
|
|
|
|
CallDescriptor* desc =
|
2015-05-29 14:05:39 +00:00
|
|
|
Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_);
|
2015-04-30 14:51:50 +00:00
|
|
|
code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph());
|
|
|
|
}
|
|
|
|
return code_.ToHandleChecked()->entry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitParameters() {
|
|
|
|
int param_count = static_cast<int>(parameter_count());
|
|
|
|
for (int i = 0; i < param_count; ++i) {
|
|
|
|
parameters_[i] = this->NewNode(common()->Parameter(i), graph()->start());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:05:39 +00:00
|
|
|
size_t parameter_count() const {
|
|
|
|
return this->machine_sig_->parameter_count();
|
|
|
|
}
|
2015-04-30 14:51:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Node** parameters_;
|
|
|
|
MaybeHandle<Code> code_;
|
2015-05-29 14:05:39 +00:00
|
|
|
|
|
|
|
// TODO(titzer): factor me elsewhere.
|
|
|
|
static MachineSignature* MakeMachineSignature(
|
|
|
|
Zone* zone, MachineType return_type, MachineType p0 = kMachNone,
|
|
|
|
MachineType p1 = kMachNone, MachineType p2 = kMachNone,
|
|
|
|
MachineType p3 = kMachNone, MachineType p4 = kMachNone) {
|
|
|
|
// Count the number of parameters.
|
|
|
|
size_t param_count = 5;
|
|
|
|
MachineType types[] = {p0, p1, p2, p3, p4};
|
|
|
|
while (param_count > 0 && types[param_count - 1] == kMachNone)
|
|
|
|
param_count--;
|
|
|
|
size_t return_count = return_type == kMachNone ? 0 : 1;
|
|
|
|
|
|
|
|
// Build the machine signature.
|
|
|
|
MachineSignature::Builder builder(zone, return_count, param_count);
|
|
|
|
if (return_count > 0) builder.AddReturn(return_type);
|
|
|
|
for (size_t i = 0; i < param_count; i++) {
|
|
|
|
builder.AddParam(types[i]);
|
|
|
|
}
|
|
|
|
return builder.Build();
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
2015-04-30 14:51:50 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_
|