[test] Refactor call-tester to use c-signature.h.

R=mstarzinger@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#28763}
This commit is contained in:
titzer 2015-06-02 08:00:55 -07:00 committed by Commit bot
parent bda7fb2246
commit 2c3e35120f
4 changed files with 48 additions and 114 deletions

View File

@ -53,21 +53,50 @@ class CSignature : public MachineSignature {
public:
template <typename P1 = void, typename P2 = void, typename P3 = void,
typename P4 = void, typename P5 = void>
void Verify() {
void VerifyParams() {
// Verifies the C signature against the machine types. Maximum {5} params.
CHECK_LT(parameter_count(), 6);
CHECK_LT(parameter_count(), 6u);
const int kMax = 5;
MachineType params[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
MachineTypeForC<P3>(), MachineTypeForC<P4>(),
MachineTypeForC<P5>()};
for (int p = kMax - 1; p >= 0; p--) {
if (p < parameter_count()) {
if (p < static_cast<int>(parameter_count())) {
CHECK_EQ(GetParam(p), params[p]);
} else {
CHECK_EQ(kMachNone, params[p]);
}
}
}
static CSignature* New(Zone* zone, MachineType ret,
MachineType p1 = kMachNone, MachineType p2 = kMachNone,
MachineType p3 = kMachNone, MachineType p4 = kMachNone,
MachineType p5 = kMachNone) {
MachineType* buffer = zone->NewArray<MachineType>(6);
int pos = 0;
size_t return_count = 0;
if (ret != kMachNone) {
buffer[pos++] = ret;
return_count++;
}
buffer[pos++] = p1;
buffer[pos++] = p2;
buffer[pos++] = p3;
buffer[pos++] = p4;
buffer[pos++] = p5;
size_t param_count = 5;
if (p5 == kMachNone) param_count--;
if (p4 == kMachNone) param_count--;
if (p3 == kMachNone) param_count--;
if (p2 == kMachNone) param_count--;
if (p1 == kMachNone) param_count--;
for (size_t i = 0; i < param_count; i++) {
// Check that there are no kMachNone's in the middle of parameters.
CHECK_NE(kMachNone, buffer[return_count + i]);
}
return new (zone) CSignature(return_count, param_count, buffer);
}
};

View File

@ -122,55 +122,48 @@ struct ParameterTraits<uint32_t> {
template <typename R>
class CallHelper {
public:
explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig)
: machine_sig_(machine_sig), isolate_(isolate) {
explicit CallHelper(Isolate* isolate, CSignature* csig)
: csig_(csig), isolate_(isolate) {
USE(isolate_);
}
virtual ~CallHelper() {}
R Call() {
typedef R V8_CDECL FType();
VerifyParameters0();
csig_->VerifyParams();
return DoCall(FUNCTION_CAST<FType*>(Generate()));
}
template <typename P1>
R Call(P1 p1) {
typedef R V8_CDECL FType(P1);
VerifyParameters1<P1>();
csig_->VerifyParams<P1>();
return DoCall(FUNCTION_CAST<FType*>(Generate()), p1);
}
template <typename P1, typename P2>
R Call(P1 p1, P2 p2) {
typedef R V8_CDECL FType(P1, P2);
VerifyParameters2<P1, P2>();
csig_->VerifyParams<P1, P2>();
return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2);
}
template <typename P1, typename P2, typename P3>
R Call(P1 p1, P2 p2, P3 p3) {
typedef R V8_CDECL FType(P1, P2, P3);
VerifyParameters3<P1, P2, P3>();
csig_->VerifyParams<P1, P2, P3>();
return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3);
}
template <typename P1, typename P2, typename P3, typename P4>
R Call(P1 p1, P2 p2, P3 p3, P4 p4) {
typedef R V8_CDECL FType(P1, P2, P3, P4);
VerifyParameters4<P1, P2, P3, P4>();
csig_->VerifyParams<P1, P2, P3, P4>();
return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3, p4);
}
protected:
MachineSignature* machine_sig_;
void VerifyParameters(size_t parameter_count, MachineType* parameter_types) {
CHECK(machine_sig_->parameter_count() == parameter_count);
for (size_t i = 0; i < parameter_count; i++) {
CHECK_EQ(machine_sig_->GetParam(i), parameter_types[i]);
}
}
CSignature* csig_;
virtual byte* Generate() = 0;
@ -308,50 +301,6 @@ class CallHelper {
}
#endif
#ifndef DEBUG
void VerifyParameters0() {}
template <typename P1>
void VerifyParameters1() {}
template <typename P1, typename P2>
void VerifyParameters2() {}
template <typename P1, typename P2, typename P3>
void VerifyParameters3() {}
template <typename P1, typename P2, typename P3, typename P4>
void VerifyParameters4() {}
#else
void VerifyParameters0() { VerifyParameters(0, NULL); }
template <typename P1>
void VerifyParameters1() {
MachineType parameters[] = {MachineTypeForC<P1>()};
VerifyParameters(arraysize(parameters), parameters);
}
template <typename P1, typename P2>
void VerifyParameters2() {
MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>()};
VerifyParameters(arraysize(parameters), parameters);
}
template <typename P1, typename P2, typename P3>
void VerifyParameters3() {
MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
MachineTypeForC<P3>()};
VerifyParameters(arraysize(parameters), parameters);
}
template <typename P1, typename P2, typename P3, typename P4>
void VerifyParameters4() {
MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(),
MachineTypeForC<P3>(), MachineTypeForC<P4>()};
VerifyParameters(arraysize(parameters), parameters);
}
#endif
Isolate* isolate_;
};

View File

@ -30,12 +30,12 @@ class RawMachineAssemblerTester : public HandleAndZoneScope,
: HandleAndZoneScope(),
CallHelper<ReturnType>(
main_isolate(),
MakeMachineSignature(main_zone(), MachineTypeForC<ReturnType>(), p0,
p1, p2, p3, p4)),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
p2, p3, p4)),
RawMachineAssembler(
main_isolate(), new (main_zone()) Graph(main_zone()),
MakeMachineSignature(main_zone(), MachineTypeForC<ReturnType>(), p0,
p1, p2, p3, p4),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
p2, p3, p4),
kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()) {}
void CheckNumber(double expected, Object* number) {
@ -64,27 +64,6 @@ class RawMachineAssemblerTester : public HandleAndZoneScope,
private:
MaybeHandle<Code> code_;
// 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();
}
};

View File

@ -52,8 +52,8 @@ class GraphBuilderTester : public HandleAndZoneScope,
: GraphAndBuilders(main_zone()),
CallHelper<ReturnType>(
main_isolate(),
MakeMachineSignature(main_zone(), MachineTypeForC<ReturnType>(), p0,
p1, p2, p3, p4)),
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
p2, p3, p4)),
SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_,
&main_machine_, &main_simplified_),
parameters_(main_zone()->template NewArray<Node*>(parameter_count())) {
@ -76,7 +76,7 @@ class GraphBuilderTester : public HandleAndZoneScope,
if (code_.is_null()) {
Zone* zone = graph()->zone();
CallDescriptor* desc =
Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_);
Linkage::GetSimplifiedCDescriptor(zone, this->csig_);
code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph());
}
return code_.ToHandleChecked()->entry();
@ -89,34 +89,11 @@ class GraphBuilderTester : public HandleAndZoneScope,
}
}
size_t parameter_count() const {
return this->machine_sig_->parameter_count();
}
size_t parameter_count() const { return this->csig_->parameter_count(); }
private:
Node** parameters_;
MaybeHandle<Code> code_;
// 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();
}
};
} // namespace compiler