Commit Graph

100 Commits

Author SHA1 Message Date
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
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
ea324e4a23 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
2015-11-10 15:57:19 -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
David Neto
db901b622e Move endian utilities to their own file. 2015-11-02 13:52:12 -05:00
David Neto
fcc7d58353 Move AssemblyGrammar into its own source files 2015-11-02 13:52:05 -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
Dejan Mircevski
d846247fd2 Fix GMOCK directory in CMakeLists.txt. 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
David Neto
005a11a4ac Use SPIRV_PERF=1 when performance tuning.
It tells the compiler to keep frame pointers, so you have good
call stacks in your profiles.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
e59e6b72f9 Added proper string escaping to the disassembler.
The disassembler now generates correct string when encountering
quotes and slashes.
2015-10-26 12:55:33 -04:00
David Neto
ac508b0d80 DiagnosticStream can convert to a stored error code
Use this to shorten error return code in the assembler.

For example, change this:

   if (error = something()) {
      diagnostic() << " Bad integer literal " << value;
      return SPV_ERROR_INVALID_VALUE;
   }

to this:

   if (error = something())
      return diagnostic() << " Bad integer literal " << value;

Also shorten code due to the fact that binaryEncodeU32 and
binaryCodeU64 can't fail (short of failure to expand a std::vector).
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
ddda85a5c5 Fix capabilities for enums in Rev32, sec 3.3-3.20 2015-10-26 12:55:33 -04:00
David Neto
ff5dce48a1 Add assembler test for OpEnqueueKernel.
Adds a form of spvtest::MakeInstruction which takes two vectors
of operands.  That leads to simpler test code.
We can clean up some other test code, in another CL.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
71fc05587b Refactored dynamic and static state out of text processing.
This reduces the number of arguments required to be passed
to every single function. This is in preparation for adding
id tracking.
2015-10-26 12:55:33 -04:00
David Neto
16df562ad3 Assembler test for Memory Semantics enum
Enables mask expression parsing for Memory Semantics arguments,
e.g. on OpMemoryBarrier.
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
5f33d31d89 Assembler test for SamplerAddressingMode, SamplerFilterMode
Uses OpConstantSampler instruction.
2015-10-26 12:55:33 -04:00
David Neto
fadbf6220e Assembler test for ExecutionScope, with OpGroupIAdd
Use spvOperandTypeStr to generalize the error message
for failure to parse an ID.
Extend spvOperandTypeStr to cover SPV_OPERAND_TYPE_EXECUTION_SCOPE.
2015-10-26 12:55:33 -04:00
David Neto
abe51c4142 Assembler test for OpTypePipe
Covers all AccessQualifier enums.

In Rev32, OpTypePipe no longer has a type argument.
Added TODOs for this.
2015-10-26 12:55:33 -04:00
David Neto
4a29131dcd Assembler test for single-valued Memory Access flag. 2015-10-26 12:55:33 -04:00
David Neto
f4fde6c60d Assembler test for single-valued FunctionControl mask
Fixed name of "Inline" enumerant.

Support for combinations of function control masks should come later.
2015-10-26 12:55:33 -04:00
David Neto
ad18c77ac9 Assembler test for single-valued SelectionControl mask
Support for combining masks should come later.
2015-10-26 12:55:33 -04:00
Lei Zhang
4e092d3ac3 Move bitwisecast.h to source/ and add include guard. 2015-10-26 12:55:33 -04:00
David Neto
c6402d64f4 Assembler tests for OpCapability.
Adds test file for instructions in the Mode-Setting section
of the SPIR-V spec.
2015-10-26 12:55:33 -04:00
David Neto
37547b2304 Assembler tests for all decorations except Linkage attributes
Fixes typos in various parser tables.

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

Updated assembler interface functions to support choice of assembly
syntax format.
2015-10-26 12:54:39 -04:00
David Neto
a08350a2c3 Assembler test for OpSourceExtension.
Add test utility function MakeVector(std::string) to encode
a string as a vector of 32-bit words, as per the SPIR-V literal
string encoding.
2015-10-26 12:54:39 -04:00
David Neto
08d89bb7a5 Test assembly of OpSource using all language enums
Adds a file to test assembly of instructions in the "Debug" section
of the SPIR-V spec.
2015-10-26 12:54:39 -04:00
David Neto
c88dcd6a72 Add OpNop, OpUndef tests for spvTextToBinary
Add text_fixture::TextToBinaryTestBase::CompiledInstructions,
to more easily just examine the generated instructions by skipping
over the header.

Add spvtest::MakeInstruction utility function to easily generate
a vector containing an opcode and its operands.
2015-10-26 12:54:39 -04:00
Lei Zhang
610c525865 Preserve float values during encoding and decoding roundtrip. 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
Andrew Woloszyn
46ba0f7574 Added option to only compile spirv library instead of all binaries as well 2015-10-26 12:52:01 -04:00
David Neto
78c3b43774 Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types.  (Internally, it is a deque,
for readability.)  Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.

The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
  extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
  operands.  These are expanded lazily during the parse.

Adds spv::OperandClass from the SPIR-V specification generator.

Modifies spv_operand_desc_t:
 - adds hasResult, hasType, and operandClass array to the opcode
description type.
 - "wordCount" is replaced with "numTypes", which counts the number
   of entries in operandTypes.  And each of those describes a
   *logical* operand, including the type id for the instruction,
   and the result id for the instruction.  A logical operand could be
   variable-width, such as a literal string.

Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)

Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH.  For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.

The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode.  So now, "OpenCL" does not look like
an opcode name.

In assembly, the EntryPoint name field is mandatory, but can be
an empty string.

Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-10-26 12:52:01 -04:00
Dejan Mircevski
0a8f219d1e Add a few unit tests for !<integer>. More to come.
Start using GMock: modify CMakeLists, fix googletest URL in readme.

Add useful utilities to the TestFixture class.  Also make it conform to
go/gunit recommendations about setup/teardown.
2015-10-26 12:52:01 -04:00
Andrew Woloszyn
7951050a95 Had spriv-tools stay inside it's own directory.
In order to facilitate having a project depend on spirv-tools,
have spirv-tools not pollute any external builds.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
f184109d7b Move ImmediateInt tests into their own file.
This is in preparation of adding many more tests in accordance with the
evolved spec.

Also sort the test-source lines in CMakeLists.
2015-10-26 12:52:01 -04:00
David Neto
affa696027 Fix some bugs in parsing literals.
- a single hyphen is a string, not a number.
- a string with more than one period is a string, not a number
- check for string overflow

Add some unit tests
2015-10-26 12:52:01 -04:00
Lei Zhang
0e149d7cc4 Move tests for GLSL std450 instructions to a separate file. 2015-10-26 12:52:01 -04:00
Lei Zhang
ee87cc2a1e Fix TextAdvance() problems involving whitespace around comment lines.
Fix the bug that TextAdvance() forgot to skip whitespace at the
beginning of the next line after a comment line.

Fix the bug that TextAdvanceLine() increase line number after going
over a character.
2015-08-24 15:05:05 -04:00
Lei Zhang
fb76d81aa0 Move test fixture into a separate header file so it can be reused. 2015-08-24 15:04:45 -04:00
David Neto
f6184a8b37 Parenthesize SPV_BIT macro to avoid surprises. 2015-08-17 17:01:42 -04:00
Lei Zhang
e3800df71c Avoid target conflicts with glslang and googletest.
This makes it easier to include spirv-tools into larger cmake-based
projects, which may already include glslang or googletest. It is
currently difficult to do this because of target clashes and a
hardcoded googletest path.

glslang defines a target named SPIRV, so rename ours to SPIRV-TOOLS.

A googletest subdirectory may already be added somewhere else, so if
the external/googletest directory does not exist, probe whether there
is a gtest target defined already. This makes spirv-tools work
out-of-the-box when plopped into a larger project already containing
googletest; otherwise the README.md procedure still works as before.
2015-07-29 16:53:58 -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