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