glsl2: Early return with visit_continue in loop_analysis::visit(ir_dereference_variab...
[mesa/nouveau-pmpeg.git] / src / glsl / glsl_parser_extras.h
blob3ccdab4ef27eb3b9e1c5a40a555dbe594fcbe743
1 /*
2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #pragma once
25 #ifndef GLSL_PARSER_EXTRAS_H
26 #define GLSL_PARSER_EXTRAS_H
29 * Most of the definitions here only apply to C++
31 #ifdef __cplusplus
34 #include <cstdlib>
35 #include "glsl_symbol_table.h"
37 enum _mesa_glsl_parser_targets {
38 vertex_shader,
39 geometry_shader,
40 fragment_shader,
41 ir_shader
44 struct __GLcontextRec;
46 struct _mesa_glsl_parse_state {
47 _mesa_glsl_parse_state(struct __GLcontextRec *ctx, GLenum target,
48 void *mem_ctx);
50 /* Callers of this talloc-based new need not call delete. It's
51 * easier to just talloc_free 'ctx' (or any of its ancestors). */
52 static void* operator new(size_t size, void *ctx)
54 void *mem = talloc_zero_size(ctx, size);
55 assert(mem != NULL);
57 return mem;
60 /* If the user *does* call delete, that's OK, we will just
61 * talloc_free in that case. */
62 static void operator delete(void *mem)
64 talloc_free(mem);
67 void *scanner;
68 exec_list translation_unit;
69 glsl_symbol_table *symbols;
71 unsigned language_version;
72 enum _mesa_glsl_parser_targets target;
74 /**
75 * Implementation defined limits that affect built-in variables, etc.
77 * \sa struct gl_constants (in mtypes.h)
79 struct {
80 /* 1.10 */
81 unsigned MaxLights;
82 unsigned MaxClipPlanes;
83 unsigned MaxTextureUnits;
84 unsigned MaxTextureCoords;
85 unsigned MaxVertexAttribs;
86 unsigned MaxVertexUniformComponents;
87 unsigned MaxVaryingFloats;
88 unsigned MaxVertexTextureImageUnits;
89 unsigned MaxCombinedTextureImageUnits;
90 unsigned MaxTextureImageUnits;
91 unsigned MaxFragmentUniformComponents;
93 /* ARB_draw_buffers */
94 unsigned MaxDrawBuffers;
95 } Const;
97 /**
98 * During AST to IR conversion, pointer to current IR function
100 * Will be \c NULL whenever the AST to IR conversion is not inside a
101 * function definition.
103 class ir_function_signature *current_function;
105 /** Have we found a return statement in this function? */
106 bool found_return;
108 /** Was there an error during compilation? */
109 bool error;
111 /** Loop or switch statement containing the current instructions. */
112 class ir_instruction *loop_or_switch_nesting;
113 class ast_iteration_statement *loop_or_switch_nesting_ast;
115 /** List of structures defined in user code. */
116 const glsl_type **user_structures;
117 unsigned num_user_structures;
119 char *info_log;
122 * \name Enable bits for GLSL extensions
124 /*@{*/
125 unsigned ARB_draw_buffers_enable:1;
126 unsigned ARB_draw_buffers_warn:1;
127 unsigned ARB_fragment_coord_conventions_enable:1;
128 unsigned ARB_fragment_coord_conventions_warn:1;
129 unsigned ARB_texture_rectangle_enable:1;
130 unsigned ARB_texture_rectangle_warn:1;
131 unsigned EXT_texture_array_enable:1;
132 unsigned EXT_texture_array_warn:1;
133 /*@}*/
135 /** Extensions supported by the OpenGL implementation. */
136 const struct gl_extensions *extensions;
138 /** Shaders containing built-in functions that are used for linking. */
139 struct gl_shader *builtins_to_link[16];
140 unsigned num_builtins_to_link;
143 typedef struct YYLTYPE {
144 int first_line;
145 int first_column;
146 int last_line;
147 int last_column;
148 unsigned source;
149 } YYLTYPE;
150 # define YYLTYPE_IS_DECLARED 1
151 # define YYLTYPE_IS_TRIVIAL 1
153 # define YYLLOC_DEFAULT(Current, Rhs, N) \
154 do { \
155 if (N) \
157 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
158 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
159 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
160 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
162 else \
164 (Current).first_line = (Current).last_line = \
165 YYRHSLOC(Rhs, 0).last_line; \
166 (Current).first_column = (Current).last_column = \
167 YYRHSLOC(Rhs, 0).last_column; \
169 (Current).source = 0; \
170 } while (0)
172 extern void _mesa_glsl_error(YYLTYPE *locp, _mesa_glsl_parse_state *state,
173 const char *fmt, ...);
176 * Emit a warning to the shader log
178 * \sa _mesa_glsl_error
180 extern void _mesa_glsl_warning(const YYLTYPE *locp,
181 _mesa_glsl_parse_state *state,
182 const char *fmt, ...);
184 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state *state,
185 const char *string);
187 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state *state);
189 union YYSTYPE;
190 extern int _mesa_glsl_lex(union YYSTYPE *yylval, YYLTYPE *yylloc,
191 void *scanner);
193 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state *);
196 * Process elements of the #extension directive
198 * \return
199 * If \c name and \c behavior are valid, \c true is returned. Otherwise
200 * \c false is returned.
202 extern bool _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp,
203 const char *behavior,
204 YYLTYPE *behavior_locp,
205 _mesa_glsl_parse_state *state);
208 * Get the textual name of the specified shader target
210 extern const char *
211 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target);
214 #endif /* __cplusplus */
218 * These definitions apply to C and C++
220 #ifdef __cplusplus
221 extern "C" {
222 #endif
224 extern int preprocess(void *ctx, const char **shader, char **info_log,
225 const struct gl_extensions *extensions);
227 extern void _mesa_destroy_shader_compiler();
228 extern void _mesa_destroy_shader_compiler_caches();
230 #ifdef __cplusplus
232 #endif
235 #endif /* GLSL_PARSER_EXTRAS_H */