Commit Graph

2576 Commits

Author SHA1 Message Date
Andrew Woloszyn
3a4bc7e61a Turned warnings-as-errors on by default.
Fixed a few warnings that appear in builds on VS2013 and VS2015.
2015-11-19 09:46:59 -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
8ddd4ec102 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
2015-11-18 15:19:43 -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
David Neto
2266ba1061 Register Glslang tool 2015-11-13 12:35:47 -06: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
David Neto
14b93e49ed 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
2015-11-13 12:35:29 -06:00
David Neto
5f7ed91e18 Support capabilities StorageImageReadWithoutFormat
Also add capability StorageImageWriteWithoutFormat.

They only affect validation rules.
2015-11-12 16:27:51 -05:00
David Neto
12511c8a4f 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)
2015-11-12 16:27:51 -05:00
Lei Zhang
972788bf23 Use opaque context object to hold SPIR-V info tables.
Previously the opcode table is declared as an global array and we
have spvOpcodeTableInitialize() modifying it. That can result in
race condition. Now spvOpcodeTabelGet() copies the whole underlying
array.
2015-11-12 16:27:51 -05:00
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
David Neto
d02f68ae79 Update to 1.0 Rev 2 work-in-progress headers
Updated readme.

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

Regenerated syntax tables for 1.0.

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

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

Add:
  image channel data type UnormInt101010_2
  AcquireReleaseMask

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

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

OpenCL source language -> OpenCL_C, OpenCL_CPP
2015-11-12 09:43:12 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
16f3ddfbb8 Use std::string instead of a huge array for storing literal strings. 2015-11-12 09:43:06 -05:00
Lei Zhang
2a0b773b27 Add missing copyright. 2015-11-12 09:43:03 -05:00
Lei Zhang
923f6c13fc Use quotation for libspirv.h and sort headers. 2015-11-12 09:43:01 -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
2119694775 Disassembler support for OpSpecConstantOp
Document the fact that we use names for extended instructions
and OpSpecConstantOp opcode operands.
2015-11-11 12:12:07 -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
Lei Zhang
aa3cd5abb9 Optional typed literal number should be concrete in BinaryParser. 2015-11-10 15:58:16 -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
9e545d7968 Assembler supports hex float constants.
The bit pattern for a hex float is preserved through
assembly and disassembly.

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

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

TODO: Assembler support for hex numbers, and therefore reading
infinities and NaNs.
2015-11-10 15:57:59 -05:00
Lei Zhang
8f6ba14b58 advance() should check current string index is in bound. 2015-11-10 15:57:52 -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
97e4a5d83d Remove TODO: Strings are always little-endian
SPIR-V strings are UTF-8 encoded, and always byte-addressed.
2015-11-10 15:57:42 -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
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
David Neto
1bcd3d16a3 Use the syntax table for opcode to name mappings.
This method is more reliably complete.
2015-11-10 15:57:14 -05:00
David Neto
bae8851111 DiagnosticStream keeps a copy of the position.
Don't store the pointer, as the underlying storage
could disappear.  This a bit more flexible and robust.
2015-11-10 15:57:04 -05:00
David Neto
ea633a6427 Empty assembly text compiles to no instructions.
But it's still a valid module.
2015-11-10 15:56:57 -05:00
David Neto
aef608c40d Consolidate: spvOpcodeIsType into spvOpcodeGeneratesType
And fix the spvOpcodeGeneratesType: OpTypeForwardPointer
does not generate a new type.
2015-11-10 15:56:54 -05:00
Lei Zhang
1a0334edee Run clang-format to enforce Google style globally.
Note that we are more strict than Google style for one aspect:
pointer/reference indicators are adjacent to their types, not
their variables.

find . -name "*.h" -exec clang-format -i {} \;
find . -name "*.cpp" -exec clang-format -i {} \;
2015-11-10 15:56:47 -05:00
Lei Zhang
b36e704a47 Use spirv.h instead of spirv.hpp.
This is a part of the effort to make libspirv.h C-compatible.
2015-11-02 13:52:20 -05:00
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
db901b622e Move endian utilities to their own file. 2015-11-02 13:52:12 -05:00
David Neto
0b9816813b Hide spvBinaryHeaderSet with its only client.
Also rename it to SetHeader since it's not part of the "binary"
API.
2015-11-02 13:52:09 -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
Andrew Woloszyn
4274f93065 Fixed UTF-8 encoding issues on windows.
Also cleaned up some warnings related to implicit size_t/uint64_t
conversions.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
157e41bf57 Added type tracking to the disassembler.
TODO: Actually use the tracked types to make sure that we print out
values correctly.
2015-10-26 12:55:33 -04: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
1bb8b70341 Use literal integers for OpenCL extended instructions. 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
Andrew Woloszyn
ccc210b4cc Some minor clean-ups to binary.{h,cpp}.
Removed spvBinaryDecodeOpcode and spvBinaryDecodeOperand from the public
interface since they were only ever used in binary.cpp.

Replaced the usage of spv_operand_table_t and it's ilk with the
AssemblyGrammar to reduce the number of passed parameters.

Fixed typo in comment.
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
980b7cb95e Avoid strlen in a loop, for speed. 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
51013d15ee SPV_FAILED_MATCH error mutes DiagnosticStream.
The DiagnosticStream will not emit the accumulated message
text if the error is SPV_FAILED_MATCH.

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

  if (is_optional) return SPV_FAILED_MATCH;
  return diagnostic() << " message text ";
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
f08c679e97 Removed un-needed comments and fixed merge issue. 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
3e69cd1b9f Updated string escaping in the assembler.
Strings are now escaped correctly when assembling.
TODO dissassembler support for strange strings (newlines for example).
2015-10-26 12:55:33 -04:00
David Neto
78e677b5cd Parse and encode literal integers to the right width
Affects OpConstant, and OpSwitch.

Adds constant libspirv::kUnknownType for readability.

Adds tests for hexadecimal number parsing.

Updates syntax.md to describe hex parsing, including
sign extension.
2015-10-26 12:55:33 -04:00
David Neto
6274120eb9 Add AssemblyContext::parseNumber
It parses a text string for a value of a given target type.
2015-10-26 12:55:33 -04:00
David Neto
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
Dejan Mircevski
d7b0f83bd1 Negative test for BuiltIn. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
355cc0c678 Negative test for FPFastMathMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
971b344150 Negative test for ImageFormat. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
f8e091af3d Clarify handling of OperandImageOperands. 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
Dejan Mircevski
d2c81cf34a Negative test for SourceLanguage.
Also, use "class" instead of "type" in the coverage CSV.
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
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
205408bae4 Make capabilities a bitfield in opcode/operand tables. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
114206e0bc Clarify !<integer> parsing.
Implement some outstanding feedback from
Ic29c5a4a8178a62a5a1acad13d02f19cc1307097:

 - use "token" instead of "word" when referring to assembly text

 - specify how the numbers are parsed

Add a test for negative numbers.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
97e2c8fc3d Try to fix the Android build. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
14c4b10d44 Detect overflow in !<integer>. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
897bff924a Simplify (and test) the alternate-parsing pattern. 2015-10-26 12:55:33 -04:00
David Neto
7cefb23ddb Document non-use of certain operand types
Operand class enum values not used in the syntax table:
- Image channel order: only used to describe a return value
- Image channel type: only used to describe a return value
- "Image operands": used to make a section in the spec
  to describe values used to construct an optional image id,
  but does not itself appear in the syntax table.

Removes some TODOs from opcode.cpp.
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
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
Dejan Mircevski
9672ad39cf Remove isIdType(), which is now dead code. 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
619db2612e Disassembler support for mask expressions. 2015-10-26 12:55:33 -04:00
David Neto
bfa3d86f7b Memory semantics Relaxed is a synonym for None
The disassembler should prefer to print Relaxed,
I think. (Untested.)
2015-10-26 12:55:33 -04:00
David Neto
e0890da603 Update core instruction syntax to Rev32
Many instructions added and a few changed structure.

Workarounds:
- Some operands can be enabled by either one of two
  capabilities.  The spv_operand_desc_t does not handle that
  now. For now just select the first one.

Fixes to tests:
- OpLoopMerge now takes a mandatory continue target.
- OpTypePipe drops the type argument.  Pipes are opaque.
- OpLine no longer takes a target ID argument.

The ID validator was fixed the OpLine and OpTypePipe
changes.  Those were the only ID validator tests affected.

The patch to the spec doc generator was updated so it handles
the two-capability case, even if in an hacky way.
2015-10-26 12:55:33 -04:00
David Neto
d768798d48 Assembler supports new decorations in Rev32
They are:
 - NoContraction
 - InputTargetIndex
 - Alignment
2015-10-26 12:55:33 -04:00
Lei Zhang
863ddbeeaa Rev32: Remove DepthAny and mark Xfb as requiring TransformFeedback. 2015-10-26 12:55:33 -04:00
David Neto
d30b2331a3 Fix Capability dependencies on capabilities, Rev32 2015-10-26 12:55:33 -04:00
David Neto
c66f5074e2 Assembler support for new capabilities in Rev32 2015-10-26 12:55:33 -04:00
David Neto
8576c9c327 Support Image operand MinLod 2015-10-26 12:55:33 -04:00
David Neto
2d1b5e5bba Assembler supports new builtins in Rev32
They are VertexIndex and InstanceIndex.
2015-10-26 12:55:33 -04:00
David Neto
49c299b094 Assembler support for Nontemporal memory access 2015-10-26 12:55:33 -04:00
Lei Zhang
85c6f79081 Define two macros to simplify code for ExecutionMode operands. 2015-10-26 12:55:33 -04:00
David Neto
aa0c3a5c07 Support Dim InputTarget 2015-10-26 12:55:33 -04:00
David Neto
9819adf4cb Support StorageClass PushConstant 2015-10-26 12:55:33 -04:00
David Neto
3e52dd915d Support ExecutionMode IndependentForwardProgress 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
Andrew Woloszyn
13804e5d63 All values now represent symbolic names instead of mixed with numeric.
Also removed un-necessary heap-allocation of spv_named_id_table.
This removed the necessity to expose a function to create/destroy it
and simplified the interface.
2015-10-26 12:55:33 -04:00
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
Andrew Woloszyn
e0d351b3ad Switched VecTypeHint to take a LiteralNumber instead of an ID 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
fabeeb863b Removed duplicate code due to what looks like a merge issue 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
5bf88fcc95 Assembler: mask expressions where 1 bits imply operands
Properly support a memory access mask with a combination
of bits, including the Aligned bit. When the Aligned bit is
set, the parser should expect an alignment value literal operand.
2015-10-26 12:55:33 -04:00
David Neto
36b0c0f6b3 Assembler support for simple mask expressions
For example, support combining mask enums with "|",
such as "NotNaN|AllowRecip" for the fast math mode.

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

TODO: disassembler support to print them as mask expressions.
2015-10-26 12:55:33 -04:00
David Neto
388c40d9c6 Generalize spvOperandTableNameLookup to take string length.
This is preparation for parsing mask expressions.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
e3a19c0d63 Forbid !<integer> preceding or succeeding '='. 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
Dejan Mircevski
ba569fb1aa Handle IDs among !<integer> operands. 2015-10-26 12:55:33 -04:00
David Neto
5494dd4334 Assembler test for Storage Class enum values
This covers the storage classes in SPIR-V Rev31.  Rev32 has more.
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
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
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
Lei Zhang
97afd5c03c Remove useless variable. 2015-10-26 12:55:33 -04:00
Lei Zhang
41bf0733c6 Simplify code for handling literals in disassembler. 2015-10-26 12:55:33 -04:00
David Neto
c09932eb1e Add patch for generating opcode.inc syntax table. 2015-10-26 12:55:33 -04:00
Lei Zhang
a94701db39 Run clang-format. 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
David Neto
a48678ab92 Fix an infinite loop during message generation.
Rename getWord to spvGetWord and unit test it.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
f79519c926 Handle operands when OpCode is !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
e994e2e283 Add TODO for capability dependencies for Rev32+ 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
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
55bdfcb0bc Assembler test for LinkageAttributes decorations 2015-10-26 12:54:39 -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
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
Dejan Mircevski
92a225b371 Simplify checking for !<integer> first word. 2015-10-26 12:54:39 -04:00
Andrew Woloszyn
4b4acded77 Added missing diagnostic when disassembling empty file.
Added diagnostic messages for what should be an internal failure
that never happens. I figure if we return "failed" for something the
user cannot control we should print a message for it.
2015-10-26 12:54:39 -04:00
Pyry Haulos
26b3b00887 Fix build on MSC
Visual C++ compiler doesn't allow ternary select where type depends on
condition even if there is a user-defined conversion operator to a common
type.
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
c9b5152b4f Remove spvOpcodeIsVariable
Nothing was using it.
2015-10-26 12:54:39 -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
e7ee4c4476 Getting the next word respects quoting and escaping.
Use double quotes (").  They can be interspersed with
other whitespace characters, just like shell quoting.

A backslash (\) always escapes the next character.

The end of the stream always terminates the word.

Add AutoText struct to unit test utilities, to easily
make spv_text_t values and reference them as spv_text values.
2015-10-26 12:52:01 -04:00
David Neto
574884cd7e Getting the next word ends at a comment (;) 2015-10-26 12:52:01 -04:00
David Neto
e3f70b9a85 Combine parsing of ID and RESULT_ID operand types 2015-10-26 12:52:01 -04:00
David Neto
98290a243e String literals must be quoted. 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
5b73214223 Add GLSL std450 extended instruction 72-80. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
afdbd2d303 Add std450 instructions 53-64. 2015-10-26 12:52:01 -04:00
Lei Zhang
3cb589639d Add GLSL std450 extended instruction 65-71. 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
2d879b9334 Simplify macro names used for GLSL std450 extended instruction table. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
c48fcce978 Add std450 instructions 49-52. 2015-10-26 12:52:01 -04:00
Lei Zhang
dca65b3f8c Reformat GLSL std450 extended instruction table.
Also add test for Smoothstep.
2015-10-26 12:52:01 -04:00
Lei Zhang
e5ae7f677f Add GLSL std450 instructions 35-48. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
a5c171544b Add std450 instructions 25-34. 2015-10-26 12:52:01 -04:00
Lei Zhang
8a37520908 Disassemble in the format of "<result-id> = <opcode> <operand>..". 2015-10-26 12:52:01 -04:00
Kenneth Benzie
31e482cdf5 Merge branch 'google-catch-up' into 'master'
Google changes during GitLab outage

These are the changes made by Google during the GitLab outage last week.

See merge request !9
2015-09-02 05:49:42 -04:00
Lei Zhang
abafd5e674 Only use '%' as variable name prefix.
Since now we can distinguish between def and use according to
the variable's location, there is no need to keep two variable
prefixes.

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

Fix the bug that TextAdvanceLine() increase line number after going
over a character.
2015-08-24 15:05:05 -04:00
Lei Zhang
dfc50086a6 Support "<result-id> = <opcode> <operand>.." format. 2015-08-24 15:04:58 -04:00
Andrew Woloszyn
0d350b5992 Make the disassembler print the Extended instruction name.
This allows the disassembled output to more closely follow the
original assembly.
2015-08-24 15:04:55 -04:00
Andrew Woloszyn
1d2a87ed1b Added the initial set of glsl450 instructions.
Also rewrote the extended-instruction tests so that they would actually
make sure that the instruction actually appears in the output.
2015-08-24 15:04:49 -04:00
Lei Zhang
7e75158c7f Address new enumerants in enum Capability for rev 31. 2015-08-18 09:49:04 -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)
81d7d49a20 Change binary header generator word to Khronos 2015-06-01 09:50:46 -07: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