Pristine Ack-5.5
[Ack-5.5.git] / util / opt / reg.c
1 #ifndef NORCSID
2 static char rcsid[] = "$Id: reg.c,v 2.9 1994/06/24 10:40:55 ceriel Exp $";
3 #endif
4
5 #include "assert.h"
6 #include "param.h"
7 #include "types.h"
8 #include "line.h"
9 #include "tes.h"
10 #include "proinf.h"
11 #include "alloc.h"
12 #include <em_spec.h>
13 #include <em_pseu.h>
14 #include <em_mes.h>
15 #include "ext.h"
16
17 /*
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".
20  *
21  * Author: Hans van Staveren
22  */
23
24 regvar(ap) register arg_p ap; {
25         register reg_p rp;
26         register i;
27
28         rp = newreg();
29         i=0;
30         while (ap!=(arg_p)0 && ap->a_typ==ARGOFF && i<4) {
31                 rp->r_par[i++]=ap->a_a.a_offset;
32                 ap=ap->a_next;
33         }
34         /*
35          * Omit incomplete messages
36          */
37         switch(i) {
38         default:assert(FALSE);
39         case 0:
40         case 1:
41         case 2: oldreg(rp); return;
42         case 3: rp->r_par[3]= (offset) 0; break;
43         case 4: break;
44         }
45         rp->r_next = curpro.freg;
46         curpro.freg = rp;
47 }
48
49 inreg(off) offset off; {
50         register reg_p rp;
51
52         for (rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
53                 if( rp->r_par[0] == off)
54                         return(TRUE);
55         return(FALSE);
56 }
57
58 outregs() {
59         register reg_p rp,tp;
60         register i;
61
62         for(rp=curpro.freg; rp != (reg_p) 0; rp = tp) {
63                 tp = rp->r_next;
64                 outinst(ps_mes);
65                 outoff((offset)ms_reg);
66                 for(i=0;i<4;i++)
67                         outoff(rp->r_par[i]);
68                 outinst(sp_cend);
69                 oldreg(rp);
70         }
71         /* List of register messages is followed by an empty ms_reg
72          * unless an ms_gto was in this procedure, then the ms_gto
73          * will be output. Kludgy.
74          */
75         outinst(ps_mes);
76         outoff((offset)(curpro.gtoproc? ms_gto : ms_reg));
77         outinst(sp_cend);
78         curpro.freg = (reg_p) 0;
79 }
80
81 /* outtes() handles the output of the top elt. messages */
82 outtes() {
83         register num_p *npp, np;
84
85         for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) {
86                 for (np = *npp; np != (num_p) 0; np=np->n_next) {
87                         if (! (np->n_flags & NUMSET) || np->n_size == 0 ||
88                             (np->n_flags & NUMCOND)) continue;
89                         outinst(ps_mes);
90                         outoff((offset)ms_tes);
91                         outoff((offset)np->n_number);
92                         outoff((offset)np->n_size);
93                         outoff((offset)((np->n_flags & NUMFALLTHROUGH) ? 1 : 0));
94                         outinst(sp_cend);
95                 }
96         }
97 }
98
99 incregusage(off) offset off; {
100         register reg_p rp;
101
102 #ifndef GLOBAL_OPT
103         /* If we're optimizing the output of the global optimizer
104          * we must not change the count fields of the register messages.
105          */
106         for(rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
107                 if (rp->r_par[0]==off) {
108                         rp->r_par[3]++;
109                         return;
110                 }
111 #endif
112 }