intermediate code generator (not finished);
[mesa.git] / src / mesa / shader / slang / slang_assemble.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_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,
48 slang_asm_float_to_int,
49 slang_asm_int_copy,
50 slang_asm_int_move,
51 slang_asm_int_push,
52 slang_asm_int_deref,
53 slang_asm_int_to_float,
54 slang_asm_int_to_addr,
55 slang_asm_bool_copy,
56 slang_asm_bool_move,
57 slang_asm_bool_push,
58 slang_asm_bool_deref,
59 slang_asm_addr_copy,
60 slang_asm_addr_push,
61 slang_asm_addr_deref,
62 slang_asm_addr_add,
63 slang_asm_addr_multiply,
64 slang_asm_jump,
65 slang_asm_jump_if_zero,
66 slang_asm_enter,
67 slang_asm_leave,
68 slang_asm_local_alloc,
69 slang_asm_local_free,
70 slang_asm_local_addr,
71 slang_asm_call,
72 slang_asm_return,
73 slang_asm_discard,
74 slang_asm_exit,
75 slang_asm__last
76 } slang_assembly_type;
77
78 typedef struct slang_assembly_
79 {
80 slang_assembly_type type;
81 GLfloat literal;
82 GLuint param[2];
83 } slang_assembly;
84
85 typedef struct slang_assembly_file_
86 {
87 slang_assembly *code;
88 unsigned int count;
89 } slang_assembly_file;
90
91 void slang_assembly_file_construct (slang_assembly_file *);
92 void slang_assembly_file_destruct (slang_assembly_file *);
93 int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
94 int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
95 int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
96 int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
97
98 typedef struct slang_assembly_flow_control_
99 {
100 unsigned int loop_start; /* for "continue" statement */
101 unsigned int loop_end; /* for "break" statement */
102 unsigned int function_end; /* for "return" statement */
103 } slang_assembly_flow_control;
104
105 typedef struct slang_assembly_name_space_
106 {
107 struct slang_function_scope_ *funcs;
108 struct slang_struct_scope_ *structs;
109 struct slang_variable_scope_ *vars;
110 } slang_assembly_name_space;
111
112 slang_function *_slang_locate_function (const char *name, slang_operation *params,
113 unsigned int num_params, slang_assembly_name_space *space);
114
115 int _slang_assemble_function (slang_assembly_file *, struct slang_function_ *,
116 slang_assembly_name_space *);
117
118 typedef struct slang_assembly_stack_info_
119 {
120 unsigned int swizzle_mask;
121 } slang_assembly_stack_info;
122
123 int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,
124 slang_assembly_name_space *);
125
126 typedef struct slang_assembly_local_info_
127 {
128 unsigned int ret_size;
129 unsigned int addr_tmp;
130 unsigned int swizzle_tmp;
131 } slang_assembly_local_info;
132
133 int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,
134 slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
135 slang_assembly_stack_info *);
136
137 void xxx_first (slang_assembly_file *);
138 void xxx_prolog (slang_assembly_file *);
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif
145