12 Bprint(&bso, "%5.2f dodata\n", cputime());
14 for(p = datap; p != P; p = p->link) {
19 diag("initialize non-data (%d): %s\n%P",
21 t = p->from.offset + p->from.displace;
23 diag("initialize bounds (%ld): %s\n%P",
24 s->value, s->name, p);
27 /* allocate small guys */
29 for(i=0; i<NHASH; i++)
30 for(s = hash[i]; s != S; s = s->link) {
36 diag("%s: no size", s->name);
48 /* allocate the rest of the data */
49 for(i=0; i<NHASH; i++)
50 for(s = hash[i]; s != S; s = s->link) {
51 if(s->type != SDATA) {
63 * pad data with bss that fits up to next
64 * 8k boundary, then push data to 8k
66 u = rnd(datsize, 8192);
68 for(i=0; i<NHASH; i++)
69 for(s = hash[i]; s != S; s = s->link) {
85 for(i=0; i<NHASH; i++)
86 for(s = hash[i]; s != S; s = s->link) {
90 s->value = bsssize + datsize;
93 xdefine("bdata", SDATA, 0L);
94 xdefine("edata", SDATA, datsize);
95 xdefine("end", SBSS, datsize+bsssize);
103 for(i=0; i<20; i++) {
104 if(p == P || p->as != ABRA)
119 Bprint(&bso, "%5.2f follow\n", cputime());
125 firstp = firstp->link;
127 for(p = firstp; p != P; p = p->link) {
130 if(p->as == ABCASE) { /* initialization for dodata */
135 diag("BCASE of non-data: %s in %s\n%P",
139 p->stkoff = -1; /* initialization for stkoff */
145 if(p->as == AADJSP && p->from.offset == 0) {
165 if((q = p->pcond) != P) {
172 /* copy up to 4 instructions to avoid branch */
173 for(i=0,q=p; i<4; i++,q=q->link) {
183 if(a == ABRA || a == ARTS || a == ARTE)
185 if(q->pcond == P || q->pcond->mark)
187 if(a == ABSR || a == ABCASE || a == ADBF)
199 if(q->as != a || q->pcond == P || q->pcond->mark)
201 q->as = relinv(q->as);
215 q->to.type = D_BRANCH;
216 q->to.offset = p->pc;
224 if(a == ARTS || a == ABRA || a == ARTE)
228 q = brchain(p->link);
229 if(q != P && q->mark)
230 if(a != ABCASE && a != ADBF) {
236 q = brchain(p->pcond);
253 case ABEQ: return ABNE;
254 case ABNE: return ABEQ;
255 case ABLE: return ABGT;
256 case ABLS: return ABHI;
257 case ABLT: return ABGE;
258 case ABMI: return ABPL;
259 case ABGE: return ABLT;
260 case ABPL: return ABMI;
261 case ABGT: return ABLE;
262 case ABHI: return ABLS;
263 case ABCS: return ABCC;
264 case ABCC: return ABCS;
265 case AFBEQ: return AFBNE;
266 case AFBF: return AFBT;
267 case AFBGE: return AFBLT;
268 case AFBGT: return AFBLE;
269 case AFBLE: return AFBGT;
270 case AFBLT: return AFBGE;
271 case AFBNE: return AFBEQ;
272 case AFBT: return AFBF;
274 diag("unknown relation: %s in %s", anames[a], TNAME);
287 Bprint(&bso, "%5.2f mkfwd\n", cputime());
291 Bprint(&bso, "%5.2f patch\n", cputime());
293 s = lookup("exit", 0);
295 for(p = firstp; p != P; p = p->link) {
298 if((p->as == ABSR || p->as == ARTS) && p->to.sym != S) {
300 if(s->type != STEXT) {
301 diag("undefined: %s in %s", s->name, TNAME);
305 p->to.offset = s->value;
306 p->to.type = D_BRANCH;
308 if(p->to.type != D_BRANCH)
311 for(q = firstp; q != P;) {
313 if(c >= q->forwd->pc) {
322 diag("branch out of range in %s\n%P", TNAME, p);
328 for(p = firstp; p != P; p = p->link) {
331 p->mark = 0; /* initialization for follow */
333 p->pcond = brloop(p->pcond);
335 if(p->to.type == D_BRANCH)
336 p->to.offset = p->pcond->pc;
347 long dwn[LOG], cnt[LOG];
350 for(i=0; i<LOG; i++) {
353 cnt[i] = LOG * cnt[i-1];
358 for(p = firstp; p != P; p = p->link) {
382 for(q = p; q != P; q = q->pcond) {
401 Bprint(&bso, "%5.2f stkoff\n", cputime());
404 for(p = firstp; p != P; p = p->link) {
412 p->from.type = D_CONST;
417 for(q = p; q != P; q = q->pcond) {
422 diag("stack offset %ld is %ld sb %ld in %s\n%P",
423 q->pc, q->stkoff, s, TNAME, p);
427 if(p->to.type == D_TOS)
429 if(p->from.type == D_TOS)
435 for(q = p->link; q != P; q = q->pcond) {
443 if(q == P || q->stkoff == s)
445 if(p->as == ABRA || p->as == ARTS || p->as == ARTE) {
449 if(p->link->as == ABCASE)
450 diag("BCASE with stack offset in %s", TNAME);
456 p->from.type = D_CONST;
460 for(p = firstp; p != P; p = p->link) {
463 a = p->from.type & D_MASK;
465 p->from.offset += p->stkoff;
467 p->from.offset += p->stkoff + 4;
468 a = p->to.type & D_MASK;
470 p->to.offset += p->stkoff;
472 p->to.offset += p->stkoff + 4;
483 q->from.type = D_CONST;
484 q->from.offset = -q->stkoff;
496 while(*s == ' ' || *s == '\t')
498 if(*s == '-' || *s == '+') {
501 while(*s == ' ' || *s == '\t')
504 if(s[0]=='0' && s[1]){
505 if(s[1]=='x' || s[1]=='X'){
508 if(*s >= '0' && *s <= '9')
509 n = n*16 + *s++ - '0';
510 else if(*s >= 'a' && *s <= 'f')
511 n = n*16 + *s++ - 'a' + 10;
512 else if(*s >= 'A' && *s <= 'F')
513 n = n*16 + *s++ - 'A' + 10;
518 while(*s >= '0' && *s <= '7')
519 n = n*8 + *s++ - '0';
521 while(*s >= '0' && *s <= '9')
522 n = n*10 + *s++ - '0';
534 for(i=0; i<NHASH; i++)
535 for(s = hash[i]; s != S; s = s->link)
537 diag("%s: not defined", s->name);