mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2025-01-12 09:20:15 +00:00
Kill diagnostic_helper & the wrapping DIAGNOSTIC macro.
This commit is contained in:
parent
2ad3b74fa3
commit
75bf78c70b
@ -34,33 +34,11 @@
|
||||
#include "spirv-tools/libspirv.h"
|
||||
|
||||
namespace libspirv {
|
||||
class diagnostic_helper {
|
||||
public:
|
||||
diagnostic_helper(spv_position_t& position, spv_diagnostic* diagnostic)
|
||||
: position_(&position), diagnostic_(diagnostic) {}
|
||||
|
||||
diagnostic_helper(spv_position position, spv_diagnostic* diagnostic)
|
||||
: position_(position), diagnostic_(diagnostic) {}
|
||||
|
||||
~diagnostic_helper() {
|
||||
*diagnostic_ = spvDiagnosticCreate(position_, stream().str().c_str());
|
||||
}
|
||||
|
||||
std::stringstream& stream() { return stream_; }
|
||||
|
||||
private:
|
||||
std::stringstream stream_;
|
||||
spv_position position_;
|
||||
spv_diagnostic* diagnostic_;
|
||||
};
|
||||
|
||||
// A DiagnosticStream remembers the current position of the input and an error
|
||||
// code, and captures diagnostic messages via the left-shift operator.
|
||||
// If the error code is not SPV_FAILED_MATCH, then captured messages are
|
||||
// emitted during the destructor.
|
||||
// TODO(awoloszyn): This is very similar to diagnostic_helper, and hides
|
||||
// the data more easily. Replace diagnostic_helper elsewhere
|
||||
// eventually.
|
||||
class DiagnosticStream {
|
||||
public:
|
||||
DiagnosticStream(spv_position_t position, spv_diagnostic* pDiagnostic,
|
||||
@ -97,10 +75,6 @@ class DiagnosticStream {
|
||||
spv_result_t error_;
|
||||
};
|
||||
|
||||
#define DIAGNOSTIC \
|
||||
libspirv::diagnostic_helper helper(position, pDiagnostic); \
|
||||
helper.stream()
|
||||
|
||||
std::string spvResultToString(spv_result_t res);
|
||||
|
||||
} // namespace libspirv
|
||||
|
@ -189,14 +189,16 @@ spv_result_t spvValidate(const spv_const_context context,
|
||||
spv_endianness_t endian;
|
||||
spv_position_t position = {};
|
||||
if (spvBinaryEndianness(binary, &endian)) {
|
||||
DIAGNOSTIC << "Invalid SPIR-V magic number.";
|
||||
return SPV_ERROR_INVALID_BINARY;
|
||||
return libspirv::DiagnosticStream(position, pDiagnostic,
|
||||
SPV_ERROR_INVALID_BINARY)
|
||||
<< "Invalid SPIR-V magic number.";
|
||||
}
|
||||
|
||||
spv_header_t header;
|
||||
if (spvBinaryHeaderGet(binary, endian, &header)) {
|
||||
DIAGNOSTIC << "Invalid SPIR-V header.";
|
||||
return SPV_ERROR_INVALID_BINARY;
|
||||
return libspirv::DiagnosticStream(position, pDiagnostic,
|
||||
SPV_ERROR_INVALID_BINARY)
|
||||
<< "Invalid SPIR-V header.";
|
||||
}
|
||||
|
||||
// NOTE: Parse the module and perform inline validation checks. These
|
||||
|
@ -97,9 +97,11 @@ class idUsage {
|
||||
vector<uint32_t> entry_points_;
|
||||
};
|
||||
|
||||
#define DIAG(INDEX) \
|
||||
position->index += INDEX; \
|
||||
DIAGNOSTIC
|
||||
#define DIAG(INDEX) \
|
||||
position->index += INDEX; \
|
||||
libspirv::DiagnosticStream helper(*position, pDiagnostic, \
|
||||
SPV_ERROR_INVALID_DIAGNOSTIC); \
|
||||
helper
|
||||
|
||||
#if 0
|
||||
template <>
|
||||
|
Loading…
Reference in New Issue
Block a user