| 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 "pass1.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
void |
| 36 |
defalign(int n) |
| 37 |
{ |
| 38 |
#if 0 |
| 39 |
char *s; |
| 40 |
|
| 41 |
n /= SZCHAR; |
| 42 |
if (lastloc == PROG || n == 1) |
| 43 |
return; |
| 44 |
s = (isinlining ? permalloc(40) : tmpalloc(40)); |
| 45 |
sprintf(s, "\t.align %d\n", n); |
| 46 |
send_passt(IP_ASM, s); |
| 47 |
#endif |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void |
| 54 |
defnam(struct symtab *p) |
| 55 |
{ |
| 56 |
char *c = p->soname; |
| 57 |
|
| 58 |
if (p->sclass == EXTDEF) |
| 59 |
printf(" PUBLIC %s\n", c); |
| 60 |
printf("%s:\n", c); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
void |
| 69 |
efcode(void) |
| 70 |
{ |
| 71 |
NODE *p, *q; |
| 72 |
int sz; |
| 73 |
|
| 74 |
if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN) |
| 75 |
return; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
p = block(REG, NIL, NIL, CHAR+PTR, 0, 0); |
| 80 |
p->n_rval = R0; |
| 81 |
q = block(OREG, NIL, NIL, CHAR+PTR, 0, 0); |
| 82 |
q->n_rval = FB; |
| 83 |
q->n_lval = 8; |
| 84 |
p = block(CM, q, p, INT, 0, 0); |
| 85 |
sz = (tsize(STRTY, cftnsp->sdf, cftnsp->ssue)+SZCHAR-1)/SZCHAR; |
| 86 |
p = block(CM, p, bcon(sz), INT, 0, 0); |
| 87 |
p->n_right->n_name = ""; |
| 88 |
p = block(CALL, bcon(0), p, CHAR+PTR, 0, 0); |
| 89 |
p->n_left->n_name = "memcpy"; |
| 90 |
send_passt(IP_NODE, p); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static void |
| 97 |
argmove(struct symtab *s, int regno) |
| 98 |
{ |
| 99 |
NODE *p, *r; |
| 100 |
|
| 101 |
s->sclass = AUTO; |
| 102 |
s->soffset = NOOFFSET; |
| 103 |
oalloc(s, &autooff); |
| 104 |
p = nametree(s); |
| 105 |
r = bcon(0); |
| 106 |
r->n_op = REG; |
| 107 |
r->n_rval = regno; |
| 108 |
r->n_type = p->n_type; |
| 109 |
r->n_sue = p->n_sue; |
| 110 |
r->n_df = p->n_df; |
| 111 |
ecode(buildtree(ASSIGN, p, r)); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
void |
| 121 |
bfcode(struct symtab **a, int n) |
| 122 |
{ |
| 123 |
struct symtab *s; |
| 124 |
int i, r0l, r0h, a0, r2, sz, hasch, stk; |
| 125 |
int argoff = ARGINIT; |
| 126 |
|
| 127 |
if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) { |
| 128 |
|
| 129 |
for (i = 0; i < n; i++) |
| 130 |
a[i]->soffset += SZPOINT(INT); |
| 131 |
} |
| 132 |
|
| 133 |
for (hasch = i = 0; i < n && i < 6; i++) |
| 134 |
if (DEUNSIGN(a[i]->stype) == CHAR) |
| 135 |
hasch = 1; |
| 136 |
|
| 137 |
stk = r0l = r0h = a0 = r2 = 0; |
| 138 |
for (i = 0; i < n; i++) { |
| 139 |
s = a[i]; |
| 140 |
sz = tsize(s->stype, s->sdf, s->ssue); |
| 141 |
if (ISPTR(s->stype) && ISFTN(DECREF(s->stype))) |
| 142 |
sz = SZLONG; |
| 143 |
if (stk == 0) |
| 144 |
switch (sz) { |
| 145 |
case SZCHAR: |
| 146 |
if (r0l) { |
| 147 |
if (r0h) |
| 148 |
break; |
| 149 |
argmove(s, 1); |
| 150 |
r0h = 1; |
| 151 |
} else { |
| 152 |
argmove(s, 0); |
| 153 |
r0l = 1; |
| 154 |
} |
| 155 |
continue; |
| 156 |
|
| 157 |
case SZINT: |
| 158 |
if (s->stype > BTMASK) { |
| 159 |
|
| 160 |
if (a0) { |
| 161 |
if (r0l || hasch) { |
| 162 |
if (r2) |
| 163 |
break; |
| 164 |
argmove(s, R2); |
| 165 |
r2 = 1; |
| 166 |
} else { |
| 167 |
argmove(s, R0); |
| 168 |
r0l = r0h = 1; |
| 169 |
} |
| 170 |
} else { |
| 171 |
argmove(s, A0); |
| 172 |
a0 = 1; |
| 173 |
} |
| 174 |
} else if (r0l || hasch) { |
| 175 |
if (r2) { |
| 176 |
if (a0) |
| 177 |
break; |
| 178 |
argmove(s, A0); |
| 179 |
a0 = 1; |
| 180 |
} else { |
| 181 |
argmove(s, R2); |
| 182 |
r2 = 1; |
| 183 |
} |
| 184 |
} else { |
| 185 |
argmove(s, R0); |
| 186 |
r0l = r0h = 1; |
| 187 |
} |
| 188 |
continue; |
| 189 |
case SZLONG: |
| 190 |
if (r0l||r0h||r2) |
| 191 |
break; |
| 192 |
argmove(s, R0); |
| 193 |
r0l = r0h = r2 = 1; |
| 194 |
continue; |
| 195 |
|
| 196 |
default: |
| 197 |
break; |
| 198 |
} |
| 199 |
stk = 1; |
| 200 |
s->soffset = argoff; |
| 201 |
argoff += sz; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
void addsym(struct symtab *); |
| 209 |
static struct symlst { |
| 210 |
struct symlst *next; |
| 211 |
struct symtab *sp; |
| 212 |
} *sympole; |
| 213 |
|
| 214 |
void |
| 215 |
addsym(struct symtab *q) |
| 216 |
{ |
| 217 |
struct symlst *w = sympole; |
| 218 |
|
| 219 |
if (q == NULL) |
| 220 |
return; |
| 221 |
|
| 222 |
while (w) { |
| 223 |
if (q == w->sp) |
| 224 |
return; |
| 225 |
w = w->next; |
| 226 |
} |
| 227 |
w = permalloc(sizeof(struct symlst)); |
| 228 |
w->sp = q; |
| 229 |
w->next = sympole; |
| 230 |
sympole = w; |
| 231 |
} |
| 232 |
|
| 233 |
struct caps { |
| 234 |
char *cap, *stat; |
| 235 |
} caps[] = { |
| 236 |
{ "__64bit_doubles", "Disabled" }, |
| 237 |
{ "__calling_convention", "Normal" }, |
| 238 |
{ "__constant_data", "near" }, |
| 239 |
{ "__data_alignment", "2" }, |
| 240 |
{ "__data_model", "near" }, |
| 241 |
{ "__processor", "M16C" }, |
| 242 |
{ "__rt_version", "1" }, |
| 243 |
{ "__variable_data", "near" }, |
| 244 |
{ NULL, NULL }, |
| 245 |
}; |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
void |
| 251 |
bjobcode(void) |
| 252 |
{ |
| 253 |
struct caps *c; |
| 254 |
|
| 255 |
printf(" NAME gurka.c\n"); |
| 256 |
for (c = caps; c->cap; c++) |
| 257 |
printf(" RTMODEL \"%s\", \"%s\"\n", c->cap, c->stat); |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
void |
| 264 |
ejobcode(int flag) |
| 265 |
{ |
| 266 |
struct symlst *w = sympole; |
| 267 |
|
| 268 |
for (w = sympole; w; w = w->next) { |
| 269 |
if (w->sp->sclass != EXTERN) |
| 270 |
continue; |
| 271 |
printf(" EXTERN %s\n", w->sp->soname); |
| 272 |
} |
| 273 |
|
| 274 |
printf(" END\n"); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
void |
| 282 |
bycode(int t, int i) |
| 283 |
{ |
| 284 |
static int lastoctal = 0; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
if (t < 0) { |
| 289 |
if (i != 0) |
| 290 |
puts("\""); |
| 291 |
} else { |
| 292 |
if (i == 0) |
| 293 |
printf("\t.ascii \""); |
| 294 |
if (t == '\\' || t == '"') { |
| 295 |
lastoctal = 0; |
| 296 |
putchar('\\'); |
| 297 |
putchar(t); |
| 298 |
} else if (t < 040 || t >= 0177) { |
| 299 |
lastoctal++; |
| 300 |
printf("\\%o",t); |
| 301 |
} else if (lastoctal && '0' <= t && t <= '9') { |
| 302 |
lastoctal = 0; |
| 303 |
printf("\"\n\t.ascii \"%c", t); |
| 304 |
} else { |
| 305 |
lastoctal = 0; |
| 306 |
putchar(t); |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
void |
| 313 |
fldty(struct symtab *p) |
| 314 |
{ |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
int |
| 321 |
mygenswitch(int num, TWORD type, struct swents **p, int n) |
| 322 |
{ |
| 323 |
return 0; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
NODE * |
| 330 |
funcode(NODE *p) |
| 331 |
{ |
| 332 |
return p; |
| 333 |
} |