Commit Graph

259 Commits

Author SHA1 Message Date
David Neto
c7a9a909a8 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.
2016-02-15 09:31:10 -05:00
David Neto
6bad02c320 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.
2016-02-12 16:01:42 -05:00
David Neto
000cad9cc6 Reject float literals with two leading signs
E.g. --1 should be rejected.
2016-02-11 14:11:16 -05:00
David Neto
b5267569d1 Add spvOperandIsConcreteMask 2016-02-02 12:05:34 -05:00
Dejan Mircevski
0c8bdfe163 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.
2016-02-02 11:40:05 -05:00
Umar Arshad
61a627586b 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
2016-01-27 08:37:23 -05:00
David Neto
c62f41e281 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.
2016-01-20 17:07:30 -05:00
Umar Arshad
1ddeb246eb 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)
2016-01-14 21:59:28 -05:00
Norbert Nopper
32197bdcd7 Fix, that spirv-tools did not build, as two casts are not present. 2016-01-13 10:29:18 -05:00
Andrew Woloszyn
7ffd8ffeb2 Minor fixes to remove warnings in VS2013.
Also fixes VS2015 build due to missing #include <iterator>
2016-01-11 16:22:34 -05:00
David Neto
5d30edb36d spvDiagnosticDestroy is safe to call on nullptr
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/62
2016-01-11 14:26:46 -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
ae7d707fdb Fix shadowing warnings reported by GCC 2016-01-06 17:36:33 -05:00
David Neto
ba73a7cee5 Fix conversion warnings reported by GCC. 2016-01-06 17:36:33 -05:00
David Neto
f80b51fa9b Fix var shadowing and width mismatches in hex_float.h 2016-01-06 13:11:42 -05:00
David Neto
d0de196439 operator<< on FloatProxy preserves float and fill
Fixes formatting of disassembler output after printing
a hex float, e.g. for a NaN or subnormal.
2016-01-05 12:49:55 -05:00
Umar Arshad
a3d0d3c719 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
2015-12-17 15:58:09 -05:00
Umar Arshad
6d37e3c5f3 Refactor validation types into another file 2015-12-17 15:56:58 -05:00
Umar Arshad
b9ad418c95 Fix warnings with Apple clang++
* Unused private member
* Overflow error when subtracting num_fraction_bits for HF16 and HF
2015-12-10 13:15:06 -05:00
Umar Arshad
f76e0f5231 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.
2015-12-09 16:15:00 -05:00
Andrew Woloszyn
4e5bc928c0 Added Float16, and HexFloat conversions 2015-12-08 14:41:57 -05:00
David Neto
d9ad050a95 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
2015-11-30 10:44:23 -05:00
David Neto
ee8a007810 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.
2015-11-30 10:36:42 -05:00
David Neto
750f205b63 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.
2015-11-27 10:19:06 -05:00
David Neto
7bff3eb6f9 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
2015-11-23 09:52:38 -05:00
Ben Vanik
01c8d7a8fb 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.
2015-11-23 01:42:46 -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
David Neto
64a9be97ca Remove old names for enums: memory semantics, scope ID 2015-11-18 15:56:38 -05:00
David Neto
748d585a9a 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.
2015-11-17 18:04:12 -05:00
Lei Zhang
af9906e4e5 Use Google comment style and fix typos. 2015-11-16 17:25:43 -05:00
Lei Zhang
acf7287c42 Fix many typos. 2015-11-13 12:35:43 -06:00
David Neto
3d348a8440 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.
2015-11-13 12:35:34 -06: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
David Neto
e7c426ac8d 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.
2015-11-12 16:27:50 -05:00
Lei Zhang
4ac601a2c3 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/.
2015-11-12 09:43:26 -05:00
Lei Zhang
a23a73671a Moves parser interface to libspirv.h. 2015-11-12 09:43:23 -05:00
Lei Zhang
8984f6f31f Move internal macros/structs for SPIR-V to a separate header. 2015-11-12 09:43:20 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
7a222e4abf Move info table related structs into table.h. 2015-11-12 09:42:58 -05:00
Lei Zhang
04736e7878 Move spv*TableGet() functions out of libspirv.h.
This is a part of the effort to clean up libspirv.h.
2015-11-12 09:42:55 -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
Andrew Woloszyn
ec691fba2a Fixed permissions 2015-11-11 12:12:16 -05:00
Andrew Woloszyn
55ecc2e097 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.
2015-11-11 12:12:13 -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
0f166be68d Assembler support for OpSpecConstantOp
Adds SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER.
2015-11-11 12:12:04 -05:00
David Neto
ce9cef71ac Fix Windows build errors.
- uint64_t != size_t sometimes
- don't use C99 runtime sized arrays
2015-11-11 09:55:51 -05:00
David Neto
2ae4a68fe8 Fix handling of OpExtInstImport
The assembler tracks mapping of extended instruction import Id
to extended instruction type.

Adds a few new ways to fail.
2015-11-10 15:58:07 -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
Lei Zhang
9042f40f7c Remove support for canonical assembly syntax format. 2015-11-10 15:57:49 -05:00
David Neto
201caf7001 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.
2015-11-10 15:57:45 -05:00
David Neto
0ca6b59bfd 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.
2015-11-10 15:57:33 -05:00
David Neto
a010444b79 Consts before the type, not after 2015-11-10 15:57:26 -05:00
David Neto
e4945def95 A spv_binary_t points to const code words. 2015-11-10 15:57:22 -05:00
Andrew Woloszyn
b3ae4b9422 Updated comment in SetBits.
It now mentions that it will fail if you try to set a bit that
does not exist.
2015-11-10 15:57:07 -05:00
Andrew Woloszyn
758b347983 Added double tests to HexFloat 2015-11-10 15:57:00 -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
Andrew Woloszyn
6dfd4186f5 Updated HexFloat parsing for windows.
It is valid for float values to be modified on copy if they are NaN,
so long as they remain the correct NaN. What this means is that
we can not rely on the float data-type for storing float values
if we want to retain bit patterns.

Added FloatProxy which stores data in an unsigned integer, and updated
the HexFloat template to deal with FloatProxy values instead.
2015-11-02 13:52:31 -05:00
Andrew Woloszyn
0b61c593a2 Added HexFloat reading to HexFloat.
This allows reading of hex-encoded floats.
2015-11-02 13:52:28 -05:00
Andrew Woloszyn
c2887f98bc Added HexFloat helper class to print out floating point numbers.
TODO Add double tests before we actually use this.
2015-11-02 13:52:25 -05:00
Andrew Woloszyn
b78d2d31c5 Changed SetBits to index from LSB and take a size. 2015-11-02 13:52:23 -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
David Neto
9f79d789ec Inclusion guards follow Google C++ style
Follow the scheme in
http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#The__define_Guard
except:
 - 'include/' is dropped from the guard token
 - 'source/' is dropped from the guard token
2015-11-02 13:52:15 -05:00
David Neto
1780fc4fcf Update to latest registered generator enums
The registry is at:
https://www.khronos.org/registry/spir-v/api/spir-v.xml
2015-11-02 13:51:54 -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
Lei Zhang
b998c81315 Use typedef instead of using in libspirv.h.
The header file should be compatible with pre-C++11 code.
2015-11-02 13:51:45 -05:00
David Neto
445ce4401d Add operand type for extension instruction number
This is required to support extended instructions that
have literal numbers as operands.  An example is OpenCL's
vloadn.

The previous code in the assembler assumed that *any* literal
number argument in any part of an OpExtInst must be the name
of the extended instruction.  That's true only for the first
literal number argument.
2015-10-26 12:55:33 -04:00
David Neto
21c4ad4b22 Add OpenCL extended instructions.
Versions 1.2, 2.0, and 2.1 all use the same
extended instruction list.

Updated the source code patch for the SPIR-V doc generator,
so it can both generate the core syntax table, and also the
OpenCL extended instructions table.

Tested the Math and Common functions.
TODO: test the remaining entries.
2015-10-26 12:55:33 -04:00
Lei Zhang
6483bd7132 Enforce suitable literal number operands to be unsigned integers.
Except for OpConstant and OpSpecConstant, all other literal number
operands are indeed unsigned integers. So,

* Rename all *LITERAL_NUMBER* operand types to *LITERAL_INTEGER*.
* Expect unsigned integers for *LITERAL_INTEGER* operands.
* Keep MULITPLE_WORD_LITERAL untouched since it is only used by
  OpConstant and OpSpecConstant.

And we want to provide the capability to specify floating-point
numbers after !<integer> in the alternate parsing mode. So,
OPTIONAL_LITERAL_NUMBER is reserved for OPTIONAL_CIV.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
537e77663d Added tracking to types and validated certain instructions.
We need to know how to generate correct SPIRV for cases like
OpConstant %int64 42 since the current parser will encode the 42 as a
32-bit value incorrectly.

This change is the first of a pair. This one tracks types, and makes
sure that OpConstant and OpSpecConstant are only ever called with
Integer or Float types, and OpSwitch is only called with integer
generating values.
2015-10-26 12:55:33 -04:00
David Neto
9db3a53897 Remove spv_opcode_flags_t and flags fields.
The flags fields in both spv_opcode_desc_t and spv_operand_desc_t
are redundant with the capabilities mask field in the same
structure.
2015-10-26 12:55:33 -04:00
David Neto
f6b865110c Accept long UTF-8 Literal Strings 2015-10-26 12:55:33 -04:00
David Neto
b5dc8fcd5d Support strings with up to 65535 chars, and null.
Move the definition of spv_instruction_t to an internal
header file, since it now depends on C++ and is not
used by the external interface.

Use a std::vector<uint32_t> in spv_instruction_t
instead of a fixed size array.
2015-10-26 12:55:33 -04:00
David Neto
8b19f27026 Define spv_capability_mask_t for readability. 2015-10-26 12:55:33 -04:00
David Neto
1b9d70a317 Test capabilities for enums sections 3.21-3.31
Fixes dependencies among capabilities.  (The table should store
the mask of capabilites, not the capability enum.)

Remove the old spot check test for capabilities of enums.
2015-10-26 12:55:33 -04:00
David Neto
ddda85a5c5 Fix capabilities for enums in Rev32, sec 3.3-3.20 2015-10-26 12:55:33 -04:00
Dejan Mircevski
4170ceca12 Create spv_language_capabilities_t and widen capabilities fields.
If this is acceptable, I'll do a wholesale switch of operand and opcode
definitions to capability bitfields.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
50babb2d00 Run clang-format. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
903f9d6b70 Implement alternate-parsing mode for !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
561dc4e975 Remove SPV_OPERAND_TYPE_LITERAL
All uses of OptionalLiteral by the SPIR-V spec are used
for literal numbers.

Also rename:
- SPV_OPERAND_TYPE_OPTIONAL_LITERAL to
  SPV_OPERAND_TYPE_OPTIONAL_LITERAL_NUMBER.
- SPV_OPERAND_TYPE_VARIABLE_LITERAL to
  SPV_OPERAND_TYPE_VARIABLE_LITERAL_NUMBER.
- SPV_OPERAND_TYPE_VARIABLE_LITERAL_ID to
  SPV_OPERAND_TYPE_VARIABLE_LITERAL_NUMBER_ID.
- SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL to
  SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_NUMBER.
- SPV_OPERAND_TYPE_LITERAL_IN_OPTIONAL_TUPLE to
  SPV_OPERAND_TYPE_LITERAL_NUMBER_IN_OPTIONAL_TUPLE.
2015-10-26 12:55:33 -04:00
David Neto
b14a727a30 Execution scope, memory semantics operands are IDs
They shouldn't be parsed or printed as masks.
2015-10-26 12:55:33 -04:00
David Neto
dbaf40718a Update to Rev32 headers. Part 1.
Just enough fixes to code make it build and pass tests.

Core changes:
 - Fix spelling for: NoPerspective, NonWritable, NonReadable,
 - Remove NoStaticUse, RelaxedMask

GLSL changes:
 - Fixed spelling for: InverseSqrt, FaceForward, MatrixInverse,
   SmoothStep, FindILsb, FindSMsb, FindUMsb
 - Replace Mix with IMix and FMix
 - Remove AddCarry, SubBorrow, MulExtended

Replace header OpenCLLib.h with OpenCL.std.h

TODO:
 - Regenerate the core instruction syntax table (source/opcode.inc)
 - Add test coverage for new enums and instructions.
2015-10-26 12:55:33 -04:00
David Neto
ee1b3bb3bb Assembler support for image operands from Rev31
Rev32 and later add many more image operands, and
rearrange their values.
2015-10-26 12:55:33 -04:00
Lei Zhang
6d41581c93 Clean up code for encoding literal operands. 2015-10-26 12:55:33 -04:00
David Neto
3fca4cddee Remove SPV_OPERAND_TYPE_VARIABLE_MEMORY_ACCESS
If a memory mask operand is present, it is a mask.  The mask appears
only once, so just use SPV_OPERAND_TYPE_OPTIONAL_MEMORY_MASK.

The "variable literals" aspect comes into play as follows: if the
Aligned bit is set in the mask, then the parser will be made to
expect the alignment value as a literal number operand that follows
the mask.  That is done through mask operand expansion.
2015-10-26 12:55:33 -04:00
David Neto
b30a0c529b Assembler test for Dim, ImageFormat enums.
Adds SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT, and the
translation tables for its values from the spv::ImageFormat values.
2015-10-26 12:55:33 -04:00
Lei Zhang
b41d150b7f Support multiple word literal numbers as constants.
Add a new operand type SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER
to represent those operands that can expand into multiple words.
Now only OpConstant and OpSpecConstant have such kind of operand.
2015-10-26 12:55:33 -04:00
Lei Zhang
4005670363 Limit the use of spvCheck and spvCheckReturn to validator.
spvCheck is indeed just an if-statement. Defining such a macro
doesn't help much.
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
Lei Zhang
29e667eb6c Add library function parameter to set assembly format for disassembler. 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
ac6f71b2de spvTextDestroy is no-op on nullptr. 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
David Neto
ec5f82082f Remove SPV_OPERAND_TYPE_ELLIPSIS 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
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
225baf88bc Add SPV_FAILED_MATCH status code
This is for future use by the parser.
2015-10-26 12:52:01 -04:00
David Neto
4799482787 Fix spelling of SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO 2015-10-26 12:52:01 -04:00
Lei Zhang
dfc50086a6 Support "<result-id> = <opcode> <operand>.." format. 2015-08-24 15:04:58 -04:00
Kenneth Benzie
67b649fa01 Merge branch 'update-header-to-rev31' into 'master'
Update external headers to rev 31

See merge request !3
2015-08-18 05:34:27 -04:00
David Neto
f6184a8b37 Parenthesize SPV_BIT macro to avoid surprises. 2015-08-17 17:01:42 -04:00
Lei Zhang
604e5cea12 Update spirv.h to revision 31.
For enum Capability and enum Op, not all newly added enumerants are
registered into capabilityInfoEntries and opcodeTableEntries yet.
That will come in following commits.
2015-08-17 11:40:24 -04:00
Lei Zhang
884c833889 Substitute GLSL450Lib.h with GLSL.std.450.h of revision 31. 2015-08-17 09:08:31 -04:00
Kenneth Benzie (Benie)
83e5a29b06 Code drop of the Codeplay spirv-tools source.
This commit contains the source for the SPIRV static library, spirv-as,
spirv-dis, and spirv-val tools.
2015-05-22 18:26:19 +01:00