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 #ifndef SLANG_COMPILE_OPERATION_H
26 #define SLANG_COMPILE_OPERATION_H
28 #if defined __cplusplus
34 * Types of slang operations.
35 * These are the types of the AST (abstract syntax tree) nodes.
36 * [foo] indicates a sub-tree or reference to another type of node
38 typedef enum slang_operation_type_
41 slang_oper_block_no_new_scope
, /* "{" sequence "}" */
42 slang_oper_block_new_scope
, /* "{" sequence "}" */
43 slang_oper_variable_decl
, /* [type] [var] or [var] = [expr] */
45 slang_oper_break
, /* "break" statement */
46 slang_oper_continue
, /* "continue" statement */
47 slang_oper_discard
, /* "discard" (kill fragment) statement */
48 slang_oper_return
, /* "return" [expr] */
49 slang_oper_goto
, /* jump to label */
50 slang_oper_label
, /* a jump target */
51 slang_oper_expression
, /* [expr] */
52 slang_oper_if
, /* "if" [0] then [1] else [2] */
53 slang_oper_while
, /* "while" [cond] [body] */
54 slang_oper_do
, /* "do" [body] "while" [cond] */
55 slang_oper_for
, /* "for" [init] [while] [incr] [body] */
56 slang_oper_void
, /* nop */
57 slang_oper_literal_bool
, /* "true" or "false" */
58 slang_oper_literal_int
, /* integer literal */
59 slang_oper_literal_float
, /* float literal */
60 slang_oper_identifier
, /* var name, func name, etc */
61 slang_oper_sequence
, /* [expr] "," [expr] "," etc */
62 slang_oper_assign
, /* [var] "=" [expr] */
63 slang_oper_addassign
, /* [var] "+=" [expr] */
64 slang_oper_subassign
, /* [var] "-=" [expr] */
65 slang_oper_mulassign
, /* [var] "*=" [expr] */
66 slang_oper_divassign
, /* [var] "/=" [expr] */
67 /*slang_oper_modassign, */
68 /*slang_oper_lshassign, */
69 /*slang_oper_rshassign, */
70 /*slang_oper_orassign, */
71 /*slang_oper_xorassign, */
72 /*slang_oper_andassign, */
73 slang_oper_select
, /* [expr] "?" [expr] ":" [expr] */
74 slang_oper_logicalor
, /* [expr] "||" [expr] */
75 slang_oper_logicalxor
, /* [expr] "^^" [expr] */
76 slang_oper_logicaland
, /* [expr] "&&" [expr] */
77 /*slang_oper_bitor, */
78 /*slang_oper_bitxor, */
79 /*slang_oper_bitand, */
80 slang_oper_equal
, /* [expr] "==" [expr] */
81 slang_oper_notequal
, /* [expr] "!=" [expr] */
82 slang_oper_less
, /* [expr] "<" [expr] */
83 slang_oper_greater
, /* [expr] ">" [expr] */
84 slang_oper_lessequal
, /* [expr] "<=" [expr] */
85 slang_oper_greaterequal
, /* [expr] ">=" [expr] */
86 /*slang_oper_lshift, */
87 /*slang_oper_rshift, */
88 slang_oper_add
, /* [expr] "+" [expr] */
89 slang_oper_subtract
, /* [expr] "-" [expr] */
90 slang_oper_multiply
, /* [expr] "*" [expr] */
91 slang_oper_divide
, /* [expr] "/" [expr] */
92 /*slang_oper_modulus, */
93 slang_oper_preincrement
, /* "++" [var] */
94 slang_oper_predecrement
, /* "--" [var] */
95 slang_oper_plus
, /* "-" [expr] */
96 slang_oper_minus
, /* "+" [expr] */
97 /*slang_oper_complement, */
98 slang_oper_not
, /* "!" [expr] */
99 slang_oper_subscript
, /* [expr] "[" [expr] "]" */
100 slang_oper_call
, /* [func name] [param] [param] [...] */
101 slang_oper_field
, /* i.e.: ".next" or ".xzy" or ".xxx" etc */
102 slang_oper_postincrement
, /* [var] "++" */
103 slang_oper_postdecrement
/* [var] "--" */
104 } slang_operation_type
;
108 * A slang_operation is basically a compiled instruction (such as assignment,
109 * a while-loop, a conditional, a multiply, a function call, etc).
110 * The AST (abstract syntax tree) is built from these nodes.
111 * NOTE: This structure could have been implemented as a union of simpler
112 * structs which would correspond to the operation types above.
114 typedef struct slang_operation_
116 slang_operation_type type
;
117 struct slang_operation_
*children
;
119 GLfloat literal
[4]; /**< Used for float, int and bool values */
120 slang_atom a_id
; /**< type: asm, identifier, call, field */
121 slang_variable_scope
*locals
; /**< local vars for scope */
122 struct slang_function_
*fun
; /**< If type == slang_oper_call */
123 struct slang_variable_
*var
; /**< If type == slang_oper_identier */
128 slang_operation_construct(slang_operation
*);
131 slang_operation_destruct(slang_operation
*);
134 slang_operation_copy(slang_operation
*, const slang_operation
*);
136 extern slang_operation
*
137 slang_operation_new(GLuint count
);
140 slang_operation_delete(slang_operation
*oper
);
142 extern slang_operation
*
143 slang_operation_grow(GLuint
*numChildren
, slang_operation
**children
);
145 extern slang_operation
*
146 slang_operation_insert(GLuint
*numChildren
, slang_operation
**children
,
154 #endif /* SLANG_COMPILE_OPERATION_H */