• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 #include "message.h"
16 
17 #include <sstream>
18 
19 namespace spvtools {
20 
StringifyMessage(spv_message_level_t level,const char * source,const spv_position_t & position,const char * message)21 std::string StringifyMessage(spv_message_level_t level, const char* source,
22                              const spv_position_t& position,
23                              const char* message) {
24   const char* level_string = nullptr;
25   switch (level) {
26     case SPV_MSG_FATAL:
27       level_string = "fatal";
28       break;
29     case SPV_MSG_INTERNAL_ERROR:
30       level_string = "internal error";
31       break;
32     case SPV_MSG_ERROR:
33       level_string = "error";
34       break;
35     case SPV_MSG_WARNING:
36       level_string = "warning";
37       break;
38     case SPV_MSG_INFO:
39       level_string = "info";
40       break;
41     case SPV_MSG_DEBUG:
42       level_string = "debug";
43       break;
44   }
45   std::ostringstream oss;
46   oss << level_string << ": ";
47   if (source) oss << source << ":";
48   oss << position.line << ":" << position.column << ":";
49   oss << position.index << ": ";
50   if (message) oss << message;
51   return oss.str();
52 }
53 
54 }  // namespace spvtools
55