Bell 32V development
[unix-history] / usr / src / cmd / f77 / vax.c
CommitLineData
0d57d6f5
TL
1#include "defs"
2#if OUTPUT==BINARY
3# include "scjdefs"
4#endif
5
6/*
7 PDP11-780/VAX - SPECIFIC PRINTING ROUTINES
8*/
9
10static char textline[50];
11int maxregvar = MAXREGVAR;
12int regnum[] = { 11, 10, 9, 8, 7, 6 } ;
13static int regmask[] = { 0, 0x800, 0xc00, 0xe00, 0xf00, 0xf80, 0xfc0 };
14
15
16
17
18prsave()
19{
20int proflab;
21p2pass( sprintf(textline, "\t.word\t0x%x", regmask[highregvar]) ); /* register variable mask */
22if(profileflag)
23 {
24 proflab = newlabel();
25 fprintf(asmfile, "L%d:\t.space\t4\n", proflab);
26 p2pass( sprintf(textline, "\tmovab\tL%d,r0", proflab) );
27 p2pass( sprintf(textline, "\tjsb\tmcount") );
28 }
29p2pass( sprintf(textline, "\tsubl2\t$.F%d,sp", procno) );
30}
31
32
33
34goret(type)
35int type;
36{
37p2pass( sprintf(textline, "\tret") );
38}
39
40
41
42
43/*
44 * move argument slot arg1 (relative to ap)
45 * to slot arg2 (relative to ARGREG)
46 */
47
48mvarg(type, arg1, arg2)
49int type, arg1, arg2;
50{
51p2pass( sprintf(textline, "\tmovl\t%d(ap),%d(fp)", arg1+ARGOFFSET, arg2+argloc) );
52}
53
54
55
56
57prlabel(fp, k)
58FILEP fp;
59int k;
60{
61fprintf(fp, "L%d:\n", k);
62}
63
64
65
66prconi(fp, type, n)
67FILEP fp;
68int type;
69ftnint n;
70{
71fprintf(fp, "\t%s\t%ld\n", (type==TYSHORT ? ".word" : ".long"), n);
72}
73
74
75
76prcona(fp, a)
77FILEP fp;
78ftnint a;
79{
80fprintf(fp, "\t.long\tL%ld\n", a);
81}
82
83
84
85#ifndef vax
86prconr(fp, type, x)
87FILEP fp;
88int type;
89float x;
90{
91fprintf(fp, "\t%s\t0f%e\n", (type==TYREAL ? ".float" : ".double"), x);
92}
93#endif
94
95#ifdef vax
96prconr(fp, type, x)
97FILEP fp;
98int type;
99double x;
100{
101long int *n;
102n = &x; /* nonportable cheat */
103if(type == TYREAL)
104 fprintf(fp, "\t.long\t0x%X\n", n[0]);
105else
106 fprintf(fp, "\t.long\t0x%X,0x%X\n", n[0], n[1]);
107}
108#endif
109
110
111
112
113
114
115
116preven(k)
117int k;
118{
119register int lg;
120
121if(k > 4)
122 lg = 3;
123else if(k > 2)
124 lg = 2;
125else if(k > 1)
126 lg = 1;
127else
128 return;
129fprintf(asmfile, "\t.align\t%d\n", lg);
130}
131
132
133
134vaxgoto(index, nlab, labs)
135expptr index;
136register int nlab;
137struct labelblock *labs[];
138{
139register int i;
140register int arrlab;
141
142putforce(TYINT, index);
143p2pass( sprintf(textline, "\tcasel\tr0,$1,$%d", nlab-1) );
144p2pass( sprintf(textline, "L%d:", arrlab = newlabel() ) );
145for(i = 0; i< nlab ; ++i)
146 p2pass( sprintf(textline, "\t.word\tL%d-L%d", labs[i]->labelno, arrlab) );
147}
148
149
150prarif(p, neg, zer, pos)
151ptr p;
152int neg, zer, pos;
153{
154putforce(p->vtype, p);
155if( ISINT(p->vtype) )
156 p2pass( sprintf(textline, "\ttstl\tr0") );
157else
158 p2pass( sprintf(textline, "\ttstd\tr0") );
159p2pass( sprintf(textline, "\tjlss\tL%d", neg) );
160p2pass( sprintf(textline, "\tjeql\tL%d", zer) );
161p2pass( sprintf(textline, "\tjbr\tL%d", pos) );
162}
163
164
165
166
167char *memname(stg, mem)
168int stg, mem;
169{
170static char s[20];
171
172switch(stg)
173 {
174 case STGCOMMON:
175 case STGEXT:
176 sprintf(s, "_%s", varstr(XL, extsymtab[mem].extname) );
177 break;
178
179 case STGBSS:
180 case STGINIT:
181 sprintf(s, "v.%d", mem);
182 break;
183
184 case STGCONST:
185 sprintf(s, "L%d", mem);
186 break;
187
188 case STGEQUIV:
189 sprintf(s, "q.%d", mem);
190 break;
191
192 default:
193 fatal1("memname: invalid vstg %d", stg);
194 }
195return(s);
196}
197
198
199
200
201prlocvar(s, len)
202char *s;
203ftnint len;
204{
205fprintf(asmfile, "\t.lcomm\t%s,%ld\n", s, len);
206}
207
208
209
210prext(name, leng, init)
211char *name;
212ftnint leng;
213int init;
214{
215if(leng == 0)
216 fprintf(asmfile, "\t.globl\t_%s\n", name);
217else
218 fprintf(asmfile, "\t.comm\t_%s,%ld\n", name, leng);
219}
220
221
222
223
224
225prendproc()
226{
227}
228
229
230
231
232prtail()
233{
234}
235
236
237
238
239
240prolog(ep, argvec)
241struct entrypoint *ep;
242struct addrblock *argvec;
243{
244int i, argslot, proflab;
245int size;
246register chainp p;
247register struct nameblock *q;
248register struct dimblock *dp;
249expptr tp;
250
251if(procclass == CLMAIN)
252 p2pass( "_MAIN__:" );
253if(ep->entryname)
254 p2pass( sprintf(textline, "_%s:", varstr(XL, ep->entryname->extname)) );
255if(procclass == CLBLOCK)
256 return;
257prsave();
258if(argvec)
259 {
260 argloc = argvec->memoffset->const.ci;
261 if(proctype == TYCHAR)
262 {
263 mvarg(TYADDR, 0, chslot);
264 mvarg(TYLENG, SZADDR, chlgslot);
265 argslot = SZADDR + SZLENG;
266 }
267 else if( ISCOMPLEX(proctype) )
268 {
269 mvarg(TYADDR, 0, cxslot);
270 argslot = SZADDR;
271 }
272 else
273 argslot = 0;
274
275 for(p = ep->arglist ; p ; p =p->nextp)
276 {
277 q = p->datap;
278 mvarg(TYADDR, argslot, q->vardesc.varno);
279 argslot += SZADDR;
280 }
281 for(p = ep->arglist ; p ; p = p->nextp)
282 {
283 q = p->datap;
284 if(q->vtype==TYCHAR || q->vclass==CLPROC)
285 {
286 if(q->vleng && q->vleng->tag!=TCONST)
287 mvarg(TYLENG, argslot, q->vleng->vardesc.varno);
288 argslot += SZLENG;
289 }
290 }
291 p2pass( sprintf(textline, "\taddl3\t$%d,fp,ap", argloc-ARGOFFSET) );
292 }
293
294for(p = ep->arglist ; p ; p = p->nextp)
295 {
296 q = p->datap;
297 if(dp = q->vdim)
298 {
299 for(i = 0 ; i < dp->ndim ; ++i)
300 if(dp->dims[i].dimexpr)
301 puteq( fixtype(cpexpr(dp->dims[i].dimsize)),
302 fixtype(cpexpr(dp->dims[i].dimexpr)));
303 size = typesize[ q->vtype ];
304 /* on VAX, get more efficient subscripting if subscripts
305 have zero-base, so fudge the argument pointers for arrays.
306 Not done if array bounds are being checked.
307 */
308 if(dp->basexpr)
309 {
310 puteq( cpexpr(fixtype(dp->baseoffset)),
311 cpexpr(fixtype(dp->basexpr)));
312 if(! checksubs)
313 {
314 putforce(TYINT,
315 fixtype( mkexpr(OPSTAR, ICON(size),
316 cpexpr(dp->baseoffset)) ));
317 p2pass( sprintf(textline, "\tsubl2\tr0,%d(ap)",
318 p->datap->vardesc.varno + ARGOFFSET) );
319 }
320 }
321 else if(!checksubs && dp->baseoffset->const.ci!=0)
322 p2pass( sprintf(textline, "\tsubl2\t$%ld,%d(ap)",
323 dp->baseoffset->const.ci * size,
324 p->datap->vardesc.varno + ARGOFFSET) );
325 }
326 }
327
328if(typeaddr)
329 puteq( cpexpr(typeaddr), mkaddcon(ep->typelabel) );
330putgoto(ep->entrylabel);
331}
332
333
334
335
336prhead(fp)
337FILEP fp;
338{
339#if FAMILY==SCJ
340# if OUTPUT == BINARY
341 p2triple(P2LBRACKET, ARGREG-highregvar, procno);
342 p2word( (long) (BITSPERCHAR*autoleng) );
343 p2flush();
344# else
345 fprintf(fp, "[%02d\t%06ld\t%02d\t\n", procno,
346 BITSPERCHAR*autoleng, ARGREG-highregvar);
347# endif
348#endif
349}
350
351
352
353prdbginfo()
354{
355}