Commit Graph

54 Commits

Author SHA1 Message Date
David Neto
feda995c84 More parsing tests for literals with leading minus
Also checks some hex literal cases.

This addresses part of
https://github.com/KhronosGroup/SPIRV-Tools/issues/45
by removing the parseNumber case for "-0" on unsigned
integers.  We don't care about that platform difference
at the level of std::istringstream, since we reject it
at a higher parsing level.
2016-02-08 16:56:41 -05:00
Andrew Woloszyn
7a35473573 Made compilation with gcc and clang more strict.
Added additional compilation flags to gcc and clang builds.
Adds -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
-WNo-sign-conversion and -Wno-missing-field-initializers
where appropriate.

Does not add -Wundef to tests, because GTEST tests undefined
macros all over the place.
2016-01-11 10:54:20 -05:00
Andrew Woloszyn
43401d2ed0 Support 16-bit float in assembler and disassembler
This adds half-precision constants to spirv-tools.
16-bit floats are always disassembled into hex-float format,
but can be assembled from floating point or hex-float inputs.
2016-01-08 10:48:39 -05:00
Dejan Mircevski
b6fe02fc39 Extend copyright to 2016. 2016-01-07 13:44:22 -05:00
David Neto
1a3734d265 Avoid relative path in #include
Adds CMAKE_CURRENT_SOURCE_DIR to the include path for UnitSPIRV
2016-01-04 13:07:45 -05:00
Lei Zhang
8bd75d650e Clean up CMake configuration and address compiler warnings.
- Removed dead configuration in CMakeLists.txt.
- Used target_compile_options() instead of CMAKE_{C|CXX}_FLAGS.
- Turned on warnings on tests.
- Fixed various warnings for comparing signed with unsigned values.
- Removed dead code exposed by compiler warnings.
2015-11-18 16:32:41 -05:00
Lei Zhang
972788bf23 Use opaque context object to hold SPIR-V info tables.
Previously the opcode table is declared as an global array and we
have spvOpcodeTableInitialize() modifying it. That can result in
race condition. Now spvOpcodeTabelGet() copies the whole underlying
array.
2015-11-12 16:27:51 -05:00
Lei Zhang
321c3e206b Remove an obselete and redundant text. 2015-11-12 16:27:51 -05:00
Lei Zhang
39b01b9988 Simplify some tests 2015-11-12 16:27:46 -05:00
David Neto
d02f68ae79 Update to 1.0 Rev 2 work-in-progress headers
Updated readme.

Note: The header advertises itself as Rev 1, but contains
many (all?) the updates intended for Rev 2.  We might need
to update one more time before SPIR-V 1.0 Rev2 is published.

Regenerated syntax tables for 1.0.

Changed names:
  InputTriangles -> Triangles
  InputQuads -> Quads
  InputIsolines -> Isolines
  WorkgroupLocal -> Workgroup
  WorkgroupGlobal -> CrossWorkgroup
  PrivateGlobal -> Private
  (Dim) InputTarget -> SubpassData
  WorkgroupLocalMemoryMask -> WorkgroupMemoryMask
  WorkgroupGlobalMemoryMask -> CrossWorkgroupMemoryMask
  AsyncGroupCopy -> GroupAsyncCopy
  WaitGroupEvents -> GroupWaitEvents

Remove:
  IndependentForwardProgress capability
  Smooth decoration
  FragColor BuiltIn
  WorkgroupLinearId in favour of LocalInvocationId
  ImageSRGBWrite capability
  Special OpenCL image instructions

Add:
  image channel data type UnormInt101010_2
  AcquireReleaseMask

InputTargetIndex updates:
  InputTargetIndex -> InputAttachmentIndex
  InputAttachmentIndex depends on InputAttachment capability,
  and it takes a literal number argument.

Capability StorageImageExtendedFormats updates:
  Enum value changed from 26 to 49. (Changes position in tables).
  Replaces AdvancedImageFormat capability.

OpenCL source language -> OpenCL_C, OpenCL_CPP
2015-11-12 09:43:12 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
df920ecb71 Remove table parameters from API functions.
Opcode, operand, and external instruction tables are no longer
passed in as parameters to spvTextToBinary(), spvBinaryToText(),
and spvValidate().
2015-11-12 09:42:50 -05:00
Lei Zhang
9049bb4877 Get magic number and version from spirv.h.
This is a part of the effort to clean up libspirv.h.
2015-11-11 12:12:10 -05:00
David Neto
9e545d7968 Assembler supports hex float constants.
The bit pattern for a hex float is preserved through
assembly and disassembly.

You can use a hex float to express Inf and any kind of NaN
in a portable way.
2015-11-10 15:58:03 -05:00
David Neto
229b90f6f4 Print OpConstant values according to type.
Zero and normal floating point values are printed with enough
enough digits to reproduce all the bits exactly.
Other float values (subnormal, infinity, and NaN) are printed
as hex floats.

Fix a binary parse bug: Count partially filled words in a
typed literal number operand.

TODO: Assembler support for hex numbers, and therefore reading
infinities and NaNs.
2015-11-10 15:57:59 -05:00
David Neto
ea633a6427 Empty assembly text compiles to no instructions.
But it's still a valid module.
2015-11-10 15:56:57 -05:00
Lei Zhang
1a0334edee Run clang-format to enforce Google style globally.
Note that we are more strict than Google style for one aspect:
pointer/reference indicators are adjacent to their types, not
their variables.

find . -name "*.h" -exec clang-format -i {} \;
find . -name "*.cpp" -exec clang-format -i {} \;
2015-11-10 15:56:47 -05:00
Lei Zhang
b36e704a47 Use spirv.h instead of spirv.hpp.
This is a part of the effort to make libspirv.h C-compatible.
2015-11-02 13:52:20 -05:00
Andrew Woloszyn
f731cbf6c4 Added set_bits<> to bitutils.
This allows us to get a constant with the given bits set at
compile-time. This is needed for a future patch for HexFloat.
2015-11-02 13:51:51 -05:00
David Neto
51013d15ee SPV_FAILED_MATCH error mutes DiagnosticStream.
The DiagnosticStream will not emit the accumulated message
text if the error is SPV_FAILED_MATCH.

Change various interfaces to accept the intended error
code instead of a boolean "is_optional".  This allows
us to avoid repeating the following type of logic deep
inside helper methods:

  if (is_optional) return SPV_FAILED_MATCH;
  return diagnostic() << " message text ";
2015-10-26 12:55:33 -04:00
David Neto
6274120eb9 Add AssemblyContext::parseNumber
It parses a text string for a value of a given target type.
2015-10-26 12:55:33 -04:00
David Neto
3d2bf53294 Move AutoText and EnumCase into spvtest namespace
Also fix using declaration order.
Also put a few tests into the anonymous namespace.
2015-10-26 12:55:33 -04:00
David Neto
42bfd4bfab Assembly test for OpSwitch
Removes old weak and fragile tests for OpSwitch.

Adds spvtest::TextToBinaryTest::CompileWithFormatFailure
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
71fc05587b Refactored dynamic and static state out of text processing.
This reduces the number of arguments required to be passed
to every single function. This is in preparation for adding
id tracking.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
13804e5d63 All values now represent symbolic names instead of mixed with numeric.
Also removed un-necessary heap-allocation of spv_named_id_table.
This removed the necessity to expose a function to create/destroy it
and simplified the interface.
2015-10-26 12:55:33 -04:00
Lei Zhang
a66952d38c Remove executable file mode bits on source files. 2015-10-26 12:55:33 -04:00
David Neto
1b5fd4962e Put the test fixture into spvtest namespace.
All test utility code should go into the spvtest namespace.
2015-10-26 12:55:33 -04:00
David Neto
d1dd2fbd7c Put const back on const char* in test case structs 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
f2d0775f1b A bunch of small fixes to build in MSVC2013.
Fixed an issue where some of the tests were testing
the wrong word with the wrong operation. (| != ||).

Coalesced the many versions of EnumCase into one.
Added a get_value() to EnumCase to convert to a uint32_t.

Replaces ASSERT_TRUE(pointer), with ASSERT_NE(nullptr, pointer),
so that we do not do implicit pointer->bool conversion.

Removed const from some test structs since gtest needs to be
able to swap them.
2015-10-26 12:55:33 -04:00
Lei Zhang
184c76dbaf Let EncodeAndDecodeSuccessfully remove preamble comments. 2015-10-26 12:55:33 -04:00
David Neto
36b0c0f6b3 Assembler support for simple mask expressions
For example, support combining mask enums with "|",
such as "NotNaN|AllowRecip" for the fast math mode.

This is supported for mask values that don't modify the
expected operand pattern:
 - fast math mode
 - function control
 - loop control
 - selection control

TODO: disassembler support to print them as mask expressions.
2015-10-26 12:55:33 -04:00
Lei Zhang
4e092d3ac3 Move bitwisecast.h to source/ and add include guard. 2015-10-26 12:55:33 -04:00
David Neto
a48678ab92 Fix an infinite loop during message generation.
Rename getWord to spvGetWord and unit test it.
2015-10-26 12:55:33 -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
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
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
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
David Neto
b3669d13fe Remove unused struct "bin" 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
Lei Zhang
0e149d7cc4 Move tests for GLSL std450 instructions to a separate file. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
a5c171544b Add std450 instructions 25-34. 2015-10-26 12:52:01 -04:00
Lei Zhang
abafd5e674 Only use '%' as variable name prefix.
Since now we can distinguish between def and use according to
the variable's location, there is no need to keep two variable
prefixes.

Also reformat tests to use the value generating instruction
format ("<result-id> = <opcode> <operand>..").
2015-08-24 15:05:11 -04:00
Lei Zhang
977e9bcfc6 Bugfix: report the correct location for wrong opcode.
Also add more tests for the "<result-id> = <opcode> <operand>.."
format.
2015-08-24 15:05:08 -04:00
Lei Zhang
ee87cc2a1e Fix TextAdvance() problems involving whitespace around comment lines.
Fix the bug that TextAdvance() forgot to skip whitespace at the
beginning of the next line after a comment line.

Fix the bug that TextAdvanceLine() increase line number after going
over a character.
2015-08-24 15:05:05 -04:00
Lei Zhang
dfc50086a6 Support "<result-id> = <opcode> <operand>.." format. 2015-08-24 15:04:58 -04:00
Andrew Woloszyn
1d2a87ed1b Added the initial set of glsl450 instructions.
Also rewrote the extended-instruction tests so that they would actually
make sure that the instruction actually appears in the output.
2015-08-24 15:04:49 -04:00