2 static char rcsid[] = "$Id: process.c,v 2.11 1994/06/24 10:40:42 ceriel Exp $";
18 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
19 * See the copyright notice in the ACK home directory, in the file "Copyright".
21 * Author: Hans van Staveren
26 if (wordsize == 0 || pointersize == 0)
27 error("No MES EMX encountered");
28 backward(); /* reverse and cleanup list */
29 symknown(); /* symbol scope is now known */
31 symvalue(); /* give symbols value */
37 checklocs(); /* check definition of locals */
39 madeopt = peephole(); /* local optimization */
40 relabel(); /* relabel local labels */
41 flow(); /* throw away unreachable code */
42 } while (madeopt && ++npasses < 5000);
45 do_tes(); /* top elt. size computation phase */
46 outpro(); /* generate PRO pseudo */
47 outregs(); /* generate MES ms_reg pseudos */
48 outtes(); /* generate MES ms_tes pseudos */
50 putlines(pseudos); /* pseudos first */
52 putlines(instrs); /* instructions next */
53 outend(); /* generate END pseudo */
54 cleanlocals(); /* forget instruction labels */
55 } else if(instrs != (line_p) 0)
56 error("instructions outside procedure");
63 register num_p *npp,np,tp;
64 register num_p repl,ttp;
67 * For each label find its final destination after crossjumping.
68 * Care has to be taken to prevent a loop in the program to
69 * cause same in the optimizer.
72 for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++)
73 for (np = *npp; np != (num_p) 0; np = np->n_next) {
74 assert(! np->n_line ||
75 ((np->n_line->l_instr&BMASK) == op_lab
76 && np->n_line->l_a.la_np == np));
77 for(tp=np; (tp->n_flags&(NUMKNOWN|NUMMARK))==0;
79 tp->n_flags |= NUMMARK;
81 for(tp=np; tp->n_flags&NUMMARK; tp = ttp) {
84 tp->n_flags &= ~ NUMMARK;
85 tp->n_flags |= NUMKNOWN;
88 for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++)
89 for (np = *npp; np != (num_p) 0; np = np->n_next) {
90 np->n_flags &= ~(NUMKNOWN|NUMSCAN|NUMREACH);
96 register sym_p *spp,sp;
98 for (spp = symhash; spp < &symhash[NSYMHASH]; spp++)
99 for (sp = *spp; sp != (sym_p) 0; sp = sp->s_next)
100 if (sp->s_flags & SYMSEEN)
101 sp->s_flags |= SYMKNOWN;
105 register num_p *npp,np,tp;
107 for (npp = curpro.numhash; npp < &curpro.numhash[NNUMHASH]; npp++) {
109 while (np != (num_p) 0) {
119 register num_p *npp,np;
121 for (npp=curpro.numhash; npp < & curpro.numhash[NNUMHASH]; npp++)
122 for (np = *npp; np != (num_p) 0; np=np->n_next)
123 if (np->n_line == (line_p) 0)
124 error("local label %u undefined",
125 (unsigned) np->n_number);
128 offset align(count,alignment) offset count,alignment; {
130 assert(alignment==1||alignment==2||alignment==4);
131 return((count+alignment-1)&~(alignment-1));
142 for (lp=pseudos; lp != (line_p) 0; lp = lp->l_next)
143 switch(lp->l_instr&BMASK) {
148 if (sp->s_frag != curfrag) {
150 curfrag = sp->s_frag;
152 count = align(count,wordsize);
157 /* nothing to do, all bss pseudos are in diff frags */
162 for (ap=lp->l_a.la_arg; ap != (arg_p) 0; ap = ap->a_next)
167 count = align(count,wordsize)+wordsize;
172 count = align(count,wordsize)+pointersize;
177 if (ap->a_a.a_con.ac_length < wordsize)
178 count = align(count,(offset)ap->a_a.a_con.ac_length);
180 count = align(count,wordsize);
181 count += ap->a_a.a_con.ac_length;
184 for (abp = &ap->a_a.a_string; abp != (argb_p) 0;
186 count += abp->ab_index;
194 register line_p insptr = instrs, oldlin = NULL, oldlin2 = NULL;
198 while (insptr != NULL) {
199 tes_instr(insptr, oldlin, oldlin2);
202 insptr = insptr->l_next;