2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +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-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +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-05-22 17:26:19 +00:00
|
|
|
|
2015-09-22 19:50:33 +00:00
|
|
|
#include <vector>
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-09-22 15:05:30 +00:00
|
|
|
#include "test_fixture.h"
|
|
|
|
#include "unit_spirv.h"
|
2015-11-19 15:30:39 +00:00
|
|
|
|
2015-08-31 19:24:32 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-11-19 15:30:39 +00:00
|
|
|
using NamedIdTest = spvtest::TextToBinaryTest;
|
|
|
|
|
|
|
|
TEST_F(NamedIdTest, Default) {
|
|
|
|
const std::string input = R"(
|
2015-08-21 15:50:55 +00:00
|
|
|
OpCapability Shader
|
|
|
|
OpMemoryModel Logical Simple
|
Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types. (Internally, it is a deque,
for readability.) Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.
The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
operands. These are expanded lazily during the parse.
Adds spv::OperandClass from the SPIR-V specification generator.
Modifies spv_operand_desc_t:
- adds hasResult, hasType, and operandClass array to the opcode
description type.
- "wordCount" is replaced with "numTypes", which counts the number
of entries in operandTypes. And each of those describes a
*logical* operand, including the type id for the instruction,
and the result id for the instruction. A logical operand could be
variable-width, such as a literal string.
Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)
Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH. For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.
The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode. So now, "OpenCL" does not look like
an opcode name.
In assembly, the EntryPoint name field is mandatory, but can be
an empty string.
Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-08-27 17:03:52 +00:00
|
|
|
OpEntryPoint Vertex %main "foo"
|
2015-08-21 15:50:55 +00:00
|
|
|
%void = OpTypeVoid
|
2015-08-21 15:52:29 +00:00
|
|
|
%fnMain = OpTypeFunction %void
|
|
|
|
%main = OpFunction %void None %fnMain
|
2015-08-21 15:50:55 +00:00
|
|
|
%lbMain = OpLabel
|
|
|
|
OpReturn
|
|
|
|
OpFunctionEnd)";
|
2015-11-19 15:30:39 +00:00
|
|
|
const std::string output =
|
|
|
|
"OpCapability Shader\n"
|
|
|
|
"OpMemoryModel Logical Simple\n"
|
|
|
|
"OpEntryPoint Vertex %1 \"foo\"\n"
|
|
|
|
"%2 = OpTypeVoid\n"
|
|
|
|
"%3 = OpTypeFunction %2\n"
|
|
|
|
"%1 = OpFunction %2 None %3\n"
|
|
|
|
"%4 = OpLabel\n"
|
|
|
|
"OpReturn\n"
|
|
|
|
"OpFunctionEnd\n";
|
|
|
|
EXPECT_EQ(output, EncodeAndDecodeSuccessfully(input));
|
2015-05-22 17:26:19 +00:00
|
|
|
}
|
2015-08-31 19:24:32 +00:00
|
|
|
|
2015-09-22 19:50:33 +00:00
|
|
|
struct IdCheckCase {
|
|
|
|
std::string id;
|
|
|
|
bool valid;
|
|
|
|
};
|
|
|
|
|
|
|
|
using IdValidityTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<IdCheckCase>>;
|
|
|
|
|
|
|
|
TEST_P(IdValidityTest, IdTypes) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = GetParam().id + " = OpTypeVoid";
|
2015-09-22 19:50:33 +00:00
|
|
|
SetText(input);
|
|
|
|
if (GetParam().valid) {
|
|
|
|
CompileSuccessfully(input);
|
|
|
|
} else {
|
|
|
|
CompileFailure(input);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
ValidAndInvalidIds, IdValidityTest,
|
|
|
|
::testing::ValuesIn(std::vector<IdCheckCase>({{"%1", true},
|
|
|
|
{"%2abc", true},
|
|
|
|
{"%3Def", true},
|
|
|
|
{"%4GHI", true},
|
|
|
|
{"%5_j_k", true},
|
|
|
|
{"%6J_M", true},
|
|
|
|
{"%n", true},
|
|
|
|
{"%O", true},
|
|
|
|
{"%p7", true},
|
|
|
|
{"%Q8", true},
|
|
|
|
{"%R_S", true},
|
|
|
|
{"%T_10_U", true},
|
|
|
|
{"%V_11", true},
|
|
|
|
{"%W_X_13", true},
|
|
|
|
{"%_A", true},
|
|
|
|
{"%_", true},
|
|
|
|
{"%__", true},
|
|
|
|
{"%A_", true},
|
|
|
|
{"%_A_", true},
|
|
|
|
|
|
|
|
{"%@", false},
|
|
|
|
{"%!", false},
|
|
|
|
{"%ABC!", false},
|
|
|
|
{"%__A__@", false},
|
|
|
|
{"%%", false},
|
|
|
|
{"%-", false},
|
|
|
|
{"%foo_@_bar", false},
|
|
|
|
{"%", false},
|
|
|
|
|
|
|
|
{"5", false},
|
|
|
|
{"32", false},
|
|
|
|
{"foo", false},
|
2016-03-18 18:13:16 +00:00
|
|
|
{"a%bar", false}})),);
|
2015-09-22 19:50:33 +00:00
|
|
|
|
2015-08-31 19:24:32 +00:00
|
|
|
} // anonymous namespace
|