diff options
author | Lei Zhang <antiagainst@google.com> | 2016-09-20 18:03:37 -0400 |
---|---|---|
committer | Lei Zhang <antiagainst@google.com> | 2016-09-21 14:42:04 -0400 |
commit | 5edf0549267ae5237c163d260f87292a35f31b10 (patch) | |
tree | 6397ad28b00194ef6cfc11415b2c9072713f9508 /source/libspirv.cpp | |
parent | 620f05e679ac65373736969cae66b9f3ac73252d (diff) |
Add more Assemble(), Disassemble() and Validate() overloads.
Diffstat (limited to 'source/libspirv.cpp')
-rw-r--r-- | source/libspirv.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/source/libspirv.cpp b/source/libspirv.cpp index dcbfa154..9afb9cb1 100644 --- a/source/libspirv.cpp +++ b/source/libspirv.cpp @@ -41,9 +41,14 @@ void SpirvTools::SetMessageConsumer(MessageConsumer consumer) { bool SpirvTools::Assemble(const std::string& text, std::vector<uint32_t>* binary) const { + return Assemble(text.data(), text.size(), binary); +} + +bool SpirvTools::Assemble(const char* text, const size_t text_size, + std::vector<uint32_t>* binary) const { spv_binary spvbinary = nullptr; - spv_result_t status = spvTextToBinary(impl_->context, text.data(), - text.size(), &spvbinary, nullptr); + spv_result_t status = + spvTextToBinary(impl_->context, text, text_size, &spvbinary, nullptr); if (status == SPV_SUCCESS) { binary->assign(spvbinary->code, spvbinary->code + spvbinary->wordCount); } @@ -53,9 +58,14 @@ bool SpirvTools::Assemble(const std::string& text, bool SpirvTools::Disassemble(const std::vector<uint32_t>& binary, std::string* text, uint32_t options) const { + return Disassemble(binary.data(), binary.size(), text, options); +} + +bool SpirvTools::Disassemble(const uint32_t* binary, const size_t binary_size, + std::string* text, uint32_t options) const { spv_text spvtext = nullptr; - spv_result_t status = spvBinaryToText( - impl_->context, binary.data(), binary.size(), options, &spvtext, nullptr); + spv_result_t status = spvBinaryToText(impl_->context, binary, binary_size, + options, &spvtext, nullptr); if (status == SPV_SUCCESS) { text->assign(spvtext->str, spvtext->str + spvtext->length); } @@ -64,8 +74,13 @@ bool SpirvTools::Disassemble(const std::vector<uint32_t>& binary, } bool SpirvTools::Validate(const std::vector<uint32_t>& binary) const { - spv_const_binary_t b = {binary.data(), binary.size()}; - return spvValidate(impl_->context, &b, nullptr) == SPV_SUCCESS; + return Validate(binary.data(), binary.size()); +} + +bool SpirvTools::Validate(const uint32_t* binary, + const size_t binary_size) const { + return spvValidateBinary(impl_->context, binary, binary_size, nullptr) == + SPV_SUCCESS; } } // namespace spvtools |