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 #include "glsl_symbol_table.h"
31 enum _mesa_glsl_parser_targets
{
38 struct __GLcontextRec
;
40 struct _mesa_glsl_parse_state
{
41 _mesa_glsl_parse_state(struct __GLcontextRec
*ctx
, GLenum target
,
44 /* Callers of this talloc-based new need not call delete. It's
45 * easier to just talloc_free 'ctx' (or any of its ancestors). */
46 static void* operator new(size_t size
, void *ctx
)
48 void *mem
= talloc_zero_size(ctx
, size
);
54 /* If the user *does* call delete, that's OK, we will just
55 * talloc_free in that case. */
56 static void operator delete(void *mem
)
62 exec_list translation_unit
;
63 glsl_symbol_table
*symbols
;
65 unsigned language_version
;
66 enum _mesa_glsl_parser_targets target
;
69 * Implementation defined limits that affect built-in variables, etc.
71 * \sa struct gl_constants (in mtypes.h)
76 unsigned MaxClipPlanes
;
77 unsigned MaxTextureUnits
;
78 unsigned MaxTextureCoords
;
79 unsigned MaxVertexAttribs
;
80 unsigned MaxVertexUniformComponents
;
81 unsigned MaxVaryingFloats
;
82 unsigned MaxVertexTextureImageUnits
;
83 unsigned MaxCombinedTextureImageUnits
;
84 unsigned MaxTextureImageUnits
;
85 unsigned MaxFragmentUniformComponents
;
87 /* ARB_draw_buffers */
88 unsigned MaxDrawBuffers
;
92 * During AST to IR conversion, pointer to current IR function
94 * Will be \c NULL whenever the AST to IR conversion is not inside a
95 * function definition.
97 class ir_function_signature
*current_function
;
99 /** Have we found a return statement in this function? */
102 /** Was there an error during compilation? */
105 /** Loop or switch statement containing the current instructions. */
106 class ir_instruction
*loop_or_switch_nesting
;
108 /** List of structures defined in user code. */
109 const glsl_type
**user_structures
;
110 unsigned num_user_structures
;
115 * \name Enable bits for GLSL extensions
118 unsigned ARB_draw_buffers_enable
:1;
119 unsigned ARB_draw_buffers_warn
:1;
120 unsigned ARB_texture_rectangle_enable
:1;
121 unsigned ARB_texture_rectangle_warn
:1;
122 unsigned EXT_texture_array_enable
:1;
123 unsigned EXT_texture_array_warn
:1;
126 /** Extensions supported by the OpenGL implementation. */
127 const struct gl_extensions
*extensions
;
129 /** Shaders containing built-in functions that are used for linking. */
130 struct gl_shader
*builtins_to_link
[16];
131 unsigned num_builtins_to_link
;
134 typedef struct YYLTYPE
{
141 # define YYLTYPE_IS_DECLARED 1
142 # define YYLTYPE_IS_TRIVIAL 1
144 # define YYLLOC_DEFAULT(Current, Rhs, N) \
148 (Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
149 (Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
150 (Current).last_line = YYRHSLOC(Rhs, N).last_line; \
151 (Current).last_column = YYRHSLOC(Rhs, N).last_column; \
155 (Current).first_line = (Current).last_line = \
156 YYRHSLOC(Rhs, 0).last_line; \
157 (Current).first_column = (Current).last_column = \
158 YYRHSLOC(Rhs, 0).last_column; \
160 (Current).source = 0; \
163 extern void _mesa_glsl_error(YYLTYPE
*locp
, _mesa_glsl_parse_state
*state
,
164 const char *fmt
, ...);
167 * Emit a warning to the shader log
169 * \sa _mesa_glsl_error
171 extern void _mesa_glsl_warning(const YYLTYPE
*locp
,
172 _mesa_glsl_parse_state
*state
,
173 const char *fmt
, ...);
176 extern int preprocess(void *ctx
, const char **shader
, char **info_log
,
177 const struct gl_extensions
*extensions
);
180 extern void _mesa_glsl_lexer_ctor(struct _mesa_glsl_parse_state
*state
,
183 extern void _mesa_glsl_lexer_dtor(struct _mesa_glsl_parse_state
*state
);
186 extern int _mesa_glsl_lex(union YYSTYPE
*yylval
, YYLTYPE
*yylloc
,
189 extern int _mesa_glsl_parse(struct _mesa_glsl_parse_state
*);
192 * Process elements of the #extension directive
195 * If \c name and \c behavior are valid, \c true is returned. Otherwise
196 * \c false is returned.
198 extern bool _mesa_glsl_process_extension(const char *name
, YYLTYPE
*name_locp
,
199 const char *behavior
,
200 YYLTYPE
*behavior_locp
,
201 _mesa_glsl_parse_state
*state
);
204 * Get the textual name of the specified shader target
207 _mesa_glsl_shader_target_name(enum _mesa_glsl_parser_targets target
);
209 void do_ir_to_mesa(exec_list
*instructions
);
211 #endif /* GLSL_PARSER_EXTRAS_H */