2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 #if !defined SLANG_ASSEMBLE_H
26 #define SLANG_ASSEMBLE_H
28 #include "slang_compile.h"
30 #if defined __cplusplus
34 typedef enum slang_assembly_type_
41 slang_asm_float_deref
,
43 slang_asm_float_multiply
,
44 slang_asm_float_divide
,
45 slang_asm_float_negate
,
47 slang_asm_float_equal_exp
,
48 slang_asm_float_equal_int
,
49 slang_asm_float_to_int
,
51 slang_asm_float_arcsine
,
52 slang_asm_float_arctan
,
53 slang_asm_float_power
,
55 slang_asm_float_floor
,
61 slang_asm_int_to_float
,
62 slang_asm_int_to_addr
,
71 slang_asm_addr_multiply
,
73 slang_asm_jump_if_zero
,
76 slang_asm_local_alloc
,
83 /* mesa-specific extensions */
84 slang_asm_float_print
,
88 } slang_assembly_type
;
90 typedef struct slang_assembly_
92 slang_assembly_type type
;
97 typedef struct slang_assembly_file_
101 unsigned int capacity
;
102 } slang_assembly_file
;
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
);
111 typedef struct slang_assembly_file_restore_point_
114 } slang_assembly_file_restore_point
;
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
*);
121 typedef struct slang_assembly_flow_control_
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
;
128 typedef struct slang_assembly_local_info_
130 unsigned int ret_size
;
131 unsigned int addr_tmp
;
132 unsigned int swizzle_tmp
;
133 } slang_assembly_local_info
;
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 } }
147 typedef struct slang_swizzle_
149 unsigned int num_components
;
150 unsigned int swizzle
[4];
153 typedef struct slang_assembly_stack_info_
155 slang_swizzle swizzle
;
156 } slang_assembly_stack_info
;
158 typedef struct slang_assembly_name_space_
160 struct slang_function_scope_
*funcs
;
161 struct slang_struct_scope_
*structs
;
162 struct slang_variable_scope_
*vars
;
163 } slang_assembly_name_space
;
165 typedef struct slang_assemble_ctx_
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
;
174 slang_assembly_stack_info swz
;
175 } slang_assemble_ctx
;
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
,
181 int _slang_assemble_function (slang_assemble_ctx
*, struct slang_function_
*);
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
*);
187 int _slang_dereference (slang_assembly_file
*, slang_operation
*, slang_assembly_name_space
*,
188 slang_assembly_local_info
*, struct slang_machine_
*, slang_atom_pool
*);
190 int _slang_assemble_function_call (slang_assemble_ctx
*, slang_function
*,
191 slang_operation
*, GLuint
, GLboolean
);
193 int _slang_assemble_function_call_name (slang_assemble_ctx
*, const char *,
194 slang_operation
*, GLuint
, GLboolean
);
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
);