From 55bdfcb0bc8dcf88724b847341af858ebb2df6cd Mon Sep 17 00:00:00 2001 From: David Neto Date: Thu, 10 Sep 2015 15:51:57 -0400 Subject: [PATCH] Assembler test for LinkageAttributes decorations --- readme.md | 1 + source/operand.cpp | 2 +- test/TextToBinary.Annotation.cpp | 39 +++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 4ebc22ff8..6f549d9b0 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,7 @@ The validator is incomplete. See the Future Work section for more information. * Values: Fixes values for some decorations: BuiltIn LocalInvocationId, and BuiltIn SubgroupId * All handling of FPFastMathMode masks. + * LinkageAttributes now requires the literal string operand. 2015-09-09 * Avoid confusion about ownership of storage: diff --git a/source/operand.cpp b/source/operand.cpp index 1f15f54a6..e52036f7a 100644 --- a/source/operand.cpp +++ b/source/operand.cpp @@ -751,7 +751,7 @@ static const spv_operand_desc_t decorationEntries[] = { DecorationLinkageAttributes, SPV_OPCODE_FLAGS_CAPABILITIES, CapabilityLinkage, - {SPV_OPERAND_TYPE_LINKAGE_TYPE, SPV_OPERAND_TYPE_NONE}}, + {SPV_OPERAND_TYPE_LITERAL_STRING, SPV_OPERAND_TYPE_LINKAGE_TYPE, SPV_OPERAND_TYPE_NONE}}, }; static const spv_operand_desc_t builtInEntries[] = { diff --git a/test/TextToBinary.Annotation.cpp b/test/TextToBinary.Annotation.cpp index 9844c73d9..808737914 100644 --- a/test/TextToBinary.Annotation.cpp +++ b/test/TextToBinary.Annotation.cpp @@ -236,7 +236,44 @@ INSTANTIATE_TEST_CASE_P(TextToBinaryDecorateFPFastMathMode, OpDecorateEnumTest, #undef CASE // clang-format on -// TODO(dneto): OpDecorate with Linkage attributes +// Test OpDecorate Linkage + +// A single test case for a linkage +struct DecorateLinkageCase { + const uint32_t linkage_type_value; + const std::string linkage_type_name; + const std::string external_name; +}; + +using OpDecorateLinkageTest = test_fixture::TextToBinaryTestBase< + ::testing::TestWithParam>; + +TEST_P(OpDecorateLinkageTest, AnyLinkageDecoration) { + // This string should assemble, but should not validate. + std::string input = "OpDecorate %1 LinkageAttributes \"" + GetParam().external_name + + "\" " + GetParam().linkage_type_name; + std::vector expected_operands{1, spv::DecorationLinkageAttributes}; + std::vector encoded_external_name = + MakeVector(GetParam().external_name); + expected_operands.insert(expected_operands.end(), + encoded_external_name.begin(), + encoded_external_name.end()); + expected_operands.push_back(GetParam().linkage_type_value); + EXPECT_THAT(CompiledInstructions(input), + Eq(MakeInstruction(spv::OpDecorate, expected_operands))); +} + +// clang-format off +#define CASE(ENUM) spv::LinkageType##ENUM, #ENUM +INSTANTIATE_TEST_CASE_P(TextToBinaryDecorateLinkage, OpDecorateLinkageTest, + ::testing::ValuesIn(std::vector{ + { CASE(Import), "a" }, + { CASE(Export), "foo" }, + { CASE(Import), "some kind of long name with spaces etc." }, + // TODO(dneto): utf-8, escaping, quoting cases. + })); +#undef CASE +// clang-format on // TODO(dneto): OpMemberDecorate // TODO(dneto): OpDecorationGroup