Support OpImage
authorDavid Neto <dneto@google.com>
Wed, 11 Nov 2015 21:36:42 +0000 (16:36 -0500)
committerDavid Neto <dneto@google.com>
Thu, 12 Nov 2015 21:27:51 +0000 (16:27 -0500)
It's already in the syntax table.  Just test it.

readme.md
test/TextToBinary.Image.cpp

index e560700..a005277 100644 (file)
--- a/readme.md
+++ b/readme.md
@@ -311,7 +311,6 @@ done so previously, CMake will detect the existence of
 <a name="future"></a>
 
 Required to complete 1.0 support:
-* Add `OpImage` instruction
 * Changes related to capabilities:
   * Check changes in dependencies on capabilities since 0.99 Rev32.
   * `GeometryStream`.
index 8412c48..d8558e5 100644 (file)
@@ -35,6 +35,7 @@
 namespace {
 
 using spvtest::MakeInstruction;
+using spvtest::TextToBinaryTest;
 using ::testing::Eq;
 
 // An example case for a mask value with operands.
@@ -112,6 +113,48 @@ TEST_F(ImageOperandsTest, WrongOperand) {
               Eq("Invalid image operand 'xxyyzz'."));
 }
 
+// Test OpImage
+
+using OpImageTest = TextToBinaryTest;
+
+TEST_F(OpImageTest, Valid) {
+  const std::string input = "%2 = OpImage %1 %3\n";
+  EXPECT_THAT(CompiledInstructions(input),
+              Eq(MakeInstruction(SpvOpImage, {1, 2, 3})));
+
+  // Test the disassembler.
+  EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input);
+}
+
+TEST_F(OpImageTest, InvalidTypeOperand) {
+  EXPECT_THAT(CompileFailure("%2 = OpImage 42"),
+              Eq("Expected id to start with %."));
+}
+
+TEST_F(OpImageTest, MissingSampledImageOperand) {
+  EXPECT_THAT(CompileFailure("%2 = OpImage %1"),
+              Eq("Expected operand, found end of stream."));
+}
+
+TEST_F(OpImageTest, InvalidSampledImageOperand) {
+  EXPECT_THAT(CompileFailure("%2 = OpImage %1 1000"),
+              Eq("Expected id to start with %."));
+}
+
+TEST_F(OpImageTest, TooManyOperands) {
+  // We should improve this message, to say what instruction we're trying to
+  // parse.
+  EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 %4"), // an Id
+              Eq("Expected '=', found end of stream."));
+
+  EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 99"),  // a number
+              Eq("Expected <opcode> or <result-id> at the beginning of an "
+                 "instruction, found '99'."));
+  EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 \"abc\""),  // a string
+              Eq("Expected <opcode> or <result-id> at the beginning of an "
+                 "instruction, found '\"abc\"'."));
+}
+
 // TODO(dneto): OpSampledImage
 // TODO(dneto): OpImageSampleImplicitLod
 // TODO(dneto): OpImageSampleExplicitLod