Pristine Ack-5.5
[Ack-5.5.git] / util / ncgg / iocc.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 #ifndef NORCSID
6 static char rcsid[]= "$Id: iocc.c,v 0.5 1994/06/24 10:37:32 ceriel Exp $";
7 #endif
8
9 #include "assert.h"
10 #include "param.h"
11 #include "set.h"
12 #include "expr.h"
13 #include "lookup.h"
14 #include "token.h"
15 #include "property.h"
16 #include "iocc.h"
17 #include <cgg_cg.h>
18 #include "regvar.h"
19 #include "extern.h"
20
21 extern set_t l_sets[];
22
23 int narexpr;
24 expr_t arexp[MAXATT];
25
26 expr_t iextoaddr();
27
28 iocc_t subr_iocc(tokarg,subreg) {
29         inst_t insta;
30         iocc_t  result;
31         register i;
32
33         insta.in_which = IN_COPY;
34         insta.in_info[0] = tokarg;
35         insta.in_info[1] = subreg;
36         result.in_index = instalookup(insta,2);
37         if (tokarg < 1) tokarg = 1;
38         if (subreg==0)
39                 for (i=0;i<SETSIZE;i++)
40                         result.in_set[i] = l_sets[tokpatset[tokarg-1]].set_val[i];
41         else {
42                 for (i=0;i<SETSIZE;i++)
43                         result.in_set[i] = 0;
44                 subregset(l_sets[tokpatset[tokarg-1]].set_val,subreg,result.in_set);
45         }
46         return(result);
47 }
48
49 iocc_t tokm_iocc(tokarg,ident) char *ident; {
50         iocc_t result;
51         inst_t insta;
52         register i;
53         char app[100];
54         int dummy;
55         
56         for(i=0;i<SETSIZE;i++)
57                 result.in_set[i] = 0;
58         insta.in_which = IN_MEMB;
59         insta.in_info[0] = tokarg;
60         if (tokarg < 1) tokarg = 1;
61         sprintf(app,"%%%d.%s",tokarg,ident);
62         insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set,
63                                     app,TYPREG,&dummy);
64         result.in_index = instalookup(insta,2);
65         return(result);
66 }
67
68 iocc_t percident_iocc(ident) char *ident; {
69         iocc_t result;
70         inst_t insta;
71         register i;
72         char app[100];
73         int dummy;
74         
75         for(i=0;i<SETSIZE;i++)
76                 result.in_set[i] = 0;
77         insta.in_which = IN_MEMB;
78         insta.in_info[0] = 0;
79         sprintf(app,"%%%s",ident);
80         insta.in_info[1] = 1+membset(cursetno,ident,result.in_set,
81                                     app,TYPREG,&dummy);
82         result.in_index = instalookup(insta,2);
83         return(result);
84 }
85
86 iocc_t ident_iocc(ident) char *ident; {
87         iocc_t result;
88         inst_t insta;
89         register i;
90         register symbol *sy_p;
91
92         for(i=0;i<SETSIZE;i++)
93                 result.in_set[i] = 0;
94         insta.in_which = IN_RIDENT;
95         sy_p = lookup(ident,symreg,mustexist);
96         insta.in_info[0] = sy_p->sy_value.syv_regno;
97         result.in_index = instalookup(insta,1);
98         BIS(result.in_set,sy_p->sy_value.syv_regno);
99         return(result);
100 }
101
102 iocc_t all_iocc(all_no,subreg) {
103         iocc_t result;
104         inst_t insta;
105         register i;
106         set_t localset;
107         register short *sp;
108
109         sp = l_props[allreg[all_no]].pr_regset;
110         for (i=0;i<SETSIZE;i++)
111                 localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0;
112         for(i=0;i<SETSIZE;i++)
113                 result.in_set[i] = 0;
114         insta.in_which = IN_ALLOC;
115         insta.in_info[0] = all_no;
116         insta.in_info[1] = subreg;
117         subregset(localset.set_val,subreg,result.in_set);
118         result.in_index = instalookup(insta,2);
119         return(result);
120 }
121
122 iocc_t descr_iocc(ident) char *ident; {
123         iocc_t result;
124         inst_t insta;
125         register symbol *sy_p;
126         register token_p tp;
127         register i;
128         int typerr;
129
130         for(i=0;i<SETSIZE;i++)
131                 result.in_set[i] = 0;
132         sy_p = lookup(ident,symtok,mustexist);
133         tp = l_tokens[sy_p->sy_value.syv_tokno];
134         BIS(result.in_set,sy_p->sy_value.syv_tokno+nregs);
135         insta.in_which = IN_DESCR;
136         if (rvused&SL_REGVAR && strcmp(ident,"LOCAL")==0)
137                 insta.in_which = IN_S_DESCR;
138         else if (rvused&DL_REGVAR && strcmp(ident,"DLOCAL")==0)
139                 insta.in_which = IN_D_DESCR;
140         insta.in_info[0] = sy_p->sy_value.syv_tokno;
141         for (i=0;i<MAXATT;i++) {
142                 if (tp->tk_att[i].ta_type == -3) {
143                         if (narexpr>i)
144                                 error("token %s initialized with too many attributes",ident);
145                         break;
146                 }
147                 if (i>= narexpr) {
148                         error("token %s initialized with too few attributes",
149                                         ident);
150                         break;
151                 }
152                 typerr = 0;
153                 switch(arexp[i].ex_typ) {
154                 default: assert(0);
155                 case TYPINT:
156                         if (tp->tk_att[i].ta_type != -1)
157                                 if (tp->tk_att[i].ta_type == -2)
158                                         arexp[i] = iextoaddr(arexp[i]);
159                                 else
160                                         typerr++;
161                         break;
162                 case TYPBOOL:
163                         typerr++; break;
164                 case TYPADDR:
165                         if (tp->tk_att[i].ta_type != -2)
166                                 typerr++;
167                         break;
168                 case TYPREG:
169                         if (tp->tk_att[i].ta_type<0)
170                                 typerr++;
171                         else if (!subset(arexp[i].ex_regset,
172                                    l_props[tp->tk_att[i].ta_type].pr_regset,
173                                    SZOFSET(MAXREGS)))
174                                 typerr++;
175                         break;
176                 }
177                 if (typerr)
178                         error("Attribute %s.%s given wrong type of value",
179                                 ident,tp->tk_att[i].ta_name);
180                 insta.in_info[i+1] = arexp[i].ex_index;
181         }
182         result.in_index = instalookup(insta,i+1);
183         return(result);
184 }
185
186 /* low level instance package */
187
188 int ninstances=1;
189 inst_t l_instances[MAXINSTANCES];
190
191 instalookup(insta,filled) inst_t insta; {
192         register i,j;
193
194         for (j=filled;j<=MAXATT;j++)
195                 insta.in_info[j] = 0;
196         for (i=0;i<ninstances;i++) {
197                 if (insta.in_which != l_instances[i].in_which)
198                         continue;
199                 for(j=0;j<=MAXATT;j++)
200                         if (insta.in_info[j]!= l_instances[i].in_info[j])
201                                 goto cont;
202                 return(i);
203             cont:;
204         }
205         NEXT(ninstances,MAXINSTANCES,"Instances");
206         l_instances[i] = insta;
207         return(i);
208 }