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
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.
25 #ifndef GLSL_PARSER_EXTRAS_H
26 #define GLSL_PARSER_EXTRAS_H
29 * Most of the definitions here only apply to C++
35 #include "glsl_symbol_table.h"
37 enum _mesa_glsl_parser_targets
{
45 struct _mesa_glsl_parse_state
{
46 _mesa_glsl_parse_state(struct gl_context
*ctx
, GLenum target
,
49 /* Callers of this ralloc-based new need not call delete. It's
50 * easier to just ralloc_free 'ctx' (or any of its ancestors). */
51 static void* operator new(size_t size
, void *ctx
)
53 void *mem
= rzalloc_size(ctx
, size
);
59 /* If the user *does* call delete, that's OK, we will just
60 * ralloc_free in that case. */
61 static void operator delete(void *mem
)
67 exec_list translation_unit
;
68 glsl_symbol_table
*symbols
;
71 unsigned language_version
;
72 const char *version_string
;
73 enum _mesa_glsl_parser_targets target
;
76 * Implementation defined limits that affect built-in variables, etc.
78 * \sa struct gl_constants (in mtypes.h)
83 unsigned MaxClipPlanes
;
84 unsigned MaxTextureUnits
;
85 unsigned MaxTextureCoords
;
86 unsigned MaxVertexAttribs
;
87 unsigned MaxVertexUniformComponents
;
88 unsigned MaxVaryingFloats
;
89 unsigned MaxVertexTextureImageUnits
;
90 unsigned MaxCombinedTextureImageUnits
;
91 unsigned MaxTextureImageUnits
;
92 unsigned MaxFragmentUniformComponents
;
94 /* ARB_draw_buffers */
95 unsigned MaxDrawBuffers
;
99 * During AST to IR conversion, pointer to current IR function
101 * Will be \c NULL whenever the AST to IR conversion is not inside a
102 * function definition.
104 class ir_function_signature
*current_function
;
106 /** Have we found a return statement in this function? */
109 /** Was there an error during compilation? */
113 * Are all shader inputs / outputs invariant?
115 * This is set when the 'STDGL invariant(all)' pragma is used.
119 /** Loop or switch statement containing the current instructions. */
120 class ir_instruction
*loop_or_switch_nesting
;
121 class ast_iteration_statement
*loop_or_switch_nesting_ast
;
123 /** List of structures defined in user code. */
124 const glsl_type
**user_structures
;
125 unsigned num_user_structures
;
130 * \name Enable bits for GLSL extensions
133 unsigned ARB_draw_buffers_enable
:1;
134 unsigned ARB_draw_buffers_warn
:1;
135 unsigned ARB_draw_instanced_enable
:1;
136 unsigned ARB_draw_instanced_warn
:1;
137 unsigned ARB_explicit_attrib_location_enable
:1;
138 unsigned ARB_explicit_attrib_location_warn
:1;
139 unsigned ARB_fragment_coord_conventions_enable
:1;
140 unsigned ARB_fragment_coord_conventions_warn
:1;
141 unsigned ARB_texture_rectangle_enable
:1;
142 unsigned ARB_texture_rectangle_warn
:1;
143 unsigned EXT_texture_array_enable
:1;
144 unsigned EXT_texture_array_warn
:1;
145 unsigned ARB_shader_stencil_export_enable
:1;
146 unsigned ARB_shader_stencil_export_warn
:1;
147 unsigned AMD_conservative_depth_enable
:1;
148 unsigned AMD_conservative_depth_warn
:1;
151 /** Extensions supported by the OpenGL implementation. */
152 const struct gl_extensions
*extensions
;
154 /** Shaders containing built-in functions that are used for linking. */
155 struct gl_shader
*builtins_to_link
[16];
156 unsigned num_builtins_to_link
;
159 typedef struct YYLTYPE
{
166 # define YYLTYPE_IS_DECLARED 1
167 # define YYLTYPE_IS_TRIVIAL 1
169 # define YYLLOC_DEFAULT(Current, Rhs, N) \
173 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
174 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
175 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
176 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
180 (Current).first_line = (Current).last_line = \
181 YYRHSLOC(Rhs, 0).last_line; \
182 (Current).first_column = (Current).last_column = \
183 YYRHSLOC(Rhs, 0).last_column; \
185 (Current).source = 0; \
188 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
189 const char *fmt
, ...);
192 * Emit a warning to the shader log
194 * \sa _mesa_glsl_error
196 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
197 _mesa_glsl_parse_state
*state
,
198 const char *fmt
, ...);
200 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
203 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
206 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
209 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
212 * Process elements of the #extension directive
215 * If \c name and \c behavior are valid, \c true is returned. Otherwise
216 * \c false is returned.
218 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
219 const char *behavior
,
220 YYLTYPE
*behavior_locp
,
221 _mesa_glsl_parse_state
*state
);
224 * Get the textual name of the specified shader target
227 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
230 #endif /* __cplusplus */
234 * These definitions apply to C and C++
240 extern int preprocess(void *ctx
, const char **shader
, char **info_log
,
241 const struct gl_extensions
*extensions
, int api
);
243 extern void _mesa_destroy_shader_compiler();
244 extern void _mesa_destroy_shader_compiler_caches();
251 #endif /* GLSL_PARSER_EXTRAS_H */