| 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 |
#include <assert.h> |
| 30 |
|
| 31 |
# include "pass2.h" |
| 32 |
|
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
int canaddr(NODE *); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int |
| 44 |
notoff(TWORD t, int r, CONSZ off, char *cp) |
| 45 |
{ |
| 46 |
#if 0 |
| 47 |
if (off >= 32767 || off <= -32768) |
| 48 |
printf("; notoff %lld TOO BIG!\n", off); |
| 49 |
#endif |
| 50 |
if (cp && cp[0]) return 1; |
| 51 |
return (off >= 32768 || off <= -32769); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
void |
| 59 |
offstar(NODE *p, int shape) |
| 60 |
{ |
| 61 |
NODE *r; |
| 62 |
|
| 63 |
if (x2debug) |
| 64 |
printf("offstar(%p)\n", p); |
| 65 |
|
| 66 |
if (isreg(p)) |
| 67 |
return; |
| 68 |
|
| 69 |
r = p->n_right; |
| 70 |
if( p->n_op == PLUS || p->n_op == MINUS ){ |
| 71 |
if( r->n_op == ICON ){ |
| 72 |
if (isreg(p->n_left) == 0) |
| 73 |
(void)geninsn(p->n_left, INAREG); |
| 74 |
|
| 75 |
return; |
| 76 |
} |
| 77 |
} |
| 78 |
(void)geninsn(p, INAREG); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
void |
| 86 |
myormake(NODE *q) |
| 87 |
{ |
| 88 |
NODE *p; |
| 89 |
|
| 90 |
if (x2debug) |
| 91 |
printf("myormake(%p)\n", q); |
| 92 |
|
| 93 |
p = q->n_left; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
if ((p->n_op == PLUS || p->n_op == MINUS) && p->n_right->n_op == ICON) { |
| 100 |
if (isreg(p->n_left) == 0) |
| 101 |
(void)geninsn(p->n_left, INAREG); |
| 102 |
if (isreg(p->n_right) == 0) |
| 103 |
(void)geninsn(p->n_right, INAREG); |
| 104 |
(void)geninsn(p, INAREG); |
| 105 |
} else if (p->n_op == REG) { |
| 106 |
q->n_op = OREG; |
| 107 |
setlval(q, getlval(p)); |
| 108 |
q->n_rval = p->n_rval; |
| 109 |
tfree(p); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
int |
| 117 |
shumul(NODE *p, int shape) |
| 118 |
{ |
| 119 |
|
| 120 |
if (x2debug) |
| 121 |
printf("shumul(%p)\n", p); |
| 122 |
|
| 123 |
|
| 124 |
if (shape & SOREG) |
| 125 |
return SROREG; |
| 126 |
return SRNOPE; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
int |
| 134 |
setbin(NODE *p) |
| 135 |
{ |
| 136 |
|
| 137 |
if (x2debug) |
| 138 |
printf("setbin(%p)\n", p); |
| 139 |
return 0; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
int |
| 145 |
setasg(NODE *p, int cookie) |
| 146 |
{ |
| 147 |
if (x2debug) |
| 148 |
printf("setasg(%p)\n", p); |
| 149 |
return(0); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
int |
| 154 |
setuni(NODE *p, int cookie) |
| 155 |
{ |
| 156 |
return 0; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
struct rspecial * |
| 163 |
nspecial(struct optab *q) |
| 164 |
{ |
| 165 |
if (x2debug) |
| 166 |
printf("nspecial: op=%d, visit=0x%x: %s", q->op, q->visit, q->cstring); |
| 167 |
|
| 168 |
switch (q->op) { |
| 169 |
|
| 170 |
|
| 171 |
case RS: |
| 172 |
case LS: |
| 173 |
if (q->lshape == SBREG) { |
| 174 |
static struct rspecial s[] = { |
| 175 |
{ NLEFT, R3R4 }, |
| 176 |
{ NRIGHT, R5 }, |
| 177 |
{ NRES, R3R4 }, |
| 178 |
{ 0 }, |
| 179 |
}; |
| 180 |
return s; |
| 181 |
} else if (q->lshape == SAREG) { |
| 182 |
static struct rspecial s[] = { |
| 183 |
{ NLEFT, R3 }, |
| 184 |
{ NRIGHT, R4 }, |
| 185 |
{ NRES, R3 }, |
| 186 |
{ 0 }, |
| 187 |
}; |
| 188 |
return s; |
| 189 |
} |
| 190 |
|
| 191 |
cerror("nspecial LS/RS"); |
| 192 |
break; |
| 193 |
|
| 194 |
case UMINUS: |
| 195 |
case SCONV: |
| 196 |
if (q->lshape == SBREG && q->rshape == SAREG) { |
| 197 |
static struct rspecial s[] = { |
| 198 |
{ NLEFT, R3R4 }, |
| 199 |
{ NRES, R3 }, |
| 200 |
{ 0 } |
| 201 |
}; |
| 202 |
return s; |
| 203 |
} else if (q->lshape == SAREG && q->rshape == SBREG) { |
| 204 |
static struct rspecial s[] = { |
| 205 |
{ NLEFT, R3 }, |
| 206 |
{ NRES, R3R4 }, |
| 207 |
{ 0 } |
| 208 |
}; |
| 209 |
return s; |
| 210 |
} else if (q->lshape == SAREG && q->rshape == SAREG) { |
| 211 |
static struct rspecial s[] = { |
| 212 |
{ NLEFT, R3 }, |
| 213 |
{ NRES, R3 }, |
| 214 |
{ 0 } |
| 215 |
}; |
| 216 |
return s; |
| 217 |
} else if (q->lshape == SBREG && q->rshape == SBREG) { |
| 218 |
static struct rspecial s[] = { |
| 219 |
{ NLEFT, R3R4 }, |
| 220 |
{ NRES, R3R4 }, |
| 221 |
{ 0 } |
| 222 |
}; |
| 223 |
return s; |
| 224 |
} else if (q->lshape == SCREG && q->rshape == SBREG) { |
| 225 |
static struct rspecial s[] = { |
| 226 |
{ NLEFT, F1 }, |
| 227 |
{ NEVER, F0 }, |
| 228 |
{ NRES, R3R4 }, |
| 229 |
{ 0 } |
| 230 |
}; |
| 231 |
return s; |
| 232 |
} else if (q->lshape == SBREG && q->rshape == SCREG) { |
| 233 |
static struct rspecial s[] = { |
| 234 |
{ NLEFT, R3R4 }, |
| 235 |
{ NEVER, F0 }, |
| 236 |
{ NRES, F1 }, |
| 237 |
{ 0 } |
| 238 |
}; |
| 239 |
return s; |
| 240 |
} else { |
| 241 |
static struct rspecial s[] = { |
| 242 |
{ NOLEFT, R0 }, |
| 243 |
{ 0 } }; |
| 244 |
return s; |
| 245 |
} |
| 246 |
|
| 247 |
break; |
| 248 |
|
| 249 |
case OPLOG: |
| 250 |
if (q->lshape == SBREG) { |
| 251 |
static struct rspecial s[] = { |
| 252 |
{ NLEFT, R3R4 }, |
| 253 |
{ NRIGHT, R5R6 }, |
| 254 |
{ NRES, R3 }, |
| 255 |
{ 0 } |
| 256 |
}; |
| 257 |
return s; |
| 258 |
} else if (q->lshape == SAREG) { |
| 259 |
static struct rspecial s[] = { |
| 260 |
{ NLEFT, R3 }, |
| 261 |
{ NRIGHT, R4 }, |
| 262 |
{ NRES, R3 }, |
| 263 |
{ 0 } |
| 264 |
}; |
| 265 |
return s; |
| 266 |
} |
| 267 |
|
| 268 |
cerror("nspecial oplog"); |
| 269 |
break; |
| 270 |
|
| 271 |
case PLUS: |
| 272 |
case MINUS: |
| 273 |
case MUL: |
| 274 |
case DIV: |
| 275 |
case MOD: |
| 276 |
if (q->lshape == SBREG && |
| 277 |
(q->ltype & (TDOUBLE|TLDOUBLE|TLONGLONG|TULONGLONG))) { |
| 278 |
static struct rspecial s[] = { |
| 279 |
{ NLEFT, R3R4 }, |
| 280 |
{ NRIGHT, R5R6 }, |
| 281 |
{ NRES, R3R4 }, |
| 282 |
{ 0 } |
| 283 |
}; |
| 284 |
return s; |
| 285 |
} else if (q->lshape == SAREG && q->ltype & TFLOAT) { |
| 286 |
static struct rspecial s[] = { |
| 287 |
{ NLEFT, R3 }, |
| 288 |
{ NRIGHT, R4 }, |
| 289 |
{ NRES, R3 }, |
| 290 |
{ 0 } |
| 291 |
}; |
| 292 |
return s; |
| 293 |
} else if (q->lshape == SAREG) { |
| 294 |
static struct rspecial s[] = { |
| 295 |
{ NOLEFT, R0 }, |
| 296 |
{ 0 } }; |
| 297 |
return s; |
| 298 |
} |
| 299 |
|
| 300 |
cerror("nspecial mul"); |
| 301 |
break; |
| 302 |
|
| 303 |
case STASG: |
| 304 |
{ |
| 305 |
static struct rspecial s[] = { |
| 306 |
{ NEVER, R3 }, |
| 307 |
{ NRIGHT, R4 }, |
| 308 |
{ NEVER, R5 }, |
| 309 |
{ 0 } }; |
| 310 |
return s; |
| 311 |
} |
| 312 |
break; |
| 313 |
|
| 314 |
case OPLTYPE: |
| 315 |
{ |
| 316 |
if (q->visit & SAREG) { |
| 317 |
static struct rspecial s[] = { |
| 318 |
{ NEVER, R0 }, |
| 319 |
{ 0 } }; |
| 320 |
return s; |
| 321 |
} |
| 322 |
} |
| 323 |
break; |
| 324 |
|
| 325 |
case ASSIGN: |
| 326 |
if (q->lshape & SNAME) { |
| 327 |
static struct rspecial s[] = { |
| 328 |
{ NEVER, R0 }, |
| 329 |
{ 0 } }; |
| 330 |
return s; |
| 331 |
} else if (q->rshape & SNAME) { |
| 332 |
static struct rspecial s[] = { |
| 333 |
{ NOLEFT, R0 }, |
| 334 |
{ 0 } }; |
| 335 |
return s; |
| 336 |
} else if (q->lshape & SOREG) { |
| 337 |
static struct rspecial s[] = { |
| 338 |
{ NOLEFT, R0 }, |
| 339 |
{ 0 } }; |
| 340 |
return s; |
| 341 |
} else if (q->rshape & SOREG) { |
| 342 |
static struct rspecial s[] = { |
| 343 |
{ NORIGHT, R0 }, |
| 344 |
{ 0 } }; |
| 345 |
return s; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
case UMUL: |
| 350 |
case AND: |
| 351 |
case OR: |
| 352 |
case ER: |
| 353 |
{ |
| 354 |
static struct rspecial s[] = { |
| 355 |
{ NOLEFT, R0 }, |
| 356 |
{ 0 } }; |
| 357 |
return s; |
| 358 |
} |
| 359 |
|
| 360 |
default: |
| 361 |
break; |
| 362 |
} |
| 363 |
|
| 364 |
comperr("nspecial entry %d: %s", q - table, q->cstring); |
| 365 |
return 0; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
int |
| 372 |
setorder(NODE *p) |
| 373 |
{ |
| 374 |
return 0; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
int * |
| 382 |
livecall(NODE *p) |
| 383 |
{ |
| 384 |
static int r[] = { R10, R9, R8, R7, R6, R5, R4, R3, R30, R31, -1 }; |
| 385 |
int num = 1; |
| 386 |
|
| 387 |
if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL) |
| 388 |
return &r[8-0]; |
| 389 |
|
| 390 |
for (p = p->n_right; p->n_op == CM; p = p->n_left) |
| 391 |
num += szty(p->n_right->n_type); |
| 392 |
num += szty(p->n_right->n_type); |
| 393 |
|
| 394 |
num = (num > 8 ? 8 : num); |
| 395 |
|
| 396 |
return &r[8 - num]; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
int |
| 403 |
acceptable(struct optab *op) |
| 404 |
{ |
| 405 |
if ((op->visit & FEATURE_PIC) != 0) |
| 406 |
return (kflag != 0); |
| 407 |
return features(op->visit & 0xffff0000); |
| 408 |
} |