From: David Neto Date: Fri, 20 Nov 2015 15:44:41 +0000 (-0500) Subject: Put DiagnosticStream and clr exports in libspirv namespace X-Git-Tag: upstream/2018.6~1423 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01656363a7234030a9917c41c09a03ab29316469;p=platform%2Fupstream%2FSPIRV-Tools.git Put DiagnosticStream and clr exports in libspirv namespace Each exported functions either has an "spv" prefix, or is inthe libspirv namespace. Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/18 --- diff --git a/source/binary.cpp b/source/binary.cpp index 3ce9ee0..1af785e 100755 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -163,12 +163,12 @@ class Parser { // 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); } diff --git a/source/diagnostic.cpp b/source/diagnostic.cpp index 0886957..b0e36c0 100644 --- a/source/diagnostic.cpp +++ b/source/diagnostic.cpp @@ -81,8 +81,12 @@ spv_result_t spvDiagnosticPrint(const spv_diagnostic diagnostic) { return SPV_ERROR_INVALID_VALUE; } +namespace libspirv { + DiagnosticStream::~DiagnosticStream() { if (pDiagnostic_ && error_ != SPV_FAILED_MATCH) { *pDiagnostic_ = spvDiagnosticCreate(&position_, stream_.str().c_str()); } } + +} // namespace libspirv diff --git a/source/diagnostic.h b/source/diagnostic.h index f8a2fe4..7c82b7f 100644 --- a/source/diagnostic.h +++ b/source/diagnostic.h @@ -33,6 +33,8 @@ #include "libspirv/libspirv.h" +namespace libspirv { + class diagnostic_helper { public: diagnostic_helper(spv_position_t& position, spv_diagnostic* pDiagnostic) @@ -95,8 +97,10 @@ class DiagnosticStream { 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_ diff --git a/source/disassemble.cpp b/source/disassemble.cpp index 14ae53a..b773256 100644 --- a/source/disassemble.cpp +++ b/source/disassemble.cpp @@ -49,6 +49,8 @@ namespace { class Disassembler { enum { kStandardIndent = 15 }; + using out_stream = libspirv::out_stream; + public: Disassembler(const libspirv::AssemblyGrammar& grammar, uint32_t const* words, uint32_t options) @@ -88,27 +90,27 @@ class Disassembler { // 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 diff --git a/source/print.cpp b/source/print.cpp index 455f2db..9269e41 100644 --- a/source/print.cpp +++ b/source/print.cpp @@ -27,6 +27,8 @@ #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"; } @@ -38,9 +40,13 @@ clr::green::operator const char*() { return "\e[32m"; } clr::yellow::operator const char*() { return "\e[33m"; } clr::blue::operator const char*() { return "\e[34m"; } + +} // namespace libspirv #elif defined(SPIRV_WINDOWS) #include +namespace libspirv { + clr::reset::operator const char*() { const DWORD color = 0Xf; HANDLE hConsole; @@ -100,4 +106,6 @@ clr::blue::operator const char*() { SetConsoleTextAttribute(hConsole, color); return ""; } + +} // namespace libspirv #endif diff --git a/source/print.h b/source/print.h index 8c88b9a..fdb1c0b 100644 --- a/source/print.h +++ b/source/print.h @@ -30,6 +30,8 @@ #include #include +namespace libspirv { + // Wrapper for out stream selection. class out_stream { public: @@ -72,6 +74,8 @@ struct yellow { struct blue { operator const char*(); }; -} +} // namespace clr + +} // namespace libspirv #endif // LIBSPIRV_PRINT_H_ diff --git a/test/DiagnosticStream.cpp b/test/DiagnosticStream.cpp index 183c69a..3508cb7 100644 --- a/test/DiagnosticStream.cpp +++ b/test/DiagnosticStream.cpp @@ -28,6 +28,8 @@ namespace { +using libspirv::DiagnosticStream; + TEST(DiagnosticStream, ConversionToResultType) { // Check after the DiagnosticStream object is destroyed. spv_result_t value;