platform/upstream/SPIRV-Tools.git
8 years agoFixed internal compiler error in gcc-4.9.
Andrew Woloszyn [Wed, 17 Feb 2016 18:00:23 +0000 (13:00 -0500)]
Fixed internal compiler error in gcc-4.9.

This showed up in mips and mips64 builds. A combination of templates
and the error reporting were causing gcc to crash. This splits up the
functionality in a way that now successfully compiles.

8 years agoRemove remaining float overflow value tests
David Neto [Wed, 17 Feb 2016 17:39:41 +0000 (12:39 -0500)]
Remove remaining float overflow value tests

Should fix tests on Windows.

8 years agoUse syntax tables for SPIR-V 1.0 Rev3
David Neto [Mon, 15 Feb 2016 18:50:00 +0000 (13:50 -0500)]
Use syntax tables for SPIR-V 1.0 Rev3

- The SPIR-V spec generator has changed how it represents optional
  operands.  Now it tracks a separate boolean flag indicating optionality.
  However, SPIRV-Tools still wants to represent both operand class
  and optionality in the same enums space (SPV_OPERAND_TYPE_*).
  So there's extra work in the patch.

- In the spec generator, OperandImage is now OperandImageOperands.
  This affects enum translation in opcode.cpp.

- In the spec generator, image operands are explicitly followed by
  Id, and VariableIds.  However, SPIRV-Tools uses the bits set
  in the image operand bitmask to control the number and meaning
  of the Ids that follow.  So in writing the opcode.inc syntax
  table, drop all operands after OperandImageOperands.

- Some enums are now more explicitly represented in the generated
  opcode.inc:
    - AccessQualifier (e.g. on OpTypeImage), in both required and
      optional flavours.
    - MemoryAccess (e.g. on loads and stores)

- Add SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER

- Add tests for the optional AccessQualifier operand on OpTypeImage.

- Update the AccessQualifier test for OpTypeImage so it's a round
  trip test through the disassembler as well.

8 years agoUpdate capabilities for 1.0 Rev3
David Neto [Sun, 14 Feb 2016 18:55:50 +0000 (13:55 -0500)]
Update capabilities for 1.0 Rev3

8 years agoDon't promise particular values when float parsing fails.
David Neto [Tue, 16 Feb 2016 17:13:51 +0000 (12:13 -0500)]
Don't promise particular values when float parsing fails.

This should address problems on Windows:
https://github.com/KhronosGroup/SPIRV-Tools/issues/104

8 years agoConfigure gmock locally only if not already configured.
David Neto [Mon, 15 Feb 2016 14:36:20 +0000 (09:36 -0500)]
Configure gmock locally only if not already configured.

Allows an enclosing project to have already configured gmock, even
if the developer has placed the googletest sources under this
project's external/googletest directory.

Describe how to enable the tests in the two essential scenarios:
where SPIR-V Tools is standalone, or where SPIR-V Tools is configured
as a part of a larger project.

8 years agoUse SPIR-V headers for 1.0 Rev3
David Neto [Sun, 14 Feb 2016 18:42:17 +0000 (13:42 -0500)]
Use SPIR-V headers for 1.0 Rev3

Refresh from the SPIR-V registry.

8 years agoParse overflow for fp16 like for 32- and 64-bit
David Neto [Sat, 6 Feb 2016 18:48:05 +0000 (13:48 -0500)]
Parse overflow for fp16  like for 32- and 64-bit

In that case, set the stream fail bit, and set the maximum normal
value or lowest normal value, depending on the sign of the original
value.

8 years agoFloat literal parsing fixes
David Neto [Sat, 6 Feb 2016 18:48:05 +0000 (13:48 -0500)]
Float literal parsing fixes

- For 32- and 64-bit floats, overflow is a parse error

  This works around a difference between Xcode's istringstream
  and other platforms.  Xcode's runtime library will happlily
  "round up" overflow values to infinity.  We want to make it fail.

- When parsing a float fails due to bad syntax, follow C++11
  behaviour for operator>> and set the value to zero.

- When parsing a 32-bit or 64-bit float overflows, follow C++11
  behaviour for operator>> and set the value to the nearest
  normal value: either max or lowest finite value for the type.

- Add FloatProxy<T>::max() and ::lowest()

- Make 16-bit overflow behaviour more consistent: we always get a
  16-bit infinity of the right sign, whether the original string
  is a normal value for 32-bit or an overflow value for 32-bit.
  That matches our earlier intent.
  Added TODO's to make 16-bit overflow always an error, just like
  for 32-bit and 64-bit.

- Simplify normal parsing of Float16 values by delegating to
  normal parsing of 32-bit floats.

8 years agoReject float literals with two leading signs
David Neto [Wed, 10 Feb 2016 16:46:05 +0000 (11:46 -0500)]
Reject float literals with two leading signs

E.g. --1 should be rejected.

8 years agoMore parsing tests for literals with leading minus
David Neto [Mon, 8 Feb 2016 19:33:41 +0000 (14:33 -0500)]
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.

8 years agoMake IsTypeNullable a transitive check.
Dejan Mircevski [Wed, 3 Feb 2016 22:16:27 +0000 (17:16 -0500)]
Make IsTypeNullable a transitive check.

8 years agoEliminate parameter-order check from ID-validation.
Dejan Mircevski [Wed, 3 Feb 2016 17:34:52 +0000 (12:34 -0500)]
Eliminate parameter-order check from ID-validation.

8 years agoAllow Op[No]Line between OpFunctionParameters.
Dejan Mircevski [Wed, 3 Feb 2016 15:26:59 +0000 (10:26 -0500)]
Allow Op[No]Line between OpFunctionParameters.

Also ensure we don't get thrown off by too many parameters.

8 years agoEnable ctest.
Dejan Mircevski [Tue, 2 Feb 2016 19:41:35 +0000 (14:41 -0500)]
Enable ctest.

8 years agoValidation of mask operand capabilities is more data driven
David Neto [Tue, 2 Feb 2016 17:12:48 +0000 (12:12 -0500)]
Validation of mask operand capabilities is more data driven

Use spvOperandIsConcreteMask to determine if an operand is
a bitmask.  Check its individual bits in a generic way.

8 years agoAdd spvOperandIsConcreteMask
David Neto [Tue, 2 Feb 2016 17:05:34 +0000 (12:05 -0500)]
Add spvOperandIsConcreteMask

8 years agoUse AssemblyGrammar for capability validation.
Dejan Mircevski [Sun, 31 Jan 2016 04:32:09 +0000 (23:32 -0500)]
Use AssemblyGrammar for capability validation.

Also:
- ForEach() for spv_capability_mask_t.
- Add capability min/max constants.
- Move max definition from validate_types.cpp to spirv_definition.h.

8 years agoForbid Generic variables.
Dejan Mircevski [Fri, 29 Jan 2016 21:49:40 +0000 (16:49 -0500)]
Forbid Generic variables.

8 years agoFix validator mem overflow when tracking capabilities
qining [Fri, 29 Jan 2016 17:09:34 +0000 (12:09 -0500)]
Fix validator mem overflow when tracking capabilities

8 years agoFix in-function storage class validation.
Dejan Mircevski [Fri, 29 Jan 2016 03:20:28 +0000 (22:20 -0500)]
Fix in-function storage class validation.

Move tests into a fixture that properly turns on the relevant passes.

8 years agoInitialize vector<string>s on first use, not statically.
Dejan Mircevski [Thu, 28 Jan 2016 18:18:00 +0000 (13:18 -0500)]
Initialize vector<string>s on first use, not statically.

8 years agoFix validation of return value.
Dejan Mircevski [Fri, 22 Jan 2016 21:52:40 +0000 (16:52 -0500)]
Fix validation of return value.

8 years agoRemove spvOpcodeIsObject().
Dejan Mircevski [Fri, 22 Jan 2016 19:27:00 +0000 (14:27 -0500)]
Remove spvOpcodeIsObject().

Also
- Add type_id to spv_id_info_t.
- Use spv_id_info_t::type_id instead of words[1].
  Triggered some asserts on tests, where the code incorrectly assumed
  words[1] had a type.  Remove the asserts and handle gracefully.
- Add tests for OpStore of a label, a void, and a function.

8 years agoInitial capability implementation and unit tests
Umar Arshad [Sat, 23 Jan 2016 19:14:32 +0000 (14:14 -0500)]
Initial capability implementation and unit tests

* Register capabilility and checks
* Add validate storage class capabilities checks and tests
* Instruction pass refactor
  - More generic form of capability checking by checking operands
    instead of instructions
* Execution Model capabilities checks
* Decorate BuiltIn capability checks
* Addressing Model capability checks
* Memory Model capability checks
* Execution Mode capability checks
* Dim capability checks
* SamplerAddressingMode capability checks

8 years agoQualify CMake function names with "spvtools" to avoid conflictions.
Lei Zhang [Tue, 26 Jan 2016 23:04:55 +0000 (18:04 -0500)]
Qualify CMake function names with "spvtools" to avoid conflictions.

If a third-party project defines a CMake function with the same
name, by importing that project's CMake configuration, we may end
up overwriting our own copy. Qualify all defined functions to
reduce that probability.

8 years agoFix spvOpcodeIsScalarType() to include Boolean.
Dejan Mircevski [Thu, 21 Jan 2016 20:55:43 +0000 (15:55 -0500)]
Fix spvOpcodeIsScalarType() to include Boolean.

Remove redundant validations of OpConstant and OpConstantComposite.
Binary parser already performs these checks, so the validations can
never be triggered.

Enable bad-constant tests.

8 years agoDon't fail validation in unimplemented cases.
Dejan Mircevski [Thu, 21 Jan 2016 14:03:58 +0000 (09:03 -0500)]
Don't fail validation in unimplemented cases.

8 years agoFix OpLoad pointee type validation.
Dejan Mircevski [Thu, 21 Jan 2016 14:00:15 +0000 (09:00 -0500)]
Fix OpLoad pointee type validation.

8 years agoAdd disassembler option to show byte offset
David Neto [Mon, 18 Jan 2016 20:29:15 +0000 (15:29 -0500)]
Add disassembler option to show byte offset

The option is disabled by default.

The offset is printed in hex, as a comment after each instruction.

8 years agoTrack uses and defs during parsing.
Dejan Mircevski [Fri, 15 Jan 2016 16:25:11 +0000 (11:25 -0500)]
Track uses and defs during parsing.

Replace two other, imperfect mechanisms for use-def tracking.

Use ValidationState_t::entry_points to track entry points.

Concentrate undefined-ID diagnostics in a single place.

Move validate_types.h content into validate.h due to increased
inter-dependency.

Track uses of all IDs: TYPE_ID, SCOPE_ID, ...

Also update some blurbs.

Fix entry-point accumulation and move it outside ProcessIds().

Remove validate_types.h from CMakeLists.txt.

Blurb for spvIsIdType.

Remove redundant diagnostics for undefined IDs.

Join "can not" and reformat.

8 years agoSince g++-4.9 has an ICE occasionally in travis add a retry.
Andrew Woloszyn [Tue, 19 Jan 2016 21:13:45 +0000 (16:13 -0500)]
Since g++-4.9 has an ICE occasionally in travis add a retry.

Try to re-run the build with ninja -j 1 if the build fails,
this should reduce the number of build failures we see.

8 years agoFix missing OpNoLine layout checks
Umar Arshad [Mon, 18 Jan 2016 18:41:52 +0000 (13:41 -0500)]
Fix missing OpNoLine layout checks

8 years agoDisable warnings C4503 on MSVC for test code
David Neto [Fri, 15 Jan 2016 15:43:39 +0000 (10:43 -0500)]
Disable warnings C4503 on MSVC for test code

C4503 is "decorated name length exceeded", triggered
by some heavily templated types.

8 years agoValidation refactor
Umar Arshad [Thu, 14 Jan 2016 04:25:11 +0000 (23:25 -0500)]
Validation refactor

* Organize passes into seperate files
* Remove module layout logic from Cfg pass
* Remove module layout logic from Functions class
* Refactor ModuleLayoutPass for readability
* Adapt consistent naming of layout sections (Stage/Section -> Section)

8 years agoAdd configuration for Travis CI.
Lei Zhang [Thu, 7 Jan 2016 04:55:16 +0000 (23:55 -0500)]
Add configuration for Travis CI.

8 years agoAdd missing branch instructions in SSA tests
Umar Arshad [Thu, 14 Jan 2016 14:48:29 +0000 (09:48 -0500)]
Add missing branch instructions in SSA tests

8 years agoRemove static vector from GetModuleOrder
Umar Arshad [Sat, 9 Jan 2016 22:25:36 +0000 (17:25 -0500)]
Remove static vector from GetModuleOrder

8 years agoFixed warning in VS2013 build.
Andrew Woloszyn [Wed, 13 Jan 2016 15:44:05 +0000 (10:44 -0500)]
Fixed warning in VS2013 build.

Signed/Unsigned mismatch in progressToNextLayoutStageOrder().

8 years agoFix, that spirv-tools did not build, as two casts are not present.
Norbert Nopper [Wed, 13 Jan 2016 09:35:44 +0000 (10:35 +0100)]
Fix, that spirv-tools did not build, as two casts are not present.

8 years agoFix build by renaming ValidationState_t constructor argument.
Dejan Mircevski [Wed, 13 Jan 2016 14:52:23 +0000 (09:52 -0500)]
Fix build by renaming ValidationState_t constructor argument.

The `diag` argument shadows the `diag` method, so the strict build fails.

8 years agoFunction and block layout checks. very basic CFG.
Umar Arshad [Wed, 16 Dec 2015 02:44:21 +0000 (21:44 -0500)]
Function and block layout checks. very basic CFG.

This adds function and block layout checks to the validator. Very
basic CFG code has been added to make sure labels and branches
are correctly ordered.

Also:
* MemoryModel and Variable instruction checks/tests
* Use spvCheckReturn instead of CHECK_RESULT
* Fix invalid SSA tests
* Created libspirv::spvResultToString in diagnostic.h
* Documented various functions and classes
* Fixed error messages
* Fixed using declaration for FunctionDecl enum class

8 years agoFixed use-after-free in isStartOfNewInst() tests.
Andrew Woloszyn [Tue, 12 Jan 2016 19:47:24 +0000 (14:47 -0500)]
Fixed use-after-free in isStartOfNewInst() tests.

8 years agoMinor fixes to remove warnings in VS2013.
Andrew Woloszyn [Mon, 11 Jan 2016 21:22:34 +0000 (16:22 -0500)]
Minor fixes to remove warnings in VS2013.

Also fixes VS2015 build due to missing #include <iterator>

8 years agospvDiagnosticDestroy is safe to call on nullptr
David Neto [Mon, 11 Jan 2016 17:28:19 +0000 (12:28 -0500)]
spvDiagnosticDestroy is safe to call on nullptr

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/62

8 years agoFix endian-ness conversion in the binary parser.
Andrew Woloszyn [Mon, 11 Jan 2016 18:54:30 +0000 (13:54 -0500)]
Fix endian-ness conversion in the binary parser.

When we were swapping endian-ness in the binary parser, we would
write outside of the bounds of our vector.

8 years agoMade compilation with gcc and clang more strict.
Andrew Woloszyn [Mon, 11 Jan 2016 15:54:20 +0000 (10:54 -0500)]
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.

8 years agoSupport 16-bit float in assembler and disassembler
Andrew Woloszyn [Fri, 8 Jan 2016 14:54:42 +0000 (09:54 -0500)]
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.

8 years agoExtend copyright to 2016.
Dejan Mircevski [Thu, 7 Jan 2016 18:44:22 +0000 (13:44 -0500)]
Extend copyright to 2016.

8 years agoUndefine a macro after use.
Dejan Mircevski [Thu, 7 Jan 2016 16:00:38 +0000 (11:00 -0500)]
Undefine a macro after use.

8 years agoFix shadowing warnings reported by GCC
David Neto [Wed, 6 Jan 2016 19:43:55 +0000 (14:43 -0500)]
Fix shadowing warnings reported by GCC

8 years agoFix conversion warnings reported by GCC.
David Neto [Wed, 6 Jan 2016 18:08:39 +0000 (13:08 -0500)]
Fix conversion warnings reported by GCC.

8 years agoExplicitly convert to narrower type.
David Neto [Tue, 5 Jan 2016 19:57:58 +0000 (14:57 -0500)]
Explicitly convert to narrower type.

Fixes a strict Clang warning.

8 years agoAvoid variable shadowing
David Neto [Tue, 5 Jan 2016 19:56:02 +0000 (14:56 -0500)]
Avoid variable shadowing

8 years agoAvoid warning for implicit conversion of char array to bool.
David Neto [Tue, 5 Jan 2016 19:49:08 +0000 (14:49 -0500)]
Avoid warning for implicit conversion of char array to bool.

Clang complains about assert("unhandled") but not
assert(false && "unhandled").

8 years agoFix var shadowing and width mismatches in hex_float.h
David Neto [Tue, 5 Jan 2016 16:25:11 +0000 (11:25 -0500)]
Fix var shadowing and width mismatches in hex_float.h

8 years agoAvoid parameter shadowing in source/diagnostic.h
David Neto [Mon, 4 Jan 2016 22:27:34 +0000 (17:27 -0500)]
Avoid parameter shadowing in source/diagnostic.h

Change the offending class to more closely follow Google C++ style:
- Member names have a trailing underscore.
- Use an accessor method for the stream_ member.

8 years agoFix list of opcodes allowed for OpSpecConstantOp
David Neto [Tue, 5 Jan 2016 23:22:22 +0000 (18:22 -0500)]
Fix list of opcodes allowed for OpSpecConstantOp

Was missing BitcastXor, GenericCastToPtr.
Remove duplicate of SLessThanEqual

8 years agooperator<< on FloatProxy preserves float and fill
David Neto [Tue, 5 Jan 2016 17:45:54 +0000 (12:45 -0500)]
operator<< on FloatProxy preserves float and fill

Fixes formatting of disassembler output after printing
a hex float, e.g. for a NaN or subnormal.

8 years agoFix parser assert failure for a bad OpSwitch
David Neto [Wed, 23 Dec 2015 18:21:43 +0000 (13:21 -0500)]
Fix parser assert failure for a bad OpSwitch

Emit a diagnostic if the OpSwitch selector refers to an ID that
is valid but has no type.

Discovered by afl-fuzz.

8 years agoAvoid relative path in #include
David Neto [Tue, 22 Dec 2015 20:15:46 +0000 (15:15 -0500)]
Avoid relative path in #include

Adds CMAKE_CURRENT_SOURCE_DIR to the include path for UnitSPIRV

8 years agoRename endian.h to spirv_endian.h
David Neto [Tue, 22 Dec 2015 20:08:41 +0000 (15:08 -0500)]
Rename endian.h to spirv_endian.h

If we later add a source/ as an -I include directory,
then avoid confusing other headers that want to include the
standard "endian.h" from /usr/include.

Also rename source/endian.cpp to source/spirv_endian.cpp

8 years agoAdd spirv.py from the SPIR-V 1.0.2 registry
David Neto [Mon, 7 Dec 2015 18:54:20 +0000 (13:54 -0500)]
Add spirv.py from the SPIR-V 1.0.2 registry

8 years agoInitial logical layout validation
Umar Arshad [Tue, 15 Dec 2015 19:50:05 +0000 (14:50 -0500)]
Initial logical layout validation

* Validates module level instructions for logical layout
  conformance
* Does not validate:
  1. Function logical layout
  2. Minor cases with OpVariable
  3. Missing MemoryModel instruction in module
  4. Order of function definition and function declaration
* 782 unit tests for logical layout

Addressed feedback

8 years agoRefactor validation types into another file
Umar Arshad [Mon, 14 Dec 2015 13:21:08 +0000 (08:21 -0500)]
Refactor validation types into another file

8 years agoFix tests which rely on OpName;Use EXPECT_THAT
Umar Arshad [Mon, 14 Dec 2015 15:57:15 +0000 (10:57 -0500)]
Fix tests which rely on OpName;Use EXPECT_THAT

All OpName calls should appear before annotation and type
declarations.

8 years agoFix warnings with Apple clang++
Umar Arshad [Thu, 10 Dec 2015 16:56:34 +0000 (11:56 -0500)]
Fix warnings with Apple clang++

* Unused private member
* Overflow error when subtracting num_fraction_bits for HF16 and HF

8 years agoFix setting of off-by-default cmake options
David Neto [Wed, 9 Dec 2015 16:40:56 +0000 (11:40 -0500)]
Fix setting of off-by-default cmake options

An enclosing CMake project should be able to set the
off-by-default CMake options in SPIRV-Tools by just doing:
  set(SPIRV_SKIP_EXECUTABLES ON)
instead of
  set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE)

Also, fix the SPIRV_WARN_EVERYTHING so it understands which options
to send to Clang vs. GCC.

Note: With SPIRV_WARN_EVERYTHING enabled, the code doesn't
compil with either Clang or GCC.

8 years agoBasic SSA Validation
Umar Arshad [Wed, 18 Nov 2015 20:43:43 +0000 (15:43 -0500)]
Basic SSA Validation

Most uses of an ID must occur after the definition
of the ID.  Forward references are allowed for
things like OpName, OpDecorate, and various cases
of control-flow instructions such as OpBranch, OpPhi,
and OpFunctionCall.

TODO: Use CFG analysis for SSA checks.  In particular,
an ID defined inside a function body is only usable inside
that function body.  Also, use dominator info to catch
some failing cases.

Also:
* Validator test cases use (standard) assignment form.
* Update style to more closely follow the Google C++ style guide
* Remove color-diagnostics flag.
  This is enabled by default on terminals with color. Prints
  hidden ASCII for terminals that can't handle color(Emacs)
* Pass functors to SSAPass to check if the
  operand can be forward referenced based on its index value
* Return SPV_ERROR_INVALID_ID for ID related errors
  spvBinaryParse returned SPV_ERROR_INVALID_BINARY for all types of
  errors. Since spvBinaryParse does some ID validation, this was
  returning inappropriate error codes for some tests.
* Common fixture for validation tests.
  It only runs certian validation passes.
* Add a SPV_VALIDATE_SSA_BIT for testing purposes
* Fixtures now return error codes
* Add OpName support in diag message and unit tests
* Binary parsing can fail with invalid ID or invalid binary error code

Tests include:
* OpDecorate
* OpName
* OpMemberName
* OpBranchConditional
* OpSelectionMerge
* OpMemberDecorate
* OpGroupDecorate
* OpDeviceEnqueue
* Enable several tests failing in ID validation.

8 years agoAdded Float16, and HexFloat conversions
Andrew Woloszyn [Thu, 3 Dec 2015 21:30:21 +0000 (16:30 -0500)]
Added Float16, and HexFloat conversions

8 years agoFix namespace on PrintTo
David Neto [Wed, 2 Dec 2015 16:55:35 +0000 (11:55 -0500)]
Fix namespace on PrintTo

8 years agoPrintTo on WordVector should preserve the fill char
David Neto [Mon, 30 Nov 2015 23:10:13 +0000 (18:10 -0500)]
PrintTo on WordVector should preserve the fill char

8 years agoStated word count is several more than expected
David Neto [Tue, 1 Dec 2015 21:45:46 +0000 (16:45 -0500)]
Stated word count is several more than expected

These are extra binary parsing cases.

8 years agoUse static_cast instead of constructor for uint32_t
David Neto [Tue, 1 Dec 2015 21:19:44 +0000 (16:19 -0500)]
Use static_cast instead of constructor for uint32_t

8 years agoOpDecorate should not accept any number of literal operands.
David Neto [Mon, 30 Nov 2015 19:39:31 +0000 (14:39 -0500)]
OpDecorate should not accept any number of literal operands.

This is a grammar fix.  The Decoration operand of OpDecorate (and
OpMemberDecorate) determines the remaining operands.  Don't just
allow any number of literal numbers as operands.

(The OperandVariableLiterals operand class as the last member
of the OpDecorate and OpMemberDecorate entries in in opcode.inc is
an artifact of how the spec generates the opcode descriptions. It's
not suitable for parsing those instructions.)

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/34

8 years agobinary parse test: extra words after string literal
David Neto [Mon, 30 Nov 2015 18:45:20 +0000 (13:45 -0500)]
binary parse test: extra words after string literal

Covers the case where the string literal is the
last operand.

TODO: Case where one more operand is expected after
the string literal.  Occurs only for the LinkageAttributes
decoration.  To test that, we need to update the grammar
as well.

8 years agoDon't add -frtti for tests. Use newer googletest.
David Neto [Tue, 1 Dec 2015 17:01:59 +0000 (12:01 -0500)]
Don't add -frtti for tests. Use newer googletest.

Using -frtti caused link failures when both of the following are
in effect:
-DDISABLE_EXCEPTIONS=ON
-DDISABLE_RTTI=ON

The correct fix is to use tip-of-tree googletest.
Specifically, we need a version of googletest with the fix in
https://github.com/google/googletest/pull/612
In particular, it must be later than googletest 1.7.0.

8 years agoAdd -frtti for tests that use mocking
David Neto [Tue, 1 Dec 2015 15:01:33 +0000 (10:01 -0500)]
Add -frtti for tests that use mocking

The tests now use mocked methods.  This requires runtime type
information for those test classes.
https://github.com/google/googletest/issues/610

This has been fixed recently upstream in googletest.  Until we pick
up that fix, add -frtti for the the test executable only.

8 years agoMerge PR #32.
Dejan Mircevski [Mon, 30 Nov 2015 23:05:21 +0000 (18:05 -0500)]
Merge PR #32.

Simplify binary parser tests using GoogleMock.

8 years agoMention that ParsedInstruction owns its components.
Dejan Mircevski [Mon, 30 Nov 2015 16:21:09 +0000 (11:21 -0500)]
Mention that ParsedInstruction owns its components.

Also close a parenthesis in ParsedInstruction printout.

8 years agospvBinaryParse: fix overruns, handle image format
David Neto [Tue, 24 Nov 2015 23:37:24 +0000 (18:37 -0500)]
spvBinaryParse: fix overruns, handle image format

Add unit tests for all diagnostics issued by spvBinaryParse.

Handle image format operands in the binary parser and the
disassembler.

Document that the callback function pointers can be null,
in which case they are ignored.

Detect exhaustion of input when parsing an operand,
to avoid buffer overruns on some invalid input cases.

Fix the description strings for some operand types.
Make the diagnostic messages for those operand types
consistent between the assembler and binary parser.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/29

8 years agoClarify the non-SPV_SUCCESS case parser callbacks.
David Neto [Tue, 24 Nov 2015 21:23:08 +0000 (16:23 -0500)]
Clarify the non-SPV_SUCCESS case parser callbacks.

When a callback returns something other than SPV_SUCCESS,
then no futher callbacks are issued (parsing terminates early),
and no additional diagnostics are emitted.

The unit tests already check this behaviour.

8 years agoSeveral unit tests for spvBinaryParse
David Neto [Thu, 5 Nov 2015 22:14:13 +0000 (17:14 -0500)]
Several unit tests for spvBinaryParse

Add a non-zero spv_result_t value SPV_REQUESTED_TERMINATION
which should be used to signal an ok result, but signals
early termination for a process, such as binary parsing.

Tests include:
 - correct contents sent to header and instruction callbacks
 - non-zero status from a callback should terminate parsing,
   but the parser should not generate its own diagnostic.

TODO: Check diagnostics generated by the parser itself.

8 years agoAliasing through a union member is valid.
David Neto [Mon, 23 Nov 2015 20:15:41 +0000 (15:15 -0500)]
Aliasing through a union member is valid.

Take back my previous TODO.

8 years agoFix compilation of an assert.
David Neto [Mon, 23 Nov 2015 19:17:35 +0000 (14:17 -0500)]
Fix compilation of an assert.

The asserts check the length of the endian-converted words
vector with the reported number of words in the instruction.

8 years agospv_parsed_instruction_t cleanup
David Neto [Fri, 20 Nov 2015 19:21:10 +0000 (14:21 -0500)]
spv_parsed_instruction_t cleanup

Add members:
 - words: a pointer to an array of words in the instruction,
   in host native endianness.
 - num_words: sizes the words member

Remove member:
 - offset

This simplifies clients of spvBinaryParse, because they don't
have to handle endianness translation.

Also, it makes the binary parse API more composable, allowing
for easy chaining of binary parse clients.  A binary parse client
is handed the array of words directly instead of having to reference
some external array of all the words in the SPIR-V binary.  It also
allows a binary parse client to mutate the instruction stream before
handing off to a downstream consumer.

TODO(dneto): Still need to write the unit tests for spvBinaryParse

Fixes: https://github.com/KhronosGroup/SPIRV-Tools/issues/1

8 years agoMerge pull request #23.
Ben Vanik [Sun, 22 Nov 2015 16:32:53 +0000 (08:32 -0800)]
Merge pull request #23.

Fixing some C++ conversion errors.
* Implicit conversion from int to bool.
* Implicit conversion from size_t to uint32_t.
* Implicit conversion from char* to uint8_t.

Adding no-op color operators so unhandled platforms can still link.

8 years agoPut DiagnosticStream and clr exports in libspirv namespace
David Neto [Fri, 20 Nov 2015 15:44:41 +0000 (10:44 -0500)]
Put DiagnosticStream and clr exports in libspirv namespace

Each exported functions either has an "spv" prefix, or is inthe libspirv
namespace.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/18

8 years agoFix paths for binaries to match changes in CMake configuration.
Lei Zhang [Fri, 20 Nov 2015 14:44:13 +0000 (09:44 -0500)]
Fix paths for binaries to match changes in CMake configuration.

8 years agoUse test fixture for a test.
Lei Zhang [Thu, 19 Nov 2015 15:30:39 +0000 (10:30 -0500)]
Use test fixture for a test.

8 years agoRemoved executable flag from HexFloat.cpp.
Andrew Woloszyn [Thu, 19 Nov 2015 15:12:44 +0000 (10:12 -0500)]
Removed executable flag from HexFloat.cpp.

8 years agoUpdated spirv.h header. Fixes SPV_VERSION macro
David Neto [Thu, 19 Nov 2015 14:38:05 +0000 (09:38 -0500)]
Updated spirv.h header. Fixes SPV_VERSION macro

The SPV_VERSION macro value was updated to be 0x10000.
Previously it was missing the "0x" prefix, which caused
confusion.

The value of the const unsigned int SpvVersion has always
been 0x00010000.  That's what should appear as the version
word in the SPIR-V header.

The SPV_VERSION symbol is to be used in preprocessor directives.

8 years agoTurned warnings-as-errors on by default.
Andrew Woloszyn [Thu, 19 Nov 2015 14:22:53 +0000 (09:22 -0500)]
Turned warnings-as-errors on by default.

Fixed a few warnings that appear in builds on VS2013 and VS2015.

8 years agoClean up CMake configuration and address compiler warnings.
Lei Zhang [Wed, 18 Nov 2015 14:22:10 +0000 (09:22 -0500)]
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.

8 years agoRemove old names for enums: memory semantics, scope ID
David Neto [Wed, 18 Nov 2015 20:48:32 +0000 (15:48 -0500)]
Remove old names for enums: memory semantics, scope ID

8 years agoBottom byte of version header word should be 0
David Neto [Tue, 17 Nov 2015 21:37:10 +0000 (16:37 -0500)]
Bottom byte of version header word should be 0

The assembler should always make it 0.
The disassembler should ignore it.

Remove the macro support for supplying a value for it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/6

8 years agoCMake: Respect user-defined install path
Pierre Moreau [Tue, 17 Nov 2015 22:27:35 +0000 (23:27 +0100)]
CMake: Respect user-defined install path

8 years agoObject files should depend on spirv.h and friends
David Neto [Tue, 17 Nov 2015 23:00:56 +0000 (18:00 -0500)]
Object files should depend on spirv.h and friends

Don't use SYSTEM attribute on include_directories directive
for the SPIR-V standard header files.  When you do, object files
are not considered dependent on those headers.

Checked by looking at the dependency file source/disassemble.cpp.o.d,
and by trying to compile after a trivial edit to spirv.h

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/7

Also, use "" inclusion instead of <> inclusion for standard SPIR-V
headers.

8 years agoFix test: version number has changed.
Lei Zhang [Tue, 17 Nov 2015 21:46:55 +0000 (16:46 -0500)]
Fix test: version number has changed.

8 years agoUpdate external headers.
Lei Zhang [Tue, 17 Nov 2015 21:00:53 +0000 (16:00 -0500)]
Update external headers.

Now use the headers published at
https://www.khronos.org/registry/spir-v/api/1.0/.