simple front-end compiler
[mesa.git] / src / mesa / shader / slang / slang_compile.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 2005 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 #if !defined SLANG_COMPILE_H
26 #define SLANG_COMPILE_H
27
28 #if defined __cplusplus
29 extern "C" {
30 #endif
31
32 typedef enum slang_type_qualifier_
33 {
34 slang_qual_none,
35 slang_qual_const,
36 slang_qual_attribute,
37 slang_qual_varying,
38 slang_qual_uniform,
39 slang_qual_out,
40 slang_qual_inout,
41 slang_qual_fixedoutput, /* internal */
42 slang_qual_fixedinput /* internal */
43 } slang_type_qualifier;
44
45 typedef enum slang_type_specifier_type_
46 {
47 slang_spec_void,
48 slang_spec_bool,
49 slang_spec_bvec2,
50 slang_spec_bvec3,
51 slang_spec_bvec4,
52 slang_spec_int,
53 slang_spec_ivec2,
54 slang_spec_ivec3,
55 slang_spec_ivec4,
56 slang_spec_float,
57 slang_spec_vec2,
58 slang_spec_vec3,
59 slang_spec_vec4,
60 slang_spec_mat2,
61 slang_spec_mat3,
62 slang_spec_mat4,
63 slang_spec_sampler1D,
64 slang_spec_sampler2D,
65 slang_spec_sampler3D,
66 slang_spec_samplerCube,
67 slang_spec_sampler1DShadow,
68 slang_spec_sampler2DShadow,
69 slang_spec_struct,
70 slang_spec_array
71 } slang_type_specifier_type;
72
73 typedef struct slang_type_specifier_
74 {
75 slang_type_specifier_type type;
76 struct slang_struct_ *_struct; /* spec_struct */
77 struct slang_type_specifier_ *_array; /* spec_array */
78 } slang_type_specifier;
79
80 typedef struct slang_fully_specified_type_
81 {
82 slang_type_qualifier qualifier;
83 slang_type_specifier specifier;
84 } slang_fully_specified_type;
85
86 typedef struct slang_variable_scope_
87 {
88 struct slang_variable_ *variables;
89 unsigned int num_variables;
90 struct slang_variable_scope_ *outer_scope;
91 } slang_variable_scope;
92
93 typedef enum slang_operation_type_
94 {
95 slang_oper_none,
96 slang_oper_block_no_new_scope,
97 slang_oper_block_new_scope,
98 slang_oper_variable_decl,
99 slang_oper_asm,
100 slang_oper_break,
101 slang_oper_continue,
102 slang_oper_discard,
103 slang_oper_return,
104 slang_oper_expression,
105 slang_oper_if,
106 slang_oper_while,
107 slang_oper_do,
108 slang_oper_for,
109 slang_oper_void,
110 slang_oper_literal_bool,
111 slang_oper_literal_int,
112 slang_oper_literal_float,
113 slang_oper_identifier,
114 slang_oper_sequence,
115 slang_oper_assign,
116 slang_oper_addassign,
117 slang_oper_subassign,
118 slang_oper_mulassign,
119 slang_oper_divassign,
120 /*slang_oper_modassign,*/
121 /*slang_oper_lshassign,*/
122 /*slang_oper_rshassign,*/
123 /*slang_oper_orassign,*/
124 /*slang_oper_xorassign,*/
125 /*slang_oper_andassign,*/
126 slang_oper_select,
127 slang_oper_logicalor,
128 slang_oper_logicalxor,
129 slang_oper_logicaland,
130 /*slang_oper_bitor,*/
131 /*slang_oper_bitxor,*/
132 /*slang_oper_bitand,*/
133 slang_oper_equal,
134 slang_oper_notequal,
135 slang_oper_less,
136 slang_oper_greater,
137 slang_oper_lessequal,
138 slang_oper_greaterequal,
139 /*slang_oper_lshift,*/
140 /*slang_oper_rshift,*/
141 slang_oper_add,
142 slang_oper_subtract,
143 slang_oper_multiply,
144 slang_oper_divide,
145 /*slang_oper_modulus,*/
146 slang_oper_preincrement,
147 slang_oper_predecrement,
148 slang_oper_plus,
149 slang_oper_minus,
150 /*slang_oper_complement,*/
151 slang_oper_not,
152 slang_oper_subscript,
153 slang_oper_call,
154 slang_oper_field,
155 slang_oper_postincrement,
156 slang_oper_postdecrement
157 } slang_operation_type;
158
159 typedef struct slang_operation_
160 {
161 slang_operation_type type;
162 struct slang_operation_ *children;
163 unsigned int num_children;
164 float literal; /* bool, literal_int, literal_float */
165 char *identifier; /* asm, identifier, call, field */
166 slang_variable_scope *locals;
167 } slang_operation;
168
169 typedef struct slang_variable_
170 {
171 slang_fully_specified_type type;
172 char *name;
173 slang_operation *array_size; /* spec_array */
174 slang_operation *initializer;
175 } slang_variable;
176
177 typedef struct slang_struct_scope_
178 {
179 struct slang_struct_ *structs;
180 unsigned int num_structs;
181 struct slang_struct_scope_ *outer_scope;
182 } slang_struct_scope;
183
184 typedef struct slang_struct_
185 {
186 char *name;
187 slang_variable_scope *fields;
188 slang_struct_scope *structs;
189 } slang_struct;
190
191 typedef enum slang_function_kind_
192 {
193 slang_func_ordinary,
194 slang_func_constructor,
195 slang_func_operator
196 } slang_function_kind;
197
198 typedef struct slang_function_
199 {
200 slang_function_kind kind;
201 slang_variable header;
202 slang_variable_scope *parameters;
203 unsigned int param_count;
204 slang_operation *body;
205 } slang_function;
206
207 typedef struct slang_function_scope_
208 {
209 slang_function *functions;
210 unsigned int num_functions;
211 struct slang_function_scope_ *outer_scope;
212 } slang_function_scope;
213
214 typedef enum slang_unit_type_
215 {
216 slang_unit_fragment_shader,
217 slang_unit_vertex_shader
218 } slang_unit_type;
219
220 typedef struct slang_translation_unit_
221 {
222 slang_variable_scope *globals;
223 slang_function_scope functions;
224 slang_struct_scope *structs;
225 slang_unit_type type;
226 } slang_translation_unit;
227
228 int _slang_compile (const char *, slang_translation_unit *, slang_unit_type type);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif
235