platform/upstream/SPIRV-Tools.git
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/.

8 years agoUse Google comment style and fix typos.
Lei Zhang [Mon, 16 Nov 2015 15:48:43 +0000 (10:48 -0500)]
Use Google comment style and fix typos.

8 years agoFix grammar: "The SPIR-V Tools project provides"
David Neto [Sat, 14 Nov 2015 14:23:03 +0000 (08:23 -0600)]
Fix grammar: "The SPIR-V Tools project provides"

8 years agoRegister Glslang tool
David Neto [Fri, 13 Nov 2015 18:03:28 +0000 (12:03 -0600)]
Register Glslang tool

8 years agoFix many typos.
Lei Zhang [Fri, 13 Nov 2015 16:00:10 +0000 (11:00 -0500)]
Fix many typos.

8 years agoRevamp the README for public release.
David Neto [Fri, 13 Nov 2015 01:42:16 +0000 (20:42 -0500)]
Revamp the README for public release.

Reorganize the README, and update its contents to more accurately
reflect the public release.
Remove the incremental "Changes" section.

Rename readme.md to README.md
Rename license.txt to LICENSE

Update the assembler tool to support -h, and make its help look
more consistent with the disassembler.

Change the target and library name to SPIRV-Tools.  To better
match the GitHub repo name.  Also, it's not SHOUTING.

8 years agoThe version header word has 3 byte-size components.
David Neto [Fri, 13 Nov 2015 00:40:21 +0000 (19:40 -0500)]
The version header word has 3 byte-size components.

Bits 24-31: 0
Bits 16-23: SPIR-V major number (1)
Bits  8-15: SPIR-V minor number (0)
Bits   0-7: SPIR-V minor number (2)

The assembler will construct the word appropriately,
and the disassemble will print it in major.minor.revision form.

8 years agoGenerator word now has two 16-bit components
David Neto [Thu, 12 Nov 2015 23:33:47 +0000 (18:33 -0500)]
Generator word now has two 16-bit components

The high 16-bits are a registered generator tool.
These are registered at
https://www.khronos.org/registry/spir-v/api/spir-v.xml

The low 16-bits are tool-specific.  It might be a version number,
for example, but is not constrained by the spec or by the registration
process.

The disassembler prints the tool name when we know it.
If we don't, print "Unknown" and then the numeric tool number
in parentheses.
In all cases, the disassembler prints lower 16-bit number on the
same line but after the tool name.

Also add newly registered generators:
  6: Khronos LLVM/SPIR-V Translator
  7: Khronos SPIR-V Tools Assembler

8 years agoSupport capabilities StorageImageReadWithoutFormat
David Neto [Thu, 12 Nov 2015 20:44:25 +0000 (15:44 -0500)]
Support capabilities StorageImageReadWithoutFormat

Also add capability StorageImageWriteWithoutFormat.

They only affect validation rules.

8 years agoDisassembler can read the binary from stdin.
David Neto [Thu, 12 Nov 2015 16:57:41 +0000 (11:57 -0500)]
Disassembler can read the binary from stdin.

Read from stdin if:
 - no input filename specified
 - the input filename is "-"

Also, output goes to stdout if the output filename (argument to -o)
is "-".

8 years agoAdd GeometryStreams capability
David Neto [Thu, 12 Nov 2015 20:30:28 +0000 (15:30 -0500)]
Add GeometryStreams capability

Decoration Stream depends on it.
GeometryStreams depends on Geometry capability.

Spot check dependence of OpEmitStreamVertex on GeometryStreams.
(Opcode dependencies on capabilities are automatically generated from
opcode.inc)

8 years agoSupport OpImage
David Neto [Wed, 11 Nov 2015 21:36:42 +0000 (16:36 -0500)]
Support OpImage

It's already in the syntax table.  Just test it.

8 years agoUse opaque context object to hold SPIR-V info tables.
Lei Zhang [Thu, 12 Nov 2015 18:48:30 +0000 (13:48 -0500)]
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.

8 years agoRemove an obselete and redundant text.
Lei Zhang [Thu, 12 Nov 2015 19:42:03 +0000 (14:42 -0500)]
Remove an obselete and redundant text.

8 years agoDisassembler tool indents to 15 by default
David Neto [Thu, 12 Nov 2015 18:53:27 +0000 (13:53 -0500)]
Disassembler tool indents to 15 by default

The assigned-to result Id appears to the left of the 15th column.

Add --no-indent option.

The API form of the disassembler does not indent by default.

8 years agospirv-dis prints to stdout by default.
David Neto [Thu, 12 Nov 2015 16:44:42 +0000 (11:44 -0500)]
spirv-dis prints to stdout by default.

Color printing is enabled only for printing to stdout.
Add --no-color to turn off color printing.

8 years agoSimplify some tests
Lei Zhang [Thu, 12 Nov 2015 15:45:36 +0000 (10:45 -0500)]
Simplify some tests

8 years agolibspirv.h doesn't depend on spirv_operands.hpp anymore.
Lei Zhang [Wed, 11 Nov 2015 22:29:23 +0000 (17:29 -0500)]
libspirv.h doesn't depend on spirv_operands.hpp anymore.

Also change spirv_operands.hpp to a C header since we only have
an enum inside it, and move it to source/.

8 years agoMoves parser interface to libspirv.h.
Lei Zhang [Wed, 11 Nov 2015 21:59:31 +0000 (16:59 -0500)]
Moves parser interface to libspirv.h.

8 years agoMove internal macros/structs for SPIR-V to a separate header.
Lei Zhang [Wed, 11 Nov 2015 21:50:55 +0000 (16:50 -0500)]
Move internal macros/structs for SPIR-V to a separate header.

8 years agoUpdate to 1.0 Rev 2 work-in-progress headers
David Neto [Wed, 11 Nov 2015 17:32:21 +0000 (12:32 -0500)]
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

8 years agoMove SPIR-V constants/limits to a separate header.
Lei Zhang [Wed, 11 Nov 2015 19:24:04 +0000 (14:24 -0500)]
Move SPIR-V constants/limits to a separate header.

8 years agoUse std::string instead of a huge array for storing literal strings.
Lei Zhang [Wed, 11 Nov 2015 20:37:01 +0000 (15:37 -0500)]
Use std::string instead of a huge array for storing literal strings.

8 years agoAdd missing copyright.
Lei Zhang [Wed, 11 Nov 2015 18:57:43 +0000 (13:57 -0500)]
Add missing copyright.

8 years agoUse quotation for libspirv.h and sort headers.
Lei Zhang [Wed, 11 Nov 2015 17:45:23 +0000 (12:45 -0500)]
Use quotation for libspirv.h and sort headers.

8 years agoMove info table related structs into table.h.
Lei Zhang [Wed, 11 Nov 2015 17:40:25 +0000 (12:40 -0500)]
Move info table related structs into table.h.

8 years agoMove spv*TableGet() functions out of libspirv.h.
Lei Zhang [Wed, 11 Nov 2015 17:14:36 +0000 (12:14 -0500)]
Move spv*TableGet() functions out of libspirv.h.

This is a part of the effort to clean up libspirv.h.

8 years agoRemove table parameters from API functions.
Lei Zhang [Wed, 11 Nov 2015 16:33:26 +0000 (11:33 -0500)]
Remove table parameters from API functions.

Opcode, operand, and external instruction tables are no longer
passed in as parameters to spvTextToBinary(), spvBinaryToText(),
and spvValidate().

8 years agoFixed permissions
Andrew Woloszyn [Wed, 11 Nov 2015 17:06:46 +0000 (12:06 -0500)]
Fixed permissions

8 years agoFixed warnings on windows and constness of spv_binary.
Andrew Woloszyn [Wed, 11 Nov 2015 16:05:07 +0000 (11:05 -0500)]
Fixed warnings on windows and constness of spv_binary.

Replaced uint64_t with size_t in the places that make sense and
added spv_const_binary{,_t} to allow the interface to accept non
modifiable spirv where appropriate.

8 years agoGet magic number and version from spirv.h.
Lei Zhang [Wed, 11 Nov 2015 15:17:16 +0000 (10:17 -0500)]
Get magic number and version from spirv.h.

This is a part of the effort to clean up libspirv.h.

8 years agoDisassembler support for OpSpecConstantOp
David Neto [Wed, 11 Nov 2015 07:45:45 +0000 (02:45 -0500)]
Disassembler support for OpSpecConstantOp

Document the fact that we use names for extended instructions
and OpSpecConstantOp opcode operands.

8 years agoAssembler support for OpSpecConstantOp
David Neto [Wed, 11 Nov 2015 06:56:49 +0000 (01:56 -0500)]
Assembler support for OpSpecConstantOp

Adds SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER.

8 years agoFix Windows build errors.
David Neto [Wed, 11 Nov 2015 14:44:23 +0000 (09:44 -0500)]
Fix Windows build errors.

- uint64_t != size_t sometimes
- don't use C99 runtime sized arrays

8 years agoFix description of NaN encoding.
David Neto [Tue, 10 Nov 2015 21:04:30 +0000 (16:04 -0500)]
Fix description of NaN encoding.

8 years agoEnable round trip tests for OpSwitch
David Neto [Tue, 10 Nov 2015 20:43:12 +0000 (15:43 -0500)]
Enable round trip tests for OpSwitch

8 years agoOptional typed literal number should be concrete in BinaryParser.
Lei Zhang [Tue, 10 Nov 2015 19:29:35 +0000 (14:29 -0500)]
Optional typed literal number should be concrete in BinaryParser.

8 years agoUpdate readme: binary parser refactor; non-32-bit literals
David Neto [Tue, 10 Nov 2015 19:14:21 +0000 (14:14 -0500)]
Update readme: binary parser refactor; non-32-bit literals

8 years agosyntax.md: Describe hex floats and their use.
David Neto [Tue, 10 Nov 2015 19:46:35 +0000 (14:46 -0500)]
syntax.md: Describe hex floats and their use.

8 years agoFix handling of OpExtInstImport
David Neto [Mon, 9 Nov 2015 23:55:42 +0000 (18:55 -0500)]
Fix handling of OpExtInstImport

The assembler tracks mapping of extended instruction import Id
to extended instruction type.

Adds a few new ways to fail.

8 years agoAssembler supports hex float constants.
David Neto [Fri, 6 Nov 2015 23:08:49 +0000 (18:08 -0500)]
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.

8 years agoPrint OpConstant values according to type.
David Neto [Fri, 6 Nov 2015 16:23:57 +0000 (11:23 -0500)]
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.

8 years agoRemove canonical assembly format in syntax.md.
Lei Zhang [Fri, 6 Nov 2015 15:10:28 +0000 (10:10 -0500)]
Remove canonical assembly format in syntax.md.

8 years agoadvance() should check current string index is in bound.
Lei Zhang [Fri, 6 Nov 2015 20:09:04 +0000 (15:09 -0500)]
advance() should check current string index is in bound.

8 years agoRemove support for canonical assembly syntax format.
Lei Zhang [Thu, 5 Nov 2015 22:45:09 +0000 (17:45 -0500)]
Remove support for canonical assembly syntax format.

8 years agospv_operand_type_t cleanup.
David Neto [Wed, 4 Nov 2015 22:38:17 +0000 (17:38 -0500)]
spv_operand_type_t cleanup.

- Concrete operand types are never optional.
  Split them to make this so, e.g. add SPV_OPERAND_TYPE_IMAGE
  since there was SPV_OPERAND_TYPE_OPTIONAL_IMAGE.
  Similarly for SPV_OPERAND_TYPE_MEMORY_ACCESS.
  This entails duplicating two operand table entries.

- The above, plus some rearranging of enums, allows us to define
  first and last optional operand types, and first and last
  variable operand types.
  This lets us simplify the code for spvOperandIsOptional, and
  spvOperandIsVariable.

- Replace SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER with the
  more accurately named SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER.
  Its special characteristic is that the type of the literal
  number is determined by some previous operand in the instruction.
  This is used for literals in OpSwitch, OpConstant, and OpSpecConstant.
  This lets us refactor operand parsing cases in the assembler.

- Remove the special required-thing-in-optional-tuple in favour of
  the corresponding concrete operand type:
        SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_ID
        SPV_OPERAND_TYPE_INTEGER_LITERAL_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_INTEGER_LITERAL

- Constrain spvOpeandTypeStr to only have to work for non-variable
  operand types.  Add a test for this.

8 years agoRemove TODO: Strings are always little-endian
David Neto [Thu, 5 Nov 2015 22:37:48 +0000 (17:37 -0500)]
Remove TODO: Strings are always little-endian

SPIR-V strings are UTF-8 encoded, and always byte-addressed.

8 years agoRefactor the binary parser.
David Neto [Fri, 30 Oct 2015 20:06:15 +0000 (16:06 -0400)]
Refactor the binary parser.

The binary parser has a C API, described in binary.h.
Eventually we will make it public in libspirv.h.
The API is event-driven in the sense that a callback is called
when a valid header is parsed, and for each parsed instruction.

Classify some operand types as "concrete".  The binary parser uses
only concrete operand types to describe parsed instructions.

The old disassembler APIs are moved into disassemble.cpp

TODO: Add unit tests for spvBinaryParse.

8 years agoSlay "undeflow."
Dejan Mircevski [Tue, 3 Nov 2015 18:52:41 +0000 (13:52 -0500)]
Slay "undeflow."

8 years agoRefactor EncodeTestHelper() and DecodeTestHelper().
Dejan Mircevski [Tue, 3 Nov 2015 17:02:07 +0000 (12:02 -0500)]
Refactor EncodeTestHelper() and DecodeTestHelper().

8 years agoConsts before the type, not after
David Neto [Tue, 3 Nov 2015 16:26:15 +0000 (11:26 -0500)]
Consts before the type, not after

8 years agoA spv_binary_t points to const code words.
David Neto [Wed, 28 Oct 2015 17:50:32 +0000 (13:50 -0400)]
A spv_binary_t points to const code words.

8 years agoMove spvBinaryToText into new disassembler file.
David Neto [Tue, 27 Oct 2015 20:56:14 +0000 (16:56 -0400)]
Move spvBinaryToText into new disassembler file.

This begins the refactoring of the disassembler into
two parts: A binary decoder in binary.cpp, and an
event-driven converter to text in disassemble.cpp

8 years agoUse the syntax table for opcode to name mappings.
David Neto [Mon, 2 Nov 2015 21:03:12 +0000 (16:03 -0500)]
Use the syntax table for opcode to name mappings.

This method is more reliably complete.