Make it a class, since it has non-trivial behaviour for converting
the enumerated value to a uint32_t value. (Comply with style guide.)

Merge EnumCaseWithOperands into EnumCase.
This commit is contained in:
David Neto 2015-09-21 17:16:45 -04:00
Родитель 1b5fd4962e
Коммит 74af05f012
8 изменённых файлов: 69 добавлений и 68 удалений

Просмотреть файл

@ -44,10 +44,10 @@ using SamplerAddressingModeTest = spvtest::TextToBinaryTestBase<
TEST_P(SamplerAddressingModeTest, AnySamplerAddressingMode) {
std::string input =
"%result = OpConstantSampler %type " + GetParam().name + " 0 Nearest";
"%result = OpConstantSampler %type " + GetParam().name() + " 0 Nearest";
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpConstantSampler,
{1, 2, GetParam().get_value(), 0, 0})));
{1, 2, GetParam().value(), 0, 0})));
}
// clang-format off
@ -71,10 +71,10 @@ using SamplerFilterModeTest = spvtest::TextToBinaryTestBase<
TEST_P(SamplerFilterModeTest, AnySamplerFilterMode) {
std::string input =
"%result = OpConstantSampler %type Clamp 0 " + GetParam().name;
"%result = OpConstantSampler %type Clamp 0 " + GetParam().name();
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpConstantSampler,
{1, 2, 2, 0, GetParam().get_value()})));
{1, 2, 2, 0, GetParam().value()})));
}
// clang-format off

Просмотреть файл

@ -43,10 +43,10 @@ using OpSelectionMergeTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<EnumCase<spv::SelectionControlMask>>>;
TEST_P(OpSelectionMergeTest, AnySingleSelectionControlMask) {
std::string input = "OpSelectionMerge %1 " + GetParam().name;
std::string input = "OpSelectionMerge %1 " + GetParam().name();
EXPECT_THAT(
CompiledInstructions(input),
Eq(MakeInstruction(spv::OpSelectionMerge, {1, GetParam().get_value()})));
Eq(MakeInstruction(spv::OpSelectionMerge, {1, GetParam().value()})));
}
// clang-format off
@ -74,10 +74,10 @@ using OpLoopMergeTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<EnumCase<spv::LoopControlMask>>>;
TEST_P(OpLoopMergeTest, AnySingleLoopControlMask) {
std::string input = "OpLoopMerge %1 " + GetParam().name;
std::string input = "OpLoopMerge %1 " + GetParam().name();
EXPECT_THAT(
CompiledInstructions(input),
Eq(MakeInstruction(spv::OpLoopMerge, {1, GetParam().get_value()})));
Eq(MakeInstruction(spv::OpLoopMerge, {1, GetParam().value()})));
}
// clang-format off

Просмотреть файл

@ -45,14 +45,14 @@ using OpFunctionControlTest = spvtest::TextToBinaryTestBase<
TEST_P(OpFunctionControlTest, AnySingleFunctionControlMask) {
std::string input = "%result_id = OpFunction %result_type " +
GetParam().name + " %function_type ";
GetParam().name() + " %function_type ";
EXPECT_THAT(
CompiledInstructions(input),
Eq(MakeInstruction(spv::OpFunction, {1, 2, GetParam().get_value(), 3})));
Eq(MakeInstruction(spv::OpFunction, {1, 2, GetParam().value(), 3})));
}
// clang-format off
#define CASE(VALUE,NAME) { spv::FunctionControl##VALUE, NAME}
#define CASE(VALUE,NAME) { spv::FunctionControl##VALUE, NAME }
INSTANTIATE_TEST_CASE_P(TextToBinaryFunctionTest, OpFunctionControlTest,
::testing::ValuesIn(std::vector<EnumCase<spv::FunctionControlMask>>{
CASE(MaskNone, "None"),

Просмотреть файл

@ -44,10 +44,10 @@ using GroupOperationTest = spvtest::TextToBinaryTestBase<
TEST_P(GroupOperationTest, AnyGroupOperation) {
std::string input =
"%result = OpGroupIAdd %type %scope " + GetParam().name + " %x";
"%result = OpGroupIAdd %type %scope " + GetParam().name() + " %x";
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpGroupIAdd,
{1, 2, 3, GetParam().get_value(), 4})));
{1, 2, 3, GetParam().value(), 4})));
}
// clang-format off

Просмотреть файл

@ -40,40 +40,29 @@ using spvtest::MakeInstruction;
using spvtest::TextToBinaryTest;
using ::testing::Eq;
// An example case for an enumerated value.
template <typename E>
struct EnumCaseWithOperands {
uint32_t get_value() const { return static_cast<uint32_t>(value); }
E value;
std::string name;
std::vector<uint32_t> operands;
};
// Test assembly of Memory Access masks
using MemoryAccessTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<EnumCaseWithOperands<spv::MemoryAccessMask>>>;
::testing::TestWithParam<EnumCase<spv::MemoryAccessMask>>>;
TEST_P(MemoryAccessTest, AnySingleMemoryAccessMask) {
std::stringstream input;
input << "OpStore %ptr %value " << GetParam().name;
for (auto operand : GetParam().operands) input << " " << operand;
std::vector<uint32_t> expected_operands{1, 2, GetParam().get_value()};
expected_operands.insert(expected_operands.end(), GetParam().operands.begin(),
GetParam().operands.end());
input << "OpStore %ptr %value " << GetParam().name();
for (auto operand : GetParam().operands()) input << " " << operand;
std::vector<uint32_t> expected_operands{1, 2, GetParam().value()};
expected_operands.insert(expected_operands.end(), GetParam().operands().begin(),
GetParam().operands().end());
EXPECT_THAT(CompiledInstructions(input.str()),
Eq(MakeInstruction(spv::OpStore, expected_operands)));
}
// clang-format off
INSTANTIATE_TEST_CASE_P(TextToBinaryMemoryAccessTest, MemoryAccessTest,
::testing::ValuesIn(std::vector<EnumCaseWithOperands<spv::MemoryAccessMask>>{
{spv::MemoryAccessMaskNone, "None", {}},
{spv::MemoryAccessVolatileMask, "Volatile", {}},
{spv::MemoryAccessAlignedMask, "Aligned", {16}},
}));
#undef CASE
// clang-format on
INSTANTIATE_TEST_CASE_P(
TextToBinaryMemoryAccessTest, MemoryAccessTest,
::testing::ValuesIn(std::vector<EnumCase<spv::MemoryAccessMask>>{
{spv::MemoryAccessMaskNone, "None", {}},
{spv::MemoryAccessVolatileMask, "Volatile", {}},
{spv::MemoryAccessAlignedMask, "Aligned", {16}},
}));
TEST_F(TextToBinaryTest, CombinedMemoryAccessMask) {
const std::string input = "OpStore %ptr %value Volatile|Aligned 16";
@ -87,31 +76,32 @@ TEST_F(TextToBinaryTest, CombinedMemoryAccessMask) {
// Test Storage Class enum values
using StorageClassTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<EnumCaseWithOperands<spv::StorageClass>>>;
::testing::TestWithParam<EnumCase<spv::StorageClass>>>;
TEST_P(StorageClassTest, AnyStorageClass) {
std::string input = "%1 = OpVariable %2 " + GetParam().name;
std::string input = "%1 = OpVariable %2 " + GetParam().name();
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpVariable, {2, 1, GetParam().get_value()})));
Eq(MakeInstruction(spv::OpVariable, {2, 1, GetParam().value()})));
}
// clang-format off
#define CASE(NAME) { spv::StorageClass##NAME, #NAME, {} }
INSTANTIATE_TEST_CASE_P(TextToBinaryStorageClassTest, StorageClassTest,
::testing::ValuesIn(std::vector<EnumCaseWithOperands<spv::StorageClass>>{
// TODO(dneto): There are more storage classes in Rev32 and later.
CASE(UniformConstant),
CASE(Input),
CASE(Uniform),
CASE(Output),
CASE(WorkgroupLocal),
CASE(WorkgroupGlobal),
CASE(PrivateGlobal),
CASE(Function),
CASE(Generic),
CASE(AtomicCounter),
CASE(Image),
}));
INSTANTIATE_TEST_CASE_P(
TextToBinaryStorageClassTest, StorageClassTest,
::testing::ValuesIn(std::vector<EnumCase<spv::StorageClass>>{
// TODO(dneto): There are more storage classes in Rev32 and later.
CASE(UniformConstant),
CASE(Input),
CASE(Uniform),
CASE(Output),
CASE(WorkgroupLocal),
CASE(WorkgroupGlobal),
CASE(PrivateGlobal),
CASE(Function),
CASE(Generic),
CASE(AtomicCounter),
CASE(Image),
}));
#undef CASE
// clang-format on

Просмотреть файл

@ -203,9 +203,9 @@ using OpCapabilityTest = spvtest::TextToBinaryTestBase<
::testing::TestWithParam<EnumCase<spv::Capability>>>;
TEST_P(OpCapabilityTest, AnyCapability) {
std::string input = "OpCapability " + GetParam().name;
std::string input = "OpCapability " + GetParam().name();
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpCapability, {GetParam().get_value()})));
Eq(MakeInstruction(spv::OpCapability, {GetParam().value()})));
}
// clang-format off

Просмотреть файл

@ -44,10 +44,10 @@ using DimTest = spvtest::TextToBinaryTestBase<
TEST_P(DimTest, AnyDim) {
std::string input = "%imageType = OpTypeImage %sampledType " +
GetParam().name + " 2 3 0 4 Rgba8";
GetParam().name() + " 2 3 0 4 Rgba8";
EXPECT_THAT(
CompiledInstructions(input),
Eq(MakeInstruction(spv::OpTypeImage, {1, 2, GetParam().get_value(), 2, 3, 0, 4,
Eq(MakeInstruction(spv::OpTypeImage, {1, 2, GetParam().value(), 2, 3, 0, 4,
spv::ImageFormatRgba8})));
}
@ -74,10 +74,10 @@ using ImageFormatTest = spvtest::TextToBinaryTestBase<
TEST_P(ImageFormatTest, AnyImageFormat) {
std::string input =
"%imageType = OpTypeImage %sampledType 1D 2 3 0 4 " + GetParam().name;
"%imageType = OpTypeImage %sampledType 1D 2 3 0 4 " + GetParam().name();
EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(spv::OpTypeImage, {1, 2, spv::Dim1D, 2, 3, 0,
4, GetParam().get_value()})));
4, GetParam().value()})));
}
// clang-format off
@ -138,10 +138,10 @@ using OpTypePipeTest = spvtest::TextToBinaryTestBase<
TEST_P(OpTypePipeTest, AnyAccessQualifier) {
// TODO(dneto): In Rev31 and later, pipes are opaque, and so the %2, which
// is the type-of-element operand, should be dropped.
std::string input = "%1 = OpTypePipe %2 " + GetParam().name;
std::string input = "%1 = OpTypePipe %2 " + GetParam().name();
EXPECT_THAT(
CompiledInstructions(input),
Eq(MakeInstruction(spv::OpTypePipe, {1, 2, GetParam().get_value()})));
Eq(MakeInstruction(spv::OpTypePipe, {1, 2, GetParam().value()})));
}
// clang-format off

Просмотреть файл

@ -150,12 +150,23 @@ struct AutoText {
spv_text_t text;
};
// An example case for an enumerated value.
// An example case for an enumerated value, optionally with operands.
template <typename E>
struct EnumCase {
uint32_t get_value() const { return static_cast<uint32_t>(value); }
E value;
std::string name;
class EnumCase {
public:
EnumCase(E value, std::string name, std::vector<uint32_t> operands = {})
: enum_value_(value), name_(name), operands_(operands) {}
// Returns the enum value as a uint32_t.
uint32_t value() const { return static_cast<uint32_t>(enum_value_); }
// Returns the name of the enumerant.
const std::string& name() const { return name_; }
// Returns a reference to the operands.
const std::vector<uint32_t>& operands() const { return operands_; }
private:
E enum_value_;
std::string name_;
std::vector<uint32_t> operands_;
};
#define I32_ENDIAN_HOST (o32_host_order.value)