SPIRV-Tools/test
Shahbaz Youssefi 02433568af
tools: Accept hex representation as binary input (#5870)
Sometimes when debugging or logging, SPIR-V may be dumped as a stream of
hex values.  There are tools to convert such a stream to binary
(such as [1]) but they create an inconvenient extra step when for
example the disassembly of that hex stream is needed.

[1]: https://www.khronos.org/spir/visualizer/hexdump.html

In this change, the binary reader used by the tools is enhanced to
detect when the binary is actually a hex stream, and parse that instead.
The following formats are accepted, detected based on how the SPIR-V
magic number is output:

=== Words

If the first token of the hex stream is one of 0x07230203, 0x7230203,
x07230203, or x7230203, the hex stream is expected to consist of 32-bit
hex words prefixed with 0x or x.  For example:

    0x7230203, 0x10400, 0x180001, 0x79, 0x0

is parsed as:

    0x07230203 0x00010400 0x00180001 0x00000079 0x00000000

Note that `,` is optional in the stream, but the hex values are expected
to be delimited by either `,` or whitespace.

=== Bytes With Prefix

If the first token of the hex stream is one of 0x07, 0x7, x07, x7, 0x03,
0x3, x03, or x3, the hex stream is expected to consist of 8-bit hex
bytes prefixed with 0x or x.  If the first token has a value of 7, the
stream is big-endian.  Otherwise it's little-endian.  For example:

    0x3, 0x2, 0x23, 0x7, 0x0, 0x4, 0x1, 0x0, 0x1, 0x0, 0x18, 0x0, 0x79, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0

is parsed as:

    0x07230203 0x00010400 0x00180001 0x00000079 0x00000000

Similar to "Words", `,` is optional in the stream, but the hex values
are expected to be delimited by either `,` or whitespace.

=== Bytes Without Prefix

If the first two characters of the hex stream is 07, or 03, the hex
stream is expected to consist of 8-bit hex bytes of 2 characters each.
If the first token is 07, the stream is big-endian.  Otherwise it's
little-endian.  Unlike the other modes, delimiter is optional (which
automatically handles 32-bit word streams), but no 0-padding is done.
For example, all of the following:

    03, 02, 23, 07, 00, 04, 01, 00, 01, 00, 18, 00, 79, 00, 00, 00, 00, 00, 00, 00
    03 02 23 07 00 04 01 00 01 00 18 00 79 00 00 00 00 00 00 00
    03022307 00040100 01001800 79000000 00000000
    07,23,02,03,00,01,04,00,00,18,00,01,00,00,00,79,00,00,00,00
    07230203, 00010400, 00180001, 00000079, 00000000

are parsed as:

    0x07230203 0x00010400 0x00180001 0x00000079 0x00000000
2024-11-04 09:57:37 -05:00
..
diff tools: Accept hex representation as binary input (#5870) 2024-11-04 09:57:37 -05:00
fuzz Update proto JSON options call. (#5867) 2024-10-31 21:08:25 -04:00
fuzzers Fix opt fuzzer test harness (#4670) 2022-01-07 15:03:29 +00:00
link spirv-link: allow linking functions with different pointer arguments (#5534) 2024-07-24 08:38:19 -04:00
lint Add divergence analysis to linter (#4465) 2021-08-23 17:03:28 -04:00
opt Add validation for SPV_NV_tensor_addressing and SPV_NV_cooperative_matrix2 (#5865) 2024-10-24 13:55:04 -04:00
reduce tools: Move io utils to cpp (#5869) 2024-10-28 13:31:54 -04:00
scripts Use python3 explicitly. (#5540) 2024-01-23 15:42:34 -05:00
tools cmake: Use modern Python3 CMake support (#5277) 2023-06-19 15:02:41 -04:00
util [OPT] Zero-extend unsigned 16-bit integers when bitcasting (#5714) 2024-06-19 19:17:05 +02:00
val Add validation for SPV_NV_tensor_addressing and SPV_NV_cooperative_matrix2 (#5865) 2024-10-24 13:55:04 -04:00
wasm Add Wasm build (#3752) 2021-11-01 16:45:51 -04:00
assembly_context_test.cpp Add descriptor array scalar replacement (#2742) 2019-08-08 10:53:19 -04:00
assembly_format_test.cpp Assembler: Can't set an ID in instruction without result ID (#2852) 2019-09-11 13:15:25 -04:00
binary_destroy_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
binary_endianness_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
binary_header_get_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
binary_parse_test.cpp Fix SPRIV -> SPIRV typos (#5735) 2024-07-15 20:10:06 -04:00
binary_strnlen_s_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
binary_to_text_test.cpp add support for SPV_INTEL_global_variable_host_access (#5786) 2024-09-17 12:31:29 -04:00
binary_to_text.literal_test.cpp spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
c_interface_test.cpp spirv-as: Add opcode name when possible (#4757) 2022-03-28 14:46:39 +00:00
CMakeLists.txt tools: Accept hex representation as binary input (#5870) 2024-11-04 09:57:37 -05:00
comment_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
cpp_interface_test.cpp Test operator overloads for SPIR-V C++ mask enums (#5021) 2022-12-16 11:17:39 -05:00
diagnostic_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
enum_set_test.cpp Fix broken build (#5505) 2023-12-11 11:45:10 -05:00
enum_string_mapping_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
ext_inst.cldebug100_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
ext_inst.debuginfo_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
ext_inst.glsl_test.cpp Remove use of deprecated googletest macro (#2286) 2019-01-29 18:56:52 -05:00
ext_inst.non_semantic_test.cpp spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
ext_inst.opencl_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
fix_word_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
generator_magic_number_test.cpp Remove use of deprecated googletest macro (#2286) 2019-01-29 18:56:52 -05:00
hex_float_test.cpp Fix undef behaviour in hex float parsing (#5025) 2022-12-19 15:46:57 -05:00
hex_to_text_test.cpp tools: Accept hex representation as binary input (#5870) 2024-11-04 09:57:37 -05:00
immediate_int_test.cpp Add FPEncoding operand type. (#5726) 2024-07-03 13:18:40 -04:00
libspirv_macros_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
name_mapper_test.cpp Add gl_BaseInstance to the name mapper. (#3462) 2020-06-26 11:54:35 -05:00
named_id_test.cpp Remove use of deprecated googletest macro (#2286) 2019-01-29 18:56:52 -05:00
opcode_make_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
opcode_require_capabilities_test.cpp Support SPV_KHR_untyped_pointers (#5736) 2024-07-17 14:51:37 -04:00
opcode_split_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
opcode_table_get_test.cpp Favour 'integrity' over 'coherence' as a replacement for 'sanity'. (#3619) 2020-09-10 09:52:21 -04:00
operand_capabilities_test.cpp update image enum tests to remove Kernel capability (#5562) 2024-02-13 11:07:39 -05:00
operand_pattern_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
operand_test.cpp Avoid operand type range checks (#3379) 2020-07-27 13:14:03 -04:00
operand-class-test-coverage.csv Fix operand class test coverage table. 2016-09-23 11:58:25 -04:00
parse_number_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
pch_test.cpp Enable precompiled headers for spirv-tools(-shared) and some unit tests (#2026) 2018-11-06 09:26:23 -05:00
pch_test.h Enable precompiled headers for spirv-tools(-shared) and some unit tests (#2026) 2018-11-06 09:26:23 -05:00
preserve_numeric_ids_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
software_version_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
string_utils_test.cpp Move utils/ to spvtools::utils 2018-07-06 16:47:46 -04:00
target_env_test.cpp Vulkan 1.3 (#4686) 2022-01-25 10:36:08 -05:00
test_fixture.h spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
text_advance_test.cpp spirv-as: Avoid recursion when skipping whitespace (#4866) 2022-07-26 10:56:04 -04:00
text_destroy_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
text_literal_test.cpp Remove use of deprecated googletest macro (#2286) 2019-01-29 18:56:52 -05:00
text_start_new_inst_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
text_to_binary_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.annotation_test.cpp spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
text_to_binary.barrier_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.composite_test.cpp spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
text_to_binary.constant_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.control_flow_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.debug_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.device_side_enqueue_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.extension_test.cpp Support SPV_KHR_untyped_pointers (#5736) 2024-07-17 14:51:37 -04:00
text_to_binary.function_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.group_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.image_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.literal_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
text_to_binary.memory_test.cpp spirv-dis: Add --nested-indent and --reorder-blocks (#5671) 2024-06-17 09:54:18 -04:00
text_to_binary.misc_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.mode_setting_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.pipe_storage_test.cpp Improve an error message in the assembler (#5219) 2023-05-15 09:56:48 -04:00
text_to_binary.reserved_sampling_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.subgroup_dispatch_test.cpp Switch SPIRV-Tools to use spirv.hpp11 internally (#4981) 2022-11-04 17:27:10 -04:00
text_to_binary.type_declaration_test.cpp Add support for SPV_EXT_shader_tile_image (#5188) 2023-04-13 16:58:00 -04:00
text_word_get_test.cpp Cleanup includes. (#1795) 2018-08-03 15:06:09 -04:00
timer_test.cpp Remove extra semis (#2717) 2019-07-08 15:07:36 -04:00
to_string_test.cpp Implement to_string(uint32_t) without using the locale (#5805) 2024-09-12 14:30:18 -07:00
unit_spirv.cpp Fix round trip tests that weren't instantiated (#3417) 2020-06-10 11:11:46 -04:00
unit_spirv.h NFC: replace EnumSet::ForEach with range-based-for (#5322) 2023-07-13 14:40:47 -04:00