| 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 |
# include "pass2.h" |
| 31 |
|
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
int canaddr(NODE *); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
int |
| 40 |
notoff(TWORD t, int r, CONSZ off, char *cp) |
| 41 |
{ |
| 42 |
return(0); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
void |
| 50 |
offstar(NODE *p, int shape) |
| 51 |
{ |
| 52 |
NODE *r; |
| 53 |
|
| 54 |
if (x2debug) |
| 55 |
printf("offstar(%p)\n", p); |
| 56 |
|
| 57 |
if (isreg(p)) |
| 58 |
return; |
| 59 |
|
| 60 |
r = p->n_right; |
| 61 |
if( p->n_op == PLUS || p->n_op == MINUS ){ |
| 62 |
if( r->n_op == ICON ){ |
| 63 |
if (isreg(p->n_left) == 0) |
| 64 |
(void)geninsn(p->n_left, INAREG); |
| 65 |
|
| 66 |
return; |
| 67 |
} |
| 68 |
if (r->n_op == LS && r->n_right->n_op == ICON && |
| 69 |
getlval(r->n_right) == 2 && p->n_op == PLUS) { |
| 70 |
if (isreg(p->n_left) == 0) |
| 71 |
(void)geninsn(p->n_left, INAREG); |
| 72 |
if (isreg(r->n_left) == 0) |
| 73 |
(void)geninsn(r->n_left, INAREG); |
| 74 |
return; |
| 75 |
} |
| 76 |
} |
| 77 |
(void)geninsn(p, INAREG); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
void |
| 84 |
myormake(NODE *q) |
| 85 |
{ |
| 86 |
NODE *p, *r; |
| 87 |
|
| 88 |
if (x2debug) |
| 89 |
printf("myormake(%p)\n", q); |
| 90 |
|
| 91 |
p = q->n_left; |
| 92 |
if (p->n_op == PLUS && (r = p->n_right)->n_op == LS && |
| 93 |
r->n_right->n_op == ICON && getlval(r->n_right) == 2 && |
| 94 |
p->n_left->n_op == REG && r->n_left->n_op == REG) { |
| 95 |
q->n_op = OREG; |
| 96 |
setlval(q, 0); |
| 97 |
q->n_rval = R2PACK(p->n_left->n_rval, r->n_left->n_rval, 0); |
| 98 |
tfree(p); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
int |
| 106 |
shumul(NODE *p, int shape) |
| 107 |
{ |
| 108 |
|
| 109 |
if (x2debug) |
| 110 |
printf("shumul(%p)\n", p); |
| 111 |
|
| 112 |
|
| 113 |
if (shape & SOREG) |
| 114 |
return SROREG; |
| 115 |
return SRNOPE; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
int |
| 123 |
setbin(NODE *p) |
| 124 |
{ |
| 125 |
|
| 126 |
if (x2debug) |
| 127 |
printf("setbin(%p)\n", p); |
| 128 |
return 0; |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
int |
| 134 |
setasg(NODE *p, int cookie) |
| 135 |
{ |
| 136 |
if (x2debug) |
| 137 |
printf("setasg(%p)\n", p); |
| 138 |
return(0); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
int |
| 143 |
setuni(NODE *p, int cookie) |
| 144 |
{ |
| 145 |
return 0; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
struct rspecial * |
| 154 |
nspecial(struct optab *q) |
| 155 |
{ |
| 156 |
switch (q->op) { |
| 157 |
case OPLOG: |
| 158 |
{ |
| 159 |
static struct rspecial s[] = { { NEVER, AX }, { 0 } }; |
| 160 |
return s; |
| 161 |
} |
| 162 |
|
| 163 |
case STASG: |
| 164 |
{ |
| 165 |
static struct rspecial s[] = { |
| 166 |
{ NEVER, DI }, |
| 167 |
{ NRIGHT, SI }, { NOLEFT, SI }, |
| 168 |
{ NOLEFT, CX }, { NORIGHT, CX }, |
| 169 |
{ NEVER, CX }, { 0 } }; |
| 170 |
return s; |
| 171 |
} |
| 172 |
|
| 173 |
case STARG: |
| 174 |
{ |
| 175 |
static struct rspecial s[] = { |
| 176 |
{ NEVER, DI }, { NEVER, CX }, |
| 177 |
{ NLEFT, SI }, { 0 } }; |
| 178 |
return s; |
| 179 |
} |
| 180 |
|
| 181 |
case SCONV: |
| 182 |
|
| 183 |
if ((q->ltype & TCHAR) && |
| 184 |
q->rtype == (TINT|TUNSIGNED)) { |
| 185 |
static struct rspecial s[] = { |
| 186 |
{ NLEFT, AL }, { NRES, AX }, |
| 187 |
{ NEVER, AX }, { NEVER, AH}, {NEVER, AL }, |
| 188 |
{ 0 } }; |
| 189 |
return s; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
if ((q->ltype & TUCHAR) && |
| 194 |
q->rtype == (TINT|TUNSIGNED)) { |
| 195 |
static struct rspecial s[] = { |
| 196 |
{ NEVER, SI }, { NEVER, DI }, |
| 197 |
{ 0 } }; |
| 198 |
return s; |
| 199 |
} else if ((q->ltype & (TINT|TUNSIGNED)) && |
| 200 |
q->rtype == (TCHAR|TUCHAR)) { |
| 201 |
static struct rspecial s[] = { |
| 202 |
{ NOLEFT, SI }, { NOLEFT, DI }, { 0 } }; |
| 203 |
return s; |
| 204 |
|
| 205 |
} else if ((q->ltype & (TINT|TSHORT)) && |
| 206 |
q->rtype == (TLONG|TULONG)) { |
| 207 |
static struct rspecial s[] = { |
| 208 |
{ NLEFT, AX }, { NRES, AXDX }, |
| 209 |
{ NEVER, AX }, { NEVER, DX }, |
| 210 |
{ 0 } }; |
| 211 |
return s; |
| 212 |
|
| 213 |
} else if (q->ltype == TCHAR && |
| 214 |
q->rtype == (TLONG|TULONG)) { |
| 215 |
static struct rspecial s[] = { |
| 216 |
{ NRES, AXDX }, { NLEFT, AL }, |
| 217 |
{ NEVER, AX }, { NEVER, DX }, |
| 218 |
{ NEVER, AH }, { NEVER, AL }, |
| 219 |
{ 0 } }; |
| 220 |
return s; |
| 221 |
} |
| 222 |
break; |
| 223 |
case DIV: |
| 224 |
if (q->lshape == SBREG) { |
| 225 |
static struct rspecial s[] = { |
| 226 |
{ NEVER, AL }, { NEVER, AH }, |
| 227 |
{ NLEFT, AL }, { NRES, AL }, |
| 228 |
{ NORIGHT, AH }, { NORIGHT, AL }, { 0 } }; |
| 229 |
return s; |
| 230 |
} else if (q->lshape == SAREG) { |
| 231 |
static struct rspecial s[] = { |
| 232 |
{ NEVER, AX }, { NEVER, DX }, |
| 233 |
{ NLEFT, AX }, { NRES, AX }, |
| 234 |
{ NORIGHT, DX }, { NORIGHT, AX }, { 0 } }; |
| 235 |
return s; |
| 236 |
} |
| 237 |
|
| 238 |
else if (q->lshape & SCREG) { |
| 239 |
static struct rspecial s[] = { |
| 240 |
{ NEVER, AX }, { NEVER, DX }, |
| 241 |
{ NEVER, CX }, { NRES, AXDX }, { 0 } }; |
| 242 |
return s; |
| 243 |
} |
| 244 |
break; |
| 245 |
case MOD: |
| 246 |
if (q->lshape == SBREG) { |
| 247 |
static struct rspecial s[] = { |
| 248 |
{ NEVER, AL }, { NEVER, AH }, |
| 249 |
{ NLEFT, AL }, { NRES, AH }, |
| 250 |
{ NORIGHT, AH }, { NORIGHT, AL }, { 0 } }; |
| 251 |
return s; |
| 252 |
} else if (q->lshape == SAREG) { |
| 253 |
static struct rspecial s[] = { |
| 254 |
{ NEVER, AX }, { NEVER, DX }, |
| 255 |
{ NLEFT, AX }, { NRES, DX }, |
| 256 |
{ NORIGHT, DX }, { NORIGHT, AX }, { 0 } }; |
| 257 |
return s; |
| 258 |
} else if (q->lshape & SCREG) { |
| 259 |
static struct rspecial s[] = { |
| 260 |
{ NEVER, AX }, { NEVER, DX }, |
| 261 |
{ NEVER, CX }, { NRES, AXDX }, { 0 } }; |
| 262 |
return s; |
| 263 |
} |
| 264 |
break; |
| 265 |
case MUL: |
| 266 |
if (q->lshape == SAREG) { |
| 267 |
static struct rspecial s[] = { |
| 268 |
{ NEVER, AX }, { NEVER, DX }, |
| 269 |
{ NLEFT, AX }, { NRES, AX }, |
| 270 |
{ NORIGHT, DX }, {NORIGHT, AX }, |
| 271 |
{ 0 } }; |
| 272 |
return s; |
| 273 |
} |
| 274 |
if (q->lshape == SBREG) { |
| 275 |
static struct rspecial s[] = { |
| 276 |
{ NEVER, AL }, { NEVER, AH }, |
| 277 |
{ NLEFT, AL }, { NRES, AL }, { 0 } }; |
| 278 |
return s; |
| 279 |
} else if (q->lshape & SCREG) { |
| 280 |
static struct rspecial s[] = { |
| 281 |
{ NEVER, AX }, { NEVER, DX }, |
| 282 |
{ NEVER, CX }, { NRES, AXDX }, { 0 } }; |
| 283 |
return s; |
| 284 |
} |
| 285 |
break; |
| 286 |
case LS: |
| 287 |
case RS: |
| 288 |
if (q->visit & (INAREG|INBREG)) { |
| 289 |
static struct rspecial s[] = { |
| 290 |
{ NRIGHT, CL }, { NOLEFT, CX }, { 0 } }; |
| 291 |
return s; |
| 292 |
} else if (q->visit & INCREG) { |
| 293 |
static struct rspecial s[] = { |
| 294 |
{ NLEFT, AXDX }, { NRIGHT, CL }, |
| 295 |
{ NRES, AXDX }, { 0 } }; |
| 296 |
return s; |
| 297 |
} |
| 298 |
break; |
| 299 |
|
| 300 |
default: |
| 301 |
break; |
| 302 |
} |
| 303 |
comperr("nspecial entry %d", q - table); |
| 304 |
return 0; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
int |
| 311 |
setorder(NODE *p) |
| 312 |
{ |
| 313 |
return 0; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
int * |
| 320 |
livecall(NODE *p) |
| 321 |
{ |
| 322 |
static int r[] = { AX, BX, -1 }; |
| 323 |
int off = 1; |
| 324 |
return kflag ? &r[off] : &r[2]; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
int |
| 331 |
acceptable(struct optab *op) |
| 332 |
{ |
| 333 |
return 1; |
| 334 |
} |