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 basic intermediate code representations.
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_expression
, /* [expr] */
50 slang_oper_if
, /* "if" [0] then [1] else [2] */
51 slang_oper_while
, /* "while" [cond] [body] */
52 slang_oper_do
, /* "do" [body] "while" [cond] */
53 slang_oper_for
, /* "for" [init] [while] [incr] [body] */
54 slang_oper_void
, /* nop */
55 slang_oper_literal_bool
, /* "true" or "false" */
56 slang_oper_literal_int
, /* integer literal */
57 slang_oper_literal_float
, /* float literal */
58 slang_oper_identifier
, /* var name, func name, etc */
59 slang_oper_sequence
, /* [expr] "," [expr] "," etc */
60 slang_oper_assign
, /* [var] "=" [expr] */
61 slang_oper_addassign
, /* [var] "+=" [expr] */
62 slang_oper_subassign
, /* [var] "-=" [expr] */
63 slang_oper_mulassign
, /* [var] "*=" [expr] */
64 slang_oper_divassign
, /* [var] "/=" [expr] */
65 /*slang_oper_modassign, */
66 /*slang_oper_lshassign, */
67 /*slang_oper_rshassign, */
68 /*slang_oper_orassign, */
69 /*slang_oper_xorassign, */
70 /*slang_oper_andassign, */
71 slang_oper_select
, /* [expr] "?" [expr] ":" [expr] */
72 slang_oper_logicalor
, /* [expr] "||" [expr] */
73 slang_oper_logicalxor
, /* [expr] "^^" [expr] */
74 slang_oper_logicaland
, /* [expr] "&&" [expr] */
75 /*slang_oper_bitor, */
76 /*slang_oper_bitxor, */
77 /*slang_oper_bitand, */
78 slang_oper_equal
, /* [expr] "==" [expr] */
79 slang_oper_notequal
, /* [expr] "!=" [expr] */
80 slang_oper_less
, /* [expr] "<" [expr] */
81 slang_oper_greater
, /* [expr] ">" [expr] */
82 slang_oper_lessequal
, /* [expr] "<=" [expr] */
83 slang_oper_greaterequal
, /* [expr] ">=" [expr] */
84 /*slang_oper_lshift, */
85 /*slang_oper_rshift, */
86 slang_oper_add
, /* [expr] "+" [expr] */
87 slang_oper_subtract
, /* [expr] "-" [expr] */
88 slang_oper_multiply
, /* [expr] "*" [expr] */
89 slang_oper_divide
, /* [expr] "/" [expr] */
90 /*slang_oper_modulus, */
91 slang_oper_preincrement
, /* "++" [var] */
92 slang_oper_predecrement
, /* "--" [var] */
93 slang_oper_plus
, /* "-" [expr] */
94 slang_oper_minus
, /* "+" [expr] */
95 /*slang_oper_complement, */
96 slang_oper_not
, /* "!" [expr] */
97 slang_oper_subscript
, /* [expr] "[" [expr] "]" */
98 slang_oper_call
, /* [func name] [param] [param] [...] */
99 slang_oper_field
, /* i.e.: ".next" or ".xzy" or ".xxx" etc */
100 slang_oper_postincrement
, /* [var] "++" */
101 slang_oper_postdecrement
/* [var] "--" */
102 } slang_operation_type
;
106 * A slang_operation is basically a compiled instruction (such as assignment,
107 * a while-loop, a conditional, a multiply, a function call, etc).
108 * NOTE: This structure could have been implemented as a union of simpler
109 * structs which would correspond to the operation types above.
111 typedef struct slang_operation_
113 slang_operation_type type
;
114 struct slang_operation_
*children
;
115 unsigned int num_children
;
116 float literal
; /**< Used for float, int and bool values */
117 slang_atom a_id
; /**< type: asm, identifier, call, field */
118 slang_variable_scope
*locals
; /**< local vars for scope */
122 extern int slang_operation_construct(slang_operation
*);
123 extern void slang_operation_destruct(slang_operation
*);
124 extern int slang_operation_copy(slang_operation
*, const slang_operation
*);
131 #endif /* SLANG_COMPILE_OPERATION_H */