1 /*	$Id: node.h,v 1.36 2010/08/11 14:08:44 ragge Exp $	*/
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef NODE_H
30 #define NODE_H
31 
32 /*
33  * The attribute struct contains stuff that might be useful in
34  * both passes; but currently it's only legal to use it in pass1.
35  */
36 union aarg {
37 	int iarg;
38 	char *sarg;
39 	void *varg;
40 };
41 
42 struct attr {
43 	struct attr *next;
44 	int atype;
45 	union aarg aa[];
46 };
47 
48 /*
49  * The node structure is the basic element in the compiler.
50  * Depending on the operator, it may be one of several types.
51  *
52  * This is rewritten to be a struct instead of a union as it
53  * was in the old compiler.
54  */
55 typedef unsigned int TWORD;
56 #define NIL (NODE *)0
57 
58 struct symtab;
59 struct suedef;
60 struct regw;
61 
62 typedef struct node {
63 	struct	node *next;
64 	int	n_op;
65 	union {
66 		int _reg;
67 		struct regw *_regw;
68 	} n_3;
69 #define	n_reg	n_3._reg
70 #define	n_regw	n_3._regw
71 	TWORD	n_type;
72 	TWORD	n_qual;
73 	int	n_su;
74 	union {
75 		char *	_name;
76 		int	_stsize;
77 		union	dimfun *_df;
78 	} n_5;
79 	union {
80 		int	_label;
81 		int	_stalign;
82 		int	_flags;
83 #if 0
84 		/* not anymore */
85 		struct	suedef *_sue;
86 #else
87 		struct attr *_ap;
88 #endif
89 	} n_6;
90 	union {
91 		struct {
92 			union {
93 				struct node *_left;
94 				CONSZ _lval;
95 #ifdef SPECIAL_INTEGERS
96 				SPECLVAL _slval;
97 #endif
98 			} n_l;
99 			union {
100 				struct node *_right;
101 				int _rval;
102 				struct symtab *_sp;
103 			} n_r;
104 		} n_u;
105 #ifdef SOFTFLOAT
106 #ifdef FDFLOAT
107 		/* To store F- or D-floats */
108 		struct softfloat {
109 			unsigned short fd1, fd2, fd3, fd4;
110 		} _dcon;
111 #else
112 #error missing softfloat structure definition
113 #endif
114 #else
115 		long double	_dcon;
116 #endif
117 	} n_f;
118 } NODE;
119 
120 #define	n_name	n_5._name
121 #define	n_stsize n_5._stsize
122 #define	n_df	n_5._df
123 
124 #define	n_label	n_6._label
125 #define	n_stalign n_6._stalign
126 #define	n_flags n_6._flags
127 #define	n_ap	n_6._ap
128 
129 #define	n_left	n_f.n_u.n_l._left
130 #define	n_lval	n_f.n_u.n_l._lval
131 #define	n_slval	n_f.n_u.n_l._slval
132 #define	n_right	n_f.n_u.n_r._right
133 #define	n_rval	n_f.n_u.n_r._rval
134 #define	n_sp	n_f.n_u.n_r._sp
135 #define	n_dcon	n_f._dcon
136 
137 #define	NLOCAL1	010000
138 #define	NLOCAL2	020000
139 #define	NLOCAL3	040000
140 /*
141  * Node types.
142  *
143  * MAXOP is the highest number used by the backend.
144  */
145 
146 #define FREE	1
147 /*
148  * Value nodes.
149  */
150 #define NAME	2
151 #define ICON	4
152 #define FCON	5
153 #define REG	6
154 #define OREG	7
155 #define TEMP	8
156 #define XARG	9
157 
158 /*
159  * Arithmetic nodes.
160  */
161 #define PLUS	10
162 #define MINUS	11
163 #define DIV	12
164 #define MOD	13
165 #define MUL	14
166 
167 /*
168  * Bitwise operations.
169  */
170 #define AND	15
171 #define OR	16
172 #define ER	17
173 #define LS	18
174 #define RS	19
175 #define COMPL	20
176 
177 #define UMUL	23
178 #define UMINUS	24
179 
180 /*
181  * Logical compare nodes.
182  */
183 #define EQ	25
184 #define NE	26
185 #define LE	27
186 #define LT	28
187 #define GE	29
188 #define GT	30
189 #define ULE	31
190 #define ULT	32
191 #define UGE	33
192 #define UGT	34
193 
194 /*
195  * Branch nodes.
196  */
197 #define CBRANCH	35
198 
199 /*
200  * Convert types.
201  */
202 #define FLD	36
203 #define SCONV	37
204 #define PCONV	38
205 #define PMCONV	39
206 #define PVCONV	40
207 
208 /*
209  * Function calls.
210  */
211 #define CALL	41
212 #define	UCALL	42
213 #define FORTCALL 43
214 #define UFORTCALL 44
215 #define STCALL	45
216 #define USTCALL	46
217 
218 /*
219  *  Other used nodes.
220  */
221 #define CCODES	47
222 #define CM	48
223 #define ASSIGN	49
224 #define STASG	50
225 #define STARG	51
226 #define FORCE	52
227 #define XASM	53
228 #define	GOTO	54
229 #define	RETURN	55
230 #define STREF	56
231 #define	FUNARG	57
232 #define	ADDROF	58
233 
234 #define	MAXOP	58
235 
236 #endif
237