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)
118 Bprint(&bso, "%5.2f follow\n", cputime());
124 firstp = firstp->link;
126 for(p = firstp; p != P; p = p->link) {
130 p->stkoff = -1; /* initialization for stkoff */
136 if(p->as == AADJSP && p->from.offset == 0) {
156 if((q = p->pcond) != P) {
163 /* copy up to 4 instructions to avoid branch */
164 for(i=0,q=p; i<4; i++,q=q->link) {
174 if(a == ABRA || a == ARTS || a == ARTE)
176 if(q->pcond == P || q->pcond->mark)
178 if(a == ABSR || a == ADBF)
190 if(q->as != a || q->pcond == P || q->pcond->mark)
192 q->as = relinv(q->as);
206 q->to.type = D_BRANCH;
207 q->to.offset = p->pc;
215 if(a == ARTS || a == ABRA || a == ARTE)
219 q = brchain(p->link);
220 if(q != P && q->mark)
227 q = brchain(p->pcond);
244 case ABEQ: return ABNE;
245 case ABNE: return ABEQ;
246 case ABLE: return ABGT;
247 case ABLS: return ABHI;
248 case ABLT: return ABGE;
249 case ABMI: return ABPL;
250 case ABGE: return ABLT;
251 case ABPL: return ABMI;
252 case ABGT: return ABLE;
253 case ABHI: return ABLS;
254 case ABCS: return ABCC;
255 case ABCC: return ABCS;
256 case AFBEQ: return AFBNE;
257 case AFBF: return AFBT;
258 case AFBGE: return AFBLT;
259 case AFBGT: return AFBLE;
260 case AFBLE: return AFBGT;
261 case AFBLT: return AFBGE;
262 case AFBNE: return AFBEQ;
263 case AFBT: return AFBF;
265 diag("unknown relation: %s in %s", anames[a], TNAME);
278 Bprint(&bso, "%5.2f mkfwd\n", cputime());
282 Bprint(&bso, "%5.2f patch\n", cputime());
284 s = lookup("exit", 0);
286 for(p = firstp; p != P; p = p->link) {
289 if((p->as == ABSR || p->as == ARTS) && p->to.sym != S) {
291 if(s->type != STEXT) {
292 diag("undefined: %s in %s", s->name, TNAME);
296 p->to.offset = s->value;
297 p->to.type = D_BRANCH;
299 if(p->to.type != D_BRANCH)
302 for(q = firstp; q != P;) {
304 if(c >= q->forwd->pc) {
313 diag("branch out of range in %s\n%P", TNAME, p);
319 for(p = firstp; p != P; p = p->link) {
322 p->mark = 0; /* initialization for follow */
324 p->pcond = brloop(p->pcond);
326 if(p->to.type == D_BRANCH)
327 p->to.offset = p->pcond->pc;
338 long dwn[LOG], cnt[LOG];
341 for(i=0; i<LOG; i++) {
344 cnt[i] = LOG * cnt[i-1];
349 for(p = firstp; p != P; p = p->link) {
373 for(q = p; q != P; q = q->pcond) {
392 Bprint(&bso, "%5.2f stkoff\n", cputime());
395 for(p = firstp; p != P; p = p->link) {
403 p->from.type = D_CONST;
409 for(q = p; q != P; q = q->pcond) {
414 diag("stack offset %ld is %ld sb %ld in %s\n%P",
415 q->pc, q->stkoff, s, TNAME, p);
418 diag("loop in stack offset 1: %P", p);
423 if(p->to.type == D_TOS)
425 if(p->from.type == D_TOS)
432 for(q = p->link; q != P; q = q->pcond) {
440 diag("loop in stack offset 2: %P", p);
444 if(q == P || q->stkoff == s)
446 if(p->as == ABRA || p->as == ARTS || p->as == ARTE) {
455 p->from.type = D_CONST;
460 Bprint(&bso, "%5.2f rewrite\n", cputime());
462 for(p = firstp; p != P; p = p->link) {
465 a = p->from.type & D_MASK;
467 p->from.offset += p->stkoff;
469 p->from.offset += p->stkoff + 4;
470 a = p->to.type & D_MASK;
472 p->to.offset += p->stkoff;
474 p->to.offset += p->stkoff + 4;
480 if(p->from.type != D_CCR)
483 if((a < D_R0 || a > D_R0+7) && a != D_TOS)
484 diag("bad dest for MOVCC %P", p);
486 p->from.type = I_INDIR|(D_A0+7);
492 p->to.type = D_BRANCH;
494 p->to.sym = prog_ccr->from.sym;
499 p->from.type = D_TOS;
506 if(a < D_R0 || a > D_R0+7)
507 diag("bad dest for EXTB");
528 if(a < D_R0 || a > D_R0+7)
529 diag("bad dest for mul/div");
540 p->to.type = D_BRANCH;
542 p->to.sym = qq->from.sym;
546 p->from.type = D_TOS;
551 p->from.type = D_TOS;
564 p->from.type = D_CONST;
565 p->from.offset = -p->stkoff;
581 while(*s == ' ' || *s == '\t')
583 if(*s == '-' || *s == '+') {
586 while(*s == ' ' || *s == '\t')
589 if(s[0]=='0' && s[1]){
590 if(s[1]=='x' || s[1]=='X'){
593 if(*s >= '0' && *s <= '9')
594 n = n*16 + *s++ - '0';
595 else if(*s >= 'a' && *s <= 'f')
596 n = n*16 + *s++ - 'a' + 10;
597 else if(*s >= 'A' && *s <= 'F')
598 n = n*16 + *s++ - 'A' + 10;
603 while(*s >= '0' && *s <= '7')
604 n = n*8 + *s++ - '0';
606 while(*s >= '0' && *s <= '9')
607 n = n*10 + *s++ - '0';
619 for(i=0; i<NHASH; i++)
620 for(s = hash[i]; s != S; s = s->link)
622 diag("%s: not defined", s->name);
628 lookup("_mull", 0)->type = SXREF;
629 lookup("_divsl", 0)->type = SXREF;
630 lookup("_divul", 0)->type = SXREF;
631 lookup("_ccr", 0)->type = SXREF;
637 Sym *s1, *s2, *s3, *s4;
642 s1 = lookup("_mull", 0);
643 s2 = lookup("_divsl", 0);
644 s3 = lookup("_divul", 0);
645 s4 = lookup("_ccr", 0);
646 for(p = firstp; p != P; p = p->link)
648 if(p->from.sym == s1)
650 if(p->from.sym == s2)
652 if(p->from.sym == s3)
654 if(p->from.sym == s4)
658 diag("undefined: %s", s1->name);
661 if(prog_divsl == P) {
662 diag("undefined: %s", s2->name);
663 prog_divsl = curtext;
665 if(prog_divul == P) {
666 diag("undefined: %s", s3->name);
667 prog_divul = curtext;
670 diag("undefined: %s", s4->name);