3d5eec210476c83cd97cfda3c2808e7341ec672a
[mesa.git] / src / mesa / shader / slang / slang_assemble.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 #if !defined SLANG_ASSEMBLE_H
26 #define SLANG_ASSEMBLE_H
27
28 #include "slang_compile.h"
29
30 #if defined __cplusplus
31 extern "C" {
32 #endif
33
34 typedef enum slang_assembly_type_
35 {
36 /* core */
37 slang_asm_none,
38 slang_asm_float_copy,
39 slang_asm_float_move,
40 slang_asm_float_push,
41 slang_asm_float_deref,
42 slang_asm_float_add,
43 slang_asm_float_multiply,
44 slang_asm_float_divide,
45 slang_asm_float_negate,
46 slang_asm_float_less,
47 slang_asm_float_equal_exp,
48 slang_asm_float_equal_int,
49 slang_asm_float_to_int,
50 slang_asm_float_sine,
51 slang_asm_float_arcsine,
52 slang_asm_float_arctan,
53 slang_asm_float_power,
54 slang_asm_float_log2,
55 slang_asm_float_floor,
56 slang_asm_float_ceil,
57 slang_asm_int_copy,
58 slang_asm_int_move,
59 slang_asm_int_push,
60 slang_asm_int_deref,
61 slang_asm_int_to_float,
62 slang_asm_int_to_addr,
63 slang_asm_bool_copy,
64 slang_asm_bool_move,
65 slang_asm_bool_push,
66 slang_asm_bool_deref,
67 slang_asm_addr_copy,
68 slang_asm_addr_push,
69 slang_asm_addr_deref,
70 slang_asm_addr_add,
71 slang_asm_addr_multiply,
72 slang_asm_jump,
73 slang_asm_jump_if_zero,
74 slang_asm_enter,
75 slang_asm_leave,
76 slang_asm_local_alloc,
77 slang_asm_local_free,
78 slang_asm_local_addr,
79 slang_asm_call,
80 slang_asm_return,
81 slang_asm_discard,
82 slang_asm_exit,
83 /* mesa-specific extensions */
84 slang_asm_float_print,
85 slang_asm_int_print,
86 slang_asm_bool_print,
87 slang_asm__last
88 } slang_assembly_type;
89
90 typedef struct slang_assembly_
91 {
92 slang_assembly_type type;
93 GLfloat literal;
94 GLuint param[2];
95 } slang_assembly;
96
97 typedef struct slang_assembly_file_
98 {
99 slang_assembly *code;
100 unsigned int count;
101 unsigned int capacity;
102 } slang_assembly_file;
103
104 int slang_assembly_file_construct (slang_assembly_file *);
105 void slang_assembly_file_destruct (slang_assembly_file *);
106 int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
107 int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
108 int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
109 int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
110
111 typedef struct slang_assembly_file_restore_point_
112 {
113 unsigned int count;
114 } slang_assembly_file_restore_point;
115
116 int slang_assembly_file_restore_point_save (slang_assembly_file *,
117 slang_assembly_file_restore_point *);
118 int slang_assembly_file_restore_point_load (slang_assembly_file *,
119 slang_assembly_file_restore_point *);
120
121 typedef struct slang_assembly_flow_control_
122 {
123 unsigned int loop_start; /* for "continue" statement */
124 unsigned int loop_end; /* for "break" statement */
125 unsigned int function_end; /* for "return" statement */
126 } slang_assembly_flow_control;
127
128 typedef struct slang_assembly_local_info_
129 {
130 unsigned int ret_size;
131 unsigned int addr_tmp;
132 unsigned int swizzle_tmp;
133 } slang_assembly_local_info;
134
135 typedef enum
136 {
137 slang_ref_force,
138 slang_ref_forbid,
139 slang_ref_freelance
140 } slang_ref_type;
141
142 /*
143 holds a complete information about vector swizzle - the <swizzle> array contains
144 vector component sources indices, where 0 is "x", 1 is "y", ...
145 example: "xwz" --> { 3, { 0, 3, 2, n/u } }
146 */
147 typedef struct slang_swizzle_
148 {
149 unsigned int num_components;
150 unsigned int swizzle[4];
151 } slang_swizzle;
152
153 typedef struct slang_assembly_stack_info_
154 {
155 slang_swizzle swizzle;
156 } slang_assembly_stack_info;
157
158 typedef struct slang_assembly_name_space_
159 {
160 struct slang_function_scope_ *funcs;
161 struct slang_struct_scope_ *structs;
162 struct slang_variable_scope_ *vars;
163 } slang_assembly_name_space;
164
165 typedef struct slang_assemble_ctx_
166 {
167 slang_assembly_file *file;
168 struct slang_machine_ *mach;
169 slang_atom_pool *atoms;
170 slang_assembly_name_space space;
171 slang_assembly_flow_control flow;
172 slang_assembly_local_info local;
173 slang_ref_type ref;
174 slang_assembly_stack_info swz;
175 } slang_assemble_ctx;
176
177 slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,
178 slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,
179 slang_atom_pool *);
180
181 int _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
182
183 int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,
184 slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);
185 int _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);
186
187 int _slang_dereference (slang_assembly_file *, slang_operation *, slang_assembly_name_space *,
188 slang_assembly_local_info *, struct slang_machine_ *, slang_atom_pool *);
189
190 int _slang_assemble_function_call (slang_assemble_ctx *, slang_function *,
191 slang_operation *, GLuint, GLboolean);
192
193 int _slang_assemble_function_call_name (slang_assemble_ctx *, const char *,
194 slang_operation *, GLuint, GLboolean);
195
196 int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,
197 slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
198 slang_assembly_stack_info *, struct slang_machine_ *, slang_atom_pool *);
199 int _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif
206