Commit Graph

65 Commits

Author SHA1 Message Date
David Neto
55bdfcb0bc Assembler test for LinkageAttributes decorations 2015-10-26 12:54:39 -04:00
David Neto
37547b2304 Assembler tests for all decorations except Linkage attributes
Fixes typos in various parser tables.

Updates readme.md with the fixes.
2015-10-26 12:54:39 -04:00
Lei Zhang
e78a7c19ff Run clang-format. 2015-10-26 12:54:39 -04:00
Lei Zhang
06efdc59e1 Add an API parameter to choose assembly syntax format for assembler.
Added a new enum for supported assembly syntax formats:
Canonical Assembly Format (CAF) and Assignment Assembly Format (AAF).

Updated assembler interface functions to support choice of assembly
syntax format.
2015-10-26 12:54:39 -04:00
David Neto
a08350a2c3 Assembler test for OpSourceExtension.
Add test utility function MakeVector(std::string) to encode
a string as a vector of 32-bit words, as per the SPIR-V literal
string encoding.
2015-10-26 12:54:39 -04:00
David Neto
08d89bb7a5 Test assembly of OpSource using all language enums
Adds a file to test assembly of instructions in the "Debug" section
of the SPIR-V spec.
2015-10-26 12:54:39 -04:00
David Neto
43f0e819c4 Avoid undefined pointer given to spvTextDestroy
The undefined pointer might get through to the call
to spvTextDestroy if the test fails on an earlier step.
In that case I just want to see the test failure, and
not a test failure followed by undefined behaviour.
2015-10-26 12:54:39 -04:00
David Neto
c88dcd6a72 Add OpNop, OpUndef tests for spvTextToBinary
Add text_fixture::TextToBinaryTestBase::CompiledInstructions,
to more easily just examine the generated instructions by skipping
over the header.

Add spvtest::MakeInstruction utility function to easily generate
a vector containing an opcode and its operands.
2015-10-26 12:54:39 -04:00
Lei Zhang
574352c7a9 Fix interface function calls to the new API. 2015-10-26 12:54:39 -04:00
Lei Zhang
610c525865 Preserve float values during encoding and decoding roundtrip. 2015-10-26 12:54:39 -04:00
Andrew Woloszyn
cfeac48a37 Removed the ambiguity in the API for cleaning input vs output data.
Previous the api used spv_text_t and spv_binary_t for both input
and output, but depending on the usage, you either MUST
call spvBinaryDestroy or you MUST NOT call spvBinaryDestroy on the
pointer.
2015-10-26 12:54:39 -04:00
David Neto
cac38f92dd Simplify uses of spvBinaryDestroy in tests
Always try to destroy the binary during common methods
of test fixtures.  This is safe if no other code in the test
attempted to destroy the binary.

Take advantage of the fact spvBinaryDestroy is a no-op on a nullptr,
by eliminating the null pointer check in the caller.
2015-10-26 12:54:39 -04:00
David Neto
ac6f71b2de spvTextDestroy is no-op on nullptr. 2015-10-26 12:54:39 -04:00
David Neto
a71138372e Fix spvBinaryDestroy test to use an API-created object 2015-10-26 12:54:39 -04:00
David Neto
b6a8898fa5 Enable OpcodeMake test, by sampling values.
The previous version of the test was disabled, presumably
because it took to long to run.
2015-10-26 12:54:39 -04:00
David Neto
f4fd780654 spvBinaryDestroy(nullptr) is a no-op. 2015-10-26 12:54:39 -04:00
David Neto
c9b5152b4f Remove spvOpcodeIsVariable
Nothing was using it.
2015-10-26 12:54:39 -04:00
Dejan Mircevski
1a3990233c Add hex-format tests for !<integer>. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
ea5a2a5242 Add invalid-operand tests for !<integer>. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
a4b834e456 Make all SpirvVectors const in ImmediateInt.cpp. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
d8454a7967 Tests for parsing recognizable words after !<integer>. 2015-10-26 12:52:01 -04:00
David Neto
f58d8c0965 Add disabled test to check float value parsing
Disabled for now because float parsing is broken.
2015-10-26 12:52:01 -04:00
David Neto
c978643748 Print diagnostics at the beginning of input.
A spv_diagnostic_t value knows if the source is textual rather
than binary.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
e75b3e769d Avoid "operands" in the !<immediate> explanation.
Also declare "!<integer> = OpCode" legal.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
d5769bf08a Test consecutive opcodes being !<integer>. 2015-10-26 12:52:01 -04:00
David Neto
78c3b43774 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-10-26 12:52:01 -04:00
Dejan Mircevski
6c03f87490 Print failing assembly text in CompileSuccessfully(). 2015-10-26 12:52:01 -04:00
David Neto
b3669d13fe Remove unused struct "bin" 2015-10-26 12:52:01 -04:00
Dejan Mircevski
741cdc4829 More !<integer> tests. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
5f45e596bd Use spvOpcodeMake() in ImmediateInt tests. 2015-10-26 12:52:01 -04:00
David Neto
d3ead501de Don't overload operators in std namespace.
Use a spvtest::WordVector proxy object to easily print
std::vector<uint32_t> and spv_binary_t values.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
0a8f219d1e Add a few unit tests for !<integer>. More to come.
Start using GMock: modify CMakeLists, fix googletest URL in readme.

Add useful utilities to the TestFixture class.  Also make it conform to
go/gunit recommendations about setup/teardown.
2015-10-26 12:52:01 -04:00
David Neto
9fa9157c4d Add bin-to-text test for operand with operands 2015-10-26 12:52:01 -04:00
David Neto
c9a23a6fd5 Add binary-to-text test for single instruction
This is easier to debug!

Binary-to-text testing needs more tests, and more
specific tests.  That's for future work.
2015-10-26 12:52:01 -04:00
David Neto
e7ee4c4476 Getting the next word respects quoting and escaping.
Use double quotes (").  They can be interspersed with
other whitespace characters, just like shell quoting.

A backslash (\) always escapes the next character.

The end of the stream always terminates the word.

Add AutoText struct to unit test utilities, to easily
make spv_text_t values and reference them as spv_text values.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
f184109d7b Move ImmediateInt tests into their own file.
This is in preparation of adding many more tests in accordance with the
evolved spec.

Also sort the test-source lines in CMakeLists.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
73d7082245 Put test classes in anonymous namespace.
Put TestFixture.h classes in a namespace.

Remove unused #includes.
2015-10-26 12:52:01 -04:00
David Neto
574884cd7e Getting the next word ends at a comment (;) 2015-10-26 12:52:01 -04:00
David Neto
98290a243e String literals must be quoted. 2015-10-26 12:52:01 -04:00
David Neto
affa696027 Fix some bugs in parsing literals.
- a single hyphen is a string, not a number.
- a string with more than one period is a string, not a number
- check for string overflow

Add some unit tests
2015-10-26 12:52:01 -04:00
Lei Zhang
5b73214223 Add GLSL std450 extended instruction 72-80. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
afdbd2d303 Add std450 instructions 53-64. 2015-10-26 12:52:01 -04:00
Lei Zhang
3cb589639d Add GLSL std450 extended instruction 65-71. 2015-10-26 12:52:01 -04:00
Lei Zhang
85d4d6d677 Add test for Modf and ModfStruct. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
c48fcce978 Add std450 instructions 49-52. 2015-10-26 12:52:01 -04:00
Lei Zhang
dca65b3f8c Reformat GLSL std450 extended instruction table.
Also add test for Smoothstep.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
c4ba8821e7 Add tests for Atan2 and Pow.
Fix a typo in "ParameterizedExtInst."
2015-10-26 12:52:01 -04:00
Lei Zhang
65bfc4d585 Unify tests for GLSL std450 extended instructions.
Previously we had two tests: one checks test to binary, the other
checks round trip. This patch merges the check in the former to
the latter.
2015-10-26 12:52:01 -04:00
Lei Zhang
e5ae7f677f Add GLSL std450 instructions 35-48. 2015-10-26 12:52:01 -04:00
Lei Zhang
0e149d7cc4 Move tests for GLSL std450 instructions to a separate file. 2015-10-26 12:52:01 -04:00