spirv_tools_sys/assembler.rs
1use crate::shared;
2
3#[repr(u32)] // SPV_FORCE_32_BIT_ENUM
4pub enum BinaryOptions {
5 None = 0x1,
6 PreserveNumberIds = 1 << 1,
7}
8
9#[repr(C)]
10pub struct Text {
11 pub data: *const std::os::raw::c_char,
12 pub length: usize,
13}
14
15pub enum DisassembleOptions {
16 None = 0x1,
17 /// Print to stdout
18 Print = 0x2,
19 /// Add color codes to output
20 Color = 0x4,
21 /// Indent assembly
22 Indent = 0x8,
23 ShowByteOffset = 0x10,
24 /// Do not output the module header as leading comments in the assembly.
25 NoHeader = 0x20,
26 /// Use friendly names where possible. The heuristic may expand over
27 /// time, but will use common names for scalar types, and debug names from
28 /// OpName instructions.
29 FriendlyNames = 0x40,
30 /// Add some comments to the generated assembly
31 Comment = 0x80,
32}
33
34extern "C" {
35 /// Encodes the given SPIR-V assembly text to its binary representation. The
36 /// length parameter specifies the number of bytes for text. Encoded binary will
37 /// be stored into *binary. Any error will be written into *diagnostic if
38 /// diagnostic is non-null, otherwise the context's message consumer will be
39 /// used. The generated binary is independent of the context and may outlive it.
40 /// The SPIR-V binary version is set to the highest version of SPIR-V supported
41 /// by the context's target environment.
42 ///
43 /// The options parameter is a bit field of
44 /// spv_text_to_binary_options_t.
45 #[link_name = "spvTextToBinaryWithOptions"]
46 pub fn assemble(
47 tool: *const shared::ToolContext,
48 text: *const std::os::raw::c_char,
49 size: usize,
50 options: u32,
51 binary: *mut *mut shared::Binary,
52 diagnostic: *mut *mut crate::diagnostics::Diagnostic,
53 ) -> shared::SpirvResult;
54
55 /// Decodes the given SPIR-V binary representation to its assembly text. The
56 /// word_count parameter specifies the number of words for binary. The options
57 /// parameter is a bit field of spv_binary_to_text_options_t. Decoded text will
58 /// be stored into *text. Any error will be written into *diagnostic if
59 /// diagnostic is non-null, otherwise the context's message consumer will be
60 /// used.
61 #[link_name = "spvBinaryToText"]
62 pub fn disassemble(
63 tool: *const shared::ToolContext,
64 binary: *const u32,
65 size: usize,
66 options: u32,
67 out_text: *mut *mut Text,
68 diagnostic: *mut *mut crate::diagnostics::Diagnostic,
69 ) -> shared::SpirvResult;
70
71 /// Frees an allocated text stream. This is a no-op if the text parameter
72 /// is a null pointer.
73 #[link_name = "spvTextDestroy"]
74 pub fn text_destroy(text: *mut Text);
75}