2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-08-31 21:42:22 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-08-31 21:42:22 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-08-31 21:42:22 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-08-31 21:42:22 +00:00
|
|
|
|
2015-09-02 18:48:33 +00:00
|
|
|
#include <cassert>
|
2015-09-11 20:34:49 +00:00
|
|
|
#include <string>
|
2015-09-02 18:48:33 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
2016-04-19 02:25:35 +00:00
|
|
|
#include "source/util/bitutils.h"
|
2017-11-27 15:16:41 +00:00
|
|
|
#include "test_fixture.h"
|
2015-08-31 21:42:22 +00:00
|
|
|
|
2018-07-06 17:25:17 +00:00
|
|
|
namespace spvtools {
|
|
|
|
namespace utils {
|
2015-08-31 21:42:22 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-10-14 21:02:39 +00:00
|
|
|
using spvtest::Concatenate;
|
2015-09-22 19:50:33 +00:00
|
|
|
using spvtest::MakeInstruction;
|
2016-04-21 19:46:08 +00:00
|
|
|
using spvtest::ScopedContext;
|
2015-09-21 15:36:44 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2015-09-02 18:48:33 +00:00
|
|
|
using ::testing::ElementsAre;
|
2015-09-22 19:50:33 +00:00
|
|
|
using ::testing::Eq;
|
2015-09-11 04:43:11 +00:00
|
|
|
using ::testing::HasSubstr;
|
|
|
|
using ::testing::StrEq;
|
2015-08-31 21:42:22 +00:00
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, ImmediateIntOpCode) {
|
|
|
|
SetText("!0x00FF00FF");
|
2016-04-19 02:25:35 +00:00
|
|
|
ASSERT_EQ(SPV_SUCCESS, spvTextToBinary(ScopedContext().context, text.str,
|
|
|
|
text.length, &binary, &diagnostic));
|
2015-11-18 14:22:10 +00:00
|
|
|
EXPECT_EQ(0x00FF00FFu, binary->code[5]);
|
2015-08-31 21:42:22 +00:00
|
|
|
if (diagnostic) {
|
|
|
|
spvDiagnosticPrint(diagnostic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, ImmediateIntOperand) {
|
|
|
|
SetText("OpCapability !0x00FF00FF");
|
2016-04-19 02:25:35 +00:00
|
|
|
EXPECT_EQ(SPV_SUCCESS, spvTextToBinary(ScopedContext().context, text.str,
|
|
|
|
text.length, &binary, &diagnostic));
|
2015-11-18 14:22:10 +00:00
|
|
|
EXPECT_EQ(0x00FF00FFu, binary->code[6]);
|
2015-08-31 21:42:22 +00:00
|
|
|
if (diagnostic) {
|
|
|
|
spvDiagnosticPrint(diagnostic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 18:48:33 +00:00
|
|
|
using ImmediateIntTest = TextToBinaryTest;
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, AnyWordInSimpleStatement) {
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("!0x00040018 %a %b %123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 2, 3})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("!0x00040018 !1 %b %123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 1, 2})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpTypeMatrix !2 %123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 2, 2})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpTypeMatrix %b !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 2, 123})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("!0x00040018 %a !2 %123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 2, 2})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("!0x00040018 !1 %b !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 1, 123})));
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("!0x00040018 !1 !2 !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpTypeMatrix, {1, 2, 123})));
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 19:03:54 +00:00
|
|
|
TEST_F(ImmediateIntTest, AnyWordAfterEqualsAndOpCode) {
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength !2 %c 123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {2, 1, 2, 123})));
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength %b !3 123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {1, 2, 3, 123})));
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength %b %c !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {1, 2, 3, 123})));
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength %b !3 !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {1, 2, 3, 123})));
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength !2 !3 123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {2, 1, 3, 123})));
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%a = OpArrayLength !2 !3 !123"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpArrayLength, {2, 1, 3, 123})));
|
2015-09-11 19:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, ResultIdInAssignment) {
|
|
|
|
EXPECT_EQ("!2 not allowed before =.",
|
|
|
|
CompileFailure("!2 = OpArrayLength %12 %1 123"));
|
|
|
|
EXPECT_EQ("!2 not allowed before =.",
|
|
|
|
CompileFailure("!2 = !0x00040044 %12 %1 123"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, OpCodeInAssignment) {
|
|
|
|
EXPECT_EQ("Invalid Opcode prefix '!0x00040044'.",
|
|
|
|
CompileFailure("%2 = !0x00040044 %12 %1 123"));
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 15:41:36 +00:00
|
|
|
// Literal integers after !<integer> are handled correctly.
|
|
|
|
TEST_F(ImmediateIntTest, IntegerFollowingImmediate) {
|
2015-11-05 22:45:09 +00:00
|
|
|
const SpirvVector original = CompiledInstructions("%1 = OpTypeInt 8 1");
|
|
|
|
EXPECT_EQ(original, CompiledInstructions("!0x00040015 1 8 1"));
|
|
|
|
EXPECT_EQ(original, CompiledInstructions("!0x00040015 !1 8 1"));
|
2015-09-08 15:41:36 +00:00
|
|
|
|
2015-10-14 21:02:39 +00:00
|
|
|
// With !<integer>, we can (and can only) accept 32-bit number literals,
|
|
|
|
// even when we declare the return type is 64-bit.
|
|
|
|
EXPECT_EQ(Concatenate({
|
2015-10-28 17:40:52 +00:00
|
|
|
MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
|
|
|
|
MakeInstruction(SpvOpConstant, {1, 2, 4294967295}),
|
2015-10-14 21:02:39 +00:00
|
|
|
}),
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("%i64 = OpTypeInt 64 0\n"
|
|
|
|
"!0x0004002b %i64 !2 4294967295"));
|
2015-10-14 21:02:39 +00:00
|
|
|
// 64-bit integer literal.
|
|
|
|
EXPECT_EQ("Invalid word following !<integer>: 5000000000",
|
2015-11-05 22:45:09 +00:00
|
|
|
CompileFailure("%2 = OpConstant !1 5000000000"));
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_EQ("Invalid word following !<integer>: 5000000000",
|
2015-11-05 22:45:09 +00:00
|
|
|
CompileFailure("%i64 = OpTypeInt 64 0\n"
|
|
|
|
"!0x0005002b %i64 !2 5000000000"));
|
2015-09-08 15:41:36 +00:00
|
|
|
|
|
|
|
// Negative integer.
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_EQ(CompiledInstructions("%i64 = OpTypeInt 32 1\n"
|
|
|
|
"%2 = OpConstant %i64 -123"),
|
|
|
|
CompiledInstructions("%i64 = OpTypeInt 32 1\n"
|
|
|
|
"!0x0004002b %i64 !2 -123"));
|
2015-09-08 18:20:12 +00:00
|
|
|
|
2015-09-29 21:07:21 +00:00
|
|
|
// TODO(deki): uncomment assertions below and make them pass.
|
2015-09-08 18:20:12 +00:00
|
|
|
// Hex value(s).
|
2015-11-05 22:45:09 +00:00
|
|
|
// EXPECT_EQ(CompileSuccessfully("%1 = OpConstant %10 0x12345678"),
|
2015-09-12 00:10:54 +00:00
|
|
|
// CompileSuccessfully("OpConstant %10 !1 0x12345678", kCAF));
|
|
|
|
// EXPECT_EQ(
|
2015-11-05 22:45:09 +00:00
|
|
|
// CompileSuccessfully("%1 = OpConstant %10 0x12345678 0x87654321"),
|
2015-09-12 00:10:54 +00:00
|
|
|
// CompileSuccessfully("OpConstant %10 !1 0x12345678 0x87654321", kCAF));
|
2015-09-08 15:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Literal floats after !<integer> are handled correctly.
|
|
|
|
TEST_F(ImmediateIntTest, FloatFollowingImmediate) {
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_EQ(
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n%2 = OpConstant %1 0.123"),
|
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n!0x0004002b %1 !2 0.123"));
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_EQ(
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0.5"),
|
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n!0x0004002b %1 !2 -0.5"));
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_EQ(
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n%2 = OpConstant %1 0.123"),
|
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n!0x0004002b %1 %2 0.123"));
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_EQ(
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0.5"),
|
|
|
|
CompiledInstructions("%1 = OpTypeFloat 32\n!0x0004002b %1 %2 -0.5"));
|
2015-10-14 21:02:39 +00:00
|
|
|
|
2015-10-28 17:40:52 +00:00
|
|
|
EXPECT_EQ(Concatenate({
|
|
|
|
MakeInstruction(SpvOpTypeInt, {1, 64, 0}),
|
|
|
|
MakeInstruction(SpvOpConstant, {1, 2, 0xb, 0xa}),
|
|
|
|
MakeInstruction(SpvOpSwitch,
|
|
|
|
{2, 1234, BitwiseCast<uint32_t>(2.5f), 3}),
|
|
|
|
}),
|
|
|
|
CompiledInstructions("%i64 = OpTypeInt 64 0\n"
|
|
|
|
"%big = OpConstant %i64 0xa0000000b\n"
|
|
|
|
"OpSwitch %big !1234 2.5 %target\n"));
|
2015-09-08 15:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Literal strings after !<integer> are handled correctly.
|
|
|
|
TEST_F(ImmediateIntTest, StringFollowingImmediate) {
|
|
|
|
// Try a variety of strings, including empty and single-character.
|
2015-09-11 20:34:49 +00:00
|
|
|
for (std::string name : {"", "s", "longish", "really looooooooooooooooong"}) {
|
2015-09-08 16:14:07 +00:00
|
|
|
const SpirvVector original =
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("OpMemberName %10 4 \"" + name + "\"");
|
|
|
|
EXPECT_EQ(original,
|
|
|
|
CompiledInstructions("OpMemberName %10 !4 \"" + name + "\""))
|
2015-09-11 20:34:49 +00:00
|
|
|
<< name;
|
|
|
|
EXPECT_EQ(original,
|
2015-11-05 22:45:09 +00:00
|
|
|
CompiledInstructions("OpMemberName !1 !4 \"" + name + "\""))
|
2015-09-11 20:34:49 +00:00
|
|
|
<< name;
|
2016-01-11 15:54:20 +00:00
|
|
|
const uint16_t wordCount = static_cast<uint16_t>(4 + name.size() / 4);
|
2015-10-28 17:40:52 +00:00
|
|
|
const uint32_t firstWord = spvOpcodeMake(wordCount, SpvOpMemberName);
|
2015-09-22 19:50:33 +00:00
|
|
|
EXPECT_EQ(original, CompiledInstructions("!" + std::to_string(firstWord) +
|
2015-11-05 22:45:09 +00:00
|
|
|
" %10 !4 \"" + name + "\""))
|
2015-09-11 20:34:49 +00:00
|
|
|
<< name;
|
2015-09-08 15:41:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IDs after !<integer> are handled correctly.
|
|
|
|
TEST_F(ImmediateIntTest, IdFollowingImmediate) {
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_EQ(CompileSuccessfully("%123 = OpDecorationGroup"),
|
|
|
|
CompileSuccessfully("!0x00020049 %123"));
|
|
|
|
EXPECT_EQ(CompileSuccessfully("%group = OpDecorationGroup"),
|
|
|
|
CompileSuccessfully("!0x00020049 %group"));
|
2015-09-08 15:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// !<integer> after !<integer> is handled correctly.
|
|
|
|
TEST_F(ImmediateIntTest, ImmediateFollowingImmediate) {
|
2015-11-05 22:45:09 +00:00
|
|
|
const SpirvVector original = CompiledInstructions("%a = OpTypeMatrix %b 7");
|
|
|
|
EXPECT_EQ(original, CompiledInstructions("%a = OpTypeMatrix !2 !7"));
|
|
|
|
EXPECT_EQ(original, CompiledInstructions("!0x00040018 %a !2 !7"));
|
2015-09-08 15:41:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 18:48:33 +00:00
|
|
|
TEST_F(ImmediateIntTest, InvalidStatement) {
|
2015-11-05 22:45:09 +00:00
|
|
|
EXPECT_THAT(Subvector(CompileSuccessfully("!4 !3 !2 !1"), kFirstInstruction),
|
|
|
|
ElementsAre(4, 3, 2, 1));
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, InvalidStatementBetweenValidOnes) {
|
2015-09-12 00:10:54 +00:00
|
|
|
EXPECT_THAT(Subvector(CompileSuccessfully(
|
2015-11-05 22:45:09 +00:00
|
|
|
"%10 = OpTypeFloat 32 !5 !6 !7 OpEmitVertex"),
|
2015-09-10 18:00:00 +00:00
|
|
|
kFirstInstruction),
|
2015-10-28 17:40:52 +00:00
|
|
|
ElementsAre(spvOpcodeMake(3, SpvOpTypeFloat), 1, 32, 5, 6, 7,
|
|
|
|
spvOpcodeMake(1, SpvOpEmitVertex)));
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, NextOpcodeRecognized) {
|
2015-09-12 00:10:54 +00:00
|
|
|
const SpirvVector original = CompileSuccessfully(R"(
|
2015-11-05 22:45:09 +00:00
|
|
|
%1 = OpLoad %10 %2 Volatile
|
|
|
|
%4 = OpCompositeInsert %11 %1 %3 0 1 2
|
|
|
|
)");
|
2015-09-12 00:10:54 +00:00
|
|
|
const SpirvVector alternate = CompileSuccessfully(R"(
|
2015-11-05 22:45:09 +00:00
|
|
|
%1 = OpLoad %10 %2 !1
|
|
|
|
%4 = OpCompositeInsert %11 %1 %3 0 1 2
|
|
|
|
)");
|
2015-09-02 18:48:33 +00:00
|
|
|
EXPECT_EQ(original, alternate);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ImmediateIntTest, WrongLengthButNextOpcodeStillRecognized) {
|
2015-09-12 00:10:54 +00:00
|
|
|
const SpirvVector original = CompileSuccessfully(R"(
|
2015-11-05 22:45:09 +00:00
|
|
|
%1 = OpLoad %10 %2 Volatile
|
2015-09-02 18:48:33 +00:00
|
|
|
OpCopyMemorySized %3 %4 %1
|
2015-11-05 22:45:09 +00:00
|
|
|
)");
|
2015-09-12 00:10:54 +00:00
|
|
|
const SpirvVector alternate = CompileSuccessfully(R"(
|
2015-09-02 18:48:33 +00:00
|
|
|
!0x0002003D %10 %1 %2 !1
|
|
|
|
OpCopyMemorySized %3 %4 %1
|
2015-11-05 22:45:09 +00:00
|
|
|
)");
|
2015-11-18 14:22:10 +00:00
|
|
|
EXPECT_EQ(0x0002003Du, alternate[kFirstInstruction]);
|
2015-09-02 18:48:33 +00:00
|
|
|
EXPECT_EQ(Subvector(original, kFirstInstruction + 1),
|
|
|
|
Subvector(alternate, kFirstInstruction + 1));
|
|
|
|
}
|
|
|
|
|
2015-09-03 21:42:50 +00:00
|
|
|
// Like NextOpcodeRecognized, but next statement is in assignment form.
|
2015-09-11 20:34:49 +00:00
|
|
|
TEST_F(ImmediateIntTest, NextAssignmentRecognized) {
|
2015-09-08 16:14:07 +00:00
|
|
|
const SpirvVector original = CompileSuccessfully(R"(
|
2015-09-10 18:00:00 +00:00
|
|
|
%1 = OpLoad %10 %2 None
|
2015-09-22 19:50:33 +00:00
|
|
|
%4 = OpFunctionCall %10 %3 %123
|
2015-09-02 21:17:42 +00:00
|
|
|
)");
|
2015-09-08 16:14:07 +00:00
|
|
|
const SpirvVector alternate = CompileSuccessfully(R"(
|
2015-09-11 20:34:49 +00:00
|
|
|
%1 = OpLoad %10 %2 !0
|
2015-09-22 19:50:33 +00:00
|
|
|
%4 = OpFunctionCall %10 %3 %123
|
2015-09-02 21:17:42 +00:00
|
|
|
)");
|
|
|
|
EXPECT_EQ(original, alternate);
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 21:42:50 +00:00
|
|
|
// Two instructions in a row each have !<integer> opcode.
|
2015-09-02 18:48:33 +00:00
|
|
|
TEST_F(ImmediateIntTest, ConsecutiveImmediateOpcodes) {
|
2015-09-08 16:14:07 +00:00
|
|
|
const SpirvVector original = CompileSuccessfully(R"(
|
2015-09-10 18:00:00 +00:00
|
|
|
%1 = OpConstantSampler %10 Clamp 78 Linear
|
|
|
|
%4 = OpFRem %11 %3 %2
|
2015-09-03 21:42:50 +00:00
|
|
|
%5 = OpIsValidEvent %12 %2
|
|
|
|
)");
|
2015-09-08 16:14:07 +00:00
|
|
|
const SpirvVector alternate = CompileSuccessfully(R"(
|
2015-09-03 21:42:50 +00:00
|
|
|
!0x0006002D %10 %1 !2 78 !1
|
|
|
|
!0x0005008C %11 %4 %3 %2
|
|
|
|
%5 = OpIsValidEvent %12 %2
|
|
|
|
)");
|
|
|
|
EXPECT_EQ(original, alternate);
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 18:17:14 +00:00
|
|
|
// !<integer> followed by, eg, an enum or '=' or a random bareword.
|
2015-09-02 18:48:33 +00:00
|
|
|
TEST_F(ImmediateIntTest, ForbiddenOperands) {
|
2015-09-08 18:17:14 +00:00
|
|
|
EXPECT_THAT(CompileFailure("OpMemoryModel !0 OpenCL"), HasSubstr("OpenCL"));
|
|
|
|
EXPECT_THAT(CompileFailure("!1 %0 = !2"), HasSubstr("="));
|
2015-09-30 13:49:00 +00:00
|
|
|
EXPECT_THAT(CompileFailure("OpMemoryModel !0 random_bareword"),
|
|
|
|
HasSubstr("random_bareword"));
|
2015-09-08 18:17:14 +00:00
|
|
|
// Immediate integers longer than one 32-bit word.
|
|
|
|
EXPECT_THAT(CompileFailure("!5000000000"), HasSubstr("5000000000"));
|
2015-09-29 21:07:21 +00:00
|
|
|
EXPECT_THAT(CompileFailure("!999999999999999999"),
|
|
|
|
HasSubstr("999999999999999999"));
|
|
|
|
EXPECT_THAT(CompileFailure("!0x00020049 !5000000000"),
|
|
|
|
HasSubstr("5000000000"));
|
2015-09-30 13:49:00 +00:00
|
|
|
// Negative numbers.
|
|
|
|
EXPECT_THAT(CompileFailure("!0x00020049 !-123"), HasSubstr("-123"));
|
2015-09-02 18:48:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 04:43:11 +00:00
|
|
|
TEST_F(ImmediateIntTest, NotInteger) {
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_THAT(CompileFailure("!abc"), StrEq("Invalid immediate integer: !abc"));
|
2015-09-11 04:43:11 +00:00
|
|
|
EXPECT_THAT(CompileFailure("!12.3"),
|
2015-10-05 17:28:46 +00:00
|
|
|
StrEq("Invalid immediate integer: !12.3"));
|
2015-10-14 21:02:39 +00:00
|
|
|
EXPECT_THAT(CompileFailure("!12K"), StrEq("Invalid immediate integer: !12K"));
|
2015-09-11 04:43:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 17:25:17 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace utils
|
|
|
|
} // namespace spvtools
|