blob: 165ac7699cb87b58193e7c99f03305bc2f3c52a5 [file] [log] [blame]
#include "libmanager.h"
#include "third_party/khronos/glslang/SPIRV/doc.h"
#include <stdio.h>
#include <fstream> // std::ifstream
#include <memory>
#include <string>
int main(int argc, char* argv[]) {
options_t options = {/*is_fragment_shader*/ false,
/*is_vertex_shader*/ false,
/*prefix_names*/ true,
/*names_prefix*/ NULL,
/*add_outputs_for_inputs*/ true,
/*output_prefix*/ NULL,
/*make_debuggable*/ true,
/*check_after_changes*/ true,
/*disassemble*/ true};
std::string filename = std::string(argv[1]);
std::string extension = filename.substr(filename.find_last_of(".") + 1);
if (extension == "frag")
options.is_fragment_shader = true;
else if (extension == "vert")
options.is_vertex_shader = true;
std::unique_ptr<char> input;
int length;
std::ifstream myfile(filename.c_str(), std::ifstream::binary);
if (myfile) {
// get length of file:
myfile.seekg(0, myfile.end);
length = myfile.tellg();
myfile.seekg(0, myfile.beg);
input.reset(new char[length + 1]);
myfile.read(input.get(), length);
myfile.close();
input.get()[length] = '\0';
} else {
printf("error: Connot read from input file.\n");
exit(0);
}
code_with_debug_info_t* result = convertGlsl(input.get(), length, &options);
if (!result->ok) {
printf("%s\n", result->message);
} else {
if (options.disassemble) {
printf("%s\n", result->disassembly_string);
}
printf("Decompiled:\n%s\n", result->source_code);
printf("OK\n\n");
printf("Debug instructions\n");
for (int i = 0; i < result->info->insts_num; i++) {
printf("Instruction: id = %u, opcode = %s\n", result->info->insts[i].id,
spv::OpcodeString(result->info->insts[i].opcode));
for (uint32_t j = 0; j < result->info->insts[i].words_num; j++)
printf("%u, ", result->info->insts[i].words[j]);
printf("%s \n", result->info->insts[i].name);
}
}
deleteGlslCodeWithDebug(result);
return 0;
}