OSDN Git Service

r600g: add POW instruction
[android-x86/external-mesa.git] / src / glsl / pp / sl_pp_error.c
1 /**************************************************************************
2  * 
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  * 
26  **************************************************************************/
27
28 #include <stdlib.h>
29 #include <string.h>
30 #include "sl_pp_context.h"
31 #include "sl_pp_process.h"
32 #include "sl_pp_public.h"
33 #include "sl_pp_token.h"
34
35
36 void
37 sl_pp_process_error(struct sl_pp_context *context,
38                     const struct sl_pp_token_info *input,
39                     unsigned int first,
40                     unsigned int last)
41 {
42    unsigned int out_len = 0;
43    unsigned int i;
44
45    for (i = first; i < last; i++) {
46       const char *s = NULL;
47       char buf[2];
48
49       switch (input[i].token) {
50       case SL_PP_WHITESPACE:
51          s = " ";
52          break;
53
54       case SL_PP_NEWLINE:
55          s = "\n";
56          break;
57
58       case SL_PP_HASH:
59          s = "#";
60          break;
61
62       case SL_PP_COMMA:
63          s = ",";
64          break;
65
66       case SL_PP_SEMICOLON:
67          s = ";";
68          break;
69
70       case SL_PP_LBRACE:
71          s = "{";
72          break;
73
74       case SL_PP_RBRACE:
75          s = "}";
76          break;
77
78       case SL_PP_LPAREN:
79          s = "(";
80          break;
81
82       case SL_PP_RPAREN:
83          s = ")";
84          break;
85
86       case SL_PP_LBRACKET:
87          s = "[";
88          break;
89
90       case SL_PP_RBRACKET:
91          s = "]";
92          break;
93
94       case SL_PP_DOT:
95          s = ".";
96          break;
97
98       case SL_PP_INCREMENT:
99          s = "++";
100          break;
101
102       case SL_PP_ADDASSIGN:
103          s = "+=";
104          break;
105
106       case SL_PP_PLUS:
107          s = "+";
108          break;
109
110       case SL_PP_DECREMENT:
111          s = "--";
112          break;
113
114       case SL_PP_SUBASSIGN:
115          s = "-=";
116          break;
117
118       case SL_PP_MINUS:
119          s = "-";
120          break;
121
122       case SL_PP_BITNOT:
123          s = "~";
124          break;
125
126       case SL_PP_NOTEQUAL:
127          s = "!=";
128          break;
129
130       case SL_PP_NOT:
131          s = "!";
132          break;
133
134       case SL_PP_MULASSIGN:
135          s = "*=";
136          break;
137
138       case SL_PP_STAR:
139          s = "*";
140          break;
141
142       case SL_PP_DIVASSIGN:
143          s = "/=";
144          break;
145
146       case SL_PP_SLASH:
147          s = "/";
148          break;
149
150       case SL_PP_MODASSIGN:
151          s = "%=";
152          break;
153
154       case SL_PP_MODULO:
155          s = "%";
156          break;
157
158       case SL_PP_LSHIFTASSIGN:
159          s = "<<=";
160          break;
161
162       case SL_PP_LSHIFT:
163          s = "<<";
164          break;
165
166       case SL_PP_LESSEQUAL:
167          s = "<=";
168          break;
169
170       case SL_PP_LESS:
171          s = "<";
172          break;
173
174       case SL_PP_RSHIFTASSIGN:
175          s = ">>=";
176          break;
177
178       case SL_PP_RSHIFT:
179          s = ">>";
180          break;
181
182       case SL_PP_GREATEREQUAL:
183          s = ">=";
184          break;
185
186       case SL_PP_GREATER:
187          s = ">";
188          break;
189
190       case SL_PP_EQUAL:
191          s = "==";
192          break;
193
194       case SL_PP_ASSIGN:
195          s = "=";
196          break;
197
198       case SL_PP_AND:
199          s = "&&";
200          break;
201
202       case SL_PP_BITANDASSIGN:
203          s = "&=";
204          break;
205
206       case SL_PP_BITAND:
207          s = "&";
208          break;
209
210       case SL_PP_XOR:
211          s = "^^";
212          break;
213
214       case SL_PP_BITXORASSIGN:
215          s = "^=";
216          break;
217
218       case SL_PP_BITXOR:
219          s = "^";
220          break;
221
222       case SL_PP_OR:
223          s = "||";
224          break;
225
226       case SL_PP_BITORASSIGN:
227          s = "|=";
228          break;
229
230       case SL_PP_BITOR:
231          s = "|";
232          break;
233
234       case SL_PP_QUESTION:
235          s = "?";
236          break;
237
238       case SL_PP_COLON:
239          s = ":";
240          break;
241
242       case SL_PP_IDENTIFIER:
243          s = sl_pp_context_cstr(context, input[i].data.identifier);
244          break;
245
246       case SL_PP_UINT:
247          s = sl_pp_context_cstr(context, input[i].data._uint);
248          break;
249
250       case SL_PP_FLOAT:
251          s = sl_pp_context_cstr(context, input[i].data._float);
252          break;
253
254       case SL_PP_OTHER:
255          buf[0] = input[i].data.other;
256          buf[1] = '\0';
257          s = buf;
258          break;
259
260       default:
261          strcpy(context->error_msg, "internal error");
262          return;
263       }
264
265       while (*s != '\0' && out_len < sizeof(context->error_msg) - 1) {
266          context->error_msg[out_len++] = *s++;
267       }
268    }
269
270    context->error_msg[out_len] = '\0';
271 }