summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang/slang_compile_operation.h
blob: 65e33dc4a2073240cbfd65d511fa065ab0b7fc54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Mesa 3-D graphics library
 * Version:  6.5.2
 *
 * Copyright (C) 2005-2006  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef SLANG_COMPILE_OPERATION_H
#define SLANG_COMPILE_OPERATION_H

#if defined __cplusplus
extern "C" {
#endif


/**
 * Types of slang operations.
 * These are the basic intermediate code representations.
 * [foo] indicates a sub-tree or reference to another type of node
 */
   typedef enum slang_operation_type_
{
   slang_oper_none,
   slang_oper_block_no_new_scope,       /* "{" sequence "}" */
   slang_oper_block_new_scope,  /* "{" sequence "}" */
   slang_oper_variable_decl,    /* [type] [var] or [var] = [expr] */
   slang_oper_asm,
   slang_oper_break,            /* "break" statement */
   slang_oper_continue,         /* "continue" statement */
   slang_oper_discard,          /* "discard" (kill fragment) statement */
   slang_oper_return,           /* "return" [expr]  */
   slang_oper_expression,       /* [expr] */
   slang_oper_if,               /* "if" [0] then [1] else [2] */
   slang_oper_while,            /* "while" [cond] [body] */
   slang_oper_do,               /* "do" [body] "while" [cond] */
   slang_oper_for,              /* "for" [init] [while] [incr] [body] */
   slang_oper_void,             /* nop */
   slang_oper_literal_bool,     /* "true" or "false" */
   slang_oper_literal_int,      /* integer literal */
   slang_oper_literal_float,    /* float literal */
   slang_oper_identifier,       /* var name, func name, etc */
   slang_oper_sequence,         /* [expr] "," [expr] "," etc */
   slang_oper_assign,           /* [var] "=" [expr] */
   slang_oper_addassign,        /* [var] "+=" [expr] */
   slang_oper_subassign,        /* [var] "-=" [expr] */
   slang_oper_mulassign,        /* [var] "*=" [expr] */
   slang_oper_divassign,        /* [var] "/=" [expr] */
   /*slang_oper_modassign, */
   /*slang_oper_lshassign, */
   /*slang_oper_rshassign, */
   /*slang_oper_orassign, */
   /*slang_oper_xorassign, */
   /*slang_oper_andassign, */
   slang_oper_select,           /* [expr] "?" [expr] ":" [expr] */
   slang_oper_logicalor,        /* [expr] "||" [expr] */
   slang_oper_logicalxor,       /* [expr] "^^" [expr] */
   slang_oper_logicaland,       /* [expr] "&&" [expr] */
   /*slang_oper_bitor, */
   /*slang_oper_bitxor, */
   /*slang_oper_bitand, */
   slang_oper_equal,            /* [expr] "==" [expr] */
   slang_oper_notequal,         /* [expr] "!=" [expr] */
   slang_oper_less,             /* [expr] "<" [expr] */
   slang_oper_greater,          /* [expr] ">" [expr] */
   slang_oper_lessequal,        /* [expr] "<=" [expr] */
   slang_oper_greaterequal,     /* [expr] ">=" [expr] */
   /*slang_oper_lshift, */
   /*slang_oper_rshift, */
   slang_oper_add,              /* [expr] "+" [expr] */
   slang_oper_subtract,         /* [expr] "-" [expr] */
   slang_oper_multiply,         /* [expr] "*" [expr] */
   slang_oper_divide,           /* [expr] "/" [expr] */
   /*slang_oper_modulus, */
   slang_oper_preincrement,     /* "++" [var] */
   slang_oper_predecrement,     /* "--" [var] */
   slang_oper_plus,             /* "-" [expr] */
   slang_oper_minus,            /* "+" [expr] */
   /*slang_oper_complement, */
   slang_oper_not,              /* "!" [expr] */
   slang_oper_subscript,        /* [expr] "[" [expr] "]" */
   slang_oper_call,             /* [func name] [param] [param] [...] */
   slang_oper_field,            /* i.e.: ".next" or ".xzy" or ".xxx" etc */
   slang_oper_postincrement,    /* [var] "++" */
   slang_oper_postdecrement     /* [var] "--" */
} slang_operation_type;


/**
 * A slang_operation is basically a compiled instruction (such as assignment,
 * a while-loop, a conditional, a multiply, a function call, etc).
 */
typedef struct slang_operation_
{
   slang_operation_type type;
   struct slang_operation_ *children;
   unsigned int num_children;
   float literal;            /**< Used for float, int and bool values */
   slang_atom a_id;          /**< type: asm, identifier, call, field */
   slang_variable_scope *locals;       /**< local vars for scope */
} slang_operation;


extern int slang_operation_construct(slang_operation *);
extern void slang_operation_destruct(slang_operation *);
extern int slang_operation_copy(slang_operation *, const slang_operation *);


#ifdef __cplusplus
}
#endif

#endif /* SLANG_COMPILE_OPERATION_H */