aboutsummaryrefslogtreecommitdiff
path: root/SPIRV/GlslangToSpv.cpp
diff options
context:
space:
mode:
authorJohannes van Waveren <janpaul.vanwaveren@oculus.com>2016-05-27 12:55:53 -0500
committerJohannes van Waveren <janpaul.vanwaveren@oculus.com>2016-05-27 12:55:53 -0500
commitecb0f3b75bd03f4732df5a86f27c24b0d0b00bec (patch)
treef72edd398a6b4d1c3587cc7151fef69ad5cf074c /SPIRV/GlslangToSpv.cpp
parent5a7f0eff698cd42c221390af4daa2c6e722ef23e (diff)
downloadglslang-ecb0f3b75bd03f4732df5a86f27c24b0d0b00bec.tar.gz
Added -x option to save SPIR-V as 32-bit hexadecimal numbers to a text file.
Diffstat (limited to 'SPIRV/GlslangToSpv.cpp')
-rwxr-xr-xSPIRV/GlslangToSpv.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index d6ae9415..0ca7d6dd 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -49,8 +49,10 @@ namespace spv {
#include "../glslang/MachineIndependent/localintermediate.h"
#include "../glslang/MachineIndependent/SymbolTable.h"
#include "../glslang/Include/Common.h"
+#include "../glslang/Include/revision.h"
#include <fstream>
+#include <iomanip>
#include <list>
#include <map>
#include <stack>
@@ -4311,7 +4313,7 @@ void GetSpirvVersion(std::string& version)
}
// Write SPIR-V out to a binary file
-void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
+void OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName)
{
std::ofstream out;
out.open(baseName, std::ios::binary | std::ios::out);
@@ -4322,6 +4324,27 @@ void OutputSpv(const std::vector<unsigned int>& spirv, const char* baseName)
out.close();
}
+// Write SPIR-V out to a text file with 32-bit hexadecimal words
+void OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName)
+{
+ std::ofstream out;
+ out.open(baseName, std::ios::binary | std::ios::out);
+ out << "\t// " GLSLANG_REVISION " " GLSLANG_DATE << std::endl;
+ const int WORDS_PER_LINE = 8;
+ for (int i = 0; i < (int)spirv.size(); i += WORDS_PER_LINE) {
+ out << "\t";
+ for (int j = 0; j < WORDS_PER_LINE && i + j < (int)spirv.size(); ++j) {
+ const unsigned int word = spirv[i + j];
+ out << "0x" << std::hex << std::setw(8) << std::setfill('0') << word;
+ if (i + j + 1 < (int)spirv.size()) {
+ out << ",";
+ }
+ }
+ out << std::endl;
+ }
+ out.close();
+}
+
//
// Set up the glslang traversal
//