| 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 |
static int |
| 46 |
inctree(NODE *p) |
| 47 |
{ |
| 48 |
if (p->n_op == MINUS && p->n_left->n_op == ASSIGN && |
| 49 |
p->n_left->n_right->n_op == PLUS && |
| 50 |
treecmp(p->n_left->n_left, p->n_left->n_right->n_left) && |
| 51 |
p->n_right->n_op == ICON && getlval(p->n_right) == 1 && |
| 52 |
p->n_left->n_right->n_right->n_op == ICON && |
| 53 |
getlval(p->n_left->n_right->n_right) == 1) { |
| 54 |
|
| 55 |
if (isreg(p->n_left->n_left)) |
| 56 |
return 1; |
| 57 |
} |
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
void |
| 66 |
offstar(NODE *p, int shape) |
| 67 |
{ |
| 68 |
if (x2debug) |
| 69 |
printf("offstar(%p)\n", p); |
| 70 |
|
| 71 |
if (isreg(p)) |
| 72 |
return; |
| 73 |
|
| 74 |
if (p->n_op == UMUL) { |
| 75 |
if (p->n_type < PTR+LONG || p->n_type > PTR+ULONGLONG) |
| 76 |
p = p->n_left; |
| 77 |
} |
| 78 |
|
| 79 |
if (inctree(p)) |
| 80 |
return; |
| 81 |
|
| 82 |
if( p->n_op == PLUS || p->n_op == MINUS ){ |
| 83 |
if (p->n_right->n_op == ICON) { |
| 84 |
if (isreg(p->n_left) == 0) |
| 85 |
(void)geninsn(p->n_left, INAREG); |
| 86 |
|
| 87 |
return; |
| 88 |
} |
| 89 |
} |
| 90 |
(void)geninsn(p, INAREG); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
void |
| 97 |
myormake(NODE *p) |
| 98 |
{ |
| 99 |
NODE *q = p->n_left; |
| 100 |
|
| 101 |
if (x2debug) { |
| 102 |
printf("myormake(%p)\n", p); |
| 103 |
fwalk(p, e2print, 0); |
| 104 |
} |
| 105 |
if (inctree(q)) { |
| 106 |
if (q->n_left->n_left->n_op == TEMP) |
| 107 |
return; |
| 108 |
p->n_op = OREG; |
| 109 |
setlval(p, 0); |
| 110 |
p->n_rval = R2PACK(regno(q->n_left->n_left), 0, 1); |
| 111 |
tfree(q); |
| 112 |
return; |
| 113 |
} |
| 114 |
if (q->n_op != OREG) |
| 115 |
return; |
| 116 |
if (TBLIDX(q->n_su)) |
| 117 |
return; |
| 118 |
if (R2TEST(regno(q))) |
| 119 |
return; |
| 120 |
if (p->n_type >= LONG && p->n_type <= ULONGLONG) |
| 121 |
return; |
| 122 |
p->n_op = OREG; |
| 123 |
setlval(p, getlval(q)); |
| 124 |
p->n_rval = R2PACK(q->n_rval, 0, 0); |
| 125 |
if (x2debug) { |
| 126 |
printf("myormake end(%p)\n", p); |
| 127 |
fwalk(p, e2print, 0); |
| 128 |
} |
| 129 |
nfree(q); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
int |
| 136 |
shumul(NODE *p, int shape) |
| 137 |
{ |
| 138 |
if (x2debug) |
| 139 |
printf("shumul(%p)\n", p); |
| 140 |
|
| 141 |
if (p->n_op == NAME && (shape & STARNM)) |
| 142 |
return SRDIR; |
| 143 |
if (shape & SOREG) |
| 144 |
return SROREG; |
| 145 |
return SRNOPE; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
int |
| 153 |
setbin(NODE *p) |
| 154 |
{ |
| 155 |
|
| 156 |
if (x2debug) |
| 157 |
printf("setbin(%p)\n", p); |
| 158 |
return 0; |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
int |
| 164 |
setasg(NODE *p, int cookie) |
| 165 |
{ |
| 166 |
if (x2debug) |
| 167 |
printf("setasg(%p)\n", p); |
| 168 |
return(0); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
int |
| 173 |
setuni(NODE *p, int cookie) |
| 174 |
{ |
| 175 |
return(0); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
struct rspecial * |
| 182 |
nspecial(struct optab *q) |
| 183 |
{ |
| 184 |
switch (q->op) { |
| 185 |
case MUL: |
| 186 |
if (q->visit == INAREG) { |
| 187 |
static struct rspecial s[] = { |
| 188 |
{ NLEFT, R1 }, { NRES, R1 }, { 0 } }; |
| 189 |
return s; |
| 190 |
} else if (q->visit == INBREG) { |
| 191 |
static struct rspecial s[] = { |
| 192 |
{ NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } }; |
| 193 |
return s; |
| 194 |
} |
| 195 |
break; |
| 196 |
|
| 197 |
case DIV: |
| 198 |
if (q->visit == INAREG && q->ltype == TUNSIGNED) { |
| 199 |
static struct rspecial s[] = { |
| 200 |
{ NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } }; |
| 201 |
return s; |
| 202 |
} else if (q->visit == INAREG) { |
| 203 |
static struct rspecial s[] = { |
| 204 |
{ NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 }, |
| 205 |
{ NRES, R0 }, { NORIGHT, R0 }, { NORIGHT, R1 }, |
| 206 |
{ 0 } }; |
| 207 |
return s; |
| 208 |
} else if (q->visit == INBREG) { |
| 209 |
static struct rspecial s[] = { |
| 210 |
{ NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } }; |
| 211 |
return s; |
| 212 |
} |
| 213 |
break; |
| 214 |
|
| 215 |
case MOD: |
| 216 |
if (q->visit == INAREG && q->ltype == TUNSIGNED) { |
| 217 |
static struct rspecial s[] = { |
| 218 |
{ NLEFT, R0 }, { NRIGHT, R1 }, { NRES, R0 }, { 0 } }; |
| 219 |
return s; |
| 220 |
} else if (q->visit == INAREG) { |
| 221 |
static struct rspecial s[] = { |
| 222 |
{ NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 }, |
| 223 |
{ NRES, R1 }, { NORIGHT, R0 }, { NORIGHT, R1 }, |
| 224 |
{ 0 } }; |
| 225 |
return s; |
| 226 |
} else if (q->visit == INBREG) { |
| 227 |
static struct rspecial s[] = { |
| 228 |
{ NEVER, R0 }, { NEVER, R1 },{ NRES, R01 }, { 0 } }; |
| 229 |
return s; |
| 230 |
} |
| 231 |
break; |
| 232 |
|
| 233 |
case RS: |
| 234 |
{ |
| 235 |
static struct rspecial s[] = { |
| 236 |
{ NEVER, R0 }, { NEVER, R1 }, { NLEFT, R1 }, |
| 237 |
{ NRES, R1 }, { NORIGHT, R0 }, { NORIGHT, R1 }, |
| 238 |
{ 0 } }; |
| 239 |
return s; |
| 240 |
} |
| 241 |
break; |
| 242 |
case SCONV: |
| 243 |
if (q->lshape == SAREG) { |
| 244 |
static struct rspecial s[] = { |
| 245 |
{ NLEFT, R1 }, { NRES, R01 }, { 0 } }; |
| 246 |
return s; |
| 247 |
} |
| 248 |
break; |
| 249 |
case STASG: { |
| 250 |
|
| 251 |
static struct rspecial s[] = { |
| 252 |
{ NEVER, R1 }, { NEVER, R0 }, { NRIGHT, R0 }, |
| 253 |
{ NOLEFT, R0 }, { NOLEFT, R2 }, { NORIGHT, R2 }, |
| 254 |
{ NEVER, R2 }, |
| 255 |
}; |
| 256 |
return s; |
| 257 |
} |
| 258 |
break; |
| 259 |
case STARG: { |
| 260 |
static struct rspecial s[] = { |
| 261 |
{ NEVER, R0 }, { NLEFT, R1 }, |
| 262 |
{ NEVER, R2 }, { 0 } |
| 263 |
}; |
| 264 |
return s; |
| 265 |
} |
| 266 |
break; |
| 267 |
} |
| 268 |
comperr("nspecial entry %d", q - table); |
| 269 |
return 0; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
int |
| 276 |
setorder(NODE *p) |
| 277 |
{ |
| 278 |
return 0; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
int * |
| 285 |
livecall(NODE *p) |
| 286 |
{ |
| 287 |
static int r[] = { -1 }; |
| 288 |
|
| 289 |
return r; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
int |
| 296 |
acceptable(struct optab *op) |
| 297 |
{ |
| 298 |
return 1; |
| 299 |
} |