Commit Graph

179 Commits

Author SHA1 Message Date
David Neto
9e11c7d301 Fix Android build: use std::numeric_limits<T>::max and friends
UINT32_MAX and friends are not available.
2015-10-26 12:55:33 -04:00
David Neto
470405e0ed Add disabled tests for disassembler literal emission
Currently, negative numbers are printed as if they were
first statically cast to unsigned.
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
Dejan Mircevski
497b226c68 Add negative-coverage location to operand-class-test-coverage.csv. 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
cc936dc613 Negative test for FunctionControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2fc334c701 Negative test for LoopControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
8386c57d0c Negative test for SelectionControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
c002213d95 Negative test for GroupOperation. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
9d0c813547 Negative test for LinkageType. 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
10fa49cd4b Negative test for AccessQualifier. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
212ba355a6 Negative test for FuncParamAttr. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
374616d98f Negative test for Decoration. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
c0eb225044 Negative test for FPRoundingMode. 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
d062f8b097 Make compilation input strings const.
Also rerun clang-format.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
57c4398759 Negative test for SamplerFilterMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
1e128260cb Negative test for SamplerAddressingMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
63af6fd409 Negative test for ImageOperands. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2fd3792c3a Negative test for Dim. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
52ff534040 Test OpTypeForwardPointer. 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
725cc2a2df Negative test for ExecutionMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
865034263d Negative test for AddressingModel, MemoryModel. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2d6796d45d Negative test for ExecutionModel. 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
David Neto
3d2bf53294 Move AutoText and EnumCase into spvtest namespace
Also fix using declaration order.
Also put a few tests into the anonymous namespace.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
78f6a4a649 Test operand-table capabilities. 2015-10-26 12:55:33 -04:00
David Neto
e3296f0945 Add TODO for fixing endianness testing.
Currently it uses a union, a write to one field, and read from
another of a different type.

Moves the endianness-determining macro close to the variable
it references.
2015-10-26 12:55:33 -04:00
David Neto
287fdb0eb0 Test SPV_CAPABILITY_AS_MASK macro 2015-10-26 12:55:33 -04:00
David Neto
0cd7352d7d Use 3-arg MakeInstruction to reduce logic in tests
Avoids open-coded vector inserts and two variables in various
tests.  Should improve readability.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
924997dc7f Test opcode table capability entries. 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
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
14c4b10d44 Detect overflow in !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
8bed0cea13 Add a .csv showing test coverage for operand class
It shows which spv::OperandClass values are used in
the syntax table in source/opcode.inc, and what tests
exercise those operand types.
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
42bfd4bfab Assembly test for OpSwitch
Removes old weak and fragile tests for OpSwitch.

Adds spvtest::TextToBinaryTest::CompileWithFormatFailure
2015-10-26 12:55:33 -04:00