// the input stream, and for the given error code. Any data written to the
// returned object will be propagated to the current parse's diagnostic
// object.
- DiagnosticStream diagnostic(spv_result_t error) {
- return DiagnosticStream({0, 0, _.word_index}, _.diagnostic, error);
+ libspirv::DiagnosticStream diagnostic(spv_result_t error) {
+ return libspirv::DiagnosticStream({0, 0, _.word_index}, _.diagnostic, error);
}
// Returns a diagnostic stream object with the default parse error code.
- DiagnosticStream diagnostic() {
+ libspirv::DiagnosticStream diagnostic() {
// The default failure for parsing is invalid binary.
return diagnostic(SPV_ERROR_INVALID_BINARY);
}
return SPV_ERROR_INVALID_VALUE;
}
+namespace libspirv {
+
DiagnosticStream::~DiagnosticStream() {
if (pDiagnostic_ && error_ != SPV_FAILED_MATCH) {
*pDiagnostic_ = spvDiagnosticCreate(&position_, stream_.str().c_str());
}
}
+
+} // namespace libspirv
#include "libspirv/libspirv.h"
+namespace libspirv {
+
class diagnostic_helper {
public:
diagnostic_helper(spv_position_t& position, spv_diagnostic* pDiagnostic)
spv_result_t error_;
};
-#define DIAGNOSTIC \
- diagnostic_helper helper(position, pDiagnostic); \
+#define DIAGNOSTIC \
+ libspirv::diagnostic_helper helper(position, pDiagnostic); \
helper.stream
+} // namespace libspirv
+
#endif // LIBSPIRV_DIAGNOSTIC_H_
class Disassembler {
enum { kStandardIndent = 15 };
+ using out_stream = libspirv::out_stream;
+
public:
Disassembler(const libspirv::AssemblyGrammar& grammar, uint32_t const* words,
uint32_t options)
// Resets the output color, if color is turned on.
void ResetColor() {
- if (color_) out_.get() << clr::reset();
+ if (color_) out_.get() << libspirv::clr::reset();
}
// Sets the output to grey, if color is turned on.
void SetGrey() {
- if (color_) out_.get() << clr::grey();
+ if (color_) out_.get() << libspirv::clr::grey();
}
// Sets the output to blue, if color is turned on.
void SetBlue() {
- if (color_) out_.get() << clr::blue();
+ if (color_) out_.get() << libspirv::clr::blue();
}
// Sets the output to yellow, if color is turned on.
void SetYellow() {
- if (color_) out_.get() << clr::yellow();
+ if (color_) out_.get() << libspirv::clr::yellow();
}
// Sets the output to red, if color is turned on.
void SetRed() {
- if (color_) out_.get() << clr::red();
+ if (color_) out_.get() << libspirv::clr::red();
}
// Sets the output to green, if color is turned on.
void SetGreen() {
- if (color_) out_.get() << clr::green();
+ if (color_) out_.get() << libspirv::clr::green();
}
// The SPIR-V binary. The endianness is not necessarily converted
#include "print.h"
#if defined(SPIRV_LINUX) || defined(SPIRV_MAC)
+namespace libspirv {
+
clr::reset::operator const char*() { return "\e[0m"; }
clr::grey::operator const char*() { return "\e[1;30m"; }
clr::yellow::operator const char*() { return "\e[33m"; }
clr::blue::operator const char*() { return "\e[34m"; }
+
+} // namespace libspirv
#elif defined(SPIRV_WINDOWS)
#include <Windows.h>
+namespace libspirv {
+
clr::reset::operator const char*() {
const DWORD color = 0Xf;
HANDLE hConsole;
SetConsoleTextAttribute(hConsole, color);
return "";
}
+
+} // namespace libspirv
#endif
#include <iostream>
#include <sstream>
+namespace libspirv {
+
// Wrapper for out stream selection.
class out_stream {
public:
struct blue {
operator const char*();
};
-}
+} // namespace clr
+
+} // namespace libspirv
#endif // LIBSPIRV_PRINT_H_
namespace {
+using libspirv::DiagnosticStream;
+
TEST(DiagnosticStream, ConversionToResultType) {
// Check after the DiagnosticStream object is destroyed.
spv_result_t value;