message.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2016 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "message.h"
  15. #include <sstream>
  16. namespace spvtools {
  17. std::string StringifyMessage(spv_message_level_t level, const char* source,
  18. const spv_position_t& position,
  19. const char* message) {
  20. const char* level_string = nullptr;
  21. switch (level) {
  22. case SPV_MSG_FATAL:
  23. level_string = "fatal";
  24. break;
  25. case SPV_MSG_INTERNAL_ERROR:
  26. level_string = "internal error";
  27. break;
  28. case SPV_MSG_ERROR:
  29. level_string = "error";
  30. break;
  31. case SPV_MSG_WARNING:
  32. level_string = "warning";
  33. break;
  34. case SPV_MSG_INFO:
  35. level_string = "info";
  36. break;
  37. case SPV_MSG_DEBUG:
  38. level_string = "debug";
  39. break;
  40. }
  41. std::ostringstream oss;
  42. oss << level_string << ": ";
  43. if (source) oss << source << ":";
  44. oss << position.line << ":" << position.column << ":";
  45. oss << position.index << ": ";
  46. if (message) oss << message;
  47. return oss.str();
  48. }
  49. } // namespace spvtools