Commit Graph

113 Commits

Author SHA1 Message Date
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