2015-01-09 14:19:55 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
#include "src/compiler/opcodes.h"
|
2016-09-13 05:15:28 +00:00
|
|
|
#include "testing/gtest-support.h"
|
2015-01-09 14:19:55 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-01-15 15:07:29 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool IsCommonOpcode(IrOpcode::Value opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
#define OPCODE(Opcode) \
|
|
|
|
case IrOpcode::k##Opcode: \
|
|
|
|
return true;
|
|
|
|
COMMON_OP_LIST(OPCODE)
|
|
|
|
CONTROL_OP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsControlOpcode(IrOpcode::Value opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
#define OPCODE(Opcode) \
|
|
|
|
case IrOpcode::k##Opcode: \
|
|
|
|
return true;
|
|
|
|
CONTROL_OP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IsJsOpcode(IrOpcode::Value opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
#define OPCODE(Opcode) \
|
|
|
|
case IrOpcode::k##Opcode: \
|
|
|
|
return true;
|
|
|
|
JS_OP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-19 15:35:03 +00:00
|
|
|
bool IsConstantOpcode(IrOpcode::Value opcode) {
|
2015-01-15 15:07:29 +00:00
|
|
|
switch (opcode) {
|
|
|
|
#define OPCODE(Opcode) \
|
|
|
|
case IrOpcode::k##Opcode: \
|
|
|
|
return true;
|
2015-01-19 15:35:03 +00:00
|
|
|
CONSTANT_OP_LIST(OPCODE)
|
2015-01-15 15:07:29 +00:00
|
|
|
#undef OPCODE
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-24 12:26:16 +00:00
|
|
|
bool IsComparisonOpcode(IrOpcode::Value opcode) {
|
|
|
|
switch (opcode) {
|
|
|
|
#define OPCODE(Opcode) \
|
|
|
|
case IrOpcode::k##Opcode: \
|
|
|
|
return true;
|
|
|
|
JS_COMPARE_BINOP_LIST(OPCODE)
|
|
|
|
SIMPLIFIED_COMPARE_BINOP_LIST(OPCODE)
|
|
|
|
MACHINE_COMPARE_BINOP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-15 15:07:29 +00:00
|
|
|
const IrOpcode::Value kInvalidOpcode = static_cast<IrOpcode::Value>(123456789);
|
|
|
|
|
2016-09-13 05:15:28 +00:00
|
|
|
char const* const kMnemonics[] = {
|
|
|
|
#define OPCODE(Opcode) #Opcode,
|
|
|
|
ALL_OP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
};
|
|
|
|
|
|
|
|
const IrOpcode::Value kOpcodes[] = {
|
|
|
|
#define OPCODE(Opcode) IrOpcode::k##Opcode,
|
|
|
|
ALL_OP_LIST(OPCODE)
|
|
|
|
#undef OPCODE
|
|
|
|
};
|
2015-01-15 15:07:29 +00:00
|
|
|
|
2016-09-13 05:15:28 +00:00
|
|
|
} // namespace
|
2015-01-15 15:07:29 +00:00
|
|
|
|
|
|
|
TEST(IrOpcodeTest, IsCommonOpcode) {
|
|
|
|
EXPECT_FALSE(IrOpcode::IsCommonOpcode(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_EQ(IsCommonOpcode(opcode), IrOpcode::IsCommonOpcode(opcode));
|
|
|
|
}
|
2015-01-15 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(IrOpcodeTest, IsControlOpcode) {
|
|
|
|
EXPECT_FALSE(IrOpcode::IsControlOpcode(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_EQ(IsControlOpcode(opcode), IrOpcode::IsControlOpcode(opcode));
|
|
|
|
}
|
2015-01-15 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(IrOpcodeTest, IsJsOpcode) {
|
|
|
|
EXPECT_FALSE(IrOpcode::IsJsOpcode(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_EQ(IsJsOpcode(opcode), IrOpcode::IsJsOpcode(opcode));
|
|
|
|
}
|
2015-01-15 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 15:35:03 +00:00
|
|
|
TEST(IrOpcodeTest, IsConstantOpcode) {
|
|
|
|
EXPECT_FALSE(IrOpcode::IsConstantOpcode(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_EQ(IsConstantOpcode(opcode), IrOpcode::IsConstantOpcode(opcode));
|
|
|
|
}
|
2015-01-15 15:07:29 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 12:26:16 +00:00
|
|
|
TEST(IrOpcodeTest, IsComparisonOpcode) {
|
|
|
|
EXPECT_FALSE(IrOpcode::IsComparisonOpcode(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_EQ(IsComparisonOpcode(opcode), IrOpcode::IsComparisonOpcode(opcode));
|
|
|
|
}
|
2015-02-24 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 14:19:55 +00:00
|
|
|
TEST(IrOpcodeTest, Mnemonic) {
|
2015-01-15 15:07:29 +00:00
|
|
|
EXPECT_STREQ("UnknownOpcode", IrOpcode::Mnemonic(kInvalidOpcode));
|
2016-09-13 05:15:28 +00:00
|
|
|
TRACED_FOREACH(IrOpcode::Value, opcode, kOpcodes) {
|
|
|
|
EXPECT_STREQ(kMnemonics[opcode], IrOpcode::Mnemonic(opcode));
|
|
|
|
}
|
2015-01-09 14:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|