@@ -184,36 +184,64 @@ extern "C"
184
184
return tools.Validate (contents, contentsSize, options);
185
185
}
186
186
187
- // Disassemble the given SPIRV-ASM instructions.
187
+ // Disassemble the given SPIRV-ASM instructions and return the result as a string .
188
188
extern " C"
189
189
#ifdef _MSC_VER
190
190
_declspec (dllexport)
191
191
#else
192
- __attribute__ ((__visibility__(" default" )))
192
+ __attribute__ ((__visibility__(" default" )))
193
193
#endif
194
- bool glslang_disassembleSPIRV (const uint32_t * contents, int contentsSize)
194
+ bool glslang_disassembleSPIRVWithResult (
195
+ const uint32_t * contents,
196
+ int contentsSize,
197
+ char ** outString)
195
198
{
196
199
static const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_5;
200
+ spv_text text;
197
201
198
202
uint32_t options = SPV_BINARY_TO_TEXT_OPTION_NONE;
199
203
options |= SPV_BINARY_TO_TEXT_OPTION_COMMENT;
200
- options |= SPV_BINARY_TO_TEXT_OPTION_PRINT;
201
- options |= SPV_BINARY_TO_TEXT_OPTION_COLOR;
202
204
options |= SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
205
+ options |= SPV_BINARY_TO_TEXT_OPTION_INDENT;
203
206
204
207
spv_diagnostic diagnostic = nullptr ;
205
208
spv_context context = spvContextCreate (kDefaultEnvironment );
206
209
spv_result_t error =
207
- spvBinaryToText (context, contents, contentsSize, options, nullptr , &diagnostic);
210
+ spvBinaryToText (context, contents, contentsSize, options, &text , &diagnostic);
208
211
spvContextDestroy (context);
209
212
if (error)
210
213
{
211
214
spvDiagnosticPrint (diagnostic);
212
215
spvDiagnosticDestroy (diagnostic);
213
216
return false ;
214
217
}
218
+ else
219
+ {
220
+ if (outString)
221
+ {
222
+ // Allocate memory for the output string and copy the result
223
+ size_t len = text->length + 1 ; // +1 for null terminator
224
+ *outString = new char [len];
225
+ memcpy (*outString, text->str , text->length );
226
+ (*outString)[text->length ] = ' \0 ' ; // Ensure null termination
227
+ }
215
228
216
- return true ;
229
+ spvTextDestroy (text);
230
+ return true ;
231
+ }
232
+ }
233
+
234
+
235
+ // Disassemble the given SPIRV-ASM instructions.
236
+ extern " C"
237
+ #ifdef _MSC_VER
238
+ _declspec (dllexport)
239
+ #else
240
+ __attribute__ ((__visibility__(" default" )))
241
+ #endif
242
+ bool glslang_disassembleSPIRV (const uint32_t * contents, int contentsSize)
243
+ {
244
+ return glslang_disassembleSPIRVWithResult (contents, contentsSize, nullptr );
217
245
}
218
246
219
247
// Apply the SPIRV-Tools optimizer to generated SPIR-V based on the desired optimization level
@@ -997,6 +1025,8 @@ extern "C"
997
1025
spvtools::Context context (SPV_ENV_UNIVERSAL_1_5);
998
1026
spvtools::LinkerOptions options = {};
999
1027
1028
+ options.SetUseHighestVersion (true );
1029
+
1000
1030
spvtools::MessageConsumer consumer = [](spv_message_level_t level,
1001
1031
const char * source,
1002
1032
const spv_position_t & position,
0 commit comments