Added dissasembler and extra options
This commit is contained in:
parent
a49840f365
commit
812c09ec9b
3 changed files with 41 additions and 2 deletions
|
|
@ -29,12 +29,15 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**/
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "glslang/Include/glslang_c_interface.h"
|
||||
|
||||
#include "SPIRV/GlslangToSpv.h"
|
||||
#include "SPIRV/Logger.h"
|
||||
#include "SPIRV/SpvTools.h"
|
||||
#include "SPIRV/disassemble.h"
|
||||
|
||||
static_assert(sizeof(glslang_spv_options_t) == sizeof(glslang::SpvOptions), "");
|
||||
|
||||
|
|
@ -118,3 +121,20 @@ GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t*
|
|||
{
|
||||
return program->loggerMessages.empty() ? nullptr : program->loggerMessages.c_str();
|
||||
}
|
||||
|
||||
GLSLANG_EXPORT char* glslang_SPIRV_disassemble(const unsigned int* spv_words, size_t spv_words_len)
|
||||
{
|
||||
std::stringstream string_stream;
|
||||
std::vector<unsigned int> words_vector;
|
||||
words_vector.assign(spv_words, spv_words + spv_words_len);
|
||||
|
||||
spv::Disassemble(string_stream, words_vector);
|
||||
|
||||
std::string string = string_stream.str();
|
||||
|
||||
const size_t size = string.size();
|
||||
char* buffer = new char[size + 1];
|
||||
memcpy(buffer, string.c_str(), size + 1);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
|||
21
build.zig
21
build.zig
|
|
@ -26,17 +26,28 @@ pub fn build(b: *Build) !void {
|
|||
const standalone_glslang = b.option(bool, "standalone", "Build glslang.exe standalone command-line compiler.") orelse false;
|
||||
const standalone_spvremap = b.option(bool, "standalone-remap", "Build spirv-remap.exe standalone command-line remapper.") orelse false;
|
||||
|
||||
if (shared and (standalone_glslang or standalone_spvremap)) {
|
||||
log.err("Cannot build standalone sources with shared glslang. Recompile without `-Dshared` or `-Dstandalone/-Dstandalone-remap`", .{});
|
||||
std.process.exit(1);
|
||||
}
|
||||
|
||||
const tools_libs: spvtools.SPVLibs = spvtools.buildSpirv(b, optimize, target, shared_tools, debug, spirv_header_name) catch |err| {
|
||||
log.err("Error building SPIRV-Tools: {s}", .{ @errorName(err) });
|
||||
std.process.exit(1);
|
||||
};
|
||||
|
||||
const tag = target.result.os.tag;
|
||||
|
||||
var cppflags = std.ArrayList([]const u8).init(b.allocator);
|
||||
|
||||
if (!debug) {
|
||||
try cppflags.append("-g0");
|
||||
}
|
||||
|
||||
if (tag == .windows and shared) {
|
||||
try cppflags.append("-rdynamic");
|
||||
}
|
||||
|
||||
try cppflags.append("-std=c++17");
|
||||
|
||||
const base_flags = &.{
|
||||
|
|
@ -94,8 +105,6 @@ pub fn build(b: *Build) !void {
|
|||
.flags = cppflags.items,
|
||||
});
|
||||
|
||||
const tag = target.result.os.tag;
|
||||
|
||||
if (tag == .windows) {
|
||||
glslang_lib.addCSourceFiles(.{
|
||||
.files = &sources_win,
|
||||
|
|
@ -159,6 +168,10 @@ pub fn build(b: *Build) !void {
|
|||
.target = target,
|
||||
});
|
||||
|
||||
if (shared) {
|
||||
glslang_exe.defineCMacro("GLSLANG_IS_SHARED_LIBRARY", "");
|
||||
}
|
||||
|
||||
const install_glslang_step = b.step("glslang-standalone", "Build and install glslang.exe");
|
||||
install_glslang_step.dependOn(&b.addInstallArtifact(glslang_exe, .{}).step);
|
||||
glslang_exe.addCSourceFiles(.{
|
||||
|
|
@ -197,6 +210,10 @@ pub fn build(b: *Build) !void {
|
|||
.target = target,
|
||||
});
|
||||
|
||||
if (shared) {
|
||||
spirv_remap.defineCMacro("GLSLANG_IS_SHARED_LIBRARY", "");
|
||||
}
|
||||
|
||||
const install_remap_step = b.step("spirv-remap", "Build and install spirv-remap.exe");
|
||||
install_remap_step.dependOn(&b.addInstallArtifact(spirv_remap, .{}).step);
|
||||
spirv_remap.addCSourceFiles(.{
|
||||
|
|
|
|||
|
|
@ -284,6 +284,8 @@ GLSLANG_EXPORT const char* glslang_program_SPIRV_get_messages(glslang_program_t*
|
|||
GLSLANG_EXPORT const char* glslang_program_get_info_log(glslang_program_t* program);
|
||||
GLSLANG_EXPORT const char* glslang_program_get_info_debug_log(glslang_program_t* program);
|
||||
|
||||
GLSLANG_EXPORT char* glslang_SPIRV_disassemble(const unsigned int* spv_words, size_t spv_words_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue