s/SLANG_ASSEMBLE_TYPEINFO_H/SLANG_TYPEINFO_H/
[mesa.git] / src / mesa / shader / slang / slang_typeinfo.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef SLANG_TYPEINFO_H
26 #define SLANG_TYPEINFO_H 1
27
28 #include "imports.h"
29 #include "mtypes.h"
30 #include "slang_utility.h"
31 #include "slang_vartable.h"
32
33
34 struct slang_operation_;
35
36
37 /**
38 * Holds complete information about vector swizzle - the <swizzle>
39 * array contains vector component source indices, where 0 is "x", 1
40 * is "y", 2 is "z" and 3 is "w".
41 * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
42 */
43 typedef struct slang_swizzle_
44 {
45 GLuint num_components;
46 GLuint swizzle[4];
47 } slang_swizzle;
48
49 typedef struct slang_name_space_
50 {
51 struct slang_function_scope_ *funcs;
52 struct slang_struct_scope_ *structs;
53 struct slang_variable_scope_ *vars;
54 } slang_name_space;
55
56
57 typedef struct slang_assemble_ctx_
58 {
59 slang_atom_pool *atoms;
60 slang_name_space space;
61 slang_swizzle swz;
62 struct gl_program *program;
63 slang_var_table *vartable;
64
65 struct slang_function_ *CurFunction;
66 slang_atom CurLoopBreak;
67 slang_atom CurLoopCont;
68 } slang_assemble_ctx;
69
70 extern struct slang_function_ *
71 _slang_locate_function(const struct slang_function_scope_ *funcs,
72 slang_atom name, const struct slang_operation_ *params,
73 GLuint num_params,
74 const slang_name_space *space,
75 slang_atom_pool *);
76
77
78 extern GLboolean
79 _slang_is_swizzle(const char *field, GLuint rows, slang_swizzle *swz);
80
81 extern GLboolean
82 _slang_is_swizzle_mask(const slang_swizzle *swz, GLuint rows);
83
84 extern GLvoid
85 _slang_multiply_swizzles(slang_swizzle *, const slang_swizzle *,
86 const slang_swizzle *);
87
88
89 /**
90 * The basic shading language types (float, vec4, mat3, etc)
91 */
92 typedef enum slang_type_specifier_type_
93 {
94 slang_spec_void,
95 slang_spec_bool,
96 slang_spec_bvec2,
97 slang_spec_bvec3,
98 slang_spec_bvec4,
99 slang_spec_int,
100 slang_spec_ivec2,
101 slang_spec_ivec3,
102 slang_spec_ivec4,
103 slang_spec_float,
104 slang_spec_vec2,
105 slang_spec_vec3,
106 slang_spec_vec4,
107 slang_spec_mat2,
108 slang_spec_mat3,
109 slang_spec_mat4,
110 slang_spec_sampler1D,
111 slang_spec_sampler2D,
112 slang_spec_sampler3D,
113 slang_spec_samplerCube,
114 slang_spec_sampler1DShadow,
115 slang_spec_sampler2DShadow,
116 slang_spec_struct,
117 slang_spec_array
118 } slang_type_specifier_type;
119
120
121 /**
122 * Describes more sophisticated types, like structs and arrays.
123 */
124 typedef struct slang_type_specifier_
125 {
126 slang_type_specifier_type type;
127 struct slang_struct_ *_struct; /**< used if type == spec_struct */
128 struct slang_type_specifier_ *_array; /**< used if type == spec_array */
129 } slang_type_specifier;
130
131
132 extern GLvoid
133 slang_type_specifier_ctr(slang_type_specifier *);
134
135 extern GLvoid
136 slang_type_specifier_dtr(slang_type_specifier *);
137
138 extern GLboolean
139 slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
140
141 extern GLboolean
142 slang_type_specifier_equal(const slang_type_specifier *,
143 const slang_type_specifier *);
144
145
146 typedef struct slang_typeinfo_
147 {
148 GLboolean can_be_referenced;
149 GLboolean is_swizzled;
150 slang_swizzle swz;
151 slang_type_specifier spec;
152 GLuint array_len;
153 } slang_typeinfo;
154
155 extern GLboolean
156 slang_typeinfo_construct(slang_typeinfo *);
157
158 extern GLvoid
159 slang_typeinfo_destruct(slang_typeinfo *);
160
161
162 /**
163 * Retrieves type information about an operation.
164 * Returns GL_TRUE on success.
165 * Returns GL_FALSE otherwise.
166 */
167 extern GLboolean
168 _slang_typeof_operation(const slang_assemble_ctx *,
169 const struct slang_operation_ *,
170 slang_typeinfo *);
171
172 extern GLboolean
173 _slang_typeof_operation_(const struct slang_operation_ *,
174 const slang_name_space *,
175 slang_typeinfo *, slang_atom_pool *);
176
177 /**
178 * Retrieves type of a function prototype, if one exists.
179 * Returns GL_TRUE on success, even if the function was not found.
180 * Returns GL_FALSE otherwise.
181 */
182 extern GLboolean
183 _slang_typeof_function(slang_atom a_name,
184 const struct slang_operation_ *params,
185 GLuint num_params, const slang_name_space *,
186 slang_type_specifier *spec, GLboolean *exists,
187 slang_atom_pool *);
188
189 extern GLboolean
190 _slang_type_is_matrix(slang_type_specifier_type);
191
192 extern GLboolean
193 _slang_type_is_vector(slang_type_specifier_type);
194
195 extern slang_type_specifier_type
196 _slang_type_base(slang_type_specifier_type);
197
198 extern GLuint
199 _slang_type_dim(slang_type_specifier_type);
200
201
202 #endif