r600g: add POW instruction
[mesa.git] / src / glsl / pp / sl_pp_pragma.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_token.h"
33
34
35 int
36 sl_pp_process_pragma(struct sl_pp_context *context,
37 const struct sl_pp_token_info *input,
38 unsigned int first,
39 unsigned int last,
40 struct sl_pp_process_state *state)
41 {
42 int pragma_name = -1;
43 struct sl_pp_token_info out;
44 int arg_name = -1;
45
46 if (first < last && input[first].token == SL_PP_IDENTIFIER) {
47 pragma_name = input[first].data.identifier;
48 first++;
49 }
50 if (pragma_name == -1) {
51 return 0;
52 }
53
54 if (pragma_name == context->dict.optimize) {
55 out.token = SL_PP_PRAGMA_OPTIMIZE;
56 } else if (pragma_name == context->dict.debug) {
57 out.token = SL_PP_PRAGMA_DEBUG;
58 } else {
59 return 0;
60 }
61
62 while (first < last && input[first].token == SL_PP_WHITESPACE) {
63 first++;
64 }
65
66 if (first < last && input[first].token == SL_PP_LPAREN) {
67 first++;
68 } else {
69 return 0;
70 }
71
72 while (first < last && input[first].token == SL_PP_WHITESPACE) {
73 first++;
74 }
75
76 if (first < last && input[first].token == SL_PP_IDENTIFIER) {
77 arg_name = input[first].data.identifier;
78 first++;
79 }
80 if (arg_name == -1) {
81 return 0;
82 }
83
84 if (arg_name == context->dict.off) {
85 out.data.pragma = 0;
86 } else if (arg_name == context->dict.on) {
87 out.data.pragma = 1;
88 } else {
89 return 0;
90 }
91
92 while (first < last && input[first].token == SL_PP_WHITESPACE) {
93 first++;
94 }
95
96 if (first < last && input[first].token == SL_PP_RPAREN) {
97 first++;
98 } else {
99 return 0;
100 }
101
102 /* Ignore the tokens that follow. */
103
104 if (sl_pp_process_out(state, &out)) {
105 strcpy(context->error_msg, "out of memory");
106 return -1;
107 }
108
109 return 0;
110 }